Add support for encoding Continuation types with specific layouts in ReadyToRun#123643
Merged
jtschuster merged 36 commits intodotnet:mainfrom Feb 6, 2026
Merged
Add support for encoding Continuation types with specific layouts in ReadyToRun#123643jtschuster merged 36 commits intodotnet:mainfrom
jtschuster merged 36 commits intodotnet:mainfrom
Conversation
…kReturningThunks
The generated IL thunk does not have valid tokens, so the tokens emitted in the EH handler info are invalid. It's not an invariant that there is always a reference to System.Exception or System.Object in the assembly that we are generating thunks for, so we can't always get a valid Token for the exception type token field. Instead, we can create a filter that does a type check against System.Exception. The reference to System.Exception will be filled in with a Fixup with a module override if we don't have a reference to System.Exception in the assembly.
…kReturningThunks
With these changes, we no longer need separate IL for nativeaot and readytorun
* Rework async thunks generation to cross module generics infra - Add ability for code generating an ILStub to mark that the tokens might be generated - Funnel through various details to ensure that we trigger creation of the ManifestModuleWrappedMethodIL as needed - Adjust method fixup signature generation to allow for VersionsWithMethodBody code which is in the MutableModule - Add a few todos about work we might do to allow cross module compilation of runtime async code. - Disable this for now though, since its much to complex to test without a working end-to-end scenario (See code in CrossModuleInlineableUncached * Revert logic which attempts to treat System.Exception in EH clause specially
…foImpl.ReadyToRun.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
…kReturningThunks
- Clear ClassTokenOrOffset when setting R2R_SYSTEM_EXCEPTION flag - Add COR_ILEXCEPTION_CLAUSE_R2R_SYSTEM_EXCEPTION to R2R dumper
Encode Continuation types in R2R images using a new fixup kind (READYTORUN_FIXUP_Continuation_Layout = 0x37): - Include OwningMethod to associate the Continuation type with the correct loader allocator at runtime - Encode the GC ref map as a bit vector expanded to a byte array - Add AsyncContinuationLayoutAlgorithm for field layout computation Add runtime support to read continuation type fixups from R2R images: - GetContinuationTypeFromLayout decodes the blob and creates the type - LoadDynamicInfoEntry handles the new fixup kind Also adds helper constants for future continuation allocation helpers. Note: These code paths are not yet exercised as async2 methods are not currently compiled to ReadyToRun images.
…g unneeded method parameters and simplifying type resolution logic.
jkotas
reviewed
Jan 27, 2026
...tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeFixupSignature.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/CompilerTypeSystemContext.ReadyToRun.cs
Outdated
Show resolved
Hide resolved
jakobbotsch
reviewed
Jan 28, 2026
src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Async.cs
Outdated
Show resolved
Hide resolved
Make getContinuationType static Move _validType.TryAdd to CreateValueFromKey Remove unnecessary using
src/coreclr/tools/Common/Internal/Runtime/ReadyToRunConstants.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs
Outdated
Show resolved
Hide resolved
This was referenced Feb 4, 2026
davidwrighton
approved these changes
Feb 4, 2026
Member
davidwrighton
left a comment
There was a problem hiding this comment.
Other than the bits of PR #123975 to remove from this change, I think this is good.
...tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeFixupSignature.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs
Outdated
Show resolved
Hide resolved
lewing
pushed a commit
to lewing/runtime
that referenced
this pull request
Feb 9, 2026
…ReadyToRun (dotnet#123643) Enable encoding and decoding of async continuation type layouts in ReadyToRun images, allowing the R2R compiler to emit continuation types that were previously only supported at JIT time. ## Crossgen2 (compile-time) changes - **New fixup kind `ContinuationLayout = 0x37`**: Added to `ReadyToRunFixupKind` in both native (`readytorun.h`) and managed (`ReadyToRunConstants.cs`) headers to represent the layout of an async method continuation type. - **Remove `NotImplementedException` for `getContinuationType` in R2R**: The `#if READYTORUN` guard that blocked `getContinuationType` is removed from `CorInfoImpl.cs`, enabling continuation type creation during R2R compilation. - **Initialize `_continuationTypeHashtable` in R2R compiler context**: The hashtable is now constructed in the `CompilerTypeSystemContext` R2R partial constructor so continuation types can be created and cached. - **Short-circuit loadability checks for continuation types**: Newly created `AsyncContinuationType` instances are added to `_validTypes` in the `ContinuationTypeHashtable` to bypass loadability verification, since these types are always valid by construction. - **Intercept `AsyncContinuationType` in `embedClassHandle`**: In `CorInfoImpl.ReadyToRun.cs`, when embedding a class handle for an `AsyncContinuationType`, emit a `PrecodeHelperImport` with the new `ContinuationLayout` fixup instead of attempting the normal type handle encoding path. - **`ContinuationTypeSymbol` and `NodeCache` in `ReadyToRunSymbolNodeFactory`**: Adds a node cache and public accessor to create `PrecodeHelperImport` nodes for continuation type fixups. - **Guard against encoding continuations on the normal type signature path**: `SignatureBuilder.EmitTypeSignature` now throws `InvalidOperationException` if it encounters an `AsyncContinuationType`, since these must go through the dedicated `ContinuationLayout` fixup path. - **`EncodeContinuationTypeLayout` in `TypeFixupSignature`**: Encodes the continuation's GC pointer map as a bit vector packed into a byte array, along with size and alignment flags. The `ContinuationLayout` fixup emits the base `Continuation` EcmaType followed by this layout blob. ## Runtime (load-time) changes - **`GetContinuationTypeFromLayout` in `jitinterface.cpp`**: Decodes the continuation layout blob from the R2R image — reads flags, size, and GC ref map bitmap — expands the bitmap back to a `bool` array, and calls into the continuation type creation infrastructure. - **`LoadDynamicInfoEntry` handles `READYTORUN_FIXUP_Continuation_Layout`**: Calls `GetContinuationTypeFromLayout` to materialize the continuation `MethodTable` at runtime when the fixup is resolved. - **Refactor `LookupOrCreateContinuationMethodTable` to accept `Module*` instead of `MethodDesc*`**: The `MethodDesc*`-taking overload of `CreateNewContinuationMethodTable` is removed and its debug naming logic is inlined into `LookupOrCreateContinuationMethodTable`, which now takes a `Module* loaderModule` directly. This enables creation of continuation types from R2R fixup decoding where no `MethodDesc` is available. A corresponding static `getContinuationType` helper is extracted from `CEEInfo::getContinuationType` for reuse by `GetContinuationTypeFromLayout`. ## Diagnostic / tooling changes - **`ReadyToRunSignature.cs` refactoring**: The inline type layout parsing logic for `Check_TypeLayout`/`Verify_TypeLayout` is extracted into a shared `ParseTypeLayout` method, which is also reused for the new `ContinuationLayout` fixup kind. Adds display of `" Align native"` and `" GCLayout 0x00 (Empty)"` for improved diagnostic output. > **Note:** These code paths are not yet exercised end-to-end, as async2 methods are not currently compiled into ReadyToRun images. Co-authored-by: David Wrighton <davidwr@microsoft.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com>
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.
Encode Continuation types in R2R images using a new fixup kind (READYTORUN_FIXUP_Continuation_Layout = 0x37):
Encode the GC ref map as a bit vector expanded to a byte array
Add runtime support to read continuation type fixups from R2R images:
GetContinuationTypeFromLayout decodes the blob and creates the type
LoadDynamicInfoEntry handles the new fixup kind
Note: These code paths are not yet exercised as async2 methods are not currently compiled to ReadyToRun images.