Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pack bits in SourceOrdinaryMethodSymbol into an existing bitflag structure we have for all source methods #68132

Merged
merged 11 commits into from
May 10, 2023
Merged
Prev Previous commit
Next Next commit
Simplify
  • Loading branch information
CyrusNajmabadi committed May 8, 2023
commit d22ed19218c8b6e992a5a3dd1fe39a9d4bf799b3
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@

#nullable disable

using System;
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Original file line number Diff line number Diff line change
@@ -191,11 +191,10 @@ public Flags(
| ReturnsVoidIsSetBit;
}

public void SetOrdinaryMethodFlags(RefKind refKind, bool isExpressionBodied, bool hasAnyBody)
public void SetOrdinaryMethodFlags(RefKind refKind, bool hasAnyBody)
{
// Only set in the constructor of SourceOrdinaryMethodSymbol, so does not need ThreadSafe operations.
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
_flags |= ((int)refKind & RefKindMask) << RefKindOffset;
_flags |= isExpressionBodied ? IsExpressionBodiedBit : 0;
_flags |= hasAnyBody ? HasAnyBodyBit : 0;
}

Original file line number Diff line number Diff line change
@@ -93,12 +93,12 @@ private SourceOrdinaryMethodSymbol(

Debug.Assert(syntax.ReturnType is not ScopedTypeSyntax);

var hasBlockBody = syntax.Body != null;
var isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null;
var hasAnyBody = hasBlockBody || isExpressionBodied;
bool hasBlockBody = syntax.Body != null;
bool isExpressionBodied = !hasBlockBody && syntax.ExpressionBody != null;
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
bool hasAnyBody = hasBlockBody || isExpressionBodied;
var refKind = syntax.ReturnType.SkipScoped(out _).GetRefKindInLocalOrReturn(diagnostics);

flags.SetOrdinaryMethodFlags(refKind, isExpressionBodied, hasAnyBody);
flags.SetOrdinaryMethodFlags(refKind, hasAnyBody);

CheckForBlockAndExpressionBody(
syntax.Body, syntax.ExpressionBody, syntax, diagnostics);