Repository navigation
Prototype: allocator-scoped runtime delegate-type factory (not for merge) - #135372
Draft
davidwrighton wants to merge 3 commits into
Draft
davidwrighton wants to merge 3 commits into
davidwrighton wants to merge 3 commits into
Conversation
Add Delegate.GetDelegateType with narrow CoreCLR QCalls and shared assemblies owned by signature loader allocators. Replace the feature-enabled Expressions custom delegate Emit path without a fallback, while preserving its existing dynamic-code scope. Include signature interoperability and lifetime tests, the reference API, and proposal validation evidence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 489cae73-8e77-4116-8467-f467e9b710bc
Move the prototype API off Delegate and route Expressions custom delegate creation through CoreLib on every runtime flavor. Move the existing Emit machinery into Mono CoreLib with a shared assembly and signature cache; preserve NativeAOT custom-generation rejection. Remove AssemblyGen and the feature gate, retain the accepted dynamic-code scope, and record cross-runtime validation and benchmark evidence. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 489cae73-8e77-4116-8467-f467e9b710bc
Mark the proposal as exploratory discussion evidence, not a design intended to merge as-is, before publishing the draft PR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 489cae73-8e77-4116-8467-f467e9b710bc
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 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
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
This was referenced Oct 8, 2026
This branch has not been deployed
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.
Warning
This is an exploratory prototype for discussion only. This is not the likely direction we will take for this problem. It is not intended to merge as-is or ship the proposed API.
Summary
Prototype a dedicated CoreLib delegate-type factory,
System.Runtime.CompilerServices.RuntimeHelpers.GetDelegateType(params Type[] typeArgs), returningTypewith the same parameter-list/return-type convention asExpression.GetDelegateType.AssemblyGenand its classic Emit fallback are removed; the existing singleAssemblyBuilder.ForceAllowDynamicCodescope remains, as do lightweight expression-body compilation dependencies.Func/Actionsupport and rejects custom generation withPlatformNotSupportedException.The public API is unapproved and exposed only as prototype evidence. This PR is not an API approval or production-adoption request.
The design/proposal document contains implementation details, alternatives, compatibility risks, exact validation commands, and benchmark methodology.
Boundaries
Custom creation requires closed runtime types; open custom signatures and unbaked
TypeBuilderinputs are not implemented. Mono retains its existing process-lifetime dynamic-assembly behavior; CoreCLR's allocator-scoped collectible implementation is not ported to Mono here. Generated names, grouping, and canonical type identity differ from the previous Expressions implementation.This is not metadata-free type synthesis: CoreCLR still creates minimal native in-memory metadata. It does not depend on MetadataUpdater/Hot Reload and does not permit
ELEMENT_TYPE_INTERNALin ordinary PE or byte-array-loaded metadata.Validation
Local Windows x64 Release builds for CoreCLR, Mono, and NativeAOT succeeded with API compatibility validation enabled and no warnings or errors.
The unmodified CoreCLR System.Runtime suite fails during discovery on
ValueTypeTests.StructWithMutualGenericFieldA; this was reproduced on clean upstream main. The broad run above uses a temporary, session-only targets file excludingSystem\ValueTypeTests.cs, not a repository test quarantine, and is not a passing run of the full unmodified suite.Mono's dynamic-method
DynamicInvokebyref writeback difference was reproduced with statically declared and legacy Emit-generated delegates as well as factory delegates; that assertion remains CoreCLR-specific. Other binding and invocation coverage runs on both runtimes.The NativeAOT test target compiled successfully but its script could not launch the unqualified executable name. Running the published executable by absolute path produced the passing result above. Other operating systems were not validated.
Measurements
Final BenchmarkDotNet comparison against preserved clean upstream-main CoreRun testhosts:
These short runs do not establish a throughput improvement. Cold-creation confidence intervals overlap and the benchmark reports minimum-iteration warnings. Measured managed allocation decreased by approximately 31%, excluding native metadata and loader allocations. Mono and NativeAOT were not benchmarked.
Note
This PR description and prototype implementation were generated with GitHub Copilot assistance.