Skip to content

test: detect runtime accessor and IL generator contract changes - #567

Open
jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:test/runtime-accessor-contracts-560
Open

jogibear9988 wants to merge 1 commit into
dadhi:masterfrom
jogibear9988:test/runtime-accessor-contracts-560

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Detect runtime-internal changes before optimizations silently disappear

Related to #560. Add strict CoreCLR runtime-contract tests on current master (734314ed), without changing production compilation or introducing a generator dependency.

  • On .NET 10, inspect all six production UnsafeAccessor declarations against the executing runtime: exact owner, member name, instance/static shape, field/byref type, method parameters and return type.
  • Bind the actual production accessor methods (not copied test stubs), and use all six to construct and execute a DynamicMethod with a local and a method token. This checks runtime binding and behavior in addition to metadata.
  • On .NET 8/10, require the local-allocation and generator-reuse optimizations to be present. Reuse one generator after emitting locals, a method call and try/finally; change its signature/local type and verify both delegates still execute correctly. Require actual reuse so a silent fallback also fails the test.
  • Exercise Standard and LightExpression before the existing suites. Explicitly propagate TestX assertion failures as a nonzero process exit. Existing Windows/Linux CI already runs this runner on .NET 8/10; no extra workflow is necessary.
  • Add --runtime-accessor-contracts for isolated execution. Document the scope and Explore internal accessor with compile checks https://github.com/aelij/IgnoresAccessChecksToGenerator #560 investigation in test/RuntimeAccessorContracts.md.

These validate the executing runtime, not merely the SDK references. Framework 4.7.2 has a different implementation and is excluded from this fixture. An intentional change to the accessor contract should update the tests too.

Validation

Windows ARM64, SDK 10.0.301:

  • Release .NET 8/10 runner build: passed, zero warnings/errors.
  • Isolated .NET 10.0.9: 3 tests per API, 6 passed.
  • Isolated .NET 8.0.28: 1 test per API, 2 passed.
  • Negative probe: deliberately disable ReuseDynamicILGenerator in a separate process. The test reports the unavailable helper and missing reuse; the isolated runner exits nonzero as intended.
  • Framework 4.7.2 runner build: passed, zero warnings/errors.
  • Full suites are not green on this ARM64 host: .NET 10 has the LightExpression nullable MultiplyChecked mismatch in LightExpressionTests; .NET 8 crashes in Issue346 by-ref float post-increment. Both reproduce by invoking the unchanged RunAllTests entry point in a fresh process without running the new fixture. They are not fixed or skipped here.

Reproduce the isolated checks:

dotnet run -c Release -f net10.0 --project test/FastExpressionCompiler.TestsRunner -- --runtime-accessor-contracts
dotnet run -c Release -f net8.0 --project test/FastExpressionCompiler.TestsRunner -- --runtime-accessor-contracts

Findings behind #560

The stock IgnoresAccessChecksToGenerator publicizes internal members, leaving private ones inaccessible. It could be extended to publicize private members/nested types in build-time references. However, framework reference assemblies omit the relevant runtime types; the stock 0.8.0 package also fails when publicizing our installed .NET 10 CoreLib implementation with Writing mixed-mode assemblies is not supported. An implementation-derived metadata-only facade is a possible further investigation; replacing the installed runtime is unnecessary.

Direct typed reuse helpers might reduce initialization work or delegate dispatch. Replacing existing UnsafeAccessor field access is not an established speedup. Those are separate experiments requiring compilation/startup/allocation measurements; this PR makes no performance claim and changes no emitted application IL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant