Repository navigation
Add trimming switch to restrict Linq Expressions to Native AOT delegate types (alternative to #135372) - #137444
Closed
davidwrighton wants to merge 1 commit into
Closed
davidwrighton wants to merge 1 commit into
davidwrighton wants to merge 1 commit into
Conversation
…te types System.Linq.Expressions.CanEmitCustomDelegateTypes=false makes delegate type inference use the same predefined delegate types as Native AOT, so the Reflection.Emit-based custom delegate type generation can be trimmed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 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: @333fred |
5 tasks
Member
|
Can you get numbers for a relinked dotnet.native.wasm? If we're able to trim out all of the managed SRE logic then we should be able to trim some of the native logic too |
Member
Author
|
@jkoritzinsky, it's not a that big of a delta unless we can drop the entire RW metadata handling logic, which isn't going to happen easily. There are too many tendrils. |
Member
Author
|
I'm going to close this for now. While I think this is better than changing Linq expressions to have a completely different delegate creation path, it is still not quite worth making a non-trivial change to System.Linq.Expressions given its archived state. |
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.
This is an alternative to #135372 (prototype runtime delegate-type factory). Rather than adding a restricted runtime surface for custom delegate creation, this adds a trimming feature switch that limits System.Linq.Expressions to the same delegate types that are supported on Native AOT.
Change
System.Linq.Expressions.CanEmitCustomDelegateTypes(defaulttrue,[FeatureSwitchDefinition]).false, delegate type inference (Expression.GetDelegateType, inferred-typeExpression.Lambda, call-site delegates) only usesFunc<...>,Action<...>, and the predefined call-site delegates. Requests that would require a custom delegate type (more than 16 parameters, or by-ref, by-ref-like, or pointer parameters) throwPlatformNotSupportedException, matching Native AOT behavior. The Reflection.Emit-based custom delegate generation (AssemblyGen/TypeBuilder) becomes trimmable.docs/workflow/trimming/feature-switches.md. An app opts in with:A follow-up could have the Blazor WebAssembly SDK set this by default, since Blazor app expression usage generally uses explicit or
Func/Action-shaped delegate types (see below).Size analysis: Havit Blazor documentation app (CoreCLR WebAssembly, composite R2R)
All publishes used the same SDK (
12.0.100-alpha.1.26480.102), Release CoreCLR browser runtime, and composite R2R publish. Sizes are the sum of all published.brfiles (94 files in each publish)..brbytestrue)falseBreakdown of switch
falsevs. default:falseHavit.Blazor.Documentation.r2r)System.Private.CoreLibSystem.Linq.Expressionsdotnet.native.wasmNotes:
AssemblyGenis no longer present in the publishedSystem.Linq.Expressionsassembly.dotnet.native.wasmis byte-identical between the two configurations. By comparison, the Prototype: allocator-scoped runtime delegate-type factory (not for merge) #135372 prototype's new QCalls add +375 bytes uncompressed / +466 bytes Brotli todotnet.native.wasm(measured from the same checkout path).dotnet.native.wasmdiffers by ~555 Brotli bytes purely due to embedded__FILE__source paths; with that removed, switchfalsesaves ~36.8 KB vs. upstream.Does Havit/Blazor need custom delegate types?
I scanned the IL of the published app dependencies for Expressions usage:
Microsoft.AspNetCore.Components.Forms/.WebandHavit.Blazor.Components.Web.BootstrapuseExpression.Lambda<TDelegate>with explicitFunc<...>types, orExpression.Lambda(Type, ...).Havit.Core(ExpressionExt.AndAlso,SubstitutionVisitor.VisitLambda) uses inferred-typeExpression.Lambda, but for predicate shapes that map toFunc<T, bool>.Microsoft.CSharpis not published, so there are nodynamiccall-site binders.So the custom delegate path is reachable by the trimmer but not needed at runtime in this scenario.
Validation
./build.sh clr+libs -rc Release— passed.dotnet build /t:Test src/libraries/System.Linq.Expressions/tests/System.Linq.Expressions.Tests.csproj /p:RuntimeConfiguration=Release— passed: 35,119 total, 0 failed, 0 skipped, including the newGetDelegateTypeTests.CustomDelegateTypesNotEmittedWhenSwitchDisabled(RemoteExecutor with the switch disabled).IsDynamicCodeSupportedis already false).Note
This PR description and change were generated with assistance from GitHub Copilot.