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

Update DynamicallyAccessedMembers annotation on EventSource #110001

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

MichalStrehovsky
Copy link
Member

This takes advantage of #109814. This is in theory a breaking change in case someone took advantage of our annotation and is doing their own reflection on EventSource descendants.

Someone else reflecting on EventSource is problematic however. We placed around various suppressions due to our own annotations like this:

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2114:ReflectionToDynamicallyAccessedMembers",
Justification = "EnsureDescriptorsInitialized's use of GetType preserves this method which " +
"has dynamically accessed members requirements, but EnsureDescriptorsInitialized does not " +
"access this member and is safe to call.")]
public static string? GenerateManifest(
[DynamicallyAccessedMembers(ManifestMemberTypes)]
Type eventSourceType,
string? assemblyPathToIncludeInManifest)
{
return GenerateManifest(eventSourceType, assemblyPathToIncludeInManifest, EventManifestOptions.None);
}

It means that if someone else is reflection-accessing various members on EventSource, they would not get a trimming warning. Hopefully, nobody does that. This PR also assumes that nobody does that (and the PR should therefore not be breaking in practice).

Cc @eerhardt @dotnet/illink

This takes advantage of dotnet#109814. This is in theory a breaking change in case someone took advantage
of our annotation and is doing their own reflection on `EventSource` descendants.

Someone else reflecting on EventSource is problematic however. We placed around various suppressions
due to our own annotations like this:

https://github.com/dotnet/runtime/blob/0d62887a30553b8177dc90f9e39559be0e6c7707/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L414-L424

It means that if someone else is reflection-accessing these, they would not get a trimming warning.
Hopefully, nobody does that. This PR also assumes that nobody does that (and the PR should therefore
not be breaking in practice).

We annotate the class for our purposes, but someone else could be taking advantage of that in their own code.
Copy link

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, 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.

1 similar comment
Copy link

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, 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.

Copy link
Contributor

Tagging subscribers to this area: @tarekgh, @tommcdon, @pjanotti
See info in area-owners.md if you want to be subscribed.

@eerhardt
Copy link
Member

It means that if someone else is reflection-accessing various members on EventSource, they would not get a trimming warning.

Why wouldn't they get a trimming warning?

@MichalStrehovsky
Copy link
Member Author

It means that if someone else is reflection-accessing various members on EventSource, they would not get a trimming warning.

Why wouldn't they get a trimming warning?

Because we suppressed them with the suppression I quoted. We annotate EventSource as "this is going to reflect on all methods" and we have a bunch of methods that should never be reflection-invoked. We suppressed it but the suppression will apply to anyone else taking advantage of the annotation because annotation doesn't discriminate.

@eerhardt
Copy link
Member

It means that if someone else is reflection-accessing various members on EventSource, they would not get a trimming warning.

Why wouldn't they get a trimming warning?

Because we suppressed them with the suppression I quoted. We annotate EventSource as "this is going to reflect on all methods" and we have a bunch of methods that should never be reflection-invoked. We suppressed it but the suppression will apply to anyone else taking advantage of the annotation because annotation doesn't discriminate.

If someone else is reflection-accessing these specific methods (GenerateManifest, WriteEventCore, WriteEventWithRelatedActivityIdCore, WriteEvent(int, object[]), CreateManifestAndDescriptors) they won't get warnings. But that is the same as it is today with using .All, so this PR isn't making it worse.

The part that could be considered breaking is that someone could have been calling GetType() on some EventSource object and getting the properties/fields/etc from it. Before they wouldn't get a warning since we used .All on the whole class. Now we are only doing methods and nested types. But in this case they WILL get a warning.

@MichalStrehovsky
Copy link
Member Author

The part that could be considered breaking is that someone could have been calling GetType() on some EventSource object and getting the properties/fields/etc from it. Before they wouldn't get a warning since we used .All on the whole class. Now we are only doing methods and nested types. But in this case they WILL get a warning.

Yep, what I meant is that we annotate this as reflected-on "for us", not for someone else to use. The suppressions are one of the indicators that this is very specifically meant for us. Unfortunately there's no annotation that could make this contractually private so someone could be still taking advantage of it.

@MichalStrehovsky MichalStrehovsky merged commit b66200e into dotnet:main Nov 21, 2024
136 of 139 checks passed
@MichalStrehovsky MichalStrehovsky deleted the evtsourceall branch November 21, 2024 07:41
sbomer added a commit that referenced this pull request Dec 6, 2024
#110001 updated annotations on
EventSource. This adjusts the expected preserved members to match.
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this pull request Dec 10, 2024
…10001)

This takes advantage of dotnet#109814. This is in theory a breaking change in case someone took advantage
of our annotation and is doing their own reflection on `EventSource` descendants.

Someone else reflecting on EventSource is problematic however. We placed around various suppressions
due to our own annotations like this:

https://github.com/dotnet/runtime/blob/0d62887a30553b8177dc90f9e39559be0e6c7707/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs#L414-L424

It means that if someone else is reflection-accessing these, they would not get a trimming warning.
Hopefully, nobody does that. This PR also assumes that nobody does that (and the PR should therefore
not be breaking in practice).

We annotate the class for our purposes, but someone else could be taking advantage of that in their own code.
akoeplinger added a commit that referenced this pull request Dec 16, 2024
* Update dependencies from https://github.com/dotnet/arcade build 20241205.6

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitAssert , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 10.0.0-beta.24605.1 -> To Version 10.0.0-beta.24605.6

* Set roll forward for cdac-build-tool

* Bump NetCoreAppToolCurrent to net10.0

* Fix CustomEventSource test

#110001 updated annotations on
EventSource. This adjusts the expected preserved members to match.

* Fix tests with Type checks

With https://github.com/dotnet/runtime/pull/106497/files,
object.GetType is no longer an internalcall. This means we no longer
mark the ctor of the return type, System.Type, so the type check
removal optimization is kicking in where it didn't before.

* Update dependencies from https://github.com/dotnet/arcade build 20241206.6

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitAssert , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 10.0.0-beta.24605.1 -> To Version 10.0.0-beta.24606.6

* Disable nativeAOT components for win-x86 temporarily

* Update baseline entries

* Bump AspNetCoreAppCurrent

* Update pinned package versions

* Update sdk dependencies

* Fix path to WebAssembly build task

* Update dependencies from https://github.com/dotnet/arcade build 20241210.1

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitAssert , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 10.0.0-beta.24605.1 -> To Version 10.0.0-beta.24610.1

* Build XUnitLogChecker as SingleFile when we can't AOT it. Our infra expects us to publish this with a host. Publishing as single file makes this a little easier (and keeps it as one file).

* Update SDK and remove obsolete condition

* Revert "Fix tests with Type checks"

This reverts commit 15a30ef.

* Fix illink tests

* Reapply "Fix tests with Type checks"

This reverts commit 7a8c1fb.

* Attempt 2

* Update dependencies from https://github.com/dotnet/arcade build 20241210.2

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitAssert , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 10.0.0-beta.24605.1 -> To Version 10.0.0-beta.24610.2

* Update sdk dependencies that are used for workloads tests

* Based on #93693, Update Wasm.Build.Tests and Wasi.Build.Tests for net10.0

* Change disable condition as hybrid globalization in the browser has been disabled and the test fails due to this condition being false now.

* Update dependencies from https://github.com/dotnet/arcade build 20241211.4

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitAssert , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 10.0.0-beta.24605.1 -> To Version 10.0.0-beta.24611.4

* Use feature switch to disable DataSet xml serialization related tests

* Update dependencies from https://github.com/dotnet/arcade build 20241212.4

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitAssert , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 10.0.0-beta.24605.1 -> To Version 10.0.0-beta.24612.4

* Workload fixes and improvements

* Remove runtimes-windows from workload manifest, it is unused

* Add net10 entries in workloads.csproj

* Fix mistakes in net8 workload manifest

* Update emsdk

* Fix msbuild conditions

* Update dependencies from https://github.com/dotnet/arcade build 20241213.2

Microsoft.SourceBuild.Intermediate.arcade , Microsoft.DotNet.Arcade.Sdk , Microsoft.DotNet.Build.Tasks.Archives , Microsoft.DotNet.Build.Tasks.Feed , Microsoft.DotNet.Build.Tasks.Installers , Microsoft.DotNet.Build.Tasks.Packaging , Microsoft.DotNet.Build.Tasks.TargetFramework , Microsoft.DotNet.Build.Tasks.Templating , Microsoft.DotNet.Build.Tasks.Workloads , Microsoft.DotNet.CodeAnalysis , Microsoft.DotNet.GenAPI , Microsoft.DotNet.GenFacades , Microsoft.DotNet.Helix.Sdk , Microsoft.DotNet.PackageTesting , Microsoft.DotNet.RemoteExecutor , Microsoft.DotNet.SharedFramework.Sdk , Microsoft.DotNet.VersionTools.Tasks , Microsoft.DotNet.XliffTasks , Microsoft.DotNet.XUnitAssert , Microsoft.DotNet.XUnitConsoleRunner , Microsoft.DotNet.XUnitExtensions
 From Version 10.0.0-beta.24605.1 -> To Version 10.0.0-beta.24613.2

* Fix regex for runtime pack path to allow space

* Fix condition in WorkloadManifest.targets.in to actually match net10.0

* Fix net version in wasm templates

* Fix one more hardcoded net9.0

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
Co-authored-by: Sven Boemer <sbomer@gmail.com>
Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
Co-authored-by: Jeremy Koritzinsky <jekoritz@microsoft.com>
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants