diff --git a/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs b/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs index b8a6a9f4e9798..cc19e25919b24 100644 --- a/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs +++ b/src/Compilers/CSharp/Portable/BoundTree/UnboundLambda.cs @@ -744,7 +744,7 @@ private BoundLambda ReallyBind(NamedTypeSymbol delegateType, bool inExpressionTr } ParameterHelpers.EnsureNativeIntegerAttributeExists(compilation, lambdaParameters, diagnostics, modifyCompilation: false); - ParameterHelpers.EnsureScopedRefAttributeExists(compilation, lambdaParameters, diagnostics, modifyCompilation: false); + ParameterHelpers.EnsureLifetimeAnnotationAttributeExists(compilation, lambdaParameters, diagnostics, modifyCompilation: false); ParameterHelpers.EnsureNullableAttributeExists(compilation, lambdaSymbol, lambdaParameters, diagnostics, modifyCompilation: false); // Note: we don't need to warn on annotations used in #nullable disable context for lambdas, as this is handled in binding already diff --git a/src/Compilers/CSharp/Portable/Emitter/Model/PEAssemblyBuilder.cs b/src/Compilers/CSharp/Portable/Emitter/Model/PEAssemblyBuilder.cs index 0730e502562b9..ee7e7fa30cdbf 100644 --- a/src/Compilers/CSharp/Portable/Emitter/Model/PEAssemblyBuilder.cs +++ b/src/Compilers/CSharp/Portable/Emitter/Model/PEAssemblyBuilder.cs @@ -40,7 +40,7 @@ internal abstract class PEAssemblyBuilderBase : PEModuleBuilder, Cci.IAssemblyRe private SynthesizedEmbeddedNullableContextAttributeSymbol _lazyNullableContextAttribute; private SynthesizedEmbeddedNullablePublicOnlyAttributeSymbol _lazyNullablePublicOnlyAttribute; private SynthesizedEmbeddedNativeIntegerAttributeSymbol _lazyNativeIntegerAttribute; - private SynthesizedEmbeddedScopedRefAttributeSymbol _lazyScopedRefAttribute; + private SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol _lazyLifetimeAnnotationAttribute; /// /// The behavior of the C# command-line compiler is as follows: @@ -99,7 +99,7 @@ internal sealed override ImmutableArray GetEmbeddedTypes(Bindin builder.AddIfNotNull(_lazyNullableContextAttribute); builder.AddIfNotNull(_lazyNullablePublicOnlyAttribute); builder.AddIfNotNull(_lazyNativeIntegerAttribute); - builder.AddIfNotNull(_lazyScopedRefAttribute); + builder.AddIfNotNull(_lazyLifetimeAnnotationAttribute); return builder.ToImmutableAndFree(); } @@ -251,17 +251,17 @@ internal override SynthesizedAttributeData SynthesizeNativeIntegerAttribute(Well return base.SynthesizeNativeIntegerAttribute(member, arguments); } - internal override SynthesizedAttributeData SynthesizeScopedRefAttribute(WellKnownMember member) + internal override SynthesizedAttributeData SynthesizeLifetimeAnnotationAttribute(WellKnownMember member, ImmutableArray arguments) { - if ((object)_lazyScopedRefAttribute != null) + if ((object)_lazyLifetimeAnnotationAttribute != null) { return new SynthesizedAttributeData( - _lazyScopedRefAttribute.Constructors[0], - ImmutableArray.Empty, + _lazyLifetimeAnnotationAttribute.Constructors[0], + arguments, ImmutableArray>.Empty); } - return base.SynthesizeScopedRefAttribute(member); + return base.SynthesizeLifetimeAnnotationAttribute(member, arguments); } protected override SynthesizedAttributeData TrySynthesizeIsReadOnlyAttribute() @@ -389,13 +389,13 @@ private void CreateEmbeddedAttributesIfNeeded(BindingDiagnosticBag diagnostics) CreateNativeIntegerAttributeSymbol); } - if ((needsAttributes & EmbeddableAttributes.ScopedRefAttribute) != 0) + if ((needsAttributes & EmbeddableAttributes.LifetimeAnnotationAttribute) != 0) { CreateAttributeIfNeeded( - ref _lazyScopedRefAttribute, + ref _lazyLifetimeAnnotationAttribute, diagnostics, - AttributeDescription.ScopedRefAttribute, - CreateScopedRefAttributeSymbol); + AttributeDescription.LifetimeAnnotationAttribute, + CreateLifetimeAnnotationAttributeSymbol); } } @@ -438,12 +438,13 @@ private SynthesizedEmbeddedNativeIntegerAttributeSymbol CreateNativeIntegerAttri GetWellKnownType(WellKnownType.System_Attribute, diagnostics), GetSpecialType(SpecialType.System_Boolean, diagnostics)); - private SynthesizedEmbeddedScopedRefAttributeSymbol CreateScopedRefAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics) - => new SynthesizedEmbeddedScopedRefAttributeSymbol( + private SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol CreateLifetimeAnnotationAttributeSymbol(string name, NamespaceSymbol containingNamespace, BindingDiagnosticBag diagnostics) + => new SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol( name, containingNamespace, SourceModule, - GetWellKnownType(WellKnownType.System_Attribute, diagnostics)); + GetWellKnownType(WellKnownType.System_Attribute, diagnostics), + GetSpecialType(SpecialType.System_Boolean, diagnostics)); private void CreateAttributeIfNeeded( ref T symbol, diff --git a/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs b/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs index 81617bf79940f..13803de6d1fff 100644 --- a/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs +++ b/src/Compilers/CSharp/Portable/Emitter/Model/PEModuleBuilder.cs @@ -1710,7 +1710,7 @@ internal virtual SynthesizedAttributeData SynthesizeNativeIntegerAttribute(WellK return Compilation.TrySynthesizeAttribute(member, arguments, isOptionalUse: true); } - internal SynthesizedAttributeData SynthesizeScopedRefAttribute(ParameterSymbol symbol, DeclarationScope scope) + internal SynthesizedAttributeData SynthesizeLifetimeAnnotationAttribute(ParameterSymbol symbol, DeclarationScope scope) { Debug.Assert(scope != DeclarationScope.Unscoped); Debug.Assert(symbol.RefKind != RefKind.Out || scope == DeclarationScope.ValueScoped); @@ -1722,14 +1722,20 @@ internal SynthesizedAttributeData SynthesizeScopedRefAttribute(ParameterSymbol s return null; } - return SynthesizeScopedRefAttribute(WellKnownMember.System_Runtime_CompilerServices_ScopedRefAttribute__ctor); + var booleanType = Compilation.GetSpecialType(SpecialType.System_Boolean); + Debug.Assert((object)booleanType != null); + return SynthesizeLifetimeAnnotationAttribute( + WellKnownMember.System_Runtime_CompilerServices_LifetimeAnnotationAttribute__ctor, + ImmutableArray.Create( + new TypedConstant(booleanType, TypedConstantKind.Primitive, scope == DeclarationScope.RefScoped), + new TypedConstant(booleanType, TypedConstantKind.Primitive, scope == DeclarationScope.ValueScoped))); } - internal virtual SynthesizedAttributeData SynthesizeScopedRefAttribute(WellKnownMember member) + internal virtual SynthesizedAttributeData SynthesizeLifetimeAnnotationAttribute(WellKnownMember member, ImmutableArray arguments) { // For modules, this attribute should be present. Only assemblies generate and embed this type. // https://github.com/dotnet/roslyn/issues/30062 Should not be optional. - return Compilation.TrySynthesizeAttribute(member, isOptionalUse: true); + return Compilation.TrySynthesizeAttribute(member, arguments, isOptionalUse: true); } internal bool ShouldEmitNullablePublicOnlyAttribute() @@ -1805,9 +1811,9 @@ internal void EnsureNativeIntegerAttributeExists() EnsureEmbeddableAttributeExists(EmbeddableAttributes.NativeIntegerAttribute); } - internal void EnsureScopedRefAttributeExists() + internal void EnsureLifetimeAnnotationAttributeExists() { - EnsureEmbeddableAttributeExists(EmbeddableAttributes.ScopedRefAttribute); + EnsureEmbeddableAttributeExists(EmbeddableAttributes.LifetimeAnnotationAttribute); } #nullable enable diff --git a/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs b/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs index a4a60a68dcb90..fb56339d1b7a1 100644 --- a/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs +++ b/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs @@ -134,7 +134,7 @@ private void EnsureAttributesExist(TypeCompilationState compilationState) ParameterHelpers.EnsureNativeIntegerAttributeExists(moduleBuilder, Parameters); } - ParameterHelpers.EnsureScopedRefAttributeExists(moduleBuilder, Parameters); + ParameterHelpers.EnsureLifetimeAnnotationAttributeExists(moduleBuilder, Parameters); if (compilationState.Compilation.ShouldEmitNullableAttributes(this)) { diff --git a/src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs b/src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs index 49576857a007d..a1cd90db4c825 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Compilation_WellKnownMembers.cs @@ -388,7 +388,8 @@ internal override ITypeSymbolInternal CommonGetWellKnownType(WellKnownType wellk ImmutableArray> namedArguments = default, bool isOptionalUse = false) { - var ctorSymbol = (MethodSymbol)Binder.GetWellKnownTypeMember(this, constructor, useSiteInfo: out _, isOptional: true); + UseSiteInfo info; + var ctorSymbol = (MethodSymbol)Binder.GetWellKnownTypeMember(this, constructor, out info, isOptional: true); if ((object)ctorSymbol == null) { @@ -412,7 +413,7 @@ internal override ITypeSymbolInternal CommonGetWellKnownType(WellKnownType wellk var builder = new ArrayBuilder>(namedArguments.Length); foreach (var arg in namedArguments) { - var wellKnownMember = Binder.GetWellKnownTypeMember(this, arg.Key, useSiteInfo: out _, isOptional: true); + var wellKnownMember = Binder.GetWellKnownTypeMember(this, arg.Key, out info, isOptional: true); if (wellKnownMember == null || wellKnownMember is ErrorTypeSymbol) { // if this assert fails, UseSiteErrors for "member" have not been checked before emitting ... @@ -543,9 +544,9 @@ internal void EnsureNativeIntegerAttributeExists(BindingDiagnosticBag? diagnosti EnsureEmbeddableAttributeExists(EmbeddableAttributes.NativeIntegerAttribute, diagnostics, location, modifyCompilation); } - internal void EnsureScopedRefAttributeExists(BindingDiagnosticBag? diagnostics, Location location, bool modifyCompilation) + internal void EnsureLifetimeAnnotationAttributeExists(BindingDiagnosticBag? diagnostics, Location location, bool modifyCompilation) { - EnsureEmbeddableAttributeExists(EmbeddableAttributes.ScopedRefAttribute, diagnostics, location, modifyCompilation); + EnsureEmbeddableAttributeExists(EmbeddableAttributes.LifetimeAnnotationAttribute, diagnostics, location, modifyCompilation); } internal bool CheckIfAttributeShouldBeEmbedded(EmbeddableAttributes attribute, BindingDiagnosticBag? diagnosticsOpt, Location locationOpt) @@ -606,12 +607,12 @@ internal bool CheckIfAttributeShouldBeEmbedded(EmbeddableAttributes attribute, B WellKnownMember.System_Runtime_CompilerServices_NativeIntegerAttribute__ctor, WellKnownMember.System_Runtime_CompilerServices_NativeIntegerAttribute__ctorTransformFlags); - case EmbeddableAttributes.ScopedRefAttribute: + case EmbeddableAttributes.LifetimeAnnotationAttribute: return CheckIfAttributeShouldBeEmbedded( diagnosticsOpt, locationOpt, - WellKnownType.System_Runtime_CompilerServices_ScopedRefAttribute, - WellKnownMember.System_Runtime_CompilerServices_ScopedRefAttribute__ctor); + WellKnownType.System_Runtime_CompilerServices_LifetimeAnnotationAttribute, + WellKnownMember.System_Runtime_CompilerServices_LifetimeAnnotationAttribute__ctor); default: throw ExceptionUtilities.UnexpectedValue(attribute); diff --git a/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs b/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs index 4f810253cade2..1aaa271c757ce 100644 --- a/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs +++ b/src/Compilers/CSharp/Portable/Symbols/DeclarationScope.cs @@ -6,7 +6,7 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols { // https://github.com/dotnet/roslyn/issues/61647: Internally, scope is represented with this enum, // but the public API uses a pair of IsRefScoped and IsValueScoped bools (see ILocalSymbol, - // IParameterSymbol, and ScopedRefAttribute). We should have a common representation. + // IParameterSymbol, and LifetimeAnnotationAttribute). We should have a common representation. // And we should use common terms for the attribute and enum names. internal enum DeclarationScope : byte { diff --git a/src/Compilers/CSharp/Portable/Symbols/EmbeddableAttributes.cs b/src/Compilers/CSharp/Portable/Symbols/EmbeddableAttributes.cs index d50efa69a818e..7b90cb00b6461 100644 --- a/src/Compilers/CSharp/Portable/Symbols/EmbeddableAttributes.cs +++ b/src/Compilers/CSharp/Portable/Symbols/EmbeddableAttributes.cs @@ -16,6 +16,6 @@ internal enum EmbeddableAttributes NullableContextAttribute = 0x10, NullablePublicOnlyAttribute = 0x20, NativeIntegerAttribute = 0x40, - ScopedRefAttribute = 0x80, + LifetimeAnnotationAttribute = 0x80, } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs index 8ba3eff6c790e..7bf85f26e74f1 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs @@ -270,6 +270,7 @@ private PEParameterSymbol( if (inOutFlags == ParameterAttributes.Out) { refKind = RefKind.Out; + scope = DeclarationScope.RefScoped; } else if (moduleSymbol.Module.HasIsReadOnlyAttribute(handle)) { @@ -293,24 +294,16 @@ private PEParameterSymbol( typeWithAnnotations = NullableTypeDecoder.TransformType(typeWithAnnotations, handle, moduleSymbol, accessSymbol: accessSymbol, nullableContext: nullableContext); typeWithAnnotations = TupleTypeDecoder.DecodeTupleTypesIfApplicable(typeWithAnnotations, handle, moduleSymbol); - if (refKind == RefKind.Out) - { - scope = DeclarationScope.RefScoped; - } - else if (_moduleSymbol.Module.HasScopedRefAttribute(_handle)) + if (_moduleSymbol.Module.HasLifetimeAnnotationAttribute(_handle, out var pair)) { - if (isByRef) - { - Debug.Assert(refKind != RefKind.None); - scope = DeclarationScope.RefScoped; - } - else if (typeWithAnnotations.Type.IsRefLikeType) + var scopeOpt = GetScope(refKind, typeWithAnnotations.Type, pair.IsRefScoped, pair.IsValueScoped); + if (scopeOpt is null) { - scope = DeclarationScope.ValueScoped; + isBad = true; } else { - isBad = true; + scope = scopeOpt.GetValueOrDefault(); } } } @@ -987,6 +980,16 @@ public override ImmutableArray DeclaringSyntaxReferences internal sealed override DeclarationScope Scope => _packedFlags.Scope; + private static DeclarationScope? GetScope(RefKind refKind, TypeSymbol type, bool isRefScoped, bool isValueScoped) + { + return (isRefScoped, isValueScoped) switch + { + (false, false) => DeclarationScope.Unscoped, + (true, false) => refKind != RefKind.None ? DeclarationScope.RefScoped : null, + (_, true) => type.IsRefLikeType ? DeclarationScope.ValueScoped : null, + }; + } + public override ImmutableArray GetAttributes() { if (_lazyCustomAttributes.IsDefault) @@ -1028,7 +1031,7 @@ public override ImmutableArray GetAttributes() out _, filterIsReadOnlyAttribute ? AttributeDescription.IsReadOnlyAttribute : default, out _, - AttributeDescription.ScopedRefAttribute, + AttributeDescription.LifetimeAnnotationAttribute, out _, default); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs index 4867c9244a389..6efcfb471c5d8 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/LocalFunctionSymbol.cs @@ -195,7 +195,7 @@ private void ComputeParameters() var compilation = DeclaringCompilation; ParameterHelpers.EnsureIsReadOnlyAttributeExists(compilation, parameters, diagnostics, modifyCompilation: false); ParameterHelpers.EnsureNativeIntegerAttributeExists(compilation, parameters, diagnostics, modifyCompilation: false); - ParameterHelpers.EnsureScopedRefAttributeExists(compilation, parameters, diagnostics, modifyCompilation: false); + ParameterHelpers.EnsureLifetimeAnnotationAttributeExists(compilation, parameters, diagnostics, modifyCompilation: false); ParameterHelpers.EnsureNullableAttributeExists(compilation, this, parameters, diagnostics, modifyCompilation: false); // Note: we don't need to warn on annotations used in #nullable disable context for local functions, as this is handled in binding already diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs index b00972c7de297..6ee4c2db96bac 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs @@ -306,7 +306,7 @@ private static void EnsureNativeIntegerAttributeExists(CSharpCompilation compila } } - internal static bool RequiresScopedRefAttribute(ParameterSymbol parameter) + internal static bool RequiresLifetimeAnnotationAttribute(ParameterSymbol parameter) { Debug.Assert(!parameter.IsThis); @@ -322,12 +322,12 @@ internal static bool RequiresScopedRefAttribute(ParameterSymbol parameter) return true; } - internal static void EnsureScopedRefAttributeExists(PEModuleBuilder moduleBuilder, ImmutableArray parameters) + internal static void EnsureLifetimeAnnotationAttributeExists(PEModuleBuilder moduleBuilder, ImmutableArray parameters) { - EnsureScopedRefAttributeExists(moduleBuilder.Compilation, parameters, diagnostics: null, modifyCompilation: false, moduleBuilder); + EnsureLifetimeAnnotationAttributeExists(moduleBuilder.Compilation, parameters, diagnostics: null, modifyCompilation: false, moduleBuilder); } - internal static void EnsureScopedRefAttributeExists(CSharpCompilation? compilation, ImmutableArray parameters, BindingDiagnosticBag diagnostics, bool modifyCompilation) + internal static void EnsureLifetimeAnnotationAttributeExists(CSharpCompilation? compilation, ImmutableArray parameters, BindingDiagnosticBag diagnostics, bool modifyCompilation) { // These parameters might not come from a compilation (example: lambdas evaluated in EE). // During rewriting, lowering will take care of flagging the appropriate PEModuleBuilder instead. @@ -336,22 +336,22 @@ internal static void EnsureScopedRefAttributeExists(CSharpCompilation? compilati return; } - EnsureScopedRefAttributeExists(compilation, parameters, diagnostics, modifyCompilation, moduleBuilder: null); + EnsureLifetimeAnnotationAttributeExists(compilation, parameters, diagnostics, modifyCompilation, moduleBuilder: null); } - private static void EnsureScopedRefAttributeExists(CSharpCompilation compilation, ImmutableArray parameters, BindingDiagnosticBag? diagnostics, bool modifyCompilation, PEModuleBuilder? moduleBuilder) + private static void EnsureLifetimeAnnotationAttributeExists(CSharpCompilation compilation, ImmutableArray parameters, BindingDiagnosticBag? diagnostics, bool modifyCompilation, PEModuleBuilder? moduleBuilder) { foreach (var parameter in parameters) { - if (RequiresScopedRefAttribute(parameter)) + if (RequiresLifetimeAnnotationAttribute(parameter)) { if (moduleBuilder is { }) { - moduleBuilder.EnsureScopedRefAttributeExists(); + moduleBuilder.EnsureLifetimeAnnotationAttributeExists(); } else { - compilation.EnsureScopedRefAttributeExists(diagnostics, GetParameterLocation(parameter), modifyCompilation); + compilation.EnsureLifetimeAnnotationAttributeExists(diagnostics, GetParameterLocation(parameter), modifyCompilation); } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs index 20673caf3d46e..49d06f3996bf4 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs @@ -94,7 +94,7 @@ internal sealed override void AfterAddingTypeMembersChecks(ConversionsBase conve var compilation = DeclaringCompilation; ParameterHelpers.EnsureIsReadOnlyAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); ParameterHelpers.EnsureNativeIntegerAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.EnsureScopedRefAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); + ParameterHelpers.EnsureLifetimeAnnotationAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); ParameterHelpers.EnsureNullableAttributeExists(compilation, this, Parameters, diagnostics, modifyCompilation: true); foreach (var parameter in this.Parameters) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs index f24beead08d5d..d5a9dbde6cf71 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs @@ -340,7 +340,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, } ParameterHelpers.EnsureNativeIntegerAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.EnsureScopedRefAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); + ParameterHelpers.EnsureLifetimeAnnotationAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); if (compilation.ShouldEmitNullableAttributes(this) && ReturnTypeWithAnnotations.NeedsNullableAttribute()) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodOrUserDefinedOperatorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodOrUserDefinedOperatorSymbol.cs index 32847d1f0f362..c952b7a10b125 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodOrUserDefinedOperatorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodOrUserDefinedOperatorSymbol.cs @@ -261,7 +261,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, ParameterHelpers.EnsureNativeIntegerAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.EnsureScopedRefAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); + ParameterHelpers.EnsureLifetimeAnnotationAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); if (compilation.ShouldEmitNullableAttributes(this) && ReturnTypeWithAnnotations.NeedsNullableAttribute()) { diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceParameterSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceParameterSymbolBase.cs index 9ada805de7ade..96700c3745f60 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceParameterSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceParameterSymbolBase.cs @@ -99,9 +99,9 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeNativeIntegerAttribute(this, type.Type)); } - if (ParameterHelpers.RequiresScopedRefAttribute(this)) + if (ParameterHelpers.RequiresLifetimeAnnotationAttribute(this)) { - AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeScopedRefAttribute(this, Scope)); + AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeLifetimeAnnotationAttribute(this, Scope)); } if (type.Type.ContainsTupleNames()) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs index 9b9a73fc39f4d..f597228d91dec 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs @@ -835,7 +835,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, ParameterHelpers.EnsureNativeIntegerAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); - ParameterHelpers.EnsureScopedRefAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); + ParameterHelpers.EnsureLifetimeAnnotationAttributeExists(compilation, Parameters, diagnostics, modifyCompilation: true); if (compilation.ShouldEmitNullableAttributes(this) && this.TypeWithAnnotations.NeedsNullableAttribute()) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol.cs index 7cabcd56d7b5a..3214a32987e8b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol.cs @@ -3,31 +3,58 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; using System.Collections.Immutable; +using System.Linq; +using Microsoft.CodeAnalysis.PooledObjects; namespace Microsoft.CodeAnalysis.CSharp.Symbols { - internal sealed class SynthesizedEmbeddedScopedRefAttributeSymbol : SynthesizedEmbeddedAttributeSymbolBase + internal sealed class SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol : SynthesizedEmbeddedAttributeSymbolBase { + private readonly ImmutableArray _fields; private readonly ImmutableArray _constructors; - public SynthesizedEmbeddedScopedRefAttributeSymbol( + public SynthesizedEmbeddedLifetimeAnnotationAttributeSymbol( string name, NamespaceSymbol containingNamespace, ModuleSymbol containingModule, - NamedTypeSymbol systemAttributeType) + NamedTypeSymbol systemAttributeType, + TypeSymbol boolType) : base(name, containingNamespace, containingModule, baseType: systemAttributeType) { + _fields = ImmutableArray.Create( + new SynthesizedFieldSymbol(this, boolType, "IsRefScoped", isPublic: true, isReadOnly: true, isStatic: false), + new SynthesizedFieldSymbol(this, boolType, "IsValueScoped", isPublic: true, isReadOnly: true, isStatic: false)); + _constructors = ImmutableArray.Create( new SynthesizedEmbeddedAttributeConstructorWithBodySymbol( this, - getParameters: m => ImmutableArray.Empty, - getConstructorBody: (_, _, _) => { })); + m => ImmutableArray.Create( + SynthesizedParameterSymbol.Create(m, TypeWithAnnotations.Create(boolType), 0, RefKind.None), + SynthesizedParameterSymbol.Create(m, TypeWithAnnotations.Create(boolType), 1, RefKind.None)), + (f, s, p) => GenerateConstructorBody(f, s, p))); } + internal override IEnumerable GetFieldsToEmit() => _fields; + public override ImmutableArray Constructors => _constructors; internal override AttributeUsageInfo GetAttributeUsageInfo() => new AttributeUsageInfo(AttributeTargets.Parameter, allowMultiple: false, inherited: false); + + private void GenerateConstructorBody(SyntheticBoundNodeFactory factory, ArrayBuilder statements, ImmutableArray parameters) + { + statements.Add( + factory.ExpressionStatement( + factory.AssignmentExpression( + factory.Field(factory.This(), _fields[0]), + factory.Parameter(parameters[0])))); + statements.Add( + factory.ExpressionStatement( + factory.AssignmentExpression( + factory.Field(factory.This(), _fields[1]), + factory.Parameter(parameters[1])))); + } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs index cbd6796524734..79a23c89a71fc 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedParameterSymbol.cs @@ -160,9 +160,9 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeNativeIntegerAttribute(this, type.Type)); } - if (ParameterHelpers.RequiresScopedRefAttribute(this)) + if (ParameterHelpers.RequiresLifetimeAnnotationAttribute(this)) { - AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeScopedRefAttribute(this, Scope)); + AddSynthesizedAttribute(ref attributes, moduleBuilder.SynthesizeLifetimeAnnotationAttribute(this, Scope)); } if (type.Type.ContainsTupleNames() && diff --git a/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs b/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs index 8363034cc9644..59bb3ecc163d4 100644 --- a/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs +++ b/src/Compilers/CSharp/Test/Emit2/Attributes/AttributeTests_LifetimeAnnotation.cs @@ -17,14 +17,21 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests { - public class AttributeTests_ScopedRef : CSharpTestBase + public class AttributeTests_LifetimeAnnotation : CSharpTestBase { - private const string ScopedRefAttributeDefinition = + private const string LifetimeAnnotationAttributeDefinition = @"namespace System.Runtime.CompilerServices { - [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] - public sealed class ScopedRefAttribute : Attribute + [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] + public sealed class LifetimeAnnotationAttribute : Attribute { + public LifetimeAnnotationAttribute(bool isRefScoped, bool isValueScoped) + { + IsRefScoped = isRefScoped; + IsValueScoped = isValueScoped; + } + public bool IsRefScoped { get; } + public bool IsValueScoped { get; } } }"; @@ -36,22 +43,22 @@ public void ExplicitAttribute_FromSource() { public static void F(scoped ref int i) { } }"; - var comp = CreateCompilation(new[] { ScopedRefAttributeDefinition, source }); + var comp = CreateCompilation(new[] { LifetimeAnnotationAttributeDefinition, source }); var expected = @" void Program.F(ref System.Int32 i) - [ScopedRef] ref System.Int32 i + [LifetimeAnnotation(True, False)] ref System.Int32 i "; CompileAndVerify(comp, symbolValidator: module => { - Assert.Equal("System.Runtime.CompilerServices.ScopedRefAttribute", GetScopedRefType(module).ToTestDisplayString()); - AssertScopedRefAttributes(module, expected); + Assert.Equal("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", GetLifetimeAnnotationType(module).ToTestDisplayString()); + AssertLifetimeAnnotationAttributes(module, expected); }); } [Fact] public void ExplicitAttribute_FromMetadata() { - var comp = CreateCompilation(ScopedRefAttributeDefinition); + var comp = CreateCompilation(LifetimeAnnotationAttributeDefinition); comp.VerifyDiagnostics(); var ref0 = comp.EmitToImageReference(); @@ -63,12 +70,12 @@ public static void F(scoped ref int i) { } comp = CreateCompilation(source, references: new[] { ref0 }); var expected = @"void Program.F(ref System.Int32 i) - [ScopedRef] ref System.Int32 i + [LifetimeAnnotation(True, False)] ref System.Int32 i "; CompileAndVerify(comp, symbolValidator: module => { - Assert.Null(GetScopedRefType(module)); - AssertScopedRefAttributes(module, expected); + Assert.Null(GetLifetimeAnnotationType(module)); + AssertLifetimeAnnotationAttributes(module, expected); }); } @@ -78,9 +85,11 @@ public void ExplicitAttribute_MissingConstructor() var source1 = @"namespace System.Runtime.CompilerServices { - public sealed class ScopedRefAttribute : Attribute + public sealed class LifetimeAnnotationAttribute : Attribute { - public ScopedRefAttribute(int i) { } + public LifetimeAnnotationAttribute() { } + public bool IsRefScoped { get; } + public bool IsValueScoped { get; } } }"; var source2 = @@ -90,9 +99,9 @@ public static void F(scoped ref int i) { } }"; var comp = CreateCompilation(new[] { source1, source2 }); comp.VerifyEmitDiagnostics( - // (3,26): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.ScopedRefAttribute..ctor' + // (3,26): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.LifetimeAnnotationAttribute..ctor' // public static void F(scoped ref int i) { } - Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "scoped ref int i").WithArguments("System.Runtime.CompilerServices.ScopedRefAttribute", ".ctor").WithLocation(3, 26)); + Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "scoped ref int i").WithArguments("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", ".ctor").WithLocation(3, 26)); } [WorkItem(62124, "https://github.com/dotnet/roslyn/issues/62124")] @@ -101,16 +110,16 @@ public void ExplicitAttribute_ReferencedInSource_01() { var source = @"using System.Runtime.CompilerServices; -delegate void D([ScopedRef] ref int i); +delegate void D([LifetimeAnnotation(true, false)] ref int i); class Program { - public static void Main([ScopedRef] string[] args) + public static void Main([LifetimeAnnotation(false, true)] string[] args) { - D d = ([ScopedRef] ref int i) => { }; + D d = ([LifetimeAnnotation(true, false)] ref int i) => { }; } }"; - var comp = CreateCompilation(new[] { ScopedRefAttributeDefinition, source }); - // https://github.com/dotnet/roslyn/issues/62124: Re-enable check for ScopedRefAttribute in ReportExplicitUseOfReservedAttributes. + var comp = CreateCompilation(new[] { LifetimeAnnotationAttributeDefinition, source }); + // https://github.com/dotnet/roslyn/issues/62124: Re-enable check for LifetimeAnnotationAttribute in ReportExplicitUseOfReservedAttributes. comp.VerifyDiagnostics(); } @@ -121,42 +130,34 @@ public void ExplicitAttribute_ReferencedInSource_02() var source = @"using System; using System.Runtime.CompilerServices; -[module: ScopedRef] -[ScopedRef] class Program -{ - [ScopedRef] object F; - [ScopedRef] event EventHandler E; - [ScopedRef] object P { get; } - [ScopedRef] static object M1() => throw null; - [ScopedRef] static object M2() => throw null; - static void M3<[ScopedRef] T>() { } -} -namespace System.Runtime.CompilerServices +[module: LifetimeAnnotation(false, true)] +[LifetimeAnnotation(false, true)] class Program { - [AttributeUsage(AttributeTargets.All, AllowMultiple = false, Inherited = false)] - public sealed class ScopedRefAttribute : Attribute - { - } -} -"; - var comp = CreateCompilation(source); - // https://github.com/dotnet/roslyn/issues/62124: Re-enable check for ScopedRefAttribute in ReportExplicitUseOfReservedAttributes. + [LifetimeAnnotation(false, true)] object F; + [LifetimeAnnotation(false, true)] event EventHandler E; + [LifetimeAnnotation(false, true)] object P { get; } + [LifetimeAnnotation(false, true)] static object M1() => throw null; + [return: LifetimeAnnotation(false, true)] static object M2() => throw null; + static void M3<[LifetimeAnnotation(false, true)] T>() { } +}"; + var comp = CreateCompilation(new[] { LifetimeAnnotationAttributeDefinition, source }); + // https://github.com/dotnet/roslyn/issues/62124: Re-enable check for LifetimeAnnotationAttribute in ReportExplicitUseOfReservedAttributes. comp.VerifyDiagnostics( - // (6,24): warning CS0169: The field 'Program.F' is never used - // [ScopedRef] object F; - Diagnostic(ErrorCode.WRN_UnreferencedField, "F").WithArguments("Program.F").WithLocation(6, 24), - // (7,36): warning CS0067: The event 'Program.E' is never used - // [ScopedRef] event EventHandler E; - Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("Program.E").WithLocation(7, 36)); + // (6,46): warning CS0169: The field 'Program.F' is never used + // [LifetimeAnnotation(false, true)] object F; + Diagnostic(ErrorCode.WRN_UnreferencedField, "F").WithArguments("Program.F").WithLocation(6, 46), + // (7,58): warning CS0067: The event 'Program.E' is never used + // [LifetimeAnnotation(false, true)] event EventHandler E; + Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("Program.E").WithLocation(7, 58)); } [Fact] public void ExplicitAttribute_UnexpectedParameterTargets() { var source0 = -@".class private System.Runtime.CompilerServices.ScopedRefAttribute extends [mscorlib]System.Attribute +@".class private System.Runtime.CompilerServices.LifetimeAnnotationAttribute extends [mscorlib]System.Attribute { - .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { ret } + .method public hidebysig specialname rtspecialname instance void .ctor(bool isRefScoped, bool isValueScoped) cil managed { ret } } .class public sealed R extends [mscorlib]System.ValueType { @@ -168,25 +169,25 @@ .class public A .method public static void F1(valuetype R r) { .param [1] - .custom instance void System.Runtime.CompilerServices.ScopedRefAttribute::.ctor() = ( 01 00 00 00 ) // ScopedRefAttribute() + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor(bool, bool) = ( 01 00 01 00 00 00 ) // LifetimeAnnotationAttribute(isRefScoped: true, isValueScoped: false) ret } .method public static void F2(int32 y) { .param [1] - .custom instance void System.Runtime.CompilerServices.ScopedRefAttribute::.ctor() = ( 01 00 00 00 ) // ScopedRefAttribute() + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor(bool, bool) = ( 01 00 00 01 00 00 ) // LifetimeAnnotationAttribute(isRefScoped: false, isValueScoped: true) ret } .method public static void F3(object x, int32& y) { .param [2] - .custom instance void System.Runtime.CompilerServices.ScopedRefAttribute::.ctor() = ( 01 00 00 00 ) // ScopedRefAttribute() + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor(bool, bool) = ( 01 00 00 01 00 00 ) // LifetimeAnnotationAttribute(isRefScoped: false, isValueScoped: true) ret } .method public static void F4(valuetype R& r) { .param [1] - .custom instance void System.Runtime.CompilerServices.ScopedRefAttribute::.ctor() = ( 01 00 00 00 ) // ScopedRefAttribute() + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor(bool, bool) = ( 01 00 01 01 00 00 ) // LifetimeAnnotationAttribute(isRefScoped: true, isValueScoped: true) ret } } @@ -209,38 +210,29 @@ static void Main() }"; var comp = CreateCompilation(source1, references: new[] { ref0 }); comp.VerifyDiagnostics( + // (6,11): error CS0570: 'A.F1(R)' is not supported by the language + // A.F1(r); + Diagnostic(ErrorCode.ERR_BindToBogus, "F1").WithArguments("A.F1(R)").WithLocation(6, 11), // (7,11): error CS0570: 'A.F2(int)' is not supported by the language // A.F2(2); - Diagnostic(ErrorCode.ERR_BindToBogus, "F2").WithArguments("A.F2(int)").WithLocation(7, 11)); + Diagnostic(ErrorCode.ERR_BindToBogus, "F2").WithArguments("A.F2(int)").WithLocation(7, 11), + // (10,11): error CS0570: 'A.F3(object, ref int)' is not supported by the language + // A.F3(x, ref y); + Diagnostic(ErrorCode.ERR_BindToBogus, "F3").WithArguments("A.F3(object, ref int)").WithLocation(10, 11)); - var method = comp.GetMember("A.F1"); - Assert.Equal("void A.F1(scoped R r)", method.ToDisplayString(SymbolDisplayFormat.TestFormat.WithCompilerInternalOptions(SymbolDisplayCompilerInternalOptions.IncludeScoped))); + var method = comp.GetMember("A.F4"); + Assert.Equal("void A.F4(ref scoped R r)", method.ToDisplayString(SymbolDisplayFormat.TestFormat.WithCompilerInternalOptions(SymbolDisplayCompilerInternalOptions.IncludeScoped))); var parameter = method.Parameters[0]; Assert.Equal(DeclarationScope.ValueScoped, parameter.Scope); - - method = comp.GetMember("A.F2"); - Assert.Equal("void A.F2(System.Int32 y)", method.ToDisplayString(SymbolDisplayFormat.TestFormat.WithCompilerInternalOptions(SymbolDisplayCompilerInternalOptions.IncludeScoped))); - parameter = method.Parameters[0]; - Assert.Equal(DeclarationScope.Unscoped, parameter.Scope); - - method = comp.GetMember("A.F3"); - Assert.Equal("void A.F3(System.Object x, scoped ref System.Int32 y)", method.ToDisplayString(SymbolDisplayFormat.TestFormat.WithCompilerInternalOptions(SymbolDisplayCompilerInternalOptions.IncludeScoped))); - parameter = method.Parameters[1]; - Assert.Equal(DeclarationScope.RefScoped, parameter.Scope); - - method = comp.GetMember("A.F4"); - Assert.Equal("void A.F4(scoped ref R r)", method.ToDisplayString(SymbolDisplayFormat.TestFormat.WithCompilerInternalOptions(SymbolDisplayCompilerInternalOptions.IncludeScoped))); - parameter = method.Parameters[0]; - Assert.Equal(DeclarationScope.RefScoped, parameter.Scope); } [Fact] public void ExplicitAttribute_UnexpectedAttributeConstructor() { var source0 = -@".class private System.Runtime.CompilerServices.ScopedRefAttribute extends [mscorlib]System.Attribute +@".class private System.Runtime.CompilerServices.LifetimeAnnotationAttribute extends [mscorlib]System.Attribute { - .method public hidebysig specialname rtspecialname instance void .ctor(bool isRefScoped, bool isValueScoped) cil managed { ret } + .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { ret } } .class public sealed R extends [mscorlib]System.ValueType { @@ -252,13 +244,13 @@ .class public A .method public static void F1(valuetype R r) { .param [1] - .custom instance void System.Runtime.CompilerServices.ScopedRefAttribute::.ctor(bool, bool) = ( 01 00 00 01 00 00 ) // ScopedRefAttribute(isRefScoped: false, isValueScoped: true) + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor() = ( 01 00 00 00 ) // LifetimeAnnotationAttribute() ret } .method public static void F2(object x, int32& y) { .param [2] - .custom instance void System.Runtime.CompilerServices.ScopedRefAttribute::.ctor(bool, bool) = ( 01 00 01 00 00 00 ) // ScopedRefAttribute(isRefScoped: true, isValueScoped: false) + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor() = ( 01 00 00 00 ) // LifetimeAnnotationAttribute() ret } } @@ -277,7 +269,7 @@ static void Main() } }"; var comp = CreateCompilation(source1, references: new[] { ref0 }); - // https://github.com/dotnet/roslyn/issues/61647: If the [ScopedRef] scoped value is an int + // https://github.com/dotnet/roslyn/issues/61647: If the [LifetimeAnnotation] scoped value is an int // rather than a pair of bools, the compiler should reject attribute values that it does not recognize. comp.VerifyDiagnostics(); } @@ -297,19 +289,19 @@ public static void F(scoped R r) { } var comp = CreateCompilation(source); var expected = @"S..ctor(ref System.Int32 i) - [ScopedRef] ref System.Int32 i + [LifetimeAnnotation(True, False)] ref System.Int32 i void S.F(R r) - [ScopedRef] R r + [LifetimeAnnotation(False, True)] R r S S.op_Addition(S a, in R b) S a - [ScopedRef] in R b + [LifetimeAnnotation(True, False)] in R b System.Object S.this[in System.Int32 i].get - [ScopedRef] in System.Int32 i + [LifetimeAnnotation(True, False)] in System.Int32 i "; CompileAndVerify(comp, symbolValidator: module => { - Assert.Equal("System.Runtime.CompilerServices.ScopedRefAttribute", GetScopedRefType(module).ToTestDisplayString()); - AssertScopedRefAttributes(module, expected); + Assert.Equal("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", GetLifetimeAnnotationType(module).ToTestDisplayString()); + AssertLifetimeAnnotationAttributes(module, expected); }); } @@ -329,8 +321,8 @@ public static void F(out int x, out R y) var comp = CreateCompilation(source); CompileAndVerify(comp, symbolValidator: module => { - Assert.Null(GetScopedRefType(module)); - AssertScopedRefAttributes(module, ""); + Assert.Null(GetLifetimeAnnotationType(module)); + AssertLifetimeAnnotationAttributes(module, ""); }); } @@ -350,8 +342,8 @@ public static void F(scoped out int x, scoped out R y) var comp = CreateCompilation(source); CompileAndVerify(comp, symbolValidator: module => { - Assert.Null(GetScopedRefType(module)); - AssertScopedRefAttributes(module, ""); + Assert.Null(GetLifetimeAnnotationType(module)); + AssertLifetimeAnnotationAttributes(module, ""); }); } @@ -365,15 +357,15 @@ public void EmitAttribute_DelegateParameters() var comp = CreateCompilation(source); var expected = @"void D.Invoke(in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x, R y) - [ScopedRef] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x - [ScopedRef] R y + [LifetimeAnnotation(True, False)] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x + [LifetimeAnnotation(False, True)] R y System.IAsyncResult D.BeginInvoke(in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x, R y, System.AsyncCallback callback, System.Object @object) - [ScopedRef] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x - [ScopedRef] R y + [LifetimeAnnotation(True, False)] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x + [LifetimeAnnotation(False, True)] R y System.AsyncCallback callback System.Object @object void D.EndInvoke(in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x, System.IAsyncResult result) - [ScopedRef] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x + [LifetimeAnnotation(True, False)] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 x System.IAsyncResult result "; CompileAndVerify( @@ -381,8 +373,8 @@ System.IAsyncResult result options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { - Assert.Equal("System.Runtime.CompilerServices.ScopedRefAttribute", GetScopedRefType(module).ToTestDisplayString()); - AssertScopedRefAttributes(module, expected); + Assert.Equal("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", GetLifetimeAnnotationType(module).ToTestDisplayString()); + AssertLifetimeAnnotationAttributes(module, expected); }); } @@ -402,24 +394,25 @@ static void Main() var comp = CreateCompilation(source); var expected = @"void D.Invoke(in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i) - [ScopedRef] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i + [LifetimeAnnotation(True, False)] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i System.IAsyncResult D.BeginInvoke(in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i, System.AsyncCallback callback, System.Object @object) - [ScopedRef] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i + [LifetimeAnnotation(True, False)] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i System.AsyncCallback callback System.Object @object void D.EndInvoke(in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i, System.IAsyncResult result) - [ScopedRef] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i + [LifetimeAnnotation(True, False)] in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 i System.IAsyncResult result void Program.<>c.
b__0_0(in System.Int32 i) - [ScopedRef] in System.Int32 i + [LifetimeAnnotation(True, False)] in System.Int32 i + "; CompileAndVerify( source, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { - Assert.Equal("System.Runtime.CompilerServices.ScopedRefAttribute", GetScopedRefType(module).ToTestDisplayString()); - AssertScopedRefAttributes(module, expected); + Assert.Equal("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", GetLifetimeAnnotationType(module).ToTestDisplayString()); + AssertLifetimeAnnotationAttributes(module, expected); }); } @@ -438,15 +431,15 @@ void L(scoped in int i) { } var comp = CreateCompilation(source); var expected = @"void Program.g__L|0_0(in System.Int32 i) - [ScopedRef] in System.Int32 i + [LifetimeAnnotation(True, False)] in System.Int32 i "; CompileAndVerify( source, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All), symbolValidator: module => { - Assert.Equal("System.Runtime.CompilerServices.ScopedRefAttribute", GetScopedRefType(module).ToTestDisplayString()); - AssertScopedRefAttributes(module, expected); + Assert.Equal("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", GetLifetimeAnnotationType(module).ToTestDisplayString()); + AssertLifetimeAnnotationAttributes(module, expected); }); } @@ -468,13 +461,13 @@ static void Main() var comp = CreateCompilation(source); var expected = @"void <>f__AnonymousDelegate0.Invoke(in System.Int32 value) - [ScopedRef] in System.Int32 value + [LifetimeAnnotation(True, False)] in System.Int32 value R <>f__AnonymousDelegate1.Invoke(R value) - [ScopedRef] R value + [LifetimeAnnotation(False, True)] R value void Program.<>c.
b__0_0(in System.Int32 i) - [ScopedRef] in System.Int32 i + [LifetimeAnnotation(True, False)] in System.Int32 i R Program.<>c.
b__0_1(R r) - [ScopedRef] R r + [LifetimeAnnotation(False, True)] R r "; CompileAndVerify( source, @@ -482,20 +475,20 @@ [ScopedRef] R r verify: Verification.Skipped, symbolValidator: module => { - Assert.Equal("System.Runtime.CompilerServices.ScopedRefAttribute", GetScopedRefType(module).ToTestDisplayString()); - AssertScopedRefAttributes(module, expected); + Assert.Equal("System.Runtime.CompilerServices.LifetimeAnnotationAttribute", GetLifetimeAnnotationType(module).ToTestDisplayString()); + AssertLifetimeAnnotationAttributes(module, expected); }); } - private static void AssertScopedRefAttributes(ModuleSymbol module, string expected) + private static void AssertLifetimeAnnotationAttributes(ModuleSymbol module, string expected) { - var actual = ScopedRefAttributesVisitor.GetString((PEModuleSymbol)module); + var actual = LifetimeAnnotationAttributesVisitor.GetString((PEModuleSymbol)module); AssertEx.AssertEqualToleratingWhitespaceDifferences(expected, actual); } - private static NamedTypeSymbol GetScopedRefType(ModuleSymbol module) + private static NamedTypeSymbol GetLifetimeAnnotationType(ModuleSymbol module) { - return module.GlobalNamespace.GetMember("System.Runtime.CompilerServices.ScopedRefAttribute"); + return module.GlobalNamespace.GetMember("System.Runtime.CompilerServices.LifetimeAnnotationAttribute"); } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index 92854472e3261..9d945efed5318 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -6854,6 +6854,47 @@ static void F7(scoped in scoped s) { } VerifyParameterSymbol(comp.GetMember("Program.FA").Parameters[0], "out scoped s", RefKind.Out, DeclarationScope.RefScoped); } + [Fact] + public void ParameterScope_10() + { + var source0 = +@".class private System.Runtime.CompilerServices.LifetimeAnnotationAttribute extends [mscorlib]System.Attribute +{ + .method public hidebysig specialname rtspecialname instance void .ctor(bool isRefScoped, bool isValueScoped) cil managed { ret } +} +.class public sealed R extends [mscorlib]System.ValueType +{ + .custom instance void [mscorlib]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor() = (01 00 00 00) + .field public int32& modreq(int32) F +} +.class public A +{ + .method public static void F(valuetype R r) + { + .param [1] + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor(bool, bool) = ( 01 00 00 00 00 00 ) // LifetimeAnnotationAttribute(isRefScoped: false, isValueScoped: false) + ret + } +} +"; + var ref0 = CompileIL(source0); + + var source1 = +@"class Program +{ + static void Main() + { + var r = new R(); + A.F(r); + } +}"; + var comp = CreateCompilation(source1, references: new[] { ref0 }); + comp.VerifyDiagnostics(); + + var method = comp.GetMember("A.F"); + VerifyParameterSymbol(method.Parameters[0], "R r", RefKind.None, DeclarationScope.Unscoped); + } + [WorkItem(62080, "https://github.com/dotnet/roslyn/issues/62080")] [Fact] public void ParameterScope_11() @@ -6889,16 +6930,23 @@ static void Main() public void ParameterScope_12() { var source0 = -@".class private System.Runtime.CompilerServices.ScopedRefAttribute extends [mscorlib]System.Attribute +@".class private System.Runtime.CompilerServices.LifetimeAnnotationAttribute extends [mscorlib]System.Attribute { - .method public hidebysig specialname rtspecialname instance void .ctor() cil managed { ret } + .method public hidebysig specialname rtspecialname instance void .ctor(bool isRefScoped, bool isValueScoped) cil managed { ret } } .class public A { .method public static void F1([out] int32& i) { .param [1] - .custom instance void System.Runtime.CompilerServices.ScopedRefAttribute::.ctor() = ( 01 00 00 00 ) // ScopedRefAttribute() + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor(bool, bool) = ( 01 00 01 00 00 00 ) // LifetimeAnnotationAttribute(isRefScoped: true, isValueScoped: false) + ldnull + throw + } + .method public static void F2([out] int32& i) + { + .param [1] + .custom instance void System.Runtime.CompilerServices.LifetimeAnnotationAttribute::.ctor(bool, bool) = ( 01 00 00 00 00 00 ) // LifetimeAnnotationAttribute(isRefScoped: false, isValueScoped: false) ldnull throw } @@ -6913,12 +6961,14 @@ static void Main() { int i; A.F1(out i); + A.F2(out i); } }"; var comp = CreateCompilation(source1, references: new[] { ref0 }); comp.VerifyDiagnostics(); VerifyParameterSymbol(comp.GetMember("A.F1").Parameters[0], "out System.Int32 i", RefKind.Out, DeclarationScope.RefScoped); + VerifyParameterSymbol(comp.GetMember("A.F2").Parameters[0], "out System.Int32 i", RefKind.Out, DeclarationScope.Unscoped); } [Fact] @@ -7253,7 +7303,7 @@ private static void VerifyParameterSymbol(ParameterSymbol parameter, string expe Assert.Equal(expectedScope, parameter.Scope); Assert.Equal(expectedDisplayString, parameter.ToDisplayString(displayFormatWithScoped)); - var attribute = parameter.GetAttributes().FirstOrDefault(a => a.GetTargetAttributeSignatureIndex(parameter, AttributeDescription.ScopedRefAttribute) != -1); + var attribute = parameter.GetAttributes().FirstOrDefault(a => a.GetTargetAttributeSignatureIndex(parameter, AttributeDescription.LifetimeAnnotationAttribute) != -1); Assert.Null(attribute); VerifyParameterSymbol(parameter.GetPublicSymbol(), expectedDisplayString, expectedRefKind, expectedScope); diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs index 1959c70e93606..e61298854268a 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs @@ -614,7 +614,7 @@ public void AllWellKnownTypes() case WellKnownType.System_Runtime_CompilerServices_DefaultInterpolatedStringHandler: case WellKnownType.System_Runtime_CompilerServices_RequiredMemberAttribute: case WellKnownType.System_Diagnostics_CodeAnalysis_SetsRequiredMembersAttribute: - case WellKnownType.System_Runtime_CompilerServices_ScopedRefAttribute: + case WellKnownType.System_Runtime_CompilerServices_LifetimeAnnotationAttribute: case WellKnownType.System_MemoryExtensions: case WellKnownType.System_Runtime_CompilerServices_CompilerFeatureRequiredAttribute: // Not yet in the platform. @@ -976,7 +976,7 @@ public void AllWellKnownTypeMembers() case WellKnownMember.System_Runtime_CompilerServices_DefaultInterpolatedStringHandler__ToStringAndClear: case WellKnownMember.System_Runtime_CompilerServices_RequiredMemberAttribute__ctor: case WellKnownMember.System_Diagnostics_CodeAnalysis_SetsRequiredMembersAttribute__ctor: - case WellKnownMember.System_Runtime_CompilerServices_ScopedRefAttribute__ctor: + case WellKnownMember.System_Runtime_CompilerServices_LifetimeAnnotationAttribute__ctor: case WellKnownMember.System_MemoryExtensions__SequenceEqual_Span_T: case WellKnownMember.System_MemoryExtensions__SequenceEqual_ReadOnlySpan_T: case WellKnownMember.System_MemoryExtensions__AsSpan_String: diff --git a/src/Compilers/Core/Portable/MetadataReader/PEModule.cs b/src/Compilers/Core/Portable/MetadataReader/PEModule.cs index 00c344d3ce050..6117c5f32428d 100644 --- a/src/Compilers/Core/Portable/MetadataReader/PEModule.cs +++ b/src/Compilers/Core/Portable/MetadataReader/PEModule.cs @@ -1087,9 +1087,16 @@ internal bool HasNativeIntegerAttribute(EntityHandle token, out ImmutableArray tupleElementNames) diff --git a/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs b/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs index 205367fae0207..abe6c5d039722 100644 --- a/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs +++ b/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs @@ -334,6 +334,7 @@ static AttributeDescription() private static readonly byte[][] s_signaturesOfNullableAttribute = { s_signature_HasThis_Void_Byte, s_signature_HasThis_Void_SzArray_Byte }; private static readonly byte[][] s_signaturesOfNullableContextAttribute = { s_signature_HasThis_Void_Byte }; private static readonly byte[][] s_signaturesOfNativeIntegerAttribute = { s_signature_HasThis_Void, s_signature_HasThis_Void_SzArray_Boolean }; + private static readonly byte[][] s_signaturesOfLifetimeAnnotationAttribute = { s_signature_HasThis_Void_Boolean_Boolean }; private static readonly byte[][] s_signaturesOfInterpolatedStringArgumentAttribute = { s_signature_HasThis_Void_String, s_signature_HasThis_Void_SzArray_String }; // early decoded attributes: @@ -469,7 +470,7 @@ static AttributeDescription() internal static readonly AttributeDescription EnumeratorCancellationAttribute = new AttributeDescription("System.Runtime.CompilerServices", "EnumeratorCancellationAttribute", s_signatures_HasThis_Void_Only); internal static readonly AttributeDescription SkipLocalsInitAttribute = new AttributeDescription("System.Runtime.CompilerServices", "SkipLocalsInitAttribute", s_signatures_HasThis_Void_Only); internal static readonly AttributeDescription NativeIntegerAttribute = new AttributeDescription("System.Runtime.CompilerServices", "NativeIntegerAttribute", s_signaturesOfNativeIntegerAttribute); - internal static readonly AttributeDescription ScopedRefAttribute = new AttributeDescription("System.Runtime.CompilerServices", "ScopedRefAttribute", s_signatures_HasThis_Void_Only); + internal static readonly AttributeDescription LifetimeAnnotationAttribute = new AttributeDescription("System.Runtime.CompilerServices", "LifetimeAnnotationAttribute", s_signaturesOfLifetimeAnnotationAttribute); internal static readonly AttributeDescription ModuleInitializerAttribute = new AttributeDescription("System.Runtime.CompilerServices", "ModuleInitializerAttribute", s_signatures_HasThis_Void_Only); internal static readonly AttributeDescription UnmanagedCallersOnlyAttribute = new AttributeDescription("System.Runtime.InteropServices", "UnmanagedCallersOnlyAttribute", s_signatures_HasThis_Void_Only); internal static readonly AttributeDescription InterpolatedStringHandlerAttribute = new AttributeDescription("System.Runtime.CompilerServices", "InterpolatedStringHandlerAttribute", s_signatures_HasThis_Void_Only); diff --git a/src/Compilers/Core/Portable/WellKnownMember.cs b/src/Compilers/Core/Portable/WellKnownMember.cs index 67710436f5cb8..e32700fdbd918 100644 --- a/src/Compilers/Core/Portable/WellKnownMember.cs +++ b/src/Compilers/Core/Portable/WellKnownMember.cs @@ -522,7 +522,7 @@ internal enum WellKnownMember System_Runtime_CompilerServices_DefaultInterpolatedStringHandler__ToStringAndClear, System_Runtime_CompilerServices_RequiredMemberAttribute__ctor, System_Diagnostics_CodeAnalysis_SetsRequiredMembersAttribute__ctor, - System_Runtime_CompilerServices_ScopedRefAttribute__ctor, + System_Runtime_CompilerServices_LifetimeAnnotationAttribute__ctor, System_MemoryExtensions__SequenceEqual_Span_T, System_MemoryExtensions__SequenceEqual_ReadOnlySpan_T, diff --git a/src/Compilers/Core/Portable/WellKnownMembers.cs b/src/Compilers/Core/Portable/WellKnownMembers.cs index ef9135e334a78..66117afc0bbae 100644 --- a/src/Compilers/Core/Portable/WellKnownMembers.cs +++ b/src/Compilers/Core/Portable/WellKnownMembers.cs @@ -3583,12 +3583,14 @@ static WellKnownMembers() 0, // Method Signature (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Void, // Return Type - // System_Runtime_CompilerServices_ScopedRefAttribute__ctor + // System_Runtime_CompilerServices_LifetimeAnnotationAttribute__ctor (byte)MemberFlags.Constructor, // Flags - (byte)WellKnownType.ExtSentinel, (byte)(WellKnownType.System_Runtime_CompilerServices_ScopedRefAttribute - WellKnownType.ExtSentinel), // DeclaringTypeId + (byte)WellKnownType.ExtSentinel, (byte)(WellKnownType.System_Runtime_CompilerServices_LifetimeAnnotationAttribute - WellKnownType.ExtSentinel), // DeclaringTypeId 0, // Arity - 0, // Method Signature + 2, // Method Signature (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Void, // Return Type + (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Boolean, + (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Boolean, // System_MemoryExtensions__SequenceEqual_Span_T (byte)(MemberFlags.Method | MemberFlags.Static), // Flags diff --git a/src/Compilers/Core/Portable/WellKnownTypes.cs b/src/Compilers/Core/Portable/WellKnownTypes.cs index 4a51179a65f76..41bf3dc7e746d 100644 --- a/src/Compilers/Core/Portable/WellKnownTypes.cs +++ b/src/Compilers/Core/Portable/WellKnownTypes.cs @@ -314,7 +314,7 @@ internal enum WellKnownType System_Text_StringBuilder, System_Runtime_CompilerServices_DefaultInterpolatedStringHandler, - System_Runtime_CompilerServices_ScopedRefAttribute, + System_Runtime_CompilerServices_LifetimeAnnotationAttribute, System_ArgumentNullException, @@ -633,7 +633,7 @@ internal static class WellKnownTypes "System.Text.StringBuilder", "System.Runtime.CompilerServices.DefaultInterpolatedStringHandler", - "System.Runtime.CompilerServices.ScopedRefAttribute", + "System.Runtime.CompilerServices.LifetimeAnnotationAttribute", "System.ArgumentNullException", "System.Runtime.CompilerServices.RequiredMemberAttribute", diff --git a/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs b/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs index d6dd72234b633..6b967d09b0193 100644 --- a/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs +++ b/src/Compilers/Test/Utilities/CSharp/LifetimeAnnotationAttributesVisitor.cs @@ -14,19 +14,19 @@ namespace Microsoft.CodeAnalysis.CSharp.Test.Utilities { - internal sealed class ScopedRefAttributesVisitor : CSharpSymbolVisitor + internal sealed class LifetimeAnnotationAttributesVisitor : CSharpSymbolVisitor { internal static string GetString(PEModuleSymbol module) { var builder = new StringBuilder(); - var visitor = new ScopedRefAttributesVisitor(builder); + var visitor = new LifetimeAnnotationAttributesVisitor(builder); visitor.Visit(module); return builder.ToString(); } private readonly StringBuilder _builder; - private ScopedRefAttributesVisitor(StringBuilder builder) + private LifetimeAnnotationAttributesVisitor(StringBuilder builder) { _builder = builder; } @@ -73,7 +73,7 @@ public override void VisitProperty(PropertySymbol property) public override void VisitMethod(MethodSymbol method) { var parameters = method.Parameters; - if (!parameters.Any(p => TryGetScopedRefAttribute((PEParameterSymbol)p))) + if (!parameters.Any(p => TryGetLifetimeAnnotationAttribute((PEParameterSymbol)p, out _))) { return; } @@ -81,18 +81,18 @@ public override void VisitMethod(MethodSymbol method) foreach (var parameter in parameters) { _builder.Append(" "); - if (TryGetScopedRefAttribute((PEParameterSymbol)parameter)) + if (TryGetLifetimeAnnotationAttribute((PEParameterSymbol)parameter, out var pair)) { - _builder.Append($"[ScopedRef] "); + _builder.Append($"[LifetimeAnnotation({pair.IsRefScoped}, {pair.IsValueScoped})] "); } _builder.AppendLine(parameter.ToTestDisplayString()); } } - private bool TryGetScopedRefAttribute(PEParameterSymbol parameter) + private bool TryGetLifetimeAnnotationAttribute(PEParameterSymbol parameter, out (bool IsRefScoped, bool IsValueScoped) pair) { var module = ((PEModuleSymbol)parameter.ContainingModule).Module; - return module.HasScopedRefAttribute(parameter.Handle); + return module.HasLifetimeAnnotationAttribute(parameter.Handle, out pair); } } } diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb index 4877aa66b5003..200cfb8e6ecf0 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb @@ -551,7 +551,7 @@ End Namespace WellKnownType.System_Diagnostics_CodeAnalysis_SetsRequiredMembersAttribute, WellKnownType.System_MemoryExtensions, WellKnownType.System_Runtime_CompilerServices_CompilerFeatureRequiredAttribute, - WellKnownType.System_Runtime_CompilerServices_ScopedRefAttribute, + WellKnownType.System_Runtime_CompilerServices_LifetimeAnnotationAttribute, WellKnownType.System_MemoryExtensions ' Not available on all platforms. Continue For @@ -623,7 +623,7 @@ End Namespace WellKnownType.System_Diagnostics_CodeAnalysis_SetsRequiredMembersAttribute, WellKnownType.System_MemoryExtensions, WellKnownType.System_Runtime_CompilerServices_CompilerFeatureRequiredAttribute, - WellKnownType.System_Runtime_CompilerServices_ScopedRefAttribute + WellKnownType.System_Runtime_CompilerServices_LifetimeAnnotationAttribute ' Not available on all platforms. Continue For Case WellKnownType.ExtSentinel @@ -715,7 +715,7 @@ End Namespace WellKnownMember.System_Runtime_CompilerServices_DefaultInterpolatedStringHandler__ToStringAndClear, WellKnownMember.System_Runtime_CompilerServices_RequiredMemberAttribute__ctor, WellKnownMember.System_Diagnostics_CodeAnalysis_SetsRequiredMembersAttribute__ctor, - WellKnownMember.System_Runtime_CompilerServices_ScopedRefAttribute__ctor, + WellKnownMember.System_Runtime_CompilerServices_LifetimeAnnotationAttribute__ctor, WellKnownMember.System_MemoryExtensions__SequenceEqual_Span_T, WellKnownMember.System_MemoryExtensions__SequenceEqual_ReadOnlySpan_T, WellKnownMember.System_MemoryExtensions__AsSpan_String, @@ -867,7 +867,7 @@ End Namespace WellKnownMember.System_Runtime_CompilerServices_DefaultInterpolatedStringHandler__ToStringAndClear, WellKnownMember.System_Runtime_CompilerServices_RequiredMemberAttribute__ctor, WellKnownMember.System_Diagnostics_CodeAnalysis_SetsRequiredMembersAttribute__ctor, - WellKnownMember.System_Runtime_CompilerServices_ScopedRefAttribute__ctor, + WellKnownMember.System_Runtime_CompilerServices_LifetimeAnnotationAttribute__ctor, WellKnownMember.System_MemoryExtensions__SequenceEqual_Span_T, WellKnownMember.System_MemoryExtensions__SequenceEqual_ReadOnlySpan_T, WellKnownMember.System_MemoryExtensions__AsSpan_String,