Background and motivation
Attributes needed for the unsafe evolution C# language feature (dotnet/roslyn#81207).
API Proposal
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public sealed class RequiresUnsafeAttribute : Attribute { }
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Module, Inherited = false, AllowMultiple = false)]
public sealed class MemorySafetyRulesAttribute : Attribute
{
public MemorySafetyRulesAttribute(int version) { Version = version; }
public int Version;
}
}
API Usage
The MemorySafetyRulesAttribute is used by the compiler (it is disallowed to use it in source). The compiler applies it to a module when updated memory safety rules are enabled.
The RequiresUnsafeAttribute is used by users but can be also applied by the compiler implicitly for extern members.
class C
{
[RequiresUnsafe] public void M() { }
}
Alternative Designs
Since the RequiresUnsafe attribute is to be used by users, perhaps it should live in System.Diagnostics.CodeAnalysis instead - in fact, it's already defined there internally:
|
internal sealed class RequiresUnsafeAttribute : Attribute |
Risks
No response
Background and motivation
Attributes needed for the unsafe evolution C# language feature (dotnet/roslyn#81207).
API Proposal
API Usage
The
MemorySafetyRulesAttributeis used by the compiler (it is disallowed to use it in source). The compiler applies it to a module when updated memory safety rules are enabled.The
RequiresUnsafeAttributeis used by users but can be also applied by the compiler implicitly forexternmembers.Alternative Designs
Since the
RequiresUnsafeattribute is to be used by users, perhaps it should live inSystem.Diagnostics.CodeAnalysisinstead - in fact, it's already defined there internally:runtime/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresUnsafeAttribute.cs
Line 16 in 9511672
Risks
No response