Skip to content

Conversation

@eerhardt
Copy link
Member

Fix #71654

With this change, all Microsoft.Extensions.* libraries in dotnet/runtime have EnableAOTAnalyzer=true on.

@ghost
Copy link

ghost commented Aug 12, 2022

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost assigned eerhardt Aug 12, 2022
@ghost
Copy link

ghost commented Aug 12, 2022

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix #71654

With this change, all Microsoft.Extensions.* libraries in dotnet/runtime have EnableAOTAnalyzer=true on.

Author: eerhardt
Assignees: -
Labels:

new-api-needs-documentation, area-Extensions-Configuration

Milestone: -

@ghost
Copy link

ghost commented Aug 12, 2022

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

Issue Details

Fix #71654

With this change, all Microsoft.Extensions.* libraries in dotnet/runtime have EnableAOTAnalyzer=true on.

Author: eerhardt
Assignees: eerhardt
Labels:

area-Extensions-Configuration, area-Extensions-Hosting

Milestone: -

Copy link
Contributor

@LakshanF LakshanF left a comment

Choose a reason for hiding this comment

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

The justification for the single suppression seems safe to me.

private PhysicalFileProvider? _defaultProvider;

[RequiresDynamicCode(Host.RequiresDynamicCodeMessage)]
public HostBuilder()
Copy link
Member

Choose a reason for hiding this comment

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

just wondering, does the attribute cannot be applied to the class fields?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it can only be applied to methods and the whole class.

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class, Inherited = false)]
#if SYSTEM_PRIVATE_CORELIB
public
#else
internal
#endif
sealed class RequiresDynamicCodeAttribute : Attribute

Here I didn't want to mark the whole class, as that has other side-effects with the analyzer - like warning if some other code is using static methods.

I kind of wish just marking the ctor as RequiresDynamicCode suppressed the code in the field initializer, but I didn't see that happening. @tlakollo - is this supposed to work?

Copy link
Contributor

Choose a reason for hiding this comment

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

It wouldn't a field initializer will not only call the .ctor but also the .cctor, we don't allow to annotate the .cctor directly and the workaround is to annotate the whole class.

Copy link
Member Author

Choose a reason for hiding this comment

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

a field initializer will not only call the .ctor but also the .cctor

Yes, it will call the .cctor, but the .cctor doesn't have any "unsafe" code in it. Just the .ctor would, with an instance field initializer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. So what you mean is that you would want something like:

...
private IServiceFactoryAdapter _serviceProviderFactory = new ServiceFactoryAdapter<IServiceCollection>(new DefaultServiceProviderFactory());
...
[RequiresDynamicCode(Host.RequiresDynamicCodeMessage)]
public HostBuilder() {}
...

To suppress the warning in the instance field?
If that is the case, yes currently that's not implemented but sounds like a feature that could be done.

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. That is exactly what I was thinking should work, but didn't.

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened dotnet/linker#2970 to track the implementation, although this will need changes in linker/analyzer/nativeAOT

Copy link
Member

Choose a reason for hiding this comment

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

although this will need changes in linker/analyzer/nativeAOT

I think that's an analyzer-only change. IL based analysis will already see this as part of the constructor method body.

Copy link
Member

Choose a reason for hiding this comment

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

(We could possibly do a pragma suppression on the field to shut up analyzer.)

Copy link
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

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

Modulo @jkotas comment, LGTM.

Plus clean up the interop in GetParentProcess.
return diagnosticListener;
}

[UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode",
Copy link
Member

Choose a reason for hiding this comment

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

Just double checking that we won't MakeGeneric over the T here?

Copy link
Member Author

Choose a reason for hiding this comment

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

My understanding is that is only a concern for the DiagnosticSource-EventSource bridge in order to write property values out to an EventSource. This isn’t for EventSource listeners. I’m honestly not even sure how that would work because these objects (IHostBuilder, Host) don’t really have properties that can be read. The usage here is that the objects are passed to listeners in the same process in order to get hooks into the building process.

Copy link
Member

Choose a reason for hiding this comment

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

I think I've seen that failing in the tests: #73420

I've had a bunch of question marks on how this all works, so I've just filed an issue on it and moved on with life.

@eerhardt eerhardt merged commit 30dc7e7 into dotnet:main Aug 13, 2022
@eerhardt eerhardt deleted the Fix71654 branch August 13, 2022 15:46
@ghost ghost locked as resolved and limited conversation to collaborators Sep 14, 2022
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.

Microsoft.Extensions.Configuration APIs haven't been AOT-annotated

6 participants