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

[API Proposal]: Obsolete attributes under S.R.CompilerServices with no effect #113042

Open
huoyaoyuan opened this issue Mar 2, 2025 · 8 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.CompilerServices untriaged New issue has not been triaged by the area owner

Comments

@huoyaoyuan
Copy link
Member

huoyaoyuan commented Mar 2, 2025

Background and motivation

In #40622 and #43247, SuppressIldasmAttribute and DisablePrivateReflectionAttribute were obsoleted because the runtime and toolchain no longer respects them. There are other attributes no longer respected by coreclr for a long time. PRs like #112975 are also removing the runtime definition of them. We may like to obsolete these attributes to provide a clear indication.

The list of attributes are:

  • DefaultDependencyAttribute
  • DependencyAttribute
  • CompilationRelaxationsAttribute still emitted by roslyn
  • CompilerGlobalScopeAttribute still used by VS debugger
  • StringFreezingAttribute
  • LoaderOptimizationAttribute

API Proposal

namespace System.Runtime.CompilerServices;
{
+   [Obsolete("LoadHint has no effect on .NET 5+", Id = ???1)]
    public partial class DefaultDependencyAttribute {}

+   [Obsolete("LoadHint has no effect on .NET 5+", Id = ???1)]
    public partial class DependencyAttribute {}

+   [Obsolete("LoadHint has no effect on .NET 5+", Id = ???1)]
    public enum LoadHint {}

+   [Obsolete("StringFreezingAttribute has no effect on .NET 5+", Id = ???2)]
    public partial class StringFreezingAttribute{}
}

namespace System
{
+   [Obsolete("LoaderOptimizationAttribute has no effect on .NET 5+", Id = ???3)]
    public partial class LoaderOptimizationAttribute {}
+   [Obsolete("LoaderOptimizationAttribute has no effect on .NET 5+", Id = ???3)]
    public enum LoaderOptimization {}
}

API Usage

N/A

Alternative Designs

How should the IDs and messages be grouped? Grouping related attributes and enum with a same ID seems reasonable.

Should the message say ".NET 5+" or ".NET 10+"? These attributes have not been respected for a long time.

Risks

We shouldn't want to re-introduce these capabilities in the future.

@huoyaoyuan huoyaoyuan added api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.CompilerServices labels Mar 2, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 2, 2025
Copy link
Contributor

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

@teo-tsirpanis
Copy link
Contributor

Roslyn emits [assembly:CompilationRelaxationsAttribute(CompilationRelaxations.NoStringInterning)] in all assemblies it compiles. If we want to obsolete this attribute I think we should also update Roslyn to not emit it (maybe by checking if it is obsolete?).

@KalleOlaviNiemitalo
Copy link

The documentation of CompilerGlobalScopeAttribute says:

This class is used only for communication with debugger tools.

Do debuggers ignore this attribute nowadays?

@huoyaoyuan
Copy link
Member Author

The documentation of CompilerGlobalScopeAttribute says:

This class is used only for communication with debugger tools.

The code comment says "VS 7 debugger":

// Attribute used to communicate to the VS7 debugger that a class should be treated as if it has global scope.

I searched runtime and diagnostics and didn't find usage in production code. However, there is some unit test mentioning it:

.custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGlobalScopeAttribute::.ctor() = ( 01 00 00 00 )

@huoyaoyuan
Copy link
Member Author

huoyaoyuan commented Mar 2, 2025

Code handling CompilationRelaxations.NoStringInterning was deleted in #57693 and #64521. There's still a piece of comment mentioning it at

// We need to update strings atomically (due to NoStringInterning attribute). Note

@jkotas
Copy link
Member

jkotas commented Mar 2, 2025

PRs like #112975 are also removing the runtime definition of them

Nit: This PR is deleting unused flags on obsolete hosting API. Some of these flags served similar purpose as some of the attributes, but this PR is not deleting runtime definition of any attributes.

Did you mean to include LoaderOptimizationAttribute that was discussed in that PR in this list?

BTW: There is a lot of attributes in the security namespaces that are candidates for obsoletion as well. For example, SecurityTransparentAttribute, SecuritySafeCriticalAttribute, SecurityRulesAttribute, SuppressUnmanagedCodeSecurityAttribute, ... .

CompilerGlobalScopeAttribute
This class is used only for communication with debugger tools.
I searched runtime and diagnostics and didn't find usage in production code.

You would have to search the closed source Visual Studio code that's the production debugger code. The attribute is used there as you can tell by looking at the binaries:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\VC\vcpackages>findstr /M CompilerGlobalScopeAttribute vcpkg.dll
vcpkg.dll

The code comment says "VS 7 debugger":

You can delete the version number from the comment so that people are confused by it.

CompilationRelaxations.NoStringInterning

Yes, it was deleted in the runtime. However, the Roslyn still emits it and there may be tools out there that may depend on this attribute. We would have to overall plan for these other places to really obsolete it. I do not think it is worth it to bother with obsoleting this one.

@huoyaoyuan
Copy link
Member Author

Updated original post. I didn't find other attributes in System namespace that looks obsolete.

BTW: There is a lot of attributes in the security namespaces that are candidates for obsoletion as well.

Should they be included in one issue? Many of them already have members obsoleted.

@jkotas
Copy link
Member

jkotas commented Mar 3, 2025

Should they be included in one issue?

They can be listed in this issue or in a new issue. It does not matter a whole lot.

Should the message say ".NET 5+" or ".NET 10+"?

Vast majority of the obsoletion messages does not mention any version numbers: https://github.com/dotnet/runtime/blob/main/docs/project/list-of-diagnostics.md#obsoletion-diagnostics-syslib0001---syslib0999 . (A few messages do mention a version number. I guess it was an oversight.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Runtime.CompilerServices untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

4 participants