Replies: 3 comments 4 replies
-
cc @dotnet/ilc-contrib |
Beta Was this translation helpful? Give feedback.
-
Related: dotnet/linker#2739 For the linker and trim analysis we had a goal that the published application behave the same as it does during Do we want to have the same goal for On the other hand if we let the |
Beta Was this translation helpful? Give feedback.
-
Ignoring if we want to do this or not, there's a design problem here. We can't reason about reflection without trim analysis. And trim analysis only really works if there are no trim warnings, otherwise the tool is effectively guessing. So to provide the same level of guarantee we do for trimming we would have to process and report all trim warnings as well. So the experience would be: "I'm trying to make a single-file app, I don't want to trim, but the tooling is generating 100s of warnings about feature I'm not interested in.". So I think that without trim analysis/warnings everything we do is best effort since we can't guarantee full understanding of the app. So this basically means there are two questions to answer:
Personally I don't know what we should do... maybe we should keep it simple for now (so keep existing analyzers as-is and don't complicate linker/AOT with things like reflection access to RAF methods). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We introduced capability attribute support in order to flag code members as requiring certain capability in code. Once the annotations are in code, we can enable the analysis of the capability attributes and provide feedback about the usage of members considering if the capability is met or not. That is, if the member is being accessed, and is marked as requiring a certain capability and that capability is not met we would rise a warning to the user.
For example, the following:
The code if executed would generate a warning representing that the analysis does not meet the requirement for certain tools like NativeAOT which doesn't support dynamic code, and therefore cannot fulfill the requirement expressed in the attribute.
As mentioned before, in order to generate the warning we verify if the capability is met on the member being accessed, therefore the analysis centers on trying to statically understand if a member will be accessed at runtime. There are basically two ways to make the reachability analysis, only understanding simple direct calls to methods and doing full reachability analysis which also tries to understand access via methods like reflection.
See the following example:
In this case, the way of accessing the method is not visible as a simple call, it's using the reflection APIs which hide the fact that we are about to call the
CallMethod()
method. With a more complex static analysis, we can infer thatCallMethod
will be used since we have all the information available in code. After executing this analysis we can generate the warning telling the user that they are about to use a member that dont fulfill the capability requirement.Full reachability analysis is a requirement for trimming applications, so it's something that has been developed and even implemented for some of the RequiresCapability attributes, for example, the
RequiresUnreferencedCode
attribute. Running the previous example code in the dotnet/linker codebase using theRequiresUnreferencedCode
attribute instead ofRequiresDynamicCode
will correctly generate a warning to the user.RequiresUnreferencedCode
attribute not only does care about reflection calls but also interacts with other attributes likeDynamicallyAccessedMembers
to help to be able to achieve full reachability analysis by helping on cross-method analysis. More info on reflection-flow documentThe point of this discussion is to talk about if the full reachability analysis should apply to all Capability attributes, from my standpoint without full reachability analysis, we are leaving holes that later on could result in a broken app at runtime without any warning to the user. As per previous discussions, most of the concerns about doing full reachability analysis on these attributes is what is going to be the warning when the analysis cannot predict what the behavior of the application will be at runtime and if the user should even be bothered of obtaining those warnings if they are not doing something like trimming.
For example:
In this case, the full reachability analysis would have no option but to warn since the analysis cannot know which member is going to be kept by the GetMethod() method. Is it a member that contains
RequiresDynamicCode
or a member that containsRequiresAssemblyFiles
? is impossible to know, but now the user will be bothered about it. Something that wouldn't happen if not in full reachability analysis.Beta Was this translation helpful? Give feedback.
All reactions