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

Fix partial trimming of assemblies on referenced in metadata #91713

Merged
merged 3 commits into from
Sep 8, 2023

Conversation

MichalStrehovsky
Copy link
Member

@MichalStrehovsky MichalStrehovsky commented Sep 7, 2023

runtime-extra-platforms are on the floor again after the rebrand to .NET 9 TFM PR.

They're failing with an obscure:

Unhandled exception. System.InvalidOperationException: Unable to get member, please check input for IsNativeAot.
   at Microsoft.DotNet.XUnitExtensions.DiscovererHelpers.Evaluate(Type calleeType, String[] conditionMemberNames) + 0xb6
   at Microsoft.DotNet.XUnitExtensions.DiscovererHelpers.<EvaluateArguments>d__13.MoveNext() + 0x209

This is because PlatformDetection.IsNativeAot is not visible from reflection.

Root caused this to:

  • PlatformDetection type is only referenced from ConditionalFact attribute. This attribute is not annotated with dataflow annotations, so the only thing we keep is the metadata for the PlatformDetection type, since there's nothing else to keep (no methods, no MethodTable).
  • This is the only reference to something from TestUtilities assembly.
  • Before the 9.0 rebrand PR, some nullable junk attributes were also generated into TestUtilities assembly. This basically helped us get some runtime artifacts for something in TestUtilities to be generated - when we were scanning attributes on PlatformDetection we'd say: oh this attribute needs a methodtable and a body for the constructor. This in turn triggered partial trimming logic to make everything in TestUtilities reflection rooted.
  • After the 9.0 rebrand PR those attributes live in CoreLib, so nothing in TestUtilities gets a runtime artifact. Partial trimming logic is not looked at from TypeMetadata node.

I'm fixing it by forcing a MethodTable whenever we have metadata for a <Module> type (this type is always generated).

But also I'm indifferent about this fix. There are many similar corner cases where we'd miss that an assembly was used (e.g. declare a local of some type and then never do anything with it). I don't think we need to fix them. This could also be fixed by just rooting TestUtilities in our testing infra. I'm open to that too.

I'm fixing it by just explicitly rooting TestUtilities.

Cc @dotnet/ilc-contrib

runtime-extra-platforms are on the floor again after the rebrand to .NET 9 TFM PR.

They're failing with an obscure:

```
Unhandled exception. System.InvalidOperationException: Unable to get member, please check input for IsNativeAot.
   at Microsoft.DotNet.XUnitExtensions.DiscovererHelpers.Evaluate(Type calleeType, String[] conditionMemberNames) + 0xb6
   at Microsoft.DotNet.XUnitExtensions.DiscovererHelpers.<EvaluateArguments>d__13.MoveNext() + 0x209
```

This is because `PlatformDetection.IsNativeAot` is not visible from reflection.

Root caused this to:

* `PlatformDetection` type is only referenced from `ConditionalFact` attribute. This attribute is not annotated with dataflow annotations, so the only thing we keep is the _metadata_ for the `PlatformDetection` type, since there's nothing else to keep (no methods, no MethodTable).
* This is the _only_ reference to something from TestUtilities assembly.
* Before the 9.0 rebrand PR, some nullable junk attributes were also generated into TestUtilities assembly. This basically helped us get _some runtime artifacts_ for _something_ in TestUtilities to be generated - when we were scanning attributes on PlatformDetection we'd say: oh this attribute needs a methodtable and a body for the constructor. This in turn triggered partial trimming logic to make _everything_ in TestUtilities reflection rooted.
* After the 9.0 rebrand PR those attributes live in CoreLib, so nothing in TestUtilities gets a runtime artifact. Partial trimming logic is not looked at from TypeMetadata node.

I'm fixing it by forcing a MethodTable whenever we have metadata for a `<Module>` type (this type is always generated).

But also I'm indifferent about this fix. There are many similar corner cases where we'd miss that an assembly was used (e.g. declare a local of some type and then never do anything with it). I don't think we need to fix them. This could also be fixed by just rooting TestUtilities in our testing infra. I'm open to that too.
@ghost
Copy link

ghost commented Sep 7, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

runtime-extra-platforms are on the floor again after the rebrand to .NET 9 TFM PR.

They're failing with an obscure:

Unhandled exception. System.InvalidOperationException: Unable to get member, please check input for IsNativeAot.
   at Microsoft.DotNet.XUnitExtensions.DiscovererHelpers.Evaluate(Type calleeType, String[] conditionMemberNames) + 0xb6
   at Microsoft.DotNet.XUnitExtensions.DiscovererHelpers.<EvaluateArguments>d__13.MoveNext() + 0x209

This is because PlatformDetection.IsNativeAot is not visible from reflection.

Root caused this to:

  • PlatformDetection type is only referenced from ConditionalFact attribute. This attribute is not annotated with dataflow annotations, so the only thing we keep is the metadata for the PlatformDetection type, since there's nothing else to keep (no methods, no MethodTable).
  • This is the only reference to something from TestUtilities assembly.
  • Before the 9.0 rebrand PR, some nullable junk attributes were also generated into TestUtilities assembly. This basically helped us get some runtime artifacts for something in TestUtilities to be generated - when we were scanning attributes on PlatformDetection we'd say: oh this attribute needs a methodtable and a body for the constructor. This in turn triggered partial trimming logic to make everything in TestUtilities reflection rooted.
  • After the 9.0 rebrand PR those attributes live in CoreLib, so nothing in TestUtilities gets a runtime artifact. Partial trimming logic is not looked at from TypeMetadata node.

I'm fixing it by forcing a MethodTable whenever we have metadata for a <Module> type (this type is always generated).

But also I'm indifferent about this fix. There are many similar corner cases where we'd miss that an assembly was used (e.g. declare a local of some type and then never do anything with it). I don't think we need to fix them. This could also be fixed by just rooting TestUtilities in our testing infra. I'm open to that too.

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: MichalStrehovsky
Labels:

area-NativeAOT-coreclr

Milestone: -

@MichalStrehovsky
Copy link
Member Author

I've changed this to just root TestUtilities now that I had some time to think about this. It doesn't make sense to try to patch these. This code is trim unsafe and that's the actual problem.

@jkotas
Copy link
Member

jkotas commented Sep 7, 2023

I've changed this to just root TestUtilities now that I had some time to think about this. It doesn't make sense to try to patch these. This code is trim unsafe and that's the actual problem.

Yeah, this looks better to me. I had mixed feelings about the original fix.

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.

Thanks!

@jkotas
Copy link
Member

jkotas commented Sep 8, 2023

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants