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
80 changes: 66 additions & 14 deletions .zf/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ $DotnetPgoVersion = "11.0.0-preview.6.26310.106"
$DotnetPgoFeed = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/flat2"
$DotnetPgoRuntimeMajor = 11

# The identity of a built assembly, and the publish properties that keep it: publishing a runner rebuilds
# Corvus.Text.Json (a project reference) into the bin/obj the package phase packs from, so a publish must be given the
# version the build gave the library, and must leave the assembly's identity as it was.
function Get-AssemblyIdentity([string] $path) {
$name = [Reflection.AssemblyName]::GetAssemblyName($path)
$info = [Diagnostics.FileVersionInfo]::GetVersionInfo($path)
return [pscustomobject]@{ AssemblyVersion = $name.Version.ToString(); FileVersion = $info.FileVersion; InformationalVersion = $info.ProductVersion }
}

function Get-VersionProperties($identity) {
# The SDK appends "+<commit>" to InformationalVersion itself (SourceLink), so pass it without the suffix.
$versionWithoutMetadata = $identity.InformationalVersion -replace '\+.*$', ''
return @(
"-p:Version=$versionWithoutMetadata",
"-p:AssemblyVersion=$($identity.AssemblyVersion)",
"-p:FileVersion=$($identity.FileVersion)",
"-p:InformationalVersion=$versionWithoutMetadata"
)
}

task GenerateAotProfile -If { $GenerateAotProfile -and $IsLinux } {
$profileDir = Join-Path $here ".zf/aot-profile"
$toolsDir = Join-Path $profileDir "tools"
Expand Down Expand Up @@ -183,23 +203,11 @@ task GenerateAotProfile -If { $GenerateAotProfile -and $IsLinux } {
if (-not (Test-Path $libraryDll)) {
throw "GenerateAotProfile must run after the build: $libraryDll is missing"
}
function Get-AssemblyIdentity([string] $path) {
$name = [Reflection.AssemblyName]::GetAssemblyName($path)
$info = [Diagnostics.FileVersionInfo]::GetVersionInfo($path)
return [pscustomobject]@{ AssemblyVersion = $name.Version.ToString(); FileVersion = $info.FileVersion; InformationalVersion = $info.ProductVersion }
}
$identity = Get-AssemblyIdentity $libraryDll
if ($identity.AssemblyVersion -eq "1.0.0.0") {
throw "The built Corvus.Text.Json.dll has the default assembly version 1.0.0.0; the build did not version it"
}
# The SDK appends "+<commit>" to InformationalVersion itself (SourceLink), so pass it without the suffix.
$versionWithoutMetadata = $identity.InformationalVersion -replace '\+.*$', ''
$versionProperties = @(
"-p:Version=$versionWithoutMetadata",
"-p:AssemblyVersion=$($identity.AssemblyVersion)",
"-p:FileVersion=$($identity.FileVersion)",
"-p:InformationalVersion=$versionWithoutMetadata"
)
$versionProperties = Get-VersionProperties $identity
Write-Host "Publishing the cold runner (framework-dependent) as $($identity.InformationalVersion)"
$runnerDir = Join-Path $profileDir "runner"
exec { & dotnet publish (Join-Path $here "benchmarks/Corvus.Text.Json.RuntimeEvaluator.ColdRunner/Corvus.Text.Json.RuntimeEvaluator.ColdRunner.csproj") -c $Configuration -r linux-x64 --self-contained false -o $runnerDir --nologo -v:minimal @versionProperties }
Expand Down Expand Up @@ -246,14 +254,58 @@ task GenerateAotProfile -If { $GenerateAotProfile -and $IsLinux } {
Write-Host "Profile written to $mibc ($((Get-Item $mibc).Length) bytes, $methods Corvus.Text.Json methods); the package takes it from there"
}

# The profile steers the native AOT compiler's inlining and devirtualisation, and a profile can make it compile
# something wrongly: with the profiles that 5.8.0 to 5.8.5 shipped, it compiled Corvus.Regex.Ecma262's automaton so that
# patterns such as ^[0-9]+(ns|ms|us|µs|s|m|h)$ matched nothing, and the jsonschema-benchmark's native AOT harness
# failed five corpora (the JIT, and native AOT without the profile, were right). So the profile just recorded is checked
# before the package takes it: the cold runner is published with native AOT and the profile, and every instance of
# every corpus must evaluate as valid, as the benchmark requires. It runs where GenerateAotProfile does.
task VerifyAotProfile -If { $GenerateAotProfile -and $IsLinux } {
$profileDir = Join-Path $here ".zf/aot-profile"
$mibc = Join-Path $here "src/Corvus.Text.Json/obj/profiles/Corvus.Text.Json.mibc"
if (-not (Test-Path $mibc)) {
throw "VerifyAotProfile must run after GenerateAotProfile: $mibc is missing"
}

$corpusDir = Join-Path $profileDir "sourcemeta"
New-Item -ItemType Directory -Path $corpusDir -Force | Out-Null
Get-ChildItem (Join-Path $here "benchmarks") -Directory -Filter "Corvus.Text.Json.*BenchmarkModels" | ForEach-Object {
Get-ChildItem $_.FullName -File | Where-Object { $_.Name -like "*-instances.jsonl" -or $_.Name -like "*-schema.json" } | Copy-Item -Destination $corpusDir -Force
}
$corpora = @(Get-ChildItem $corpusDir -Filter "*-instances.jsonl" | ForEach-Object { $_.Name -replace "-instances\.jsonl$", "" } | Sort-Object)
if ($corpora.Count -lt 30) {
throw "VerifyAotProfile found $($corpora.Count) corpora under benchmarks, not the 37 the benchmark runs"
}

$libraryDll = Join-Path $here "src/Corvus.Text.Json/bin/$Configuration/net10.0/Corvus.Text.Json.dll"
$identity = Get-AssemblyIdentity $libraryDll
$versionProperties = Get-VersionProperties $identity
Write-Host "Publishing the cold runner with native AOT and the profile, as $($identity.InformationalVersion)"
$runnerDir = Join-Path $profileDir "aot-runner"
exec { & dotnet publish (Join-Path $here "benchmarks/Corvus.Text.Json.RuntimeEvaluator.ColdRunner/Corvus.Text.Json.RuntimeEvaluator.ColdRunner.csproj") -c $Configuration -r linux-x64 -p:ColdAot=true "-p:ColdMibc=$mibc" -o $runnerDir --nologo -v:minimal @versionProperties }
$after = Get-AssemblyIdentity $libraryDll
if (($after.AssemblyVersion -ne $identity.AssemblyVersion) -or ($after.FileVersion -ne $identity.FileVersion) -or ($after.InformationalVersion -ne $identity.InformationalVersion)) {
throw "Publishing the native AOT runner changed Corvus.Text.Json.dll from $($identity.InformationalVersion) ($($identity.AssemblyVersion)) to $($after.InformationalVersion) ($($after.AssemblyVersion))"
}

Write-Host "Evaluating every instance of $($corpora.Count) corpora with the native AOT runner"
$env:COLD_ROOT = $corpusDir
try {
exec { & (Join-Path $runnerDir "Corvus.Text.Json.RuntimeEvaluator.ColdRunner") verify @corpora }
}
finally {
Remove-Item Env:\COLD_ROOT -ErrorAction SilentlyContinue
}
}

# The generated-code analyzer configuration (analyzers/generated-code.globalconfig and the generated region of
# .editorconfig) is derived from the analyzers in use; a stale copy would let an analyzer run on generated code unnoticed.
# It needs the restored solution, so it runs after the build.
task CheckGeneratedCodeAnalyzerConfig {
Write-Host "Checking the generated-code analyzer configuration is up to date"
exec { & pwsh -File (Join-Path $here "update-generated-code-analyzer-config.ps1") -Check }
}
task PostBuild CheckGeneratedCodeAnalyzerConfig, GenerateAotProfile, BuildWebSiteLocal
task PostBuild CheckGeneratedCodeAnalyzerConfig, GenerateAotProfile, VerifyAotProfile, BuildWebSiteLocal
# Synopsis: Restore the solution before packaging. In CI the Package job does not build, so nothing restores on its
# runner, and 'dotnet pack --no-build --no-restore' still resolves each project's framework references. Where the
# runner's .NET install lacks a targeting pack that the Compile job's runner had, pack fails with NETSDK1127 (as it did
Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing" Version="1.1.3" />
<!-- BCL / runtime polyfills -->
<PackageVersion Include="IndexRange" Version="1.1.1" />
<PackageVersion Include="Corvus.Regex.Ecma262" Version="1.0.12" />
<PackageVersion Include="Corvus.Regex.Ecma262.CodeGeneration.Sources" Version="1.0.12" />
<PackageVersion Include="Corvus.Regex.Ecma262" Version="1.0.15" />
<PackageVersion Include="Corvus.Regex.Ecma262.CodeGeneration.Sources" Version="1.0.15" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="10.0.7" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.Bcl.Memory" Version="10.0.7" />
Expand Down
12 changes: 12 additions & 0 deletions VERSIONHISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Version History

## V5.8.8

V5.8.8 fixes wrong answers from `pattern` in an application published with native AOT.

### Bug fixes

- **A `pattern` gives the right answer under native AOT.** The package hands the AOT compiler a static profile (`profiles/Corvus.Text.Json.mibc`), and with the profiles that V5.8.0 to V5.8.5 shipped, the compiler compiled the automaton of Corvus.Regex.Ecma262 wrongly: patterns that it answers, such as `^[0-9]+(ns|ms|us|µs|s|m|h)$` and `^(0|[1-9]\d*)\.(0|[1-9]\d*)$`, matched nothing, so valid values were refused. The JIT, and native AOT without the profile, were right. Corvus.Regex.Ecma262 1.0.15 removes the interface call the compiler devirtualised wrongly. V5.8.7's profile happened not to trigger it, but each build records a different profile, so V5.8.0 to V5.8.7 are all affected in principle. An application that cannot move can publish with `-p:CorvusTextJsonUseProfile=false`.

### Other changes

- **Every build checks its profile under native AOT.** After the build records the profile, it publishes the cold runner with native AOT and that profile, and every instance of the 37 jsonschema-benchmark corpora must evaluate as valid, or the build fails. [docs/ReleaseProcess.md](docs/ReleaseProcess.md) describes it.

## V5.8.7

V5.8.7 publishes V5.8.6 to NuGet.org. V5.8.6 was tagged, and has a GitHub release, but its packages were never published to NuGet.org: nuget.org refused the release build's Trusted Publishing token, so the version is skipped there. V5.8.7 has no changes of its own beyond how it is published, so it ships everything in V5.8.6, which is listed below.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

<!-- The cold run (ColdRun.cs) and the warm per-evaluation measurement (BlazeBasis.cs) of a corpus, publishable as
native AOT or ReadyToRun for a like-for-like comparison with the Blaze CLI:
dotnet publish -c Release -r linux-x64 -p:ColdAot=true. `warm <loops> <corpus...>`, `<corpus> [image]`, or
`protocol <corpus>` (the jsonschema-benchmark protocol, for comparison with the other engines' harnesses). -->
dotnet publish -c Release -r linux-x64 -p:ColdAot=true. `warm <loops> <corpus...>`, `<corpus> [image]`,
`verify <corpus...>` (every instance must be valid), or `protocol <corpus>` (the jsonschema-benchmark protocol,
for comparison with the other engines' harnesses). -->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
}
#endif

if (args.Length > 1 && args[0] == "verify")
{
return Verify.Run(args[1..]);
}

if (args.Length > 1 && args[0] == "tiertrace")
{
return Corvus.Text.Json.RuntimeEvaluator.Benchmarks.SourceMeta.ProtocolRun.RunTierTrace(args[1..]);
Expand Down
61 changes: 61 additions & 0 deletions benchmarks/Corvus.Text.Json.RuntimeEvaluator.ColdRunner/Verify.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// <copyright file="Verify.cs" company="Endjin Limited">
// Copyright (c) Endjin Limited. All rights reserved.
// </copyright>

using Corvus.Text.Json;
using Corvus.Text.Json.RuntimeEvaluator;
using Corvus.Text.Json.RuntimeEvaluator.Benchmarks.SourceMeta;

/// <summary>
/// Checks that every instance of each corpus is valid against its schema (<c>verify &lt;corpus...&gt;</c>), as the
/// jsonschema-benchmark requires: every instance in its corpora is valid, and <c>format</c> is not asserted. The build
/// publishes the runner with native AOT and the package's freshly recorded profile and runs this, so that a profile
/// that makes the AOT compiler compile something wrongly fails the build instead of shipping.
/// </summary>
internal static class Verify
{
/// <summary>Evaluates every instance of each corpus named, and reports the ones that are not valid.</summary>
/// <param name="corpora">The corpora, by name (<c>&lt;name&gt;-schema.json</c> and <c>&lt;name&gt;-instances.jsonl</c> under
/// <c>COLD_ROOT</c>).</param>
/// <returns>0 when every instance is valid, otherwise 1.</returns>
public static int Run(string[] corpora)
{
string root = Environment.GetEnvironmentVariable("COLD_ROOT") ?? Path.Combine(AppContext.BaseDirectory, "sourcemeta");
int instances = 0;
int wrong = 0;
foreach (string corpus in corpora)
{
JsonSchemaDialect dialect = JsonSchemaDialect.Draft7;
foreach ((string file, JsonSchemaDialect d) in SourceMetaCases.All)
{
if (file == corpus)
{
dialect = d;
}
}

byte[] schema = File.ReadAllBytes(Path.Combine(root, corpus + "-schema.json"));
string[] lines = [.. File.ReadAllLines(Path.Combine(root, corpus + "-instances.jsonl")).Where(l => l.Length > 0)];
using JsonSchemaEvaluator evaluator = JsonSchemaEvaluator.Compile(schema, new JsonSchemaEvaluatorOptions { DefaultDialect = dialect, AssertFormat = false });
var invalid = new List<int>();
for (int i = 0; i < lines.Length; i++)
{
using var document = ParsedJsonDocument<JsonElement>.Parse(System.Text.Encoding.UTF8.GetBytes(lines[i]));
if (!evaluator.Evaluate(document.RootElement))
{
invalid.Add(i);
}
}

instances += lines.Length;
wrong += invalid.Count;
if (invalid.Count > 0)
{
Console.Error.WriteLine($"{corpus}: {invalid.Count} of {lines.Length} valid instances evaluated as not valid (the first: {string.Join(", ", invalid.Take(10))})");
}
}

Console.WriteLine($"{instances - wrong} of {instances} instances of {corpora.Length} corpora are valid");
return wrong == 0 ? 0 : 1;
}
}
11 changes: 10 additions & 1 deletion docs/ReleaseProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,16 @@ an application"). It is recorded from the code being packaged by the build's `Ge
methods stay instrumented, `ReadyToRun=0`, the runtime provider at keyword 0x1E000080018 level 5);
3. `create-mibc` into `src/Corvus.Text.Json/obj/profiles/Corvus.Text.Json.mibc`, which `Corvus.Text.Json.csproj`
packs in preference to the checked-in file when it exists (`obj` travels between the pipeline's phases in the
build cache), and fails the build if the result is small or names fewer than 1,000 of the library's methods.
build cache), and fails the build if the result is small or names fewer than 1,000 of the library's methods;
4. then the `VerifyAotProfile` task publishes the cold runner with native AOT and that profile (with the same identity
check) and runs `verify` over every corpus: each instance must evaluate as valid, as the jsonschema-benchmark
requires, or the build fails.

The profile steers the AOT compiler's inlining and devirtualisation, and a profile can make it compile something
wrongly. With the profiles that 5.8.0 to 5.8.5 shipped, it compiled Corvus.Regex.Ecma262's automaton (before 1.0.15) so
that patterns such as `^[0-9]+(ns|ms|us|µs|s|m|h)$` matched nothing, and the benchmark's native AOT harness failed five
corpora, while the JIT and native AOT without the profile were right. Each build records a different profile, so a
release that passed proves nothing about the next: the check runs on every build.

The checked-in `src/Corvus.Text.Json/profiles/Corvus.Text.Json.mibc` is the fallback for local packs and is refreshed
when the evaluator changes: `BUILDVAR_GenerateAotProfile=true ./build.ps1 -Tasks GenerateAotProfile`, then copy the
Expand Down
8 changes: 4 additions & 4 deletions docs/code-sample-catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1502,10 +1502,10 @@ main-docs:
blocks:
- {index: 0, language: yaml, lines: [18, 36]}
- {index: 1, language: powershell, lines: [143, 151]}
- {index: 2, language: bash, lines: [218, 223]}
- {index: 3, language: sh, lines: [629, 631]}
- {index: 4, language: xml, lines: [764, 768]}
- {index: 5, language: xml, lines: [772, 774]}
- {index: 2, language: bash, lines: [227, 232]}
- {index: 3, language: sh, lines: [638, 640]}
- {index: 4, language: xml, lines: [773, 777]}
- {index: 5, language: xml, lines: [781, 783]}
- path: "docs/RunningTests.md"
blocks:
- {index: 0, language: powershell, lines: [7, 10]}
Expand Down
8 changes: 4 additions & 4 deletions src-v4/Corvus.Json.Benchmarking/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
"type": "Project",
"dependencies": {
"Corvus.Json.JsonReference": "[1.0.0, )",
"Corvus.Regex.Ecma262": "[1.0.12, )",
"Corvus.Regex.Ecma262": "[1.0.15, )",
"Corvus.UriTemplates": "[2.3.2, )",
"NodaTime": "[3.3.1, )"
}
Expand Down Expand Up @@ -487,9 +487,9 @@
},
"Corvus.Regex.Ecma262": {
"type": "CentralTransitive",
"requested": "[1.0.12, )",
"resolved": "1.0.12",
"contentHash": "0ErVXFzGlUEgEVvk//BZqf0hbsM+zGo0utwyEqc9hc5eub886A6Qudn3M29BoLsFEdOVHo3HSEbJkA4zuvIhVQ=="
"requested": "[1.0.15, )",
"resolved": "1.0.15",
"contentHash": "wDC21MqsPI9L8PBs3dst8kebfY0rxE9KFiacCuk2Zwju6q3+DO49JFnQ61SwBBJgVUh2xSx2L6NQ4C6LXL6Vrg=="
},
"Corvus.UriTemplates": {
"type": "CentralTransitive",
Expand Down
16 changes: 8 additions & 8 deletions src-v4/Corvus.JsonPatch.Benchmarking/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@
"type": "Project",
"dependencies": {
"Corvus.Json.JsonReference": "[1.0.0, )",
"Corvus.Regex.Ecma262": "[1.0.12, )",
"Corvus.Regex.Ecma262": "[1.0.15, )",
"Corvus.UriTemplates": "[2.3.2, )",
"Microsoft.Bcl.Memory": "[10.0.7, )",
"NodaTime": "[3.3.1, )",
Expand Down Expand Up @@ -518,9 +518,9 @@
},
"Corvus.Regex.Ecma262": {
"type": "CentralTransitive",
"requested": "[1.0.12, )",
"resolved": "1.0.12",
"contentHash": "0ErVXFzGlUEgEVvk//BZqf0hbsM+zGo0utwyEqc9hc5eub886A6Qudn3M29BoLsFEdOVHo3HSEbJkA4zuvIhVQ==",
"requested": "[1.0.15, )",
"resolved": "1.0.15",
"contentHash": "wDC21MqsPI9L8PBs3dst8kebfY0rxE9KFiacCuk2Zwju6q3+DO49JFnQ61SwBBJgVUh2xSx2L6NQ4C6LXL6Vrg==",
"dependencies": {
"System.Memory": "4.6.3"
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@
"type": "Project",
"dependencies": {
"Corvus.Json.JsonReference": "[1.0.0, )",
"Corvus.Regex.Ecma262": "[1.0.12, )",
"Corvus.Regex.Ecma262": "[1.0.15, )",
"Corvus.UriTemplates": "[2.3.2, )",
"NodaTime": "[3.3.1, )"
}
Expand Down Expand Up @@ -1105,9 +1105,9 @@
},
"Corvus.Regex.Ecma262": {
"type": "CentralTransitive",
"requested": "[1.0.12, )",
"resolved": "1.0.12",
"contentHash": "0ErVXFzGlUEgEVvk//BZqf0hbsM+zGo0utwyEqc9hc5eub886A6Qudn3M29BoLsFEdOVHo3HSEbJkA4zuvIhVQ=="
"requested": "[1.0.15, )",
"resolved": "1.0.15",
"contentHash": "wDC21MqsPI9L8PBs3dst8kebfY0rxE9KFiacCuk2Zwju6q3+DO49JFnQ61SwBBJgVUh2xSx2L6NQ4C6LXL6Vrg=="
},
"Corvus.UriTemplates": {
"type": "CentralTransitive",
Expand Down
Loading
Loading