Make wasm 'V' signature raising deterministic and add a regression test - #131429
Merged
tannergooding merged 1 commit intoJul 27, 2026
Merged
Conversation
RaiseSignature resolved 'V' to whichever v128 type lowering happened to see first, cached racily from parallel compilation. 'V' is fully determined by the ABI, so resolve a fixed Vector128<byte> instead, and move the 16-byte alignment assert into IsWasmV128Type so it covers every v128 type rather than just the first one cached. The test also covers the Vector<T> alignment fix from dotnet#131328; issue dotnet#131339 proposed testing Vector128<T>, which was never under-aligned. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes wasm signature raising for the 'V' (v128) encoding deterministic by resolving it to a fixed canonical type (Vector128<byte>) rather than relying on whichever v128 type happened to be cached first during lowering. It also adds targeted regression tests in ILCompiler.ReadyToRun.Tests to validate v128 alignment and argument layout invariants for the wasm ABI, and refactors test infrastructure to share a consistent System.Private.CoreLib.dll resolution path.
Changes:
- Make
RaiseSignaturemap'V'toCompilerTypeSystemContext.WasmV128Type(canonicalVector128<byte>) and move the 16-byte alignment invariant assertion intoIsWasmV128Type. - Add
WasmArgumentLayoutTestscovering v128 type alignment, argument offsets, non-v128 SIMD widths, and raising independence from lowering order. - Hoist
System.Private.CoreLib.dllpath resolution intoTestPaths.SystemPrivateCoreLibPathand reuse it fromR2RTestRunnerand the new tests.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/Common/JitInterface/WasmLowering.cs | Removes order-dependent v128 caching during lowering, asserts v128 alignment via IsWasmV128Type, and raises 'V' via a canonical type. |
| src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Wasm.cs | Replaces the “first-seen” v128 cache with a lazy canonical Vector128<byte> (WasmV128Type). |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj | Adds InternalsVisibleTo to allow the test project to access internal crossgen2 APIs. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/ILCompiler.ReadyToRun.Tests.csproj | Adds an aliased reference to ILCompiler.ReadyToRun for internal API access without namespace/type collisions. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/WasmArgumentLayoutTests.cs | New regression tests validating wasm v128 alignment and argument layout behavior, including raising determinism. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCasesRunner/TestPaths.cs | Adds SystemPrivateCoreLibPath with runtime-pack → CoreCLR-artifacts fallback. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCasesRunner/R2RTestRunner.cs | Switches SPCL resolution to the shared TestPaths.SystemPrivateCoreLibPath. |
Copilot's findings
- Files reviewed: 7/7 changed files
- Comments generated: 0
lewing
approved these changes
Jul 27, 2026
davidwrighton
approved these changes
Jul 27, 2026
davidwrighton
left a comment
Member
There was a problem hiding this comment.
I like the compiler changes, but please get Jackson to take a look at the test changes.
adamperlin
approved these changes
Jul 27, 2026
jtschuster
approved these changes
Jul 27, 2026
tannergooding
enabled auto-merge (squash)
July 27, 2026 19:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #131339 -- though not in the way the issue proposed; see the note at the bottom.
RaiseSignatureresolved the'V'(v128) signature char toCompilerTypeSystemContext.CachedV128Type, i.e. literally whichever v128 type lowering happened to encounter first, written racily from parallel compilation.'V'is fully determined by the wasm ABI (16 bytes, 16-byte aligned), so raising now resolves a fixed canonicalVector128<byte>instead. Any v128 type round-trips'V'identically, soRaiseSignature's own round-trip assert still holds, and the raised signature no longer depends on compilation order.The 16-byte alignment
Debug.Assertthat guarded this invariant moved fromCacheV128TypeintoIsWasmV128Type.CacheV128Typeonly ever saw the first cached type, where-asIsWasmV128Typehas three call sites and so covers every v128 type.This also drops the
?? throw new InvalidOperationException(...)on the'V'path -- that failure mode is simply gone, since raising no longer needs lowering to have run first.ILCompiler.ReadyToRun.TestsgainsWasmArgumentLayoutTests: 20 cases driving crossgen2's type system andGCRefMapBuilder.BuildArgIteratordirectly, so they need neither a wasm JIT nor a runtime to execute against.WasmV128TypesAre16ByteAligned-- 12 cases overVector128<T>/Vector<T>x 6 element types.WasmV128ArgumentsStartOn16ByteBoundaries--static void M(long, TVector, ref int)must lay out as[0, 16, 32].OtherSimdWidthsAreNotV128--Vector64/256/512<T>must fall back to the generic struct ABI.RaisingV128SignatureIsIndependentOfLoweringOrder-- lowers a different vector type first, then asserts the raised'V'is unchanged and that its offsets match the original signature's.These also cover the
Vector<T>alignment fix from #131328, and I verified they bite: with that fix reverted, 7 cases fail -- the sixVector<T>alignment cases report 8 instead of 16, andWasmV128ArgumentsStartOn16ByteBoundariesforVector<T>reports[0, 8, 24]instead of[0, 16, 32].On #131339 itself. The issue asks for a test asserting
Vector128<T>is 16-byte aligned, on the premise that this is what #131328 fixed. That is not correct --Vector128<T>gets alignment 16 fromVectorFieldLayoutAlgorithmon every architecture except ARM and was untouched by that fix. I confirmed empirically that the proposed test passes unchanged against a compiler with #131328 reverted, so it would have been a no-op. The actual regression wasSystem.Numerics.Vector<T>, which kept the 8-byte alignment from its metadata layout. The tests here cover both.The issue also says the test was deferred for lack of a CI-runnable home. That premise is stale: #130866 added the
WasmSimdModulewasm crossgen2 suite toILCompiler.ReadyToRun.Teststhree days before the issue was filed, and that is where these tests live.Also hoisted the
System.Private.CoreLib.dllresolution out ofR2RTestRunnerintoTestPaths.SystemPrivateCoreLibPathso the new tests share the existing runtime-pack to CoreCLR-artifacts fallback. Without it they would hard-fail in partial builds that skiplibs.pretest, e.g. a bareclr.toolstests.Out of scope, to be filed separately:
CacheStructBySize/GetCachedStructOfSizehas the same first-wins-cache shape for the'S<N>'encoding, and there it is a live miscompile rather than a latent hazard.GuidandInt128are both 16 bytes and both encodeS16, but their clamped alignments are 8 and 16, so the shared thunk signaturevlS16ipgets two different frame layouts. Fixing that means changing the on-disk encoding across crossgen2,src/coreclr/vm/wasm/helpers.cpp,WasmAppBuilder, and the R2R format doc, so it does not belong here.Local test run:
ILCompiler.ReadyToRun.Testsis 58 total / 1 failed. The failure isCompositeManifestAssemblyMvidsArePaddedWhenPdbPresent, anArgumentNullExceptionout of the native PDB COM writer in my Debug layout. Confirmed pre-existing -- it reproduces identically with this branch's changes stashed.CC. @lewing @adamperlin -- ready for review.
Note
This PR description was drafted by Copilot.