Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src-jl/CorvusJsonSchema/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CorvusJsonSchema"
uuid = "7b662be2-3602-4bf9-b859-13b2e88448f1"
authors = ["Endjin Limited"]
version = "0.1.1"
version = "0.1.2"

[compat]
julia = "1.10"
Expand Down
8 changes: 8 additions & 0 deletions src-jl/CorvusJsonSchema/VERSIONHISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

The version history of `CorvusJsonSchema`, the Julia port of the Corvus.Text.Json V5 runtime evaluator. It is versioned independently of the Corvus NuGet packages, whose history is in the repository's [VERSIONHISTORY.md](../../VERSIONHISTORY.md).

## V0.1.2

V0.1.2 fixes the installation of the package on a slow machine. There are no API changes. Version 0.1.1 is affected, and 0.1.0 is not.

### Bug fixes

- **Precompilation on a slow machine.** Julia runs a workload while it writes the package's image, so that a process starts with the code compiled, and an error in it fails the installation. The workload of 0.1.1 sets a limit of 10 ms on a match, and expects two of its matches to answer within it: one against a string of a few characters, and the search of a string of 20,000 characters. Where they take longer, such as in a build of an image for another processor under emulation, the match reached its limit, the `PatternMatchError` was not caught, and `Pkg.add` or `Pkg.precompile` failed with "The following 1 package failed to precompile". Each timed match of the workload now ends at the limit without an error. No answer of the package changes.

## V0.1.1

V0.1.1 gives patterns the answers of ECMA-262 on every file of the [ECMA-262 regular expression test data](https://github.com/corvus-dotnet/ecma262-regex-test-data), bounds what a pattern and a format can cost, and carries the notice of the Unicode data its tables are derived from. The functions that were there are unchanged. There is one new option and there are two new errors. Version 0.1.0 is affected by the bugs.
Expand Down
26 changes: 15 additions & 11 deletions src-jl/CorvusJsonSchema/src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The workload runs only during precompilation. It leaves nothing behind but compiled code: the caches it filled
# are emptied, since a compiled pattern of the engine holds memory of the process that made it.

function precompile_workload()
function precompile_workload(; pattern_match_limit::Float64=0.01)
large = join(["\"p$i\": $i" for i in 0:79], ",")
cases = Tuple{String,NamedTuple,Vector{String}}[
("""{
Expand Down Expand Up @@ -188,17 +188,21 @@ function precompile_workload()
end
isvalid(engine, "[1, 2")
# A match that uses the steps it starts with, one that is timed and given up at its limit, the search of a long
# string in parts, and a pattern over a limit of size.
# string in parts, and a pattern over a limit of size. Each is timed, and whether one answers within the limit
# depends on the machine (under emulation the search of the long string takes longer than 10 ms), so each may end
# at the limit: an error here would fail the installation of the package.
slow = compile_schema("""{"pattern": "^(?:a|a)+\$", "patternProperties": {"fo+|ba+r": true}}""";
pattern_match_limit=0.01)
isvalid(slow, "\"" * "a"^12 * "b\"")
try
isvalid(slow, "\"" * "a"^40 * "b\"")
catch err
err isa PatternMatchError || rethrow()
sprint(showerror, err)
end
isvalid(slow, "{\"" * "x"^20_000 * "\": 1}")
pattern_match_limit)
timed(f) =
try
f()
catch err
err isa PatternMatchError || rethrow()
sprint(showerror, err)
end
timed(() -> isvalid(slow, "\"" * "a"^12 * "b\""))
timed(() -> isvalid(slow, "\"" * "a"^40 * "b\""))
timed(() -> isvalid(slow, "{\"" * "x"^20_000 * "\": 1}"))
try
compile_schema("{\"pattern\": \"" * "("^300 * "\"}")
catch err
Expand Down
11 changes: 11 additions & 0 deletions src-jl/CorvusJsonSchema/test/precompile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# The precompile workload runs while a package image is written, on whatever machine installs the package, and an
# error in it fails the installation. Its timed matches must not depend on how fast that machine is: 0.1.1 failed to
# precompile under emulation, where a match it expected to answer reached the workload's limit of 10 ms.

@testset "the precompile workload does not depend on the speed of the machine" begin
# A limit that every timed match of the workload reaches at its first reading of the clock.
@test CorvusJsonSchema.precompile_workload(pattern_match_limit=1e-9) === nothing
@test CorvusJsonSchema.precompile_workload() === nothing
# The workload leaves the package as it found it.
@test isvalid(compile_schema("""{"patternProperties": {"fo+|ba+r": {"type": "integer"}}}"""), """{"foo": 1}""")
end
1 change: 1 addition & 0 deletions src-jl/CorvusJsonSchema/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ include("allocations.jl")
include("stability.jl")
include("differential.jl")
include("docs.jl")
include("precompile.jl")
include("ecmaregex/runtests.jl")
Loading