Repository navigation
Don't emit DynamicDependency under --reflectionfree - #21012
Open
charlesroddie wants to merge 2 commits into
Open
charlesroddie wants to merge 2 commits into
charlesroddie wants to merge 2 commits into
Conversation
Record, union and anonymous record constructors carry [DynamicDependency] so that %A formatting survives trimming. %A is a compile error under --reflectionfree, so there the attributes only make trimming and NativeAOT keep the types' fields and properties reflection-visible. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
Description
The compiler puts
[DynamicDependency]on record, anonymous record and union constructors (#14941, #15077, #15079) so that%Aformatting keeps working after trimming. Under--reflectionfree,%Ais a compile error and these types get a generatedToString(#19976), so the attributes have no purpose in the compiling assembly.This PR stops emitting the attribute when
--reflectionfreeis set. Output without the flag is unchanged.In a NativeAOT evaluation of a large reflection-free F# application, removing these attributes reduced the app size by 5.7% (1.7MB of 30.2MB).
Behaviour change
Under trimming or NativeAOT, code elsewhere that reflects over these types (
%Afrom another assembly,FSharp.Reflection, reflection-based serializers) may stop working, but 1. this seems clearly correct given the namereflectionfree, and 2. such code is unlikely to be found in trimming/NativeAOT environments.Testing
CompilerOptions.Fsc.ReflectionFreeandEmittedIL.ReflectionFreeToStringpass on net11.0 (24 tests). Two are new: the attribute is absent with--reflectionfreeand present without it, across records, struct records, unions, nullary unions, struct unions and both kinds of anonymous record.Checklist