-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pack bits in SourceOrdinaryMethodSymbol into an existing bitflag structure we have for all source methods #68158
Changes from 2 commits
3e67b7c
ce343a6
1319147
eee77ee
d2a9c02
824b5b1
1932ed3
9f7d914
a0295b7
27e28b7
54c18cf
d3a9476
c74ca1a
e73807b
2ad5f4c
5eb5236
08eee6e
5640b00
0e4f6fb
d02d68e
5d757af
94a74c9
fb5eaa9
48a1a41
d4bfe7e
43aab35
efe37fc
2e34e56
ff7192b
a27e807
c11f580
aa120d2
31a6277
fc9d571
77474b1
d3b2b40
b76e78e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIt: we have all sorts of logic for computing these values in different places. We also name the variable inconsistently all over the place (hasBody sometimes means 'has any body' and sometimes means 'has block body'). It woudl be good to make this all consistent. |
||
|
||
_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<SyntaxList<AttributeListSyntax>> GetAttributeDeclara | |
return OneOrMany.Create(((ConstructorDeclarationSyntax)this.SyntaxNode).AttributeLists); | ||
} | ||
|
||
internal override bool IsExpressionBodied | ||
{ | ||
get | ||
{ | ||
return _isExpressionBodied; | ||
} | ||
} | ||
|
||
internal override bool IsNullableAnalysisEnabled() | ||
{ | ||
return _hasThisInitializer ? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,25 +27,26 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be replaced with HasAnyBody. Not sure how such refactorings are viewed though. |
||
{ | ||
if (IsExtern) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_ExternHasBody, location, this); | ||
} | ||
} | ||
|
||
if (!modifierErrors && !hasBlockBody && !_isExpressionBodied && !IsExtern) | ||
if (!modifierErrors && !hasBlockBody && !isExpressionBodied && !IsExtern) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be replaced with !HasAnyBody. Not sure how such refactorings are viewed though. |
||
{ | ||
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<SyntaxList<AttributeListSyntax>> GetAttributeDeclarations() | ||
{ | ||
// destructors can't have return type attributes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. def a wrong statement. |
||
get { return false; } | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could consider moving this bit down as well. That would save another unnecessary 32bits in constructors. however, constructors seem to be orders of magnitude less common than methods, so it's not high on my priority list.