From 3e67b7c68c0bdb4bd684737484f5c18866f216f8 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Wed, 10 May 2023 11:05:31 -0700 Subject: [PATCH 01/34] Pack bits in SourceOrdinaryMethodSymbol into an existing bitflag structure we have for all source methods (#68132) * In progresS * Utilize * initialize once * Save space in other methods * reorder * reorder * Move down * Reorder * Simplify * Add docs * move up --- .../SynthesizedClosureMethod.cs | 1 - .../Lowering/SynthesizedMethodBaseSymbol.cs | 8 +- .../Symbols/Source/SourceConstructorSymbol.cs | 15 +--- .../Source/SourceCustomEventAccessorSymbol.cs | 15 +--- .../Source/SourceDelegateMethodSymbol.cs | 8 +- .../Symbols/Source/SourceDestructorSymbol.cs | 22 ++---- .../Source/SourceEventAccessorSymbol.cs | 10 +-- .../Source/SourceMemberMethodSymbol.cs | 73 ++++++++++++++++--- .../Source/SourceOrdinaryMethodSymbol.cs | 32 +++----- .../Source/SourceOrdinaryMethodSymbolBase.cs | 7 +- .../Source/SourcePropertyAccessorSymbol.cs | 11 +-- .../SourceUserDefinedOperatorSymbolBase.cs | 9 +-- .../Records/SynthesizedPrimaryConstructor.cs | 3 +- .../SynthesizedRecordOrdinaryMethod.cs | 4 +- .../SynthesizedEventAccessorSymbol.cs | 2 +- ...ynthesizedSimpleProgramEntryPointSymbol.cs | 3 +- 16 files changed, 107 insertions(+), 116 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs b/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs index 7c8842384cb5c..94d75be8c52a3 100644 --- a/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs +++ b/src/Compilers/CSharp/Portable/Lowering/ClosureConversion/SynthesizedClosureMethod.cs @@ -218,7 +218,6 @@ protected override ImmutableArray ExtraSynthesizedRefParameters internal override bool InheritsBaseMethodAttributes => true; internal override bool GenerateDebugInfo => !this.IsAsync; - internal override bool IsExpressionBodied => false; internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree localTree) { diff --git a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs index 409c5e74098a2..7362f09560c79 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs @@ -50,7 +50,8 @@ protected SynthesizedMethodBaseSymbol(NamedTypeSymbol containingType, returnsVoid: baseMethod.ReturnsVoid, isExtensionMethod: false, isNullableAnalysisEnabled: false, - isMetadataVirtualIgnoringModifiers: false); + isMetadataVirtualIgnoringModifiers: false, + isExpressionBodied: false); } protected void AssignTypeMapAndTypeParameters(TypeMap typeMap, ImmutableArray typeParameters) @@ -226,10 +227,5 @@ public sealed override bool IsImplicitlyDeclared { get { return true; } } - - internal override bool IsExpressionBodied - { - get { return false; } - } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs index 38371b2442a00..8fdcd2fbfd338 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs @@ -12,7 +12,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols { internal sealed class SourceConstructorSymbol : SourceConstructorSymbolBase { - private readonly bool _isExpressionBodied; private readonly bool _hasThisInitializer; public static SourceConstructorSymbol CreateConstructorSymbol( @@ -35,14 +34,14 @@ private SourceConstructorSymbol( base(containingType, location, syntax, SyntaxFacts.HasYieldOperations(syntax)) { bool hasBlockBody = syntax.Body != null; - _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; - bool hasBody = hasBlockBody || _isExpressionBodied; + bool isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; + bool hasBody = hasBlockBody || isExpressionBodied; _hasThisInitializer = syntax.Initializer?.Kind() == SyntaxKind.ThisConstructorInitializer; bool modifierErrors; var declarationModifiers = this.MakeModifiers(syntax.Modifiers, methodKind, hasBody, location, diagnostics, out modifierErrors); - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); + this.MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (syntax.Identifier.ValueText != containingType.Name) { @@ -163,14 +162,6 @@ internal override OneOrMany> GetAttributeDeclara return OneOrMany.Create(((ConstructorDeclarationSyntax)this.SyntaxNode).AttributeLists); } - internal override bool IsExpressionBodied - { - get - { - return _isExpressionBodied; - } - } - internal override bool IsNullableAnalysisEnabled() { return _hasThisInitializer ? diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs index 69ca26275e2ac..cc309bcce023e 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs @@ -4,6 +4,7 @@ #nullable disable +using System; using System.Collections.Immutable; using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -32,7 +33,8 @@ internal SourceCustomEventAccessorSymbol( syntax.Keyword.GetLocation(), explicitlyImplementedEventOpt, aliasQualifierOpt, isAdder: syntax.Kind() == SyntaxKind.AddAccessorDeclaration, isIterator: SyntaxFacts.HasYieldOperations(syntax.Body), - isNullableAnalysisEnabled: isNullableAnalysisEnabled) + isNullableAnalysisEnabled: isNullableAnalysisEnabled, + isExpressionBodied: syntax is { Body: null, ExpressionBody: not null }) { Debug.Assert(syntax != null); Debug.Assert(syntax.Kind() == SyntaxKind.AddAccessorDeclaration || syntax.Kind() == SyntaxKind.RemoveAccessorDeclaration); @@ -91,16 +93,5 @@ internal override bool GenerateDebugInfo { get { return true; } } - - internal override bool IsExpressionBodied - { - get - { - var syntax = GetSyntax(); - var hasBody = syntax.Body != null; - var hasExpressionBody = syntax.ExpressionBody != null; - return !hasBody && hasExpressionBody; - } - } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs index 28d792d0608a1..94a3fa6819e54 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs @@ -28,7 +28,8 @@ protected SourceDelegateMethodSymbol( : base(delegateType, syntax.GetReference(), location: syntax.Identifier.GetLocation(), isIterator: false) { _returnType = returnType; - this.MakeFlags(methodKind, declarationModifiers, _returnType.IsVoidType(), isExtensionMethod: false, isNullableAnalysisEnabled: false); + this.MakeFlags( + methodKind, declarationModifiers, _returnType.IsVoidType(), isExpressionBodied: false, isExtensionMethod: false, isNullableAnalysisEnabled: false); } internal sealed override ExecutableCodeBinder TryGetBodyBinder(BinderFactory binderFactoryOpt = null, bool ignoreAccessibility = false) => throw ExceptionUtilities.Unreachable(); @@ -176,11 +177,6 @@ public sealed override bool IsImplicitlyDeclared } } - internal override bool IsExpressionBodied - { - get { return false; } - } - internal override bool GenerateDebugInfo { get { return false; } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs index 26dc833d7353d..c2071844d64e2 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs @@ -14,7 +14,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols internal sealed class SourceDestructorSymbol : SourceMemberMethodSymbol { private TypeWithAnnotations _lazyReturnType; - private readonly bool _isExpressionBodied; internal SourceDestructorSymbol( SourceMemberContainerTypeSymbol containingType, @@ -28,17 +27,18 @@ internal SourceDestructorSymbol( bool modifierErrors; var declarationModifiers = MakeModifiers(syntax.Modifiers, location, diagnostics, out modifierErrors); - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); + + bool hasBlockBody = syntax.Body != null; + bool isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; + + this.MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (syntax.Identifier.ValueText != containingType.Name) { diagnostics.Add(ErrorCode.ERR_BadDestructorName, syntax.Identifier.GetLocation()); } - bool hasBlockBody = syntax.Body != null; - _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; - - if (hasBlockBody || _isExpressionBodied) + if (hasBlockBody || isExpressionBodied) { if (IsExtern) { @@ -46,7 +46,7 @@ internal SourceDestructorSymbol( } } - if (!modifierErrors && !hasBlockBody && !_isExpressionBodied && !IsExtern) + if (!modifierErrors && !hasBlockBody && !isExpressionBodied && !IsExtern) { diagnostics.Add(ErrorCode.ERR_ConcreteMissingBody, location, this); } @@ -142,14 +142,6 @@ public override string Name get { return WellKnownMemberNames.DestructorName; } } - internal override bool IsExpressionBodied - { - get - { - return _isExpressionBodied; - } - } - internal override OneOrMany> GetAttributeDeclarations() { // destructors can't have return type attributes diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs index dc99d2054c40d..00d2c4cdd71d4 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs @@ -29,7 +29,8 @@ public SourceEventAccessorSymbol( string aliasQualifierOpt, bool isAdder, bool isIterator, - bool isNullableAnalysisEnabled) + bool isNullableAnalysisEnabled, + bool isExpressionBodied) : base(@event.containingType, syntaxReference, location, isIterator) { _event = @event; @@ -56,6 +57,7 @@ public SourceEventAccessorSymbol( isAdder ? MethodKind.EventAdd : MethodKind.EventRemove, @event.Modifiers, returnsVoid: false, // until we learn otherwise (in LazyMethodChecks). + isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: @event.IsExplicitInterfaceImplementation && (@event.Modifiers & DeclarationModifiers.Static) == 0); @@ -246,11 +248,5 @@ protected string GetOverriddenAccessorName(SourceEventSymbol @event, bool isAdde return null; } - - internal override bool IsExpressionBodied - { - // Events cannot be expression-bodied - get { return false; } - } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index a6288faa15dd7..82008e1cb88c4 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -24,9 +24,10 @@ protected struct Flags { // We currently pack everything into a 32 bit int with the following layout: // - // | |n|vvv|yy|s|r|q|z|wwwww| + // | |a|b|e|n|vvv|yy|s|r|q|z|kk|wwwww| // // w = method kind. 5 bits. + // k = ref kind. 2 bits. // z = isExtensionMethod. 1 bit. // q = isMetadataVirtualIgnoringInterfaceChanges. 1 bit. // r = isMetadataVirtual. 1 bit. (At least as true as isMetadataVirtualIgnoringInterfaceChanges.) @@ -34,12 +35,20 @@ protected struct Flags // y = ReturnsVoid. 2 bits. // v = NullableContext. 3 bits. // n = IsNullableAnalysisEnabled. 1 bit. + // e = IsExpressionBody. 1 bit. + // b = HasAnyBody. 1 bit. + // a = IsVarArg. 1 bit private int _flags; private const int MethodKindOffset = 0; private const int MethodKindSize = 5; + private const int MethodKindMask = (1 << MethodKindSize) - 1; + + private const int RefKindOffset = MethodKindOffset + MethodKindSize; + private const int RefKindSize = 2; + private const int RefKindMask = (1 << RefKindSize) - 1; - private const int IsExtensionMethodOffset = MethodKindOffset + MethodKindSize; + private const int IsExtensionMethodOffset = RefKindOffset + RefKindSize; private const int IsExtensionMethodSize = 1; private const int IsMetadataVirtualIgnoringInterfaceChangesOffset = IsExtensionMethodOffset + IsExtensionMethodSize; @@ -56,24 +65,33 @@ protected struct Flags private const int NullableContextOffset = ReturnsVoidOffset + ReturnsVoidSize; private const int NullableContextSize = 3; + private const int NullableContextMask = (1 << NullableContextSize) - 1; private const int IsNullableAnalysisEnabledOffset = NullableContextOffset + NullableContextSize; -#pragma warning disable IDE0051 // Remove unused private members private const int IsNullableAnalysisEnabledSize = 1; -#pragma warning restore IDE0051 // Remove unused private members - private const int MethodKindMask = (1 << MethodKindSize) - 1; + private const int IsExpressionBodiedOffset = IsNullableAnalysisEnabledOffset + IsNullableAnalysisEnabledSize; + private const int IsExpressionBodiedSize = 1; + + private const int HasAnyBodyOffset = IsExpressionBodiedOffset + IsExpressionBodiedSize; + private const int HasAnyBodySize = 1; + private const int IsVarArgOffset = HasAnyBodyOffset + HasAnyBodySize; +#pragma warning disable IDE0051 // Remove unused private members + private const int IsVarArgSize = 1; +#pragma warning restore IDE0051 // Remove unused private members + + private const int HasAnyBodyBit = 1 << HasAnyBodyOffset; + private const int IsExpressionBodiedBit = 1 << IsExpressionBodiedOffset; private const int IsExtensionMethodBit = 1 << IsExtensionMethodOffset; private const int IsMetadataVirtualIgnoringInterfaceChangesBit = 1 << IsMetadataVirtualIgnoringInterfaceChangesOffset; private const int IsMetadataVirtualBit = 1 << IsMetadataVirtualIgnoringInterfaceChangesOffset; private const int IsMetadataVirtualLockedBit = 1 << IsMetadataVirtualLockedOffset; + private const int IsVarArgBit = 1 << IsVarArgOffset; private const int ReturnsVoidBit = 1 << ReturnsVoidOffset; private const int ReturnsVoidIsSetBit = 1 << ReturnsVoidOffset + 1; - private const int NullableContextMask = (1 << NullableContextSize) - 1; - private const int IsNullableAnalysisEnabledBit = 1 << IsNullableAnalysisEnabledOffset; public bool TryGetReturnsVoid(out bool value) @@ -93,9 +111,25 @@ public MethodKind MethodKind get { return (MethodKind)((_flags >> MethodKindOffset) & MethodKindMask); } } + public RefKind RefKind + { + get { return (RefKind)((_flags >> RefKindOffset) & RefKindMask); } + } + + public bool HasAnyBody + { + get { return (_flags & HasAnyBodyBit) != 0; } + } + + public bool IsExpressionBodied + { + get { return (_flags & IsExpressionBodiedBit) != 0; } + } + public bool IsExtensionMethod { get { return (_flags & IsExtensionMethodBit) != 0; } + set { ThreadSafeFlagOperations.Set(ref _flags, value ? IsExtensionMethodBit : 0); } } public bool IsNullableAnalysisEnabled @@ -108,11 +142,18 @@ public bool IsMetadataVirtualLocked get { return (_flags & IsMetadataVirtualLockedBit) != 0; } } + public bool IsVarArg + { + get { return (_flags & IsVarArgBit) != 0; } + set { ThreadSafeFlagOperations.Set(ref _flags, value ? IsVarArgBit : 0); } + } + #if DEBUG static Flags() { // Verify masks are sufficient for values. Debug.Assert(EnumUtilities.ContainsAllValues(MethodKindMask)); + Debug.Assert(EnumUtilities.ContainsAllValues(RefKindMask)); Debug.Assert(EnumUtilities.ContainsAllValues(NullableContextMask)); } #endif @@ -126,6 +167,7 @@ public Flags( MethodKind methodKind, DeclarationModifiers declarationModifiers, bool returnsVoid, + bool isExpressionBodied, bool isExtensionMethod, bool isNullableAnalysisEnabled, bool isMetadataVirtualIgnoringModifiers = false) @@ -133,12 +175,14 @@ public Flags( bool isMetadataVirtual = isMetadataVirtualIgnoringModifiers || ModifiersRequireMetadataVirtual(declarationModifiers); int methodKindInt = ((int)methodKind & MethodKindMask) << MethodKindOffset; + int isExpressionBodyInt = isExpressionBodied ? IsExpressionBodiedBit : 0; int isExtensionMethodInt = isExtensionMethod ? IsExtensionMethodBit : 0; int isNullableAnalysisEnabledInt = isNullableAnalysisEnabled ? IsNullableAnalysisEnabledBit : 0; int isMetadataVirtualIgnoringInterfaceImplementationChangesInt = isMetadataVirtual ? IsMetadataVirtualIgnoringInterfaceChangesBit : 0; int isMetadataVirtualInt = isMetadataVirtual ? IsMetadataVirtualBit : 0; _flags = methodKindInt + | isExpressionBodyInt | isExtensionMethodInt | isNullableAnalysisEnabledInt | isMetadataVirtualIgnoringInterfaceImplementationChangesInt @@ -147,6 +191,16 @@ public Flags( | ReturnsVoidIsSetBit; } + /// + /// Only allowed to be called in constructors of SourceMemberMethodSymbol (and derived constructors), so + /// does not need ThreadSafe operations. + /// + public void SetOrdinaryMethodFlags(RefKind refKind, bool hasAnyBody) + { + _flags |= ((int)refKind & RefKindMask) << RefKindOffset; + _flags |= hasAnyBody ? HasAnyBodyBit : 0; + } + public bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false) { // This flag is immutable, so there's no reason to set a lock bit, as we do below. @@ -292,12 +346,13 @@ protected void MakeFlags( MethodKind methodKind, DeclarationModifiers declarationModifiers, bool returnsVoid, + bool isExpressionBodied, bool isExtensionMethod, bool isNullableAnalysisEnabled, bool isMetadataVirtualIgnoringModifiers = false) { DeclarationModifiers = declarationModifiers; - this.flags = new Flags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod, isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers); + this.flags = new Flags(methodKind, declarationModifiers, returnsVoid, isExpressionBodied, isExtensionMethod, isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers); } protected void SetReturnsVoid(bool returnsVoid) @@ -1003,7 +1058,7 @@ protected void CheckFeatureAvailabilityAndRuntimeSupport(SyntaxNode declarationS /// If the method has both block body and an expression body /// present, this is not treated as expression-bodied. /// - internal abstract bool IsExpressionBodied { get; } + internal bool IsExpressionBodied => flags.IsExpressionBodied; internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree localTree) { diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index 55127be6d829e..ed4fabc071d81 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -20,10 +20,6 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols internal sealed class SourceOrdinaryMethodSymbol : SourceOrdinaryMethodSymbolBase { private readonly TypeSymbol _explicitInterfaceType; - private readonly bool _isExpressionBodied; - private readonly bool _hasAnyBody; - private readonly RefKind _refKind; - private bool _lazyIsVararg; /// /// A collection of type parameter constraint types, populated when @@ -87,19 +83,16 @@ private SourceOrdinaryMethodSymbol( firstParam.Modifiers.Any(SyntaxKind.ThisKeyword), isReadOnly: false, hasBody: syntax.Body != null || syntax.ExpressionBody != null, + isExpressionBodied: syntax is { Body: null, ExpressionBody: not null }, isNullableAnalysisEnabled: isNullableAnalysisEnabled, - diagnostics) + diagnostics, + refKind: syntax.ReturnType.SkipScoped(out _).GetRefKindInLocalOrReturn(diagnostics)) { Debug.Assert(diagnostics.DiagnosticBag is object); _explicitInterfaceType = explicitInterfaceType; - bool hasBlockBody = syntax.Body != null; - _isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; - bool hasBody = hasBlockBody || _isExpressionBodied; - _hasAnyBody = hasBody; Debug.Assert(syntax.ReturnType is not ScopedTypeSyntax); - _refKind = syntax.ReturnType.SkipScoped(out _).GetRefKindInLocalOrReturn(diagnostics); CheckForBlockAndExpressionBody( syntax.Body, syntax.ExpressionBody, syntax, diagnostics); @@ -140,7 +133,7 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray(); - _lazyIsVararg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword); + flags.IsVarArg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword); var returnTypeSyntax = syntax.ReturnType; Debug.Assert(returnTypeSyntax is not ScopedTypeSyntax); @@ -194,7 +187,7 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray declaredConstraints) { @@ -285,7 +278,7 @@ protected override MethodSymbol FindExplicitlyImplementedMethod(BindingDiagnosti protected override TypeSymbol ExplicitInterfaceType => _explicitInterfaceType; - protected override bool HasAnyBody => _hasAnyBody; + protected override bool HasAnyBody => flags.HasAnyBody; internal MethodDeclarationSyntax GetSyntax() { @@ -360,7 +353,7 @@ public override bool IsVararg get { LazyMethodChecks(); - return _lazyIsVararg; + return flags.IsVarArg; } } @@ -370,7 +363,7 @@ public override RefKind RefKind { get { - return _refKind; + return flags.RefKind; } } @@ -400,7 +393,7 @@ internal bool IsPartialDefinition { get { - return this.IsPartial && !_hasAnyBody && !HasExternModifier; + return this.IsPartial && !flags.HasAnyBody && !HasExternModifier; } } @@ -411,7 +404,7 @@ internal bool IsPartialImplementation { get { - return this.IsPartial && (_hasAnyBody || HasExternModifier); + return this.IsPartial && (flags.HasAnyBody || HasExternModifier); } } @@ -516,11 +509,6 @@ private SyntaxList AttributeDeclarationSyntaxList } } - internal override bool IsExpressionBodied - { - get { return _isExpressionBodied; } - } - protected override DeclarationModifiers MakeDeclarationModifiers(DeclarationModifiers allowedModifiers, BindingDiagnosticBag diagnostics) { var syntax = GetSyntax(); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index 9769624caabcf..298ab3c16db03 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -36,8 +36,10 @@ protected SourceOrdinaryMethodSymbolBase( bool isExtensionMethod, bool isReadOnly, bool hasBody, + bool isExpressionBodied, bool isNullableAnalysisEnabled, - BindingDiagnosticBag diagnostics) : + BindingDiagnosticBag diagnostics, + RefKind refKind = RefKind.None) : base(containingType, syntax.GetReference(), location, @@ -60,7 +62,8 @@ protected SourceOrdinaryMethodSymbolBase( bool isExplicitInterfaceImplementation = methodKind == MethodKind.ExplicitInterfaceImplementation; var isMetadataVirtualIgnoringModifiers = isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0; - this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); + this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExpressionBodied: isExpressionBodied, isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); + flags.SetOrdinaryMethodFlags(refKind, hasBody); _typeParameters = MakeTypeParameters(syntax, diagnostics); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs index c1c7d572ce5d5..6ca6c0c0bc229 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs @@ -23,7 +23,6 @@ internal class SourcePropertyAccessorSymbol : SourceMemberMethodSymbol private ImmutableArray _lazyExplicitInterfaceImplementations; private string _lazyName; private readonly bool _isAutoPropertyAccessor; - private readonly bool _isExpressionBodied; private readonly bool _usesInit; public static SourcePropertyAccessorSymbol CreateAccessorSymbol( @@ -128,9 +127,6 @@ public static SourcePropertyAccessorSymbol CreateAccessorSymbol( } #nullable disable - internal sealed override bool IsExpressionBodied - => _isExpressionBodied; - internal sealed override ImmutableArray NotNullMembers => _property.NotNullMembers.Concat(base.NotNullMembers); @@ -152,7 +148,6 @@ private SourcePropertyAccessorSymbol( { _property = property; _isAutoPropertyAccessor = false; - _isExpressionBodied = true; // The modifiers for the accessor are the same as the modifiers for the property, // minus the indexer and readonly bit @@ -161,7 +156,7 @@ private SourcePropertyAccessorSymbol( // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. bool isExplicitInterfaceImplementation = property.IsExplicitInterfaceImplementation; - this.MakeFlags(MethodKind.PropertyGet, declarationModifiers, returnsVoid: false, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, + this.MakeFlags(MethodKind.PropertyGet, declarationModifiers, returnsVoid: false, isExpressionBodied: true, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0); CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody: true, diagnostics: diagnostics); @@ -196,7 +191,7 @@ protected SourcePropertyAccessorSymbol( _property = property; _isAutoPropertyAccessor = isAutoPropertyAccessor; Debug.Assert(!_property.IsExpressionBodied, "Cannot have accessors in expression bodied lightweight properties"); - _isExpressionBodied = !hasBody && hasExpressionBody; + var isExpressionBodied = !hasBody && hasExpressionBody; _usesInit = usesInit; if (_usesInit) { @@ -217,7 +212,7 @@ protected SourcePropertyAccessorSymbol( // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, + this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0); CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody: hasBody || hasExpressionBody || isAutoPropertyAccessor, diagnostics); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs index 973254524cca1..3fa2de838216b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs @@ -17,7 +17,6 @@ internal abstract class SourceUserDefinedOperatorSymbolBase : SourceOrdinaryMeth // tomat: ignoreDynamic should be true, but we don't want to introduce breaking change. See bug 605326. private const TypeCompareKind ComparisonForUserDefinedOperators = TypeCompareKind.IgnoreTupleNames | TypeCompareKind.IgnoreNullableModifiersForReferenceTypes; private readonly string _name; - private readonly bool _isExpressionBodied; #nullable enable private readonly TypeSymbol? _explicitInterfaceType; #nullable disable @@ -39,7 +38,6 @@ protected SourceUserDefinedOperatorSymbolBase( { _explicitInterfaceType = explicitInterfaceType; _name = name; - _isExpressionBodied = isExpressionBodied; this.CheckUnsafeModifier(declarationModifiers, diagnostics); @@ -47,7 +45,7 @@ protected SourceUserDefinedOperatorSymbolBase( // assume that the return type is non-void; when we do the lazy initialization // of the parameters and return type we will update the flag if necessary. - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); + this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (this.ContainingType.IsInterface && !(IsAbstract || IsVirtual) && !IsExplicitInterfaceImplementation && @@ -795,11 +793,6 @@ public sealed override RefKind RefKind get { return RefKind.None; } } - internal sealed override bool IsExpressionBodied - { - get { return _isExpressionBodied; } - } - protected sealed override void CheckConstraintsForExplicitInterfaceType(ConversionsBase conversions, BindingDiagnosticBag diagnostics) { if ((object)_explicitInterfaceType != null) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs index 2703847c97b27..765999431fa70 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs @@ -30,6 +30,7 @@ public SynthesizedPrimaryConstructor( MethodKind.Constructor, containingType.IsAbstract ? DeclarationModifiers.Protected : DeclarationModifiers.Public, returnsVoid: true, + isExpressionBodied: false, isExtensionMethod: false, isNullableAnalysisEnabled: false); // IsNullableAnalysisEnabled uses containing type instead. } @@ -69,8 +70,6 @@ protected override ParameterListSyntax GetParameterList() protected override bool AllowRefOrOut => !(ContainingType is { IsRecord: true } or { IsRecordStruct: true }); - internal override bool IsExpressionBodied => false; - internal override bool IsNullableAnalysisEnabled() { return ContainingType.IsNullableEnabledForConstructorsAndInitializers(IsStatic); diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs index c497dbc226869..eb7b8ee4c95b7 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs @@ -22,15 +22,13 @@ internal abstract class SynthesizedRecordOrdinaryMethod : SourceOrdinaryMethodSy protected SynthesizedRecordOrdinaryMethod(SourceMemberContainerTypeSymbol containingType, string name, bool isReadOnly, bool hasBody, int memberOffset, BindingDiagnosticBag diagnostics) : base(containingType, name, containingType.GetFirstLocation(), (CSharpSyntaxNode)containingType.SyntaxReferences[0].GetSyntax(), MethodKind.Ordinary, - isIterator: false, isExtensionMethod: false, isReadOnly: isReadOnly, hasBody: hasBody, isNullableAnalysisEnabled: false, diagnostics) + isIterator: false, isExtensionMethod: false, isReadOnly: isReadOnly, hasBody: hasBody, isExpressionBodied: false, isNullableAnalysisEnabled: false, diagnostics) { _memberOffset = memberOffset; } protected sealed override bool HasAnyBody => true; - internal sealed override bool IsExpressionBodied => false; - public sealed override bool IsImplicitlyDeclared => true; protected sealed override Location ReturnTypeLocation => GetFirstLocation(); diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs index e165c6b2f3da6..a1e01aa551d49 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs @@ -25,7 +25,7 @@ internal sealed class SynthesizedEventAccessorSymbol : SourceEventAccessorSymbol private readonly object _methodChecksLockObject = new object(); internal SynthesizedEventAccessorSymbol(SourceEventSymbol @event, bool isAdder, EventSymbol explicitlyImplementedEventOpt = null, string aliasQualifierOpt = null) - : base(@event, null, @event.Location, explicitlyImplementedEventOpt, aliasQualifierOpt, isAdder, isIterator: false, isNullableAnalysisEnabled: false) + : base(@event, null, @event.Location, explicitlyImplementedEventOpt, aliasQualifierOpt, isAdder, isIterator: false, isNullableAnalysisEnabled: false, isExpressionBodied: false) { } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs index 232f54a690883..5aba0636c498b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs @@ -57,6 +57,7 @@ internal SynthesizedSimpleProgramEntryPointSymbol(SourceMemberContainerTypeSymbo MethodKind.Ordinary, DeclarationModifiers.Static | DeclarationModifiers.Private | (hasAwait ? DeclarationModifiers.Async : DeclarationModifiers.None), returnsVoid: !hasAwait && !hasReturnWithExpression, + isExpressionBodied: false, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: false); @@ -198,8 +199,6 @@ protected override void MethodChecks(BindingDiagnosticBag diagnostics) { } - internal override bool IsExpressionBodied => false; - public override ImmutableArray> GetTypeParameterConstraintTypes() => ImmutableArray>.Empty; From ce343a65d43288f8a26ccb1a52ecafca0a512ab1 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 11:16:38 -0700 Subject: [PATCH 02/34] Compute IsVarArg up front --- .../Portable/Symbols/Source/SourceMemberMethodSymbol.cs | 4 ++-- .../Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs | 8 +++----- .../Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index 82008e1cb88c4..432984c2885c6 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -145,7 +145,6 @@ public bool IsMetadataVirtualLocked public bool IsVarArg { get { return (_flags & IsVarArgBit) != 0; } - set { ThreadSafeFlagOperations.Set(ref _flags, value ? IsVarArgBit : 0); } } #if DEBUG @@ -195,10 +194,11 @@ public Flags( /// Only allowed to be called in constructors of SourceMemberMethodSymbol (and derived constructors), so /// does not need ThreadSafe operations. /// - public void SetOrdinaryMethodFlags(RefKind refKind, bool hasAnyBody) + public void SetOrdinaryMethodFlags(RefKind refKind, bool hasAnyBody, bool isVarArg) { _flags |= ((int)refKind & RefKindMask) << RefKindOffset; _flags |= hasAnyBody ? HasAnyBodyBit : 0; + _flags |= isVarArg ? IsVarArgBit : 0; } public bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index ed4fabc071d81..d391a431443a1 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -86,7 +86,8 @@ private SourceOrdinaryMethodSymbol( isExpressionBodied: syntax is { Body: null, ExpressionBody: not null }, isNullableAnalysisEnabled: isNullableAnalysisEnabled, diagnostics, - refKind: syntax.ReturnType.SkipScoped(out _).GetRefKindInLocalOrReturn(diagnostics)) + refKind: syntax.ReturnType.SkipScoped(out _).GetRefKindInLocalOrReturn(diagnostics), + isVarArg: syntax.ParameterList.Parameters.Any(p => p.IsArgList)) { Debug.Assert(diagnostics.DiagnosticBag is object); @@ -117,8 +118,6 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray parameters = ParameterHelpers.MakeParameters( - signatureBinder, this, syntax.ParameterList, out arglistToken, + signatureBinder, this, syntax.ParameterList, out _, allowRefOrOut: true, allowThis: true, addRefReadOnlyModifier: IsVirtual || IsAbstract, diagnostics: diagnostics).Cast(); - flags.IsVarArg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword); var returnTypeSyntax = syntax.ReturnType; Debug.Assert(returnTypeSyntax is not ScopedTypeSyntax); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index 298ab3c16db03..41314d62034f8 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -39,7 +39,8 @@ protected SourceOrdinaryMethodSymbolBase( bool isExpressionBodied, bool isNullableAnalysisEnabled, BindingDiagnosticBag diagnostics, - RefKind refKind = RefKind.None) : + RefKind refKind = RefKind.None, + bool isVarArg = false) : base(containingType, syntax.GetReference(), location, @@ -63,7 +64,7 @@ protected SourceOrdinaryMethodSymbolBase( var isMetadataVirtualIgnoringModifiers = isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0; this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExpressionBodied: isExpressionBodied, isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); - flags.SetOrdinaryMethodFlags(refKind, hasBody); + flags.SetOrdinaryMethodFlags(refKind, hasBody, isVarArg); _typeParameters = MakeTypeParameters(syntax, diagnostics); From 1319147332c3748ff7d2980d42c20d9b59378ea7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 16:31:34 -0700 Subject: [PATCH 03/34] Remove unused usings --- .../Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs index cc309bcce023e..7ffd478df9134 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs @@ -4,8 +4,6 @@ #nullable disable -using System; -using System.Collections.Immutable; using System.Diagnostics; using Microsoft.CodeAnalysis.CSharp.Syntax; using Roslyn.Utilities; From eee77ee6285ca19db9ec612403739c2df5c2752d Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 16:32:51 -0700 Subject: [PATCH 04/34] Remove --- .../CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index 432984c2885c6..780a99a18b5bf 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -129,7 +129,6 @@ public bool IsExpressionBodied public bool IsExtensionMethod { get { return (_flags & IsExtensionMethodBit) != 0; } - set { ThreadSafeFlagOperations.Set(ref _flags, value ? IsExtensionMethodBit : 0); } } public bool IsNullableAnalysisEnabled From d2a9c02a4636e5b4491d14817350b992a644f158 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 17:21:54 -0700 Subject: [PATCH 05/34] Remove passing of flag --- .../Symbols/Source/SourceOrdinaryMethodSymbol.cs | 4 ++-- .../Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 10 ++++++---- .../Synthesized/Records/SynthesizedRecordBaseEquals.cs | 3 +-- .../Synthesized/Records/SynthesizedRecordClone.cs | 3 +-- .../Records/SynthesizedRecordDeconstruct.cs | 3 +-- .../Synthesized/Records/SynthesizedRecordEquals.cs | 3 +-- .../Records/SynthesizedRecordGetHashCode.cs | 3 +-- .../Synthesized/Records/SynthesizedRecordObjEquals.cs | 3 +-- .../Records/SynthesizedRecordPrintMembers.cs | 3 +-- .../Synthesized/Records/SynthesizedRecordToString.cs | 3 +-- 10 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index d391a431443a1..f4a93dce1e0ef 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -113,7 +113,7 @@ protected override ImmutableArray MakeTypeParameters(CSharp } } - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var syntax = GetSyntax(); var withTypeParamsBinder = this.DeclaringCompilation.GetBinderFactory(syntax.SyntaxTree).GetBinder(syntax.ReturnType, syntax, this); @@ -185,7 +185,7 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray declaredConstraints) { diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index 41314d62034f8..39f96ddd5cc18 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -85,7 +85,7 @@ protected override void MethodChecks(BindingDiagnosticBag diagnostics) { Debug.Assert(this.MethodKind != MethodKind.UserDefinedOperator, "SourceUserDefinedOperatorSymbolBase overrides this"); - var (returnType, parameters, isVararg, declaredConstraints) = MakeParametersAndBindReturnType(diagnostics); + var (returnType, parameters, declaredConstraints) = MakeParametersAndBindReturnType(diagnostics); MethodSymbol? overriddenOrExplicitlyImplementedMethod = MethodChecks(returnType, parameters, diagnostics); @@ -128,11 +128,11 @@ protected override void MethodChecks(BindingDiagnosticBag diagnostics) } } - CheckModifiers(MethodKind == MethodKind.ExplicitInterfaceImplementation, isVararg, HasAnyBody, _location, diagnostics); + CheckModifiers(MethodKind == MethodKind.ExplicitInterfaceImplementation, HasAnyBody, _location, diagnostics); } #nullable disable - protected abstract (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics); + protected abstract (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics); protected abstract bool HasAnyBody { get; } @@ -312,8 +312,10 @@ private static DeclarationModifiers AddImpliedModifiers(DeclarationModifiers mod internal bool HasExtendedPartialModifier => (DeclarationModifiers & PartialMethodExtendedModifierMask) != 0; - private void CheckModifiers(bool isExplicitInterfaceImplementation, bool isVararg, bool hasBody, Location location, BindingDiagnosticBag diagnostics) + private void CheckModifiers(bool isExplicitInterfaceImplementation, bool hasBody, Location location, BindingDiagnosticBag diagnostics) { + bool isVararg = flags.IsVarArg; + Debug.Assert(!IsStatic || !IsOverride); // Otherwise should have been reported and cleared earlier. Debug.Assert(!IsStatic || ContainingType.IsInterface || (!IsAbstract && !IsVirtual)); // Otherwise should have been reported and cleared earlier. diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordBaseEquals.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordBaseEquals.cs index bfcd9b9a62aa5..ed73aa912dd53 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordBaseEquals.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordBaseEquals.cs @@ -29,7 +29,7 @@ protected override DeclarationModifiers MakeDeclarationModifiers(DeclarationModi return result; } - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var compilation = DeclaringCompilation; var location = ReturnTypeLocation; @@ -38,7 +38,6 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray.Empty); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordClone.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordClone.cs index c59a619a611d3..af74e3e402f7e 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordClone.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordClone.cs @@ -95,13 +95,12 @@ static bool modifiersAreValid(DeclarationModifiers modifiers) return null; } - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { return (ReturnType: !ContainingAssembly.RuntimeSupportsCovariantReturnsOfClasses && VirtualCloneInBase() is { } baseClone ? baseClone.ReturnTypeWithAnnotations : TypeWithAnnotations.Create(isNullableEnabled: true, ContainingType), Parameters: ImmutableArray.Empty, - IsVararg: false, DeclaredConstraintsForOverrideOrImplementation: ImmutableArray.Empty); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordDeconstruct.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordDeconstruct.cs index 6610ac14985f0..e542fe47fc9fc 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordDeconstruct.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordDeconstruct.cs @@ -35,7 +35,7 @@ protected override DeclarationModifiers MakeDeclarationModifiers(DeclarationModi return result; } - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var compilation = DeclaringCompilation; var location = ReturnTypeLocation; @@ -50,7 +50,6 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray.Empty); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEquals.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEquals.cs index ef03c9a21b5f1..c0049393fec9c 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEquals.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEquals.cs @@ -32,7 +32,7 @@ protected override DeclarationModifiers MakeDeclarationModifiers(DeclarationModi return result; } - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var compilation = DeclaringCompilation; @@ -43,7 +43,6 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray.Empty); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordGetHashCode.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordGetHashCode.cs index 183930cc2411f..f9ea532a468ae 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordGetHashCode.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordGetHashCode.cs @@ -26,14 +26,13 @@ public SynthesizedRecordGetHashCode(SourceMemberContainerTypeSymbol containingTy protected override SpecialMember OverriddenSpecialMember => SpecialMember.System_Object__GetHashCode; - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var compilation = DeclaringCompilation; var location = ReturnTypeLocation; return (ReturnType: TypeWithAnnotations.Create(Binder.GetSpecialType(compilation, SpecialType.System_Int32, location, diagnostics)), Parameters: ImmutableArray.Empty, - IsVararg: false, DeclaredConstraintsForOverrideOrImplementation: ImmutableArray.Empty); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordObjEquals.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordObjEquals.cs index e3779ce65dc53..e944deede9a62 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordObjEquals.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordObjEquals.cs @@ -23,7 +23,7 @@ public SynthesizedRecordObjEquals(SourceMemberContainerTypeSymbol containingType protected override SpecialMember OverriddenSpecialMember => SpecialMember.System_Object__Equals; - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var compilation = DeclaringCompilation; @@ -34,7 +34,6 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray.Empty); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordPrintMembers.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordPrintMembers.cs index 9129525d2f92f..3781497a6ec4a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordPrintMembers.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordPrintMembers.cs @@ -85,7 +85,7 @@ bool modifiersAreValid(DeclarationModifiers modifiers) #endif } - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var compilation = DeclaringCompilation; var location = ReturnTypeLocation; @@ -95,7 +95,6 @@ protected override (TypeWithAnnotations ReturnType, ImmutableArray.Empty); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordToString.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordToString.cs index f66a3a786f0ef..33220633ece8a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordToString.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordToString.cs @@ -36,14 +36,13 @@ public SynthesizedRecordToString(SourceMemberContainerTypeSymbol containingType, protected override SpecialMember OverriddenSpecialMember => SpecialMember.System_Object__ToString; - protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, bool IsVararg, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) + protected override (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics) { var compilation = DeclaringCompilation; var location = ReturnTypeLocation; var annotation = ContainingType.IsRecordStruct ? NullableAnnotation.Oblivious : NullableAnnotation.NotAnnotated; return (ReturnType: TypeWithAnnotations.Create(Binder.GetSpecialType(compilation, SpecialType.System_String, location, diagnostics), annotation), Parameters: ImmutableArray.Empty, - IsVararg: false, DeclaredConstraintsForOverrideOrImplementation: ImmutableArray.Empty); } From 824b5b1098f72b5ee6fb891f74eab487ac7042b5 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 17:24:20 -0700 Subject: [PATCH 06/34] move up and make non-virtual --- .../Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs | 2 -- .../Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 2 +- .../Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index f4a93dce1e0ef..fac8fcf8443ac 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -276,8 +276,6 @@ protected override MethodSymbol FindExplicitlyImplementedMethod(BindingDiagnosti protected override TypeSymbol ExplicitInterfaceType => _explicitInterfaceType; - protected override bool HasAnyBody => flags.HasAnyBody; - internal MethodDeclarationSyntax GetSyntax() { Debug.Assert(syntaxReferenceOpt != null); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index 39f96ddd5cc18..e99fe42f008fe 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -134,7 +134,7 @@ protected override void MethodChecks(BindingDiagnosticBag diagnostics) protected abstract (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics); - protected abstract bool HasAnyBody { get; } + protected bool HasAnyBody => flags.HasAnyBody; protected sealed override void LazyAsyncMethodChecks(CancellationToken cancellationToken) { diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs index eb7b8ee4c95b7..16ca2e2fa8f4a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs @@ -27,8 +27,6 @@ protected SynthesizedRecordOrdinaryMethod(SourceMemberContainerTypeSymbol contai _memberOffset = memberOffset; } - protected sealed override bool HasAnyBody => true; - public sealed override bool IsImplicitlyDeclared => true; protected sealed override Location ReturnTypeLocation => GetFirstLocation(); From 1932ed3592854a256ce85a3153a645b0515e0399 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 17:29:59 -0700 Subject: [PATCH 07/34] "move up and make sealed" --- .../Symbols/Source/SourceOrdinaryMethodSymbol.cs | 9 --------- .../Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 2 ++ .../Records/SynthesizedRecordOrdinaryMethod.cs | 2 -- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index fac8fcf8443ac..2949f5634af81 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -344,15 +344,6 @@ public override ImmutableArray GetTypeParameterCons return _lazyTypeParameterConstraintKinds; } - public override bool IsVararg - { - get - { - LazyMethodChecks(); - return flags.IsVarArg; - } - } - protected override int GetParameterCountFromSyntax() => GetSyntax().ParameterList.ParameterCount; public override RefKind RefKind diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index e99fe42f008fe..350840fd2c0cb 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -443,5 +443,7 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r WellKnownMember.System_Runtime_CompilerServices_ExtensionAttribute__ctor)); } } + + public sealed override bool IsVararg => flags.IsVarArg; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs index 16ca2e2fa8f4a..14f8f14832697 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs @@ -74,8 +74,6 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r public sealed override string? GetDocumentationCommentXml(CultureInfo? preferredCulture = null, bool expandIncludes = false, CancellationToken cancellationToken = default) => null; - public sealed override bool IsVararg => false; - public sealed override RefKind RefKind => RefKind.None; internal sealed override bool GenerateDebugInfo => false; From 9f7d914e614d5eda33b9c6452692ac6a1a455ac3 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 17:31:34 -0700 Subject: [PATCH 08/34] move up and make sealed --- .../Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs | 8 -------- .../Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 2 ++ .../Records/SynthesizedRecordOrdinaryMethod.cs | 2 -- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index 2949f5634af81..9c885320320f3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -346,14 +346,6 @@ public override ImmutableArray GetTypeParameterCons protected override int GetParameterCountFromSyntax() => GetSyntax().ParameterList.ParameterCount; - public override RefKind RefKind - { - get - { - return flags.RefKind; - } - } - internal static void InitializePartialMethodParts(SourceOrdinaryMethodSymbol definition, SourceOrdinaryMethodSymbol implementation) { Debug.Assert(definition.IsPartialDefinition); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index 350840fd2c0cb..f243cf360ce46 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -445,5 +445,7 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r } public sealed override bool IsVararg => flags.IsVarArg; + + public sealed override RefKind RefKind => flags.RefKind; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs index 14f8f14832697..ff56174debb95 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs @@ -74,8 +74,6 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r public sealed override string? GetDocumentationCommentXml(CultureInfo? preferredCulture = null, bool expandIncludes = false, CancellationToken cancellationToken = default) => null; - public sealed override RefKind RefKind => RefKind.None; - internal sealed override bool GenerateDebugInfo => false; internal sealed override bool SynthesizesLoweredBoundBody => true; From a0295b77e649e46c1ab2ce6b55f74a691a92c75c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Wed, 10 May 2023 17:32:18 -0700 Subject: [PATCH 09/34] use properties instead of flags --- .../Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index 9c885320320f3..a75fbe1deacb6 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -372,7 +372,7 @@ internal bool IsPartialDefinition { get { - return this.IsPartial && !flags.HasAnyBody && !HasExternModifier; + return this.IsPartial && !HasAnyBody && !HasExternModifier; } } @@ -383,7 +383,7 @@ internal bool IsPartialImplementation { get { - return this.IsPartial && (flags.HasAnyBody || HasExternModifier); + return this.IsPartial && (HasAnyBody || HasExternModifier); } } From 54c18cfd3b6861cda1a3fb12c12c0d999f8baf21 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 08:38:10 -0700 Subject: [PATCH 10/34] Make parameters non-optional --- .../Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs | 6 +++--- .../Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 6 +++--- .../Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index a75fbe1deacb6..1853cd0f1e282 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -77,6 +77,7 @@ private SourceOrdinaryMethodSymbol( location, syntax, methodKind, + refKind: syntax.ReturnType.SkipScoped(out _).GetRefKindInLocalOrReturn(diagnostics), isIterator: SyntaxFacts.HasYieldOperations(syntax.Body), isExtensionMethod: syntax.ParameterList.Parameters.FirstOrDefault() is ParameterSyntax firstParam && !firstParam.IsArgList && @@ -85,9 +86,8 @@ private SourceOrdinaryMethodSymbol( hasBody: syntax.Body != null || syntax.ExpressionBody != null, isExpressionBodied: syntax is { Body: null, ExpressionBody: not null }, isNullableAnalysisEnabled: isNullableAnalysisEnabled, - diagnostics, - refKind: syntax.ReturnType.SkipScoped(out _).GetRefKindInLocalOrReturn(diagnostics), - isVarArg: syntax.ParameterList.Parameters.Any(p => p.IsArgList)) + isVarArg: syntax.ParameterList.Parameters.Any(p => p.IsArgList), + diagnostics) { Debug.Assert(diagnostics.DiagnosticBag is object); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index f243cf360ce46..6db072eaba66b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -32,15 +32,15 @@ protected SourceOrdinaryMethodSymbolBase( Location location, CSharpSyntaxNode syntax, MethodKind methodKind, + RefKind refKind, bool isIterator, bool isExtensionMethod, bool isReadOnly, bool hasBody, bool isExpressionBodied, bool isNullableAnalysisEnabled, - BindingDiagnosticBag diagnostics, - RefKind refKind = RefKind.None, - bool isVarArg = false) : + bool isVarArg, + BindingDiagnosticBag diagnostics) : base(containingType, syntax.GetReference(), location, diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs index ff56174debb95..7b9a2d95221ec 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs @@ -21,8 +21,8 @@ internal abstract class SynthesizedRecordOrdinaryMethod : SourceOrdinaryMethodSy private readonly int _memberOffset; protected SynthesizedRecordOrdinaryMethod(SourceMemberContainerTypeSymbol containingType, string name, bool isReadOnly, bool hasBody, int memberOffset, BindingDiagnosticBag diagnostics) - : base(containingType, name, containingType.GetFirstLocation(), (CSharpSyntaxNode)containingType.SyntaxReferences[0].GetSyntax(), MethodKind.Ordinary, - isIterator: false, isExtensionMethod: false, isReadOnly: isReadOnly, hasBody: hasBody, isExpressionBodied: false, isNullableAnalysisEnabled: false, diagnostics) + : base(containingType, name, containingType.GetFirstLocation(), (CSharpSyntaxNode)containingType.SyntaxReferences[0].GetSyntax(), MethodKind.Ordinary, RefKind.None, + isIterator: false, isExtensionMethod: false, isReadOnly: isReadOnly, hasBody: hasBody, isExpressionBodied: false, isNullableAnalysisEnabled: false, isVarArg: false, diagnostics) { _memberOffset = memberOffset; } From d3a9476e1a19bde03e63519603cf2ec3fbe0b062 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 08:48:33 -0700 Subject: [PATCH 11/34] Pass all args --- .../Lowering/SynthesizedMethodBaseSymbol.cs | 3 +++ .../Symbols/Source/SourceMemberMethodSymbol.cs | 17 +++++++++++++---- .../Source/SourceOrdinaryMethodSymbolBase.cs | 5 ++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs index 7362f09560c79..531b601afd774 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs @@ -46,10 +46,13 @@ protected SynthesizedMethodBaseSymbol(NamedTypeSymbol containingType, this.MakeFlags( methodKind: MethodKind.Ordinary, + refKind: baseMethod.RefKind, declarationModifiers: declarationModifiers, returnsVoid: baseMethod.ReturnsVoid, + hasAnyBody: false, isExtensionMethod: false, isNullableAnalysisEnabled: false, + isVarArg: baseMethod.IsVararg, isMetadataVirtualIgnoringModifiers: false, isExpressionBodied: false); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index 780a99a18b5bf..938aa1a4e7ecf 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -163,26 +163,35 @@ private static bool ModifiersRequireMetadataVirtual(DeclarationModifiers modifie public Flags( MethodKind methodKind, + RefKind refKind, DeclarationModifiers declarationModifiers, bool returnsVoid, + bool hasAnyBody, bool isExpressionBodied, bool isExtensionMethod, bool isNullableAnalysisEnabled, + bool isVarArg, bool isMetadataVirtualIgnoringModifiers = false) { bool isMetadataVirtual = isMetadataVirtualIgnoringModifiers || ModifiersRequireMetadataVirtual(declarationModifiers); int methodKindInt = ((int)methodKind & MethodKindMask) << MethodKindOffset; + int refKindInt = ((int)refKind & RefKindMask) << RefKindOffset; + int hasAnyBodyInt = hasAnyBody? HasAnyBodyBit : 0; int isExpressionBodyInt = isExpressionBodied ? IsExpressionBodiedBit : 0; int isExtensionMethodInt = isExtensionMethod ? IsExtensionMethodBit : 0; int isNullableAnalysisEnabledInt = isNullableAnalysisEnabled ? IsNullableAnalysisEnabledBit : 0; + int isVarArgInt = isVarArg ? IsVarArgBit : 0; int isMetadataVirtualIgnoringInterfaceImplementationChangesInt = isMetadataVirtual ? IsMetadataVirtualIgnoringInterfaceChangesBit : 0; int isMetadataVirtualInt = isMetadataVirtual ? IsMetadataVirtualBit : 0; _flags = methodKindInt + | refKindInt + | hasAnyBodyInt | isExpressionBodyInt | isExtensionMethodInt | isNullableAnalysisEnabledInt + | isVarArgInt | isMetadataVirtualIgnoringInterfaceImplementationChangesInt | isMetadataVirtualInt | (returnsVoid ? ReturnsVoidBit : 0) @@ -195,9 +204,6 @@ public Flags( /// public void SetOrdinaryMethodFlags(RefKind refKind, bool hasAnyBody, bool isVarArg) { - _flags |= ((int)refKind & RefKindMask) << RefKindOffset; - _flags |= hasAnyBody ? HasAnyBodyBit : 0; - _flags |= isVarArg ? IsVarArgBit : 0; } public bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false) @@ -343,15 +349,18 @@ protected void CheckFileTypeUsage(TypeWithAnnotations returnType, ImmutableArray protected void MakeFlags( MethodKind methodKind, + RefKind refKind, DeclarationModifiers declarationModifiers, bool returnsVoid, + bool hasAnyBody, bool isExpressionBodied, bool isExtensionMethod, bool isNullableAnalysisEnabled, + bool isVarArg, bool isMetadataVirtualIgnoringModifiers = false) { DeclarationModifiers = declarationModifiers; - this.flags = new Flags(methodKind, declarationModifiers, returnsVoid, isExpressionBodied, isExtensionMethod, isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers); + this.flags = new Flags(methodKind, refKind, declarationModifiers, returnsVoid, hasAnyBody, isExpressionBodied, isExtensionMethod, isNullableAnalysisEnabled, isVarArg, isMetadataVirtualIgnoringModifiers); } protected void SetReturnsVoid(bool returnsVoid) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index 6db072eaba66b..d87c320b03715 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -63,7 +63,10 @@ protected SourceOrdinaryMethodSymbolBase( bool isExplicitInterfaceImplementation = methodKind == MethodKind.ExplicitInterfaceImplementation; var isMetadataVirtualIgnoringModifiers = isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0; - this.MakeFlags(methodKind, declarationModifiers, returnsVoid, isExpressionBodied: isExpressionBodied, isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); + this.MakeFlags( + methodKind, refKind, declarationModifiers, returnsVoid, hasBody: hasBody, isExpressionBodied: isExpressionBodied, + isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isVarArg: isVarArg, + isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); flags.SetOrdinaryMethodFlags(refKind, hasBody, isVarArg); _typeParameters = MakeTypeParameters(syntax, diagnostics); From c74ca1acede191d3779c9bef6c43d35ebb512a22 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 08:55:05 -0700 Subject: [PATCH 12/34] move more down --- .../Lowering/SynthesizedMethodBaseSymbol.cs | 10 --------- .../Symbols/Source/SourceConstructorSymbol.cs | 4 +++- .../Source/SourceConstructorSymbolBase.cs | 21 ++----------------- .../Source/SourceEventAccessorSymbol.cs | 13 +++--------- .../Source/SourceMemberMethodSymbol.cs | 10 +++++++++ .../SourceUserDefinedOperatorSymbolBase.cs | 17 +++------------ 6 files changed, 21 insertions(+), 54 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs index 531b601afd774..315f9b87c9c39 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs @@ -200,11 +200,6 @@ internal sealed override IEnumerable GetSecurityInformation() #nullable disable - public sealed override RefKind RefKind - { - get { return this.BaseMethod.RefKind; } - } - public sealed override TypeWithAnnotations ReturnTypeWithAnnotations { get { return this.TypeMap.SubstituteType(this.BaseMethod.OriginalDefinition.ReturnTypeWithAnnotations); } @@ -216,11 +211,6 @@ public sealed override TypeWithAnnotations ReturnTypeWithAnnotations public sealed override FlowAnalysisAnnotations FlowAnalysisAnnotations => FlowAnalysisAnnotations.None; - public sealed override bool IsVararg - { - get { return this.BaseMethod.IsVararg; } - } - public sealed override string Name { get { return _name; } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs index 8fdcd2fbfd338..d4cf02aeeac63 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs @@ -41,7 +41,9 @@ private SourceConstructorSymbol( bool modifierErrors; var declarationModifiers = this.MakeModifiers(syntax.Modifiers, methodKind, hasBody, location, diagnostics, out modifierErrors); - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); + this.MakeFlags( + methodKind, RefKind.None, declarationModifiers, returnsVoid: true, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, + isExtensionMethod: false, isVarArg: syntax.ParameterList.Parameters.Any(static p => p.IsArgList), isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (syntax.Identifier.ValueText != containingType.Name) { diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs index 431d62ece58b7..00e94036b411f 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbolBase.cs @@ -18,7 +18,6 @@ internal abstract class SourceConstructorSymbolBase : SourceMemberMethodSymbol { protected ImmutableArray _lazyParameters; private TypeWithAnnotations _lazyReturnType; - private bool _lazyIsVararg; protected SourceConstructorSymbolBase( SourceMemberContainerTypeSymbol containingType, @@ -48,15 +47,13 @@ protected sealed override void MethodChecks(BindingDiagnosticBag diagnostics) // instance). Constraints are checked in AfterAddingTypeMembersChecks. var signatureBinder = bodyBinder.WithAdditionalFlagsAndContainingMemberOrLambda(BinderFlags.SuppressConstraintChecks, this); - SyntaxToken arglistToken; _lazyParameters = ParameterHelpers.MakeParameters( - signatureBinder, this, parameterList, out arglistToken, + signatureBinder, this, parameterList, out _, allowRefOrOut: AllowRefOrOut, allowThis: false, addRefReadOnlyModifier: false, diagnostics: diagnostics).Cast(); - _lazyIsVararg = (arglistToken.Kind() == SyntaxKind.ArgListKeyword); _lazyReturnType = TypeWithAnnotations.Create(bodyBinder.GetSpecialType(SpecialType.System_Void, diagnostics, syntax)); var location = this.GetFirstLocation(); @@ -72,7 +69,7 @@ protected sealed override void MethodChecks(BindingDiagnosticBag diagnostics) this.CheckEffectiveAccessibility(_lazyReturnType, _lazyParameters, diagnostics); this.CheckFileTypeUsage(_lazyReturnType, _lazyParameters, diagnostics); - if (_lazyIsVararg && (IsGenericMethod || ContainingType.IsGenericType || _lazyParameters.Length > 0 && _lazyParameters[_lazyParameters.Length - 1].IsParams)) + if (this.IsVararg && (IsGenericMethod || ContainingType.IsGenericType || _lazyParameters.Length > 0 && _lazyParameters[_lazyParameters.Length - 1].IsParams)) { diagnostics.Add(ErrorCode.ERR_BadVarargs, location); } @@ -100,15 +97,6 @@ internal sealed override void AfterAddingTypeMembersChecks(ConversionsBase conve } } - public sealed override bool IsVararg - { - get - { - LazyMethodChecks(); - return _lazyIsVararg; - } - } - public sealed override bool IsImplicitlyDeclared { get @@ -150,11 +138,6 @@ public sealed override ImmutableArray> GetTy public sealed override ImmutableArray GetTypeParameterConstraintKinds() => ImmutableArray.Empty; - public override RefKind RefKind - { - get { return RefKind.None; } - } - public sealed override TypeWithAnnotations ReturnTypeWithAnnotations { get diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs index 00d2c4cdd71d4..2230e921befd5 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs @@ -55,11 +55,14 @@ public SourceEventAccessorSymbol( this.MakeFlags( isAdder ? MethodKind.EventAdd : MethodKind.EventRemove, + RefKind.None, @event.Modifiers, returnsVoid: false, // until we learn otherwise (in LazyMethodChecks). + hasAnyBody: false, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, + isVarArg: false, isMetadataVirtualIgnoringModifiers: @event.IsExplicitInterfaceImplementation && (@event.Modifiers & DeclarationModifiers.Static) == 0); _name = GetOverriddenAccessorName(@event, isAdder) ?? name; @@ -165,11 +168,6 @@ public sealed override bool ReturnsVoid } } - public override RefKind RefKind - { - get { return RefKind.None; } - } - public sealed override TypeWithAnnotations ReturnTypeWithAnnotations { get @@ -198,11 +196,6 @@ public sealed override ImmutableArray Parameters } } - public sealed override bool IsVararg - { - get { return false; } - } - public sealed override ImmutableArray TypeParameters { get { return ImmutableArray.Empty; } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index 938aa1a4e7ecf..751b3b486a241 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -1093,5 +1093,15 @@ internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree l return localPosition - bodySyntax.SpanStart; } + + public sealed override RefKind RefKind + { + get { return this.flags.RefKind; } + } + + public sealed override bool IsVararg + { + get { return this.flags.IsVarArg; } + } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs index 3fa2de838216b..a330f2039ea41 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs @@ -45,7 +45,9 @@ protected SourceUserDefinedOperatorSymbolBase( // assume that the return type is non-void; when we do the lazy initialization // of the parameters and return type we will update the flag if necessary. - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); + this.MakeFlags( + methodKind, RefKind.None, declarationModifiers, returnsVoid: false, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, + isExtensionMethod: false, isVarArg: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (this.ContainingType.IsInterface && !(IsAbstract || IsVirtual) && !IsExplicitInterfaceImplementation && @@ -761,14 +763,6 @@ public sealed override string Name } } - public sealed override bool IsVararg - { - get - { - return false; - } - } - public sealed override bool IsExtensionMethod { get @@ -788,11 +782,6 @@ public sealed override ImmutableArray> GetTy public sealed override ImmutableArray GetTypeParameterConstraintKinds() => ImmutableArray.Empty; - public sealed override RefKind RefKind - { - get { return RefKind.None; } - } - protected sealed override void CheckConstraintsForExplicitInterfaceType(ConversionsBase conversions, BindingDiagnosticBag diagnostics) { if ((object)_explicitInterfaceType != null) From e73807bd70895ebc9448c9b03b4d20784e285ece Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 08:55:46 -0700 Subject: [PATCH 13/34] move more down --- ...ynthesizedSimpleProgramEntryPointSymbol.cs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs index 5aba0636c498b..f36a020c6be36 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs @@ -55,11 +55,14 @@ internal SynthesizedSimpleProgramEntryPointSymbol(SourceMemberContainerTypeSymbo bool isNullableAnalysisEnabled = IsNullableAnalysisEnabled(compilation, CompilationUnit); this.MakeFlags( MethodKind.Ordinary, + RefKind.None, DeclarationModifiers.Static | DeclarationModifiers.Private | (hasAwait ? DeclarationModifiers.Async : DeclarationModifiers.None), returnsVoid: !hasAwait && !hasReturnWithExpression, + hasAnyBody: false, isExpressionBodied: false, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, + isVarArg: false, isMetadataVirtualIgnoringModifiers: false); _parameters = ImmutableArray.Create(SynthesizedParameterSymbol.Create(this, @@ -112,14 +115,6 @@ internal override System.Reflection.MethodImplAttributes ImplementationAttribute get { return default(System.Reflection.MethodImplAttributes); } } - public override bool IsVararg - { - get - { - return false; - } - } - public override ImmutableArray TypeParameters { get @@ -144,14 +139,6 @@ public override ImmutableArray Parameters } } - public override RefKind RefKind - { - get - { - return RefKind.None; - } - } - public override TypeWithAnnotations ReturnTypeWithAnnotations { get From 2ad5f4ccdcf71c3573c6b0522bc9d6ba14a9f6cc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 08:56:39 -0700 Subject: [PATCH 14/34] Pass all args --- .../Symbols/Source/SourceDestructorSymbol.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs index c2071844d64e2..0cd158be76f8d 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs @@ -30,8 +30,11 @@ internal SourceDestructorSymbol( bool hasBlockBody = syntax.Body != null; bool isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; + bool hasBody = hasBlockBody || isExpressionBodied; - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: true, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); + this.MakeFlags( + methodKind, RefKind.None, declarationModifiers, returnsVoid: true, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, + isVarArg: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (syntax.Identifier.ValueText != containingType.Name) { @@ -84,11 +87,6 @@ internal override ExecutableCodeBinder TryGetBodyBinder(BinderFactory binderFact return TryGetBodyBinderFromSyntax(binderFactoryOpt, ignoreAccessibility); } - public override bool IsVararg - { - get { return false; } - } - internal override int ParameterCount { get { return 0; } @@ -110,11 +108,6 @@ public override ImmutableArray> GetTypeParam public override ImmutableArray GetTypeParameterConstraintKinds() => ImmutableArray.Empty; - public override RefKind RefKind - { - get { return RefKind.None; } - } - public override TypeWithAnnotations ReturnTypeWithAnnotations { get From 5eb5236131317308466b1c2b6fb342b484bd19ff Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 08:59:07 -0700 Subject: [PATCH 15/34] move more down --- .../Source/SourceDelegateMethodSymbol.cs | 44 ++++--------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs index 94a3fa6819e54..804ee3eea2b57 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDelegateMethodSymbol.cs @@ -24,12 +24,14 @@ protected SourceDelegateMethodSymbol( TypeWithAnnotations returnType, DelegateDeclarationSyntax syntax, MethodKind methodKind, + RefKind refKind, DeclarationModifiers declarationModifiers) : base(delegateType, syntax.GetReference(), location: syntax.Identifier.GetLocation(), isIterator: false) { _returnType = returnType; this.MakeFlags( - methodKind, declarationModifiers, _returnType.IsVoidType(), isExpressionBodied: false, isExtensionMethod: false, isNullableAnalysisEnabled: false); + methodKind, refKind, declarationModifiers, _returnType.IsVoidType(), hasAnyBody: false, isExpressionBodied: false, + isExtensionMethod: false, isVarArg: false, isNullableAnalysisEnabled: false); } internal sealed override ExecutableCodeBinder TryGetBodyBinder(BinderFactory binderFactoryOpt = null, bool ignoreAccessibility = false) => throw ExceptionUtilities.Unreachable(); @@ -130,14 +132,6 @@ protected override void MethodChecks(BindingDiagnosticBag diagnostics) // TODO: move more functionality into here, making these symbols more lazy } - public sealed override bool IsVararg - { - get - { - return false; - } - } - public sealed override ImmutableArray Parameters { get @@ -215,7 +209,7 @@ internal Constructor( TypeWithAnnotations objectType, TypeWithAnnotations intPtrType, DelegateDeclarationSyntax syntax) - : base(delegateType, voidType, syntax, MethodKind.Constructor, DeclarationModifiers.Public) + : base(delegateType, voidType, syntax, MethodKind.Constructor, RefKind.None, DeclarationModifiers.Public) { InitializeParameters(ImmutableArray.Create( SynthesizedParameterSymbol.Create(this, objectType, 0, RefKind.None, "object"), @@ -227,11 +221,6 @@ public override string Name get { return WellKnownMemberNames.InstanceConstructorName; } } - public override RefKind RefKind - { - get { return RefKind.None; } - } - internal override OneOrMany> GetReturnTypeAttributeDeclarations() { // Constructors don't have return type attributes @@ -254,7 +243,6 @@ internal override LexicalSortKey GetLexicalSortKey() private sealed class InvokeMethod : SourceDelegateMethodSymbol { - private readonly RefKind _refKind; private readonly ImmutableArray _refCustomModifiers; internal InvokeMethod( @@ -264,10 +252,8 @@ internal InvokeMethod( DelegateDeclarationSyntax syntax, Binder binder, BindingDiagnosticBag diagnostics) - : base(delegateType, returnType, syntax, MethodKind.DelegateInvoke, DeclarationModifiers.Virtual | DeclarationModifiers.Public) + : base(delegateType, returnType, syntax, MethodKind.DelegateInvoke, refKind, DeclarationModifiers.Virtual | DeclarationModifiers.Public) { - this._refKind = refKind; - SyntaxToken arglistToken; var parameters = ParameterHelpers.MakeParameters( binder, this, syntax.ParameterList, out arglistToken, @@ -284,7 +270,7 @@ internal InvokeMethod( diagnostics.Add(ErrorCode.ERR_IllegalVarArgs, new SourceLocation(arglistToken)); } - if (_refKind == RefKind.RefReadOnly) + if (this.RefKind == RefKind.RefReadOnly) { var modifierType = binder.GetWellKnownType(WellKnownType.System_Runtime_InteropServices_InAttribute, diagnostics, syntax.ReturnType); _refCustomModifiers = ImmutableArray.Create(CSharpCustomModifier.CreateRequired(modifierType)); @@ -302,11 +288,6 @@ public override string Name get { return WellKnownMemberNames.DelegateInvokeName; } } - public override RefKind RefKind - { - get { return _refKind; } - } - internal override LexicalSortKey GetLexicalSortKey() { // associate "Invoke and .ctor" with whole delegate declaration for the sorting purposes @@ -328,7 +309,7 @@ internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, base.AfterAddingTypeMembersChecks(conversions, diagnostics); - if (_refKind == RefKind.RefReadOnly) + if (this.RefKind == RefKind.RefReadOnly) { compilation.EnsureIsReadOnlyAttributeExists(diagnostics, location, modifyCompilation: true); } @@ -363,7 +344,7 @@ internal BeginInvokeMethod( TypeWithAnnotations objectType, TypeWithAnnotations asyncCallbackType, DelegateDeclarationSyntax syntax) - : base((SourceNamedTypeSymbol)invoke.ContainingType, iAsyncResultType, syntax, MethodKind.Ordinary, DeclarationModifiers.Virtual | DeclarationModifiers.Public) + : base((SourceNamedTypeSymbol)invoke.ContainingType, iAsyncResultType, syntax, MethodKind.Ordinary, RefKind.None, DeclarationModifiers.Virtual | DeclarationModifiers.Public) { var parameters = ArrayBuilder.GetInstance(); foreach (SourceParameterSymbol p in invoke.Parameters) @@ -384,11 +365,6 @@ public override string Name get { return WellKnownMemberNames.DelegateBeginInvokeName; } } - public override RefKind RefKind - { - get { return RefKind.None; } - } - internal override OneOrMany> GetReturnTypeAttributeDeclarations() { // BeginInvoke method doesn't have return type attributes @@ -406,7 +382,7 @@ internal EndInvokeMethod( InvokeMethod invoke, TypeWithAnnotations iAsyncResultType, DelegateDeclarationSyntax syntax) - : base((SourceNamedTypeSymbol)invoke.ContainingType, invoke.ReturnTypeWithAnnotations, syntax, MethodKind.Ordinary, DeclarationModifiers.Virtual | DeclarationModifiers.Public) + : base((SourceNamedTypeSymbol)invoke.ContainingType, invoke.ReturnTypeWithAnnotations, syntax, MethodKind.Ordinary, invoke.RefKind, DeclarationModifiers.Virtual | DeclarationModifiers.Public) { _invoke = invoke; @@ -430,8 +406,6 @@ internal EndInvokeMethod( public override string Name => WellKnownMemberNames.DelegateEndInvokeName; - public override RefKind RefKind => _invoke.RefKind; - public override ImmutableArray RefCustomModifiers => _invoke.RefCustomModifiers; } From 08eee6ed0c838f184c1f886a610634f9f8c840b9 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 08:59:29 -0700 Subject: [PATCH 16/34] move more down --- .../Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index d87c320b03715..af9ba133d6067 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -446,9 +446,5 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r WellKnownMember.System_Runtime_CompilerServices_ExtensionAttribute__ctor)); } } - - public sealed override bool IsVararg => flags.IsVarArg; - - public sealed override RefKind RefKind => flags.RefKind; } } From 5640b006d45c7cfbbffe65639e40960a3f6e307e Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 09:02:18 -0700 Subject: [PATCH 17/34] move more down --- .../Source/SourceOrdinaryMethodSymbolBase.cs | 2 +- .../Source/SourcePropertyAccessorSymbol.cs | 18 ++++-------------- .../Records/SynthesizedPrimaryConstructor.cs | 3 +++ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index af9ba133d6067..3a50e2ba6bc3c 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -64,7 +64,7 @@ protected SourceOrdinaryMethodSymbolBase( var isMetadataVirtualIgnoringModifiers = isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0; this.MakeFlags( - methodKind, refKind, declarationModifiers, returnsVoid, hasBody: hasBody, isExpressionBodied: isExpressionBodied, + methodKind, refKind, declarationModifiers, returnsVoid, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isVarArg: isVarArg, isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); flags.SetOrdinaryMethodFlags(refKind, hasBody, isVarArg); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs index 6ca6c0c0bc229..66aea01deb3f6 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs @@ -156,8 +156,8 @@ private SourcePropertyAccessorSymbol( // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. bool isExplicitInterfaceImplementation = property.IsExplicitInterfaceImplementation; - this.MakeFlags(MethodKind.PropertyGet, declarationModifiers, returnsVoid: false, isExpressionBodied: true, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, - isMetadataVirtualIgnoringModifiers: isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0); + this.MakeFlags(MethodKind.PropertyGet, _property.RefKind, declarationModifiers, returnsVoid: false, hasAnyBody: true, isExpressionBodied: true, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, + isVarArg: false, isMetadataVirtualIgnoringModifiers: isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0); CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody: true, diagnostics: diagnostics); CheckModifiersForBody(location, diagnostics); @@ -212,8 +212,8 @@ protected SourcePropertyAccessorSymbol( // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. - this.MakeFlags(methodKind, declarationModifiers, returnsVoid: false, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, - isMetadataVirtualIgnoringModifiers: isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0); + this.MakeFlags(methodKind, _property.RefKind, declarationModifiers, returnsVoid: false, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, + isVarArg: false, isMetadataVirtualIgnoringModifiers: isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0); CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody: hasBody || hasExpressionBody || isAutoPropertyAccessor, diagnostics); @@ -303,11 +303,6 @@ public sealed override Symbol AssociatedSymbol get { return _property; } } - public sealed override bool IsVararg - { - get { return false; } - } - public sealed override bool ReturnsVoid { get { return this.ReturnType.IsVoidType(); } @@ -333,11 +328,6 @@ public sealed override ImmutableArray> GetTy public sealed override ImmutableArray GetTypeParameterConstraintKinds() => ImmutableArray.Empty; - public sealed override RefKind RefKind - { - get { return _property.RefKind; } - } - public sealed override TypeWithAnnotations ReturnTypeWithAnnotations { get diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs index 765999431fa70..e28d97e6e9da6 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs @@ -28,10 +28,13 @@ public SynthesizedPrimaryConstructor( this.MakeFlags( MethodKind.Constructor, + RefKind.None, containingType.IsAbstract ? DeclarationModifiers.Protected : DeclarationModifiers.Public, returnsVoid: true, + hasAnyBody: false, isExpressionBodied: false, isExtensionMethod: false, + isVarArg: false, isNullableAnalysisEnabled: false); // IsNullableAnalysisEnabled uses containing type instead. } From 0e4f6fbb500ec0ef10cc3e5c4ad85e428abd7212 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 09:03:33 -0700 Subject: [PATCH 18/34] move more down --- .../Symbols/Source/SourceMemberMethodSymbol.cs | 10 ++-------- .../Symbols/Source/SourceOrdinaryMethodSymbolBase.cs | 5 +---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index 751b3b486a241..1cdc33d906640 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -198,14 +198,6 @@ public Flags( | ReturnsVoidIsSetBit; } - /// - /// Only allowed to be called in constructors of SourceMemberMethodSymbol (and derived constructors), so - /// does not need ThreadSafe operations. - /// - public void SetOrdinaryMethodFlags(RefKind refKind, bool hasAnyBody, bool isVarArg) - { - } - public bool IsMetadataVirtual(bool ignoreInterfaceImplementationChanges = false) { // This flag is immutable, so there's no reason to set a lock bit, as we do below. @@ -1103,5 +1095,7 @@ public sealed override bool IsVararg { get { return this.flags.IsVarArg; } } + + protected bool HasAnyBody => flags.HasAnyBody; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index 3a50e2ba6bc3c..37ad614ed248f 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -67,7 +67,6 @@ protected SourceOrdinaryMethodSymbolBase( methodKind, refKind, declarationModifiers, returnsVoid, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isVarArg: isVarArg, isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); - flags.SetOrdinaryMethodFlags(refKind, hasBody, isVarArg); _typeParameters = MakeTypeParameters(syntax, diagnostics); @@ -137,8 +136,6 @@ protected override void MethodChecks(BindingDiagnosticBag diagnostics) protected abstract (TypeWithAnnotations ReturnType, ImmutableArray Parameters, ImmutableArray DeclaredConstraintsForOverrideOrImplementation) MakeParametersAndBindReturnType(BindingDiagnosticBag diagnostics); - protected bool HasAnyBody => flags.HasAnyBody; - protected sealed override void LazyAsyncMethodChecks(CancellationToken cancellationToken) { Debug.Assert(this.IsPartial == state.HasComplete(CompletionPart.FinishMethodChecks), @@ -317,7 +314,7 @@ private static DeclarationModifiers AddImpliedModifiers(DeclarationModifiers mod private void CheckModifiers(bool isExplicitInterfaceImplementation, bool hasBody, Location location, BindingDiagnosticBag diagnostics) { - bool isVararg = flags.IsVarArg; + bool isVararg = this.IsVararg; Debug.Assert(!IsStatic || !IsOverride); // Otherwise should have been reported and cleared earlier. Debug.Assert(!IsStatic || ContainingType.IsInterface || (!IsAbstract && !IsVirtual)); // Otherwise should have been reported and cleared earlier. From d02d68ea8be174c0be66c612fe15be081c3095ad Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 12:32:13 -0700 Subject: [PATCH 19/34] Name consistently --- .../Source/SourceMemberMethodSymbol.cs | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index 1cdc33d906640..bfb32374422a5 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -76,9 +76,9 @@ protected struct Flags private const int HasAnyBodyOffset = IsExpressionBodiedOffset + IsExpressionBodiedSize; private const int HasAnyBodySize = 1; - private const int IsVarArgOffset = HasAnyBodyOffset + HasAnyBodySize; + private const int IsVarargOffset = HasAnyBodyOffset + HasAnyBodySize; #pragma warning disable IDE0051 // Remove unused private members - private const int IsVarArgSize = 1; + private const int IsVarargSize = 1; #pragma warning restore IDE0051 // Remove unused private members private const int HasAnyBodyBit = 1 << HasAnyBodyOffset; @@ -87,7 +87,7 @@ protected struct Flags private const int IsMetadataVirtualIgnoringInterfaceChangesBit = 1 << IsMetadataVirtualIgnoringInterfaceChangesOffset; private const int IsMetadataVirtualBit = 1 << IsMetadataVirtualIgnoringInterfaceChangesOffset; private const int IsMetadataVirtualLockedBit = 1 << IsMetadataVirtualLockedOffset; - private const int IsVarArgBit = 1 << IsVarArgOffset; + private const int IsVarargBit = 1 << IsVarargOffset; private const int ReturnsVoidBit = 1 << ReturnsVoidOffset; private const int ReturnsVoidIsSetBit = 1 << ReturnsVoidOffset + 1; @@ -141,9 +141,9 @@ public bool IsMetadataVirtualLocked get { return (_flags & IsMetadataVirtualLockedBit) != 0; } } - public bool IsVarArg + public bool IsVararg { - get { return (_flags & IsVarArgBit) != 0; } + get { return (_flags & IsVarargBit) != 0; } } #if DEBUG @@ -170,18 +170,18 @@ public Flags( bool isExpressionBodied, bool isExtensionMethod, bool isNullableAnalysisEnabled, - bool isVarArg, + bool isVararg, bool isMetadataVirtualIgnoringModifiers = false) { bool isMetadataVirtual = isMetadataVirtualIgnoringModifiers || ModifiersRequireMetadataVirtual(declarationModifiers); int methodKindInt = ((int)methodKind & MethodKindMask) << MethodKindOffset; int refKindInt = ((int)refKind & RefKindMask) << RefKindOffset; - int hasAnyBodyInt = hasAnyBody? HasAnyBodyBit : 0; + int hasAnyBodyInt = hasAnyBody ? HasAnyBodyBit : 0; int isExpressionBodyInt = isExpressionBodied ? IsExpressionBodiedBit : 0; int isExtensionMethodInt = isExtensionMethod ? IsExtensionMethodBit : 0; int isNullableAnalysisEnabledInt = isNullableAnalysisEnabled ? IsNullableAnalysisEnabledBit : 0; - int isVarArgInt = isVarArg ? IsVarArgBit : 0; + int isVarargInt = isVararg ? IsVarargBit : 0; int isMetadataVirtualIgnoringInterfaceImplementationChangesInt = isMetadataVirtual ? IsMetadataVirtualIgnoringInterfaceChangesBit : 0; int isMetadataVirtualInt = isMetadataVirtual ? IsMetadataVirtualBit : 0; @@ -191,7 +191,7 @@ public Flags( | isExpressionBodyInt | isExtensionMethodInt | isNullableAnalysisEnabledInt - | isVarArgInt + | isVarargInt | isMetadataVirtualIgnoringInterfaceImplementationChangesInt | isMetadataVirtualInt | (returnsVoid ? ReturnsVoidBit : 0) @@ -1059,6 +1059,10 @@ protected void CheckFeatureAvailabilityAndRuntimeSupport(SyntaxNode declarationS /// present, this is not treated as expression-bodied. /// internal bool IsExpressionBodied => flags.IsExpressionBodied; + protected bool HasAnyBody => flags.HasAnyBody; + + public sealed override RefKind RefKind => this.flags.RefKind; + public sealed override bool IsVararg => this.flags.IsVararg; internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree localTree) { @@ -1085,17 +1089,5 @@ internal override int CalculateLocalSyntaxOffset(int localPosition, SyntaxTree l return localPosition - bodySyntax.SpanStart; } - - public sealed override RefKind RefKind - { - get { return this.flags.RefKind; } - } - - public sealed override bool IsVararg - { - get { return this.flags.IsVarArg; } - } - - protected bool HasAnyBody => flags.HasAnyBody; } } From 5d757aff3b2d38567f26fd40c88b14d2e2f41094 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 12:35:09 -0700 Subject: [PATCH 20/34] Set flag consistently --- .../Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs | 1 + .../Portable/Symbols/Source/SourceEventAccessorSymbol.cs | 3 ++- .../Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs index 7ffd478df9134..33b135319d643 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventAccessorSymbol.cs @@ -32,6 +32,7 @@ internal SourceCustomEventAccessorSymbol( isAdder: syntax.Kind() == SyntaxKind.AddAccessorDeclaration, isIterator: SyntaxFacts.HasYieldOperations(syntax.Body), isNullableAnalysisEnabled: isNullableAnalysisEnabled, + hasAnyBody: syntax.Body is not null || syntax.ExpressionBody is not null, isExpressionBodied: syntax is { Body: null, ExpressionBody: not null }) { Debug.Assert(syntax != null); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs index 2230e921befd5..c67ba98104cce 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventAccessorSymbol.cs @@ -30,6 +30,7 @@ public SourceEventAccessorSymbol( bool isAdder, bool isIterator, bool isNullableAnalysisEnabled, + bool hasAnyBody, bool isExpressionBodied) : base(@event.containingType, syntaxReference, location, isIterator) { @@ -58,7 +59,7 @@ public SourceEventAccessorSymbol( RefKind.None, @event.Modifiers, returnsVoid: false, // until we learn otherwise (in LazyMethodChecks). - hasAnyBody: false, + hasAnyBody: hasAnyBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs index a1e01aa551d49..fd8ff0670df5f 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs @@ -25,7 +25,7 @@ internal sealed class SynthesizedEventAccessorSymbol : SourceEventAccessorSymbol private readonly object _methodChecksLockObject = new object(); internal SynthesizedEventAccessorSymbol(SourceEventSymbol @event, bool isAdder, EventSymbol explicitlyImplementedEventOpt = null, string aliasQualifierOpt = null) - : base(@event, null, @event.Location, explicitlyImplementedEventOpt, aliasQualifierOpt, isAdder, isIterator: false, isNullableAnalysisEnabled: false, isExpressionBodied: false) + : base(@event, null, @event.Location, explicitlyImplementedEventOpt, aliasQualifierOpt, isAdder, isIterator: false, isNullableAnalysisEnabled: false, hasAnyBody: false, isExpressionBodied: false) { } From 94a74c9f2bc5d0c11ec92ea4d170c892e62f55a4 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 11 May 2023 12:35:28 -0700 Subject: [PATCH 21/34] Rename --- .../CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs index bfb32374422a5..7cd2ddded6a85 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberMethodSymbol.cs @@ -37,7 +37,7 @@ protected struct Flags // n = IsNullableAnalysisEnabled. 1 bit. // e = IsExpressionBody. 1 bit. // b = HasAnyBody. 1 bit. - // a = IsVarArg. 1 bit + // a = IsVararg. 1 bit private int _flags; private const int MethodKindOffset = 0; From 48a1a419417dcf27470be8ab04fc5d3237b842fc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 09:38:12 -0700 Subject: [PATCH 22/34] Fix usage of hasBody where it means hasBlockBody --- .../Symbols/Source/SourceConstructorSymbol.cs | 14 ++++++++------ .../Symbols/Source/SourceDestructorSymbol.cs | 4 ++-- .../Source/SourceOrdinaryMethodSymbol.cs | 2 +- .../Source/SourceOrdinaryMethodSymbolBase.cs | 10 +++++----- .../Source/SourcePropertyAccessorSymbol.cs | 17 +++++++++-------- .../Source/SourceUserDefinedConversionSymbol.cs | 2 +- .../Source/SourceUserDefinedOperatorSymbol.cs | 2 +- .../SourceUserDefinedOperatorSymbolBase.cs | 8 ++++---- ...SynthesizedRecordEqualityContractProperty.cs | 2 +- .../SynthesizedRecordEqualityOperatorBase.cs | 2 +- .../Records/SynthesizedRecordOrdinaryMethod.cs | 2 +- 11 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs index d4cf02aeeac63..640ee996895ff 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +// Ignore Spelling: Nullable + #nullable disable using System.Diagnostics; @@ -35,14 +37,14 @@ private SourceConstructorSymbol( { bool hasBlockBody = syntax.Body != null; bool isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; - bool hasBody = hasBlockBody || isExpressionBodied; + bool hasAnyBody = hasBlockBody || isExpressionBodied; _hasThisInitializer = syntax.Initializer?.Kind() == SyntaxKind.ThisConstructorInitializer; bool modifierErrors; - var declarationModifiers = this.MakeModifiers(syntax.Modifiers, methodKind, hasBody, location, diagnostics, out modifierErrors); + var declarationModifiers = this.MakeModifiers(syntax.Modifiers, methodKind, hasAnyBody, location, diagnostics, out modifierErrors); this.MakeFlags( - methodKind, RefKind.None, declarationModifiers, returnsVoid: true, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, + methodKind, RefKind.None, declarationModifiers, returnsVoid: true, hasAnyBody: hasAnyBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isVarArg: syntax.ParameterList.Parameters.Any(static p => p.IsArgList), isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (syntax.Identifier.ValueText != containingType.Name) @@ -58,7 +60,7 @@ private SourceConstructorSymbol( diagnostics.Add(ErrorCode.ERR_ExternHasConstructorInitializer, location, this); } - if (hasBody) + if (hasAnyBody) { diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this); } @@ -66,14 +68,14 @@ private SourceConstructorSymbol( if (methodKind == MethodKind.StaticConstructor) { - CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody, diagnostics); + CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasAnyBody, diagnostics); } ModifierUtils.CheckAccessibility(this.DeclarationModifiers, this, isExplicitInterfaceImplementation: false, diagnostics, location); if (!modifierErrors) { - this.CheckModifiers(methodKind, hasBody, location, diagnostics); + this.CheckModifiers(methodKind, hasAnyBody, location, diagnostics); } CheckForBlockAndExpressionBody( diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs index 0cd158be76f8d..fe0457aee98d3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceDestructorSymbol.cs @@ -30,10 +30,10 @@ internal SourceDestructorSymbol( bool hasBlockBody = syntax.Body != null; bool isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null; - bool hasBody = hasBlockBody || isExpressionBodied; + bool hasAnyBody = hasBlockBody || isExpressionBodied; this.MakeFlags( - methodKind, RefKind.None, declarationModifiers, returnsVoid: true, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, + methodKind, RefKind.None, declarationModifiers, returnsVoid: true, hasAnyBody: hasAnyBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isVarArg: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (syntax.Identifier.ValueText != containingType.Name) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs index cfbf6d669bcf4..89d6fdf22a057 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbol.cs @@ -70,7 +70,7 @@ private SourceOrdinaryMethodSymbol( !firstParam.IsArgList && firstParam.Modifiers.Any(SyntaxKind.ThisKeyword), isReadOnly: false, - hasBody: syntax.Body != null || syntax.ExpressionBody != null, + hasAnyBody: syntax.Body != null || syntax.ExpressionBody != null, isExpressionBodied: syntax is { Body: null, ExpressionBody: not null }, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isVarArg: syntax.ParameterList.Parameters.Any(p => p.IsArgList), diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs index f5e89d207ab3d..28184ed27f878 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceOrdinaryMethodSymbolBase.cs @@ -35,7 +35,7 @@ protected SourceOrdinaryMethodSymbolBase( bool isIterator, bool isExtensionMethod, bool isReadOnly, - bool hasBody, + bool hasAnyBody, bool isExpressionBodied, bool isNullableAnalysisEnabled, bool isVarArg, @@ -56,20 +56,20 @@ protected SourceOrdinaryMethodSymbolBase( const bool returnsVoid = false; DeclarationModifiers declarationModifiers; - (declarationModifiers, HasExplicitAccessModifier) = this.MakeModifiers(methodKind, isReadOnly, hasBody, location, diagnostics); + (declarationModifiers, HasExplicitAccessModifier) = this.MakeModifiers(methodKind, isReadOnly, hasAnyBody, location, diagnostics); //explicit impls must be marked metadata virtual unless static bool isExplicitInterfaceImplementation = methodKind == MethodKind.ExplicitInterfaceImplementation; var isMetadataVirtualIgnoringModifiers = isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0; this.MakeFlags( - methodKind, refKind, declarationModifiers, returnsVoid, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, + methodKind, refKind, declarationModifiers, returnsVoid, hasAnyBody: hasAnyBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: isExtensionMethod, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isVarArg: isVarArg, isMetadataVirtualIgnoringModifiers: isMetadataVirtualIgnoringModifiers); - CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody, diagnostics); + CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasAnyBody, diagnostics); - if (hasBody) + if (hasAnyBody) { CheckModifiersForBody(location, diagnostics); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs index 66aea01deb3f6..634f427a7a537 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertyAccessorSymbol.cs @@ -98,7 +98,7 @@ public static SourcePropertyAccessorSymbol CreateAccessorSymbol( propertyModifiers, location, syntax, - hasBody: false, + hasBlockBody: false, hasExpressionBody: false, isIterator: false, modifiers: default, @@ -174,7 +174,7 @@ protected SourcePropertyAccessorSymbol( DeclarationModifiers propertyModifiers, Location location, CSharpSyntaxNode syntax, - bool hasBody, + bool hasBlockBody, bool hasExpressionBody, bool isIterator, SyntaxTokenList modifiers, @@ -191,7 +191,8 @@ protected SourcePropertyAccessorSymbol( _property = property; _isAutoPropertyAccessor = isAutoPropertyAccessor; Debug.Assert(!_property.IsExpressionBodied, "Cannot have accessors in expression bodied lightweight properties"); - var isExpressionBodied = !hasBody && hasExpressionBody; + var isExpressionBodied = !hasBlockBody && hasExpressionBody; + var hasAnyBody = hasBlockBody || hasExpressionBody; _usesInit = usesInit; if (_usesInit) { @@ -200,7 +201,7 @@ protected SourcePropertyAccessorSymbol( bool modifierErrors; bool isExplicitInterfaceImplementation = property.IsExplicitInterfaceImplementation; - var declarationModifiers = this.MakeModifiers(modifiers, isExplicitInterfaceImplementation, hasBody || hasExpressionBody, location, diagnostics, out modifierErrors); + var declarationModifiers = this.MakeModifiers(modifiers, isExplicitInterfaceImplementation, hasAnyBody, location, diagnostics, out modifierErrors); // Include some modifiers from the containing property, but not the accessibility modifiers. declarationModifiers |= GetAccessorModifiers(propertyModifiers) & ~DeclarationModifiers.AccessibilityMask; @@ -212,12 +213,12 @@ protected SourcePropertyAccessorSymbol( // ReturnsVoid property is overridden in this class so // returnsVoid argument to MakeFlags is ignored. - this.MakeFlags(methodKind, _property.RefKind, declarationModifiers, returnsVoid: false, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, + this.MakeFlags(methodKind, _property.RefKind, declarationModifiers, returnsVoid: false, hasAnyBody: hasAnyBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, isVarArg: false, isMetadataVirtualIgnoringModifiers: isExplicitInterfaceImplementation && (declarationModifiers & DeclarationModifiers.Static) == 0); - CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody: hasBody || hasExpressionBody || isAutoPropertyAccessor, diagnostics); + CheckFeatureAvailabilityAndRuntimeSupport(syntax, location, hasBody: hasAnyBody || isAutoPropertyAccessor, diagnostics); - if (hasBody || hasExpressionBody) + if (hasAnyBody) { CheckModifiersForBody(location, diagnostics); } @@ -226,7 +227,7 @@ protected SourcePropertyAccessorSymbol( if (!modifierErrors) { - this.CheckModifiers(location, hasBody || hasExpressionBody, isAutoPropertyAccessor, diagnostics); + this.CheckModifiers(location, hasAnyBody, isAutoPropertyAccessor, diagnostics); } if (modifiers.Count > 0) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedConversionSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedConversionSymbol.cs index 0e9bac249c720..8d891bdcfe1af 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedConversionSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedConversionSymbol.cs @@ -67,7 +67,7 @@ private SourceUserDefinedConversionSymbol( location, syntax, MakeDeclarationModifiers(methodKind, containingType.IsInterface, syntax, location, diagnostics), - hasBody: syntax.HasAnyBody(), + hasAnyBody: syntax.HasAnyBody(), isExpressionBodied: syntax.Body == null && syntax.ExpressionBody != null, isIterator: SyntaxFacts.HasYieldOperations(syntax.Body), isNullableAnalysisEnabled: isNullableAnalysisEnabled, diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbol.cs index 4a9c89330c33f..647fcc7f676ef 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbol.cs @@ -72,7 +72,7 @@ private SourceUserDefinedOperatorSymbol( location, syntax, MakeDeclarationModifiers(methodKind, containingType.IsInterface, syntax, location, diagnostics), - hasBody: syntax.HasAnyBody(), + hasAnyBody: syntax.HasAnyBody(), isExpressionBodied: syntax.Body == null && syntax.ExpressionBody != null, isIterator: SyntaxFacts.HasYieldOperations(syntax.Body), isNullableAnalysisEnabled: isNullableAnalysisEnabled, diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs index a330f2039ea41..a13bf13ecb34b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceUserDefinedOperatorSymbolBase.cs @@ -29,7 +29,7 @@ protected SourceUserDefinedOperatorSymbolBase( Location location, CSharpSyntaxNode syntax, DeclarationModifiers declarationModifiers, - bool hasBody, + bool hasAnyBody, bool isExpressionBodied, bool isIterator, bool isNullableAnalysisEnabled, @@ -46,7 +46,7 @@ protected SourceUserDefinedOperatorSymbolBase( // of the parameters and return type we will update the flag if necessary. this.MakeFlags( - methodKind, RefKind.None, declarationModifiers, returnsVoid: false, hasAnyBody: hasBody, isExpressionBodied: isExpressionBodied, + methodKind, RefKind.None, declarationModifiers, returnsVoid: false, hasAnyBody: hasAnyBody, isExpressionBodied: isExpressionBodied, isExtensionMethod: false, isVarArg: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled); if (this.ContainingType.IsInterface && @@ -94,7 +94,7 @@ protected SourceUserDefinedOperatorSymbolBase( { diagnostics.Add(ErrorCode.ERR_AbstractNotVirtual, location, this.Kind.Localize(), this); } - else if (hasBody && (IsExtern || IsAbstract)) + else if (hasAnyBody && (IsExtern || IsAbstract)) { Debug.Assert(!(IsAbstract && IsExtern)); if (IsExtern) @@ -106,7 +106,7 @@ protected SourceUserDefinedOperatorSymbolBase( diagnostics.Add(ErrorCode.ERR_AbstractHasBody, location, this); } } - else if (!hasBody && !IsExtern && !IsAbstract && !IsPartial) + else if (!hasAnyBody && !IsExtern && !IsAbstract && !IsPartial) { // Do not report that the body is missing if the operator is marked as // partial or abstract; we will already have given an error for that so diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityContractProperty.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityContractProperty.cs index b2c452ed7382c..0ac9cd56a77fe 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityContractProperty.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityContractProperty.cs @@ -137,7 +137,7 @@ internal GetAccessorSymbol( propertyModifiers, location, syntax, - hasBody: true, + hasBlockBody: true, hasExpressionBody: false, isIterator: false, modifiers: default, diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs index af2b12f8d6e80..e56734b5105b4 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordEqualityOperatorBase.cs @@ -37,7 +37,7 @@ internal abstract class SynthesizedRecordEqualityOperatorBase : SourceUserDefine protected SynthesizedRecordEqualityOperatorBase(SourceMemberContainerTypeSymbol containingType, string name, int memberOffset, BindingDiagnosticBag diagnostics) : base(MethodKind.UserDefinedOperator, explicitInterfaceType: null, name, containingType, containingType.GetFirstLocation(), (CSharpSyntaxNode)containingType.SyntaxReferences[0].GetSyntax(), - DeclarationModifiers.Public | DeclarationModifiers.Static, hasBody: true, isExpressionBodied: false, isIterator: false, isNullableAnalysisEnabled: false, diagnostics) + DeclarationModifiers.Public | DeclarationModifiers.Static, hasAnyBody: true, isExpressionBodied: false, isIterator: false, isNullableAnalysisEnabled: false, diagnostics) { Debug.Assert(name == WellKnownMemberNames.EqualityOperatorName || name == WellKnownMemberNames.InequalityOperatorName); _memberOffset = memberOffset; diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs index 138969b6804c4..0306e1c830606 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedRecordOrdinaryMethod.cs @@ -22,7 +22,7 @@ internal abstract class SynthesizedRecordOrdinaryMethod : SourceOrdinaryMethodSy protected SynthesizedRecordOrdinaryMethod(SourceMemberContainerTypeSymbol containingType, string name, bool isReadOnly, bool hasBody, int memberOffset, BindingDiagnosticBag diagnostics) : base(containingType, name, containingType.GetFirstLocation(), (CSharpSyntaxNode)containingType.SyntaxReferences[0].GetSyntax(), MethodKind.Ordinary, RefKind.None, - isIterator: false, isExtensionMethod: false, isReadOnly: isReadOnly, hasBody: hasBody, isExpressionBodied: false, isNullableAnalysisEnabled: false, isVarArg: false, diagnostics) + isIterator: false, isExtensionMethod: false, isReadOnly: isReadOnly, hasAnyBody: hasBody, isExpressionBodied: false, isNullableAnalysisEnabled: false, isVarArg: false, diagnostics) { _memberOffset = memberOffset; } From d4bfe7eb64a446e9a90cdeca60e7a3ccdc411b60 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 09:42:08 -0700 Subject: [PATCH 23/34] Change to true --- .../CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs index 315f9b87c9c39..4496b6fe86b11 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs @@ -49,7 +49,8 @@ protected SynthesizedMethodBaseSymbol(NamedTypeSymbol containingType, refKind: baseMethod.RefKind, declarationModifiers: declarationModifiers, returnsVoid: baseMethod.ReturnsVoid, - hasAnyBody: false, + // Consider synthesized methods to always have bodies. + hasAnyBody: true, isExtensionMethod: false, isNullableAnalysisEnabled: false, isVarArg: baseMethod.IsVararg, From 43aab35f57900160b23cb4c91da6dc7a37efc2e2 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 09:42:59 -0700 Subject: [PATCH 24/34] Change to true --- .../Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs index f36a020c6be36..e102925092460 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedSimpleProgramEntryPointSymbol.cs @@ -58,7 +58,8 @@ internal SynthesizedSimpleProgramEntryPointSymbol(SourceMemberContainerTypeSymbo RefKind.None, DeclarationModifiers.Static | DeclarationModifiers.Private | (hasAwait ? DeclarationModifiers.Async : DeclarationModifiers.None), returnsVoid: !hasAwait && !hasReturnWithExpression, - hasAnyBody: false, + // Consider the synthesized entrypoint to always have a body (conceptually the top level statements). + hasAnyBody: true, isExpressionBodied: false, isExtensionMethod: false, isNullableAnalysisEnabled: isNullableAnalysisEnabled, From efe37fc597303f9f7be6c38657d6b6cdd1900987 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 09:44:04 -0700 Subject: [PATCH 25/34] Fix vararg check --- .../Synthesized/Records/SynthesizedPrimaryConstructor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs index e28d97e6e9da6..2ecd3b903aeba 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs @@ -34,7 +34,7 @@ public SynthesizedPrimaryConstructor( hasAnyBody: false, isExpressionBodied: false, isExtensionMethod: false, - isVarArg: false, + isVarArg: GetSyntax().ParameterList.Parameters.Any(static p => p.IsArgList), isNullableAnalysisEnabled: false); // IsNullableAnalysisEnabled uses containing type instead. } From 2e34e566e372703d7a2724a6c480aefb01859393 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 09:45:43 -0700 Subject: [PATCH 26/34] Change to true --- .../Synthesized/Records/SynthesizedPrimaryConstructor.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs index 2ecd3b903aeba..92264ca34b97a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs @@ -31,7 +31,9 @@ public SynthesizedPrimaryConstructor( RefKind.None, containingType.IsAbstract ? DeclarationModifiers.Protected : DeclarationModifiers.Public, returnsVoid: true, - hasAnyBody: false, + // We consider synthesized constructors to have a body, since they effectively span the entire type, and + // can do things like create constructor assignments that write into the fields/props of the type. + hasAnyBody: true, isExpressionBodied: false, isExtensionMethod: false, isVarArg: GetSyntax().ParameterList.Parameters.Any(static p => p.IsArgList), From ff7192bf27d230b3934f2f014712a45886284cdc Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 11:40:06 -0700 Subject: [PATCH 27/34] NRT --- .../Synthesized/Records/SynthesizedPrimaryConstructor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs index 92264ca34b97a..8b04b7d9f6cce 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs @@ -36,7 +36,7 @@ public SynthesizedPrimaryConstructor( hasAnyBody: true, isExpressionBodied: false, isExtensionMethod: false, - isVarArg: GetSyntax().ParameterList.Parameters.Any(static p => p.IsArgList), + isVarArg: syntax.ParameterList?.Parameters.Any(static p => p.IsArgList) ?? false, isNullableAnalysisEnabled: false); // IsNullableAnalysisEnabled uses containing type instead. } From a27e8076fbb874fac263274057485b9715c28120 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 11:44:14 -0700 Subject: [PATCH 28/34] Pass values explicitly --- .../Portable/Symbols/Source/SourceCustomEventSymbol.cs | 5 +++-- .../Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs | 5 +++-- .../Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventSymbol.cs index 44e86f087ab08..7f379c7072076 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceCustomEventSymbol.cs @@ -155,8 +155,9 @@ internal SourceCustomEventSymbol(SourceMemberContainerTypeSymbol containingType, diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportDefaultInterfaceImplementation, this.GetFirstLocation()); } - _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, explicitlyImplementedEvent, aliasQualifierOpt); - _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, explicitlyImplementedEvent, aliasQualifierOpt); + // No body as this was an abstract event. + _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: false, isExpressionBodied: false, explicitlyImplementedEvent, aliasQualifierOpt); + _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: false, isExpressionBodied: false, explicitlyImplementedEvent, aliasQualifierOpt); } else { diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs index 0998929b2dbad..ea7e989fc05c9 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs @@ -114,8 +114,9 @@ internal SourceFieldLikeEventSymbol(SourceMemberContainerTypeSymbol containingTy } // Accessors will assume that Type is available. - _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true); - _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false); + // No body, as this was declared by a event-field, nothing that has an actual block or expression body. + _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: false, isExpressionBodied: false); + _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: false, isExpressionBodied: false); if (declarationSyntax.Variables[0] == declaratorSyntax) { diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs index fd8ff0670df5f..5c133e454d8d1 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedEventAccessorSymbol.cs @@ -24,8 +24,8 @@ internal sealed class SynthesizedEventAccessorSymbol : SourceEventAccessorSymbol // Since we don't have a syntax reference, we'll have to use another object for locking. private readonly object _methodChecksLockObject = new object(); - internal SynthesizedEventAccessorSymbol(SourceEventSymbol @event, bool isAdder, EventSymbol explicitlyImplementedEventOpt = null, string aliasQualifierOpt = null) - : base(@event, null, @event.Location, explicitlyImplementedEventOpt, aliasQualifierOpt, isAdder, isIterator: false, isNullableAnalysisEnabled: false, hasAnyBody: false, isExpressionBodied: false) + internal SynthesizedEventAccessorSymbol(SourceEventSymbol @event, bool isAdder, bool hasAnyBody, bool isExpressionBodied, EventSymbol explicitlyImplementedEventOpt = null, string aliasQualifierOpt = null) + : base(@event, null, @event.Location, explicitlyImplementedEventOpt, aliasQualifierOpt, isAdder, isIterator: false, isNullableAnalysisEnabled: false, hasAnyBody: hasAnyBody, isExpressionBodied: isExpressionBodied) { } From c11f580bd76b31caca8a9aef6a856f7623d55acf Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 13:14:17 -0700 Subject: [PATCH 29/34] Add assert --- .../Synthesized/Records/SynthesizedPrimaryConstructor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs index 8b04b7d9f6cce..eb4f79ecf69a2 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/Records/SynthesizedPrimaryConstructor.cs @@ -25,6 +25,7 @@ public SynthesizedPrimaryConstructor( Debug.Assert(containingType.HasPrimaryConstructor); Debug.Assert(containingType is SourceNamedTypeSymbol); Debug.Assert(containingType is IAttributeTargetSymbol); + Debug.Assert(syntax.ParameterList != null); this.MakeFlags( MethodKind.Constructor, @@ -36,7 +37,7 @@ public SynthesizedPrimaryConstructor( hasAnyBody: true, isExpressionBodied: false, isExtensionMethod: false, - isVarArg: syntax.ParameterList?.Parameters.Any(static p => p.IsArgList) ?? false, + isVarArg: syntax.ParameterList.Parameters.Any(static p => p.IsArgList), isNullableAnalysisEnabled: false); // IsNullableAnalysisEnabled uses containing type instead. } From aa120d2ed23c44cb67dd262b1911cb83b3dc39ac Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 13:16:30 -0700 Subject: [PATCH 30/34] Flip depending on if something is abstract or not. --- .../Symbols/Source/SourceFieldLikeEventSymbol.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs index ea7e989fc05c9..20d69082339a3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs @@ -113,10 +113,11 @@ internal SourceFieldLikeEventSymbol(SourceMemberContainerTypeSymbol containingTy } } - // Accessors will assume that Type is available. - // No body, as this was declared by a event-field, nothing that has an actual block or expression body. - _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: false, isExpressionBodied: false); - _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: false, isExpressionBodied: false); + // Accessors will assume that Type is available. We consider abstract field events to not have a body, but + // all other field events do have one. hasAnyBody here effectively is just proxy for marking if something + // is abstract or not. Note: unclear if this should also apply to Extern events. + _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: !IsAbstract, isExpressionBodied: false); + _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: !IsAbstract, isExpressionBodied: false); if (declarationSyntax.Variables[0] == declaratorSyntax) { From fc9d57174079be0978af429e6b84637a560a820c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 May 2023 18:53:22 -0700 Subject: [PATCH 31/34] Update check --- .../Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs index 20d69082339a3..6a84365537594 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs @@ -116,8 +116,9 @@ internal SourceFieldLikeEventSymbol(SourceMemberContainerTypeSymbol containingTy // Accessors will assume that Type is available. We consider abstract field events to not have a body, but // all other field events do have one. hasAnyBody here effectively is just proxy for marking if something // is abstract or not. Note: unclear if this should also apply to Extern events. - _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: !IsAbstract, isExpressionBodied: false); - _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: !IsAbstract, isExpressionBodied: false); + var hasAnyBody = !IsAbstract && !IsExtern; + _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: hasAnyBody, isExpressionBodied: false); + _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: hasAnyBody, isExpressionBodied: false); if (declarationSyntax.Variables[0] == declaratorSyntax) { From 77474b192713a4e3e45d7e44f252e80db0954eef Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sun, 14 May 2023 20:09:34 -0700 Subject: [PATCH 32/34] Fix ocmment --- .../Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs index 6a84365537594..963f998ac51cf 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs @@ -113,9 +113,8 @@ internal SourceFieldLikeEventSymbol(SourceMemberContainerTypeSymbol containingTy } } - // Accessors will assume that Type is available. We consider abstract field events to not have a body, but - // all other field events do have one. hasAnyBody here effectively is just proxy for marking if something - // is abstract or not. Note: unclear if this should also apply to Extern events. + // Accessors will assume that Type is available. We consider abstract/extern field events to not have a + // body, but all other field events do have one. var hasAnyBody = !IsAbstract && !IsExtern; _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: hasAnyBody, isExpressionBodied: false); _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: hasAnyBody, isExpressionBodied: false); From d3b2b40415ca9d4491d2f37ad2213abc036b6813 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sun, 14 May 2023 20:10:29 -0700 Subject: [PATCH 33/34] Fix ocmment --- .../Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs index 963f998ac51cf..0db8d93d0c41c 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldLikeEventSymbol.cs @@ -113,8 +113,8 @@ internal SourceFieldLikeEventSymbol(SourceMemberContainerTypeSymbol containingTy } } - // Accessors will assume that Type is available. We consider abstract/extern field events to not have a - // body, but all other field events do have one. + // Accessors will assume that Type is available. We consider abstract/extern accessors to not have a + // body, but all others do have one. var hasAnyBody = !IsAbstract && !IsExtern; _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, hasAnyBody: hasAnyBody, isExpressionBodied: false); _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, hasAnyBody: hasAnyBody, isExpressionBodied: false); From b76e78e0163bdb54060e3377e63ee88ff933c0d0 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 15 May 2023 17:11:34 -0700 Subject: [PATCH 34/34] Update src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs --- .../CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs index 640ee996895ff..2119ddccd1841 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceConstructorSymbol.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -// Ignore Spelling: Nullable - #nullable disable using System.Diagnostics;