Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace old ReflectionMethodBodyScanner with the illink-based one #594

Merged
merged 4 commits into from
Jan 27, 2021

Conversation

MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Jan 26, 2021

This required beefing up the illink-based one a little:

  • Attempt to instantiate generic things. This matches the behavior of the old scanner that was able to make typeof(SomeType<>).MakeGenericType(otherType).GetMethod("Foo") work for reference-type otherType. This is a heuristic. MakeGenericType just needs to warn as being unsafe.
  • Recognize Enum.GetValues and Marshal.SizeOf. As a bonus, this hooks into the flow analysis infra, so we can potentially figure out more use cases. As another bonus, there's now a warning.
  • Detect when Type.GetType resolved things through a forwarder and add the forwarder metadata.

Lost features:

  • We no longer do the optimization for typeof(T) == typeof(Foo) that was trying to avoid seeing Foo as constructed (with a fully populated vtable). This can be added later; I'm leaving the compiler infra inplace.
  • Ability to run the scanner to only scan for interop pattern.

@MichalStrehovsky MichalStrehovsky added area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) labels Jan 26, 2021
@@ -492,7 +481,7 @@ public override void GetDependenciesDueToAccess(ref DependencyList dependencies,
public override void GetDependenciesDueToAccess(ref DependencyList dependencies, NodeFactory factory, MethodIL methodIL, MethodDesc calledMethod)
{
bool scanReflection = (_generationOptions & UsageBasedMetadataGenerationOptions.ReflectionILScanning) != 0;
if (scanReflection && FlowAnnotations.RequiresDataflowAnalysis(calledMethod))
if (scanReflection && Dataflow.ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(FlowAnnotations, calledMethod))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an ooops. We were running the analysis less often than we should (we need to run it not just when calling into an annotated method, but also if the method is an intrinsic. Most, but not all, intrinsics have annotations.

@MichalStrehovsky MichalStrehovsky removed the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Jan 27, 2021
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@MichalStrehovsky MichalStrehovsky merged commit 0e6888d into dotnet:feature/NativeAOT Jan 27, 2021
@MichalStrehovsky MichalStrehovsky deleted the scanAot branch January 27, 2021 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants