Skip to content

[AST] Split out "is compound" bit on FunctionRefKind #77896

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

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 52 additions & 56 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "swift/AST/DeclContext.h"
#include "swift/AST/DeclNameLoc.h"
#include "swift/AST/FreestandingMacroExpansion.h"
#include "swift/AST/FunctionRefKind.h"
#include "swift/AST/FunctionRefInfo.h"
#include "swift/AST/ProtocolConformanceRef.h"
#include "swift/AST/ThrownErrorDestination.h"
#include "swift/AST/TypeAlignments.h"
Expand Down Expand Up @@ -193,16 +193,16 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
LiteralCapacity : 32
);

SWIFT_INLINE_BITFIELD(DeclRefExpr, Expr, 2+2+1+1,
SWIFT_INLINE_BITFIELD(DeclRefExpr, Expr, 2+3+1+1,
Semantics : 2, // an AccessSemantics
FunctionRefKind : 2,
FunctionRefInfo : 3,
IsImplicitlyAsync : 1,
IsImplicitlyThrows : 1
);

SWIFT_INLINE_BITFIELD(UnresolvedDeclRefExpr, Expr, 2+2,
SWIFT_INLINE_BITFIELD(UnresolvedDeclRefExpr, Expr, 2+3,
DeclRefKind : 2,
FunctionRefKind : 2
FunctionRefInfo : 3
);

SWIFT_INLINE_BITFIELD(MemberRefExpr, LookupExpr, 2,
Expand All @@ -225,8 +225,8 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
NumElements : 32
);

SWIFT_INLINE_BITFIELD(UnresolvedDotExpr, Expr, 2,
FunctionRefKind : 2
SWIFT_INLINE_BITFIELD(UnresolvedDotExpr, Expr, 3,
FunctionRefInfo : 3
);

SWIFT_INLINE_BITFIELD_FULL(SubscriptExpr, LookupExpr, 2,
Expand All @@ -235,12 +235,12 @@ class alignas(8) Expr : public ASTAllocated<Expr> {

SWIFT_INLINE_BITFIELD_EMPTY(DynamicSubscriptExpr, DynamicLookupExpr);

SWIFT_INLINE_BITFIELD_FULL(UnresolvedMemberExpr, Expr, 2,
FunctionRefKind : 2
SWIFT_INLINE_BITFIELD_FULL(UnresolvedMemberExpr, Expr, 3,
FunctionRefInfo : 3
);

SWIFT_INLINE_BITFIELD(OverloadSetRefExpr, Expr, 2,
FunctionRefKind : 2
SWIFT_INLINE_BITFIELD(OverloadSetRefExpr, Expr, 3,
FunctionRefInfo : 3
);

SWIFT_INLINE_BITFIELD(BooleanLiteralExpr, LiteralExpr, 1,
Expand Down Expand Up @@ -1230,12 +1230,10 @@ class DeclRefExpr : public Expr {
Type Ty = Type())
: Expr(ExprKind::DeclRef, Implicit, Ty), D(D), Loc(Loc),
implicitActorHopTarget(ActorIsolation::forUnspecified()) {
Bits.DeclRefExpr.Semantics = (unsigned) semantics;
Bits.DeclRefExpr.FunctionRefKind =
static_cast<unsigned>(Loc.isCompound() ? FunctionRefKind::Compound
: FunctionRefKind::Unapplied);
Bits.DeclRefExpr.Semantics = (unsigned)semantics;
Bits.DeclRefExpr.IsImplicitlyAsync = false;
Bits.DeclRefExpr.IsImplicitlyThrows = false;
setFunctionRefInfo(FunctionRefInfo::unapplied(Loc));
}

/// Retrieve the declaration to which this expression refers.
Expand Down Expand Up @@ -1300,13 +1298,14 @@ class DeclRefExpr : public Expr {
DeclNameLoc getNameLoc() const { return Loc; }

/// Retrieve the kind of function reference.
FunctionRefKind getFunctionRefKind() const {
return static_cast<FunctionRefKind>(Bits.DeclRefExpr.FunctionRefKind);
FunctionRefInfo getFunctionRefInfo() const {
return FunctionRefInfo::fromOpaque(Bits.DeclRefExpr.FunctionRefInfo);
}

/// Set the kind of function reference.
void setFunctionRefKind(FunctionRefKind refKind) {
Bits.DeclRefExpr.FunctionRefKind = static_cast<unsigned>(refKind);
void setFunctionRefInfo(FunctionRefInfo refKind) {
Bits.DeclRefExpr.FunctionRefInfo = refKind.getOpaqueValue();
ASSERT(refKind == getFunctionRefInfo() && "FunctionRefInfo truncated");
}

static bool classof(const Expr *E) {
Expand Down Expand Up @@ -1506,10 +1505,9 @@ class OverloadSetRefExpr : public Expr {

protected:
OverloadSetRefExpr(ExprKind Kind, ArrayRef<ValueDecl*> decls,
FunctionRefKind functionRefKind, bool Implicit, Type Ty)
FunctionRefInfo functionRefInfo, bool Implicit, Type Ty)
: Expr(Kind, Implicit, Ty), Decls(decls) {
Bits.OverloadSetRefExpr.FunctionRefKind =
static_cast<unsigned>(functionRefKind);
setFunctionRefInfo(functionRefInfo);
}

public:
Expand All @@ -1529,14 +1527,14 @@ class OverloadSetRefExpr : public Expr {
bool hasBaseObject() const;

/// Retrieve the kind of function reference.
FunctionRefKind getFunctionRefKind() const {
return static_cast<FunctionRefKind>(
Bits.OverloadSetRefExpr.FunctionRefKind);
FunctionRefInfo getFunctionRefInfo() const {
return FunctionRefInfo::fromOpaque(Bits.OverloadSetRefExpr.FunctionRefInfo);
}

/// Set the kind of function reference.
void setFunctionRefKind(FunctionRefKind refKind) {
Bits.OverloadSetRefExpr.FunctionRefKind = static_cast<unsigned>(refKind);
void setFunctionRefInfo(FunctionRefInfo refKind) {
Bits.OverloadSetRefExpr.FunctionRefInfo = refKind.getOpaqueValue();
ASSERT(refKind == getFunctionRefInfo() && "FunctionRefInfo truncated");
}

static bool classof(const Expr *E) {
Expand All @@ -1552,9 +1550,9 @@ class OverloadedDeclRefExpr final : public OverloadSetRefExpr {

public:
OverloadedDeclRefExpr(ArrayRef<ValueDecl*> Decls, DeclNameLoc Loc,
FunctionRefKind functionRefKind,
FunctionRefInfo functionRefInfo,
bool Implicit, Type Ty = Type())
: OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, functionRefKind,
: OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, functionRefInfo,
Implicit, Ty),
Loc(Loc) {
}
Expand Down Expand Up @@ -1584,9 +1582,7 @@ class UnresolvedDeclRefExpr : public Expr {
: Expr(ExprKind::UnresolvedDeclRef, /*Implicit=*/loc.isInvalid()),
Name(name), Loc(loc) {
Bits.UnresolvedDeclRefExpr.DeclRefKind = static_cast<unsigned>(refKind);
Bits.UnresolvedDeclRefExpr.FunctionRefKind =
static_cast<unsigned>(Loc.isCompound() ? FunctionRefKind::Compound
: FunctionRefKind::Unapplied);
setFunctionRefInfo(FunctionRefInfo::unapplied(loc));
}

static UnresolvedDeclRefExpr *createImplicit(
Expand Down Expand Up @@ -1616,14 +1612,15 @@ class UnresolvedDeclRefExpr : public Expr {
}

/// Retrieve the kind of function reference.
FunctionRefKind getFunctionRefKind() const {
return static_cast<FunctionRefKind>(
Bits.UnresolvedDeclRefExpr.FunctionRefKind);
FunctionRefInfo getFunctionRefInfo() const {
return FunctionRefInfo::fromOpaque(
Bits.UnresolvedDeclRefExpr.FunctionRefInfo);
}

/// Set the kind of function reference.
void setFunctionRefKind(FunctionRefKind refKind) {
Bits.UnresolvedDeclRefExpr.FunctionRefKind = static_cast<unsigned>(refKind);
void setFunctionRefInfo(FunctionRefInfo refKind) {
Bits.UnresolvedDeclRefExpr.FunctionRefInfo = refKind.getOpaqueValue();
ASSERT(refKind == getFunctionRefInfo() && "FunctionRefInfo truncated");
}

DeclNameLoc getNameLoc() const { return Loc; }
Expand Down Expand Up @@ -1901,19 +1898,18 @@ class UnresolvedMemberExpr final
bool implicit)
: Expr(ExprKind::UnresolvedMember, implicit), DotLoc(dotLoc),
NameLoc(nameLoc), Name(name) {
// FIXME: Really, we should be setting this to `FunctionRefKind::Compound`
// if `NameLoc` is compound, but this would be a source break for cases like
// FIXME(FunctionRefInfo): Really, we should be passing `nameLoc` directly,
// allowing the FunctionRefInfo to be treated as compound. This would
// require us to enable IUOs for compound names, e.g:
// ```
// struct S {
// static func makeS(_: Int) -> S! { S() }
// }
//
// let s: S = .makeS(_:)(0)
// ```
// Instead, we should store compound-ness as a separate bit from applied/
// unapplied.
Bits.UnresolvedMemberExpr.FunctionRefKind =
static_cast<unsigned>(FunctionRefKind::Unapplied);
setFunctionRefInfo(
FunctionRefInfo::unapplied(DeclNameLoc(nameLoc.getBaseNameLoc())));
}

DeclNameRef getName() const { return Name; }
Expand All @@ -1926,16 +1922,17 @@ class UnresolvedMemberExpr final
SourceLoc getEndLoc() const { return NameLoc.getSourceRange().End; }

/// Retrieve the kind of function reference.
FunctionRefKind getFunctionRefKind() const {
return static_cast<FunctionRefKind>(
Bits.UnresolvedMemberExpr.FunctionRefKind);
FunctionRefInfo getFunctionRefInfo() const {
return FunctionRefInfo::fromOpaque(
Bits.UnresolvedMemberExpr.FunctionRefInfo);
}

/// Set the kind of function reference.
void setFunctionRefKind(FunctionRefKind refKind) {
Bits.UnresolvedMemberExpr.FunctionRefKind = static_cast<unsigned>(refKind);
void setFunctionRefInfo(FunctionRefInfo refKind) {
Bits.UnresolvedMemberExpr.FunctionRefInfo = refKind.getOpaqueValue();
ASSERT(refKind == getFunctionRefInfo() && "FunctionRefInfo truncated");
}

static bool classof(const Expr *E) {
return E->getKind() == ExprKind::UnresolvedMember;
}
Expand Down Expand Up @@ -2627,9 +2624,7 @@ class UnresolvedDotExpr : public Expr {
: Expr(ExprKind::UnresolvedDot, Implicit), SubExpr(subexpr),
DotLoc(dotloc), NameLoc(nameloc), Name(name),
OuterAlternatives(outerAlternatives) {
Bits.UnresolvedDotExpr.FunctionRefKind =
static_cast<unsigned>(NameLoc.isCompound() ? FunctionRefKind::Compound
: FunctionRefKind::Unapplied);
setFunctionRefInfo(FunctionRefInfo::unapplied(nameloc));
}

static UnresolvedDotExpr *createImplicit(
Expand Down Expand Up @@ -2692,13 +2687,14 @@ class UnresolvedDotExpr : public Expr {
}

/// Retrieve the kind of function reference.
FunctionRefKind getFunctionRefKind() const {
return static_cast<FunctionRefKind>(Bits.UnresolvedDotExpr.FunctionRefKind);
FunctionRefInfo getFunctionRefInfo() const {
return FunctionRefInfo::fromOpaque(Bits.UnresolvedDotExpr.FunctionRefInfo);
}

/// Set the kind of function reference.
void setFunctionRefKind(FunctionRefKind refKind) {
Bits.UnresolvedDotExpr.FunctionRefKind = static_cast<unsigned>(refKind);
void setFunctionRefInfo(FunctionRefInfo refKind) {
Bits.UnresolvedDotExpr.FunctionRefInfo = refKind.getOpaqueValue();
ASSERT(refKind == getFunctionRefInfo() && "FunctionRefInfo truncated");
}

static bool classof(const Expr *E) {
Expand Down
Loading