26
26
#include " swift/AST/DeclContext.h"
27
27
#include " swift/AST/DeclNameLoc.h"
28
28
#include " swift/AST/FreestandingMacroExpansion.h"
29
- #include " swift/AST/FunctionRefKind .h"
29
+ #include " swift/AST/FunctionRefInfo .h"
30
30
#include " swift/AST/ProtocolConformanceRef.h"
31
31
#include " swift/AST/ThrownErrorDestination.h"
32
32
#include " swift/AST/TypeAlignments.h"
@@ -193,16 +193,16 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
193
193
LiteralCapacity : 32
194
194
);
195
195
196
- SWIFT_INLINE_BITFIELD (DeclRefExpr, Expr, 2 +2 +1 +1 ,
196
+ SWIFT_INLINE_BITFIELD (DeclRefExpr, Expr, 2 +3 +1 +1 ,
197
197
Semantics : 2 , // an AccessSemantics
198
- FunctionRefKind : 2 ,
198
+ FunctionRefInfo : 3 ,
199
199
IsImplicitlyAsync : 1 ,
200
200
IsImplicitlyThrows : 1
201
201
);
202
202
203
- SWIFT_INLINE_BITFIELD (UnresolvedDeclRefExpr, Expr, 2 +2 ,
203
+ SWIFT_INLINE_BITFIELD (UnresolvedDeclRefExpr, Expr, 2 +3 ,
204
204
DeclRefKind : 2 ,
205
- FunctionRefKind : 2
205
+ FunctionRefInfo : 3
206
206
);
207
207
208
208
SWIFT_INLINE_BITFIELD (MemberRefExpr, LookupExpr, 2 ,
@@ -225,8 +225,8 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
225
225
NumElements : 32
226
226
);
227
227
228
- SWIFT_INLINE_BITFIELD (UnresolvedDotExpr, Expr, 2 ,
229
- FunctionRefKind : 2
228
+ SWIFT_INLINE_BITFIELD (UnresolvedDotExpr, Expr, 3 ,
229
+ FunctionRefInfo : 3
230
230
);
231
231
232
232
SWIFT_INLINE_BITFIELD_FULL (SubscriptExpr, LookupExpr, 2 ,
@@ -235,12 +235,12 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
235
235
236
236
SWIFT_INLINE_BITFIELD_EMPTY (DynamicSubscriptExpr, DynamicLookupExpr);
237
237
238
- SWIFT_INLINE_BITFIELD_FULL (UnresolvedMemberExpr, Expr, 2 ,
239
- FunctionRefKind : 2
238
+ SWIFT_INLINE_BITFIELD_FULL (UnresolvedMemberExpr, Expr, 3 ,
239
+ FunctionRefInfo : 3
240
240
);
241
241
242
- SWIFT_INLINE_BITFIELD (OverloadSetRefExpr, Expr, 2 ,
243
- FunctionRefKind : 2
242
+ SWIFT_INLINE_BITFIELD (OverloadSetRefExpr, Expr, 3 ,
243
+ FunctionRefInfo : 3
244
244
);
245
245
246
246
SWIFT_INLINE_BITFIELD (BooleanLiteralExpr, LiteralExpr, 1 ,
@@ -1230,12 +1230,10 @@ class DeclRefExpr : public Expr {
1230
1230
Type Ty = Type())
1231
1231
: Expr(ExprKind::DeclRef, Implicit, Ty), D(D), Loc(Loc),
1232
1232
implicitActorHopTarget (ActorIsolation::forUnspecified()) {
1233
- Bits.DeclRefExpr .Semantics = (unsigned ) semantics;
1234
- Bits.DeclRefExpr .FunctionRefKind =
1235
- static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1236
- : FunctionRefKind::Unapplied);
1233
+ Bits.DeclRefExpr .Semantics = (unsigned )semantics;
1237
1234
Bits.DeclRefExpr .IsImplicitlyAsync = false ;
1238
1235
Bits.DeclRefExpr .IsImplicitlyThrows = false ;
1236
+ setFunctionRefInfo (FunctionRefInfo::unapplied (Loc));
1239
1237
}
1240
1238
1241
1239
// / Retrieve the declaration to which this expression refers.
@@ -1300,13 +1298,14 @@ class DeclRefExpr : public Expr {
1300
1298
DeclNameLoc getNameLoc () const { return Loc; }
1301
1299
1302
1300
// / Retrieve the kind of function reference.
1303
- FunctionRefKind getFunctionRefKind () const {
1304
- return static_cast <FunctionRefKind> (Bits.DeclRefExpr .FunctionRefKind );
1301
+ FunctionRefInfo getFunctionRefInfo () const {
1302
+ return FunctionRefInfo::fromOpaque (Bits.DeclRefExpr .FunctionRefInfo );
1305
1303
}
1306
1304
1307
1305
// / Set the kind of function reference.
1308
- void setFunctionRefKind (FunctionRefKind refKind) {
1309
- Bits.DeclRefExpr .FunctionRefKind = static_cast <unsigned >(refKind);
1306
+ void setFunctionRefInfo (FunctionRefInfo refKind) {
1307
+ Bits.DeclRefExpr .FunctionRefInfo = refKind.getOpaqueValue ();
1308
+ ASSERT (refKind == getFunctionRefInfo () && " FunctionRefInfo truncated" );
1310
1309
}
1311
1310
1312
1311
static bool classof (const Expr *E) {
@@ -1506,10 +1505,9 @@ class OverloadSetRefExpr : public Expr {
1506
1505
1507
1506
protected:
1508
1507
OverloadSetRefExpr (ExprKind Kind, ArrayRef<ValueDecl*> decls,
1509
- FunctionRefKind functionRefKind , bool Implicit, Type Ty)
1508
+ FunctionRefInfo functionRefInfo , bool Implicit, Type Ty)
1510
1509
: Expr(Kind, Implicit, Ty), Decls(decls) {
1511
- Bits.OverloadSetRefExpr .FunctionRefKind =
1512
- static_cast <unsigned >(functionRefKind);
1510
+ setFunctionRefInfo (functionRefInfo);
1513
1511
}
1514
1512
1515
1513
public:
@@ -1529,14 +1527,14 @@ class OverloadSetRefExpr : public Expr {
1529
1527
bool hasBaseObject () const ;
1530
1528
1531
1529
// / Retrieve the kind of function reference.
1532
- FunctionRefKind getFunctionRefKind () const {
1533
- return static_cast <FunctionRefKind>(
1534
- Bits.OverloadSetRefExpr .FunctionRefKind );
1530
+ FunctionRefInfo getFunctionRefInfo () const {
1531
+ return FunctionRefInfo::fromOpaque (Bits.OverloadSetRefExpr .FunctionRefInfo );
1535
1532
}
1536
1533
1537
1534
// / Set the kind of function reference.
1538
- void setFunctionRefKind (FunctionRefKind refKind) {
1539
- Bits.OverloadSetRefExpr .FunctionRefKind = static_cast <unsigned >(refKind);
1535
+ void setFunctionRefInfo (FunctionRefInfo refKind) {
1536
+ Bits.OverloadSetRefExpr .FunctionRefInfo = refKind.getOpaqueValue ();
1537
+ ASSERT (refKind == getFunctionRefInfo () && " FunctionRefInfo truncated" );
1540
1538
}
1541
1539
1542
1540
static bool classof (const Expr *E) {
@@ -1552,9 +1550,9 @@ class OverloadedDeclRefExpr final : public OverloadSetRefExpr {
1552
1550
1553
1551
public:
1554
1552
OverloadedDeclRefExpr (ArrayRef<ValueDecl*> Decls, DeclNameLoc Loc,
1555
- FunctionRefKind functionRefKind ,
1553
+ FunctionRefInfo functionRefInfo ,
1556
1554
bool Implicit, Type Ty = Type())
1557
- : OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, functionRefKind ,
1555
+ : OverloadSetRefExpr(ExprKind::OverloadedDeclRef, Decls, functionRefInfo ,
1558
1556
Implicit, Ty),
1559
1557
Loc (Loc) {
1560
1558
}
@@ -1584,9 +1582,7 @@ class UnresolvedDeclRefExpr : public Expr {
1584
1582
: Expr(ExprKind::UnresolvedDeclRef, /* Implicit=*/ loc.isInvalid()),
1585
1583
Name (name), Loc(loc) {
1586
1584
Bits.UnresolvedDeclRefExpr .DeclRefKind = static_cast <unsigned >(refKind);
1587
- Bits.UnresolvedDeclRefExpr .FunctionRefKind =
1588
- static_cast <unsigned >(Loc.isCompound () ? FunctionRefKind::Compound
1589
- : FunctionRefKind::Unapplied);
1585
+ setFunctionRefInfo (FunctionRefInfo::unapplied (loc));
1590
1586
}
1591
1587
1592
1588
static UnresolvedDeclRefExpr *createImplicit (
@@ -1616,14 +1612,15 @@ class UnresolvedDeclRefExpr : public Expr {
1616
1612
}
1617
1613
1618
1614
// / Retrieve the kind of function reference.
1619
- FunctionRefKind getFunctionRefKind () const {
1620
- return static_cast <FunctionRefKind> (
1621
- Bits.UnresolvedDeclRefExpr .FunctionRefKind );
1615
+ FunctionRefInfo getFunctionRefInfo () const {
1616
+ return FunctionRefInfo::fromOpaque (
1617
+ Bits.UnresolvedDeclRefExpr .FunctionRefInfo );
1622
1618
}
1623
1619
1624
1620
// / Set the kind of function reference.
1625
- void setFunctionRefKind (FunctionRefKind refKind) {
1626
- Bits.UnresolvedDeclRefExpr .FunctionRefKind = static_cast <unsigned >(refKind);
1621
+ void setFunctionRefInfo (FunctionRefInfo refKind) {
1622
+ Bits.UnresolvedDeclRefExpr .FunctionRefInfo = refKind.getOpaqueValue ();
1623
+ ASSERT (refKind == getFunctionRefInfo () && " FunctionRefInfo truncated" );
1627
1624
}
1628
1625
1629
1626
DeclNameLoc getNameLoc () const { return Loc; }
@@ -1901,19 +1898,18 @@ class UnresolvedMemberExpr final
1901
1898
bool implicit)
1902
1899
: Expr(ExprKind::UnresolvedMember, implicit), DotLoc(dotLoc),
1903
1900
NameLoc (nameLoc), Name(name) {
1904
- // FIXME: Really, we should be setting this to `FunctionRefKind::Compound`
1905
- // if `NameLoc` is compound, but this would be a source break for cases like
1901
+ // FIXME(FunctionRefInfo): Really, we should be passing `nameLoc` directly,
1902
+ // allowing the FunctionRefInfo to be treated as compound. This would
1903
+ // require us to enable IUOs for compound names, e.g:
1906
1904
// ```
1907
1905
// struct S {
1908
1906
// static func makeS(_: Int) -> S! { S() }
1909
1907
// }
1910
1908
//
1911
1909
// let s: S = .makeS(_:)(0)
1912
1910
// ```
1913
- // Instead, we should store compound-ness as a separate bit from applied/
1914
- // unapplied.
1915
- Bits.UnresolvedMemberExpr .FunctionRefKind =
1916
- static_cast <unsigned >(FunctionRefKind::Unapplied);
1911
+ setFunctionRefInfo (
1912
+ FunctionRefInfo::unapplied (DeclNameLoc (nameLoc.getBaseNameLoc ())));
1917
1913
}
1918
1914
1919
1915
DeclNameRef getName () const { return Name; }
@@ -1926,16 +1922,17 @@ class UnresolvedMemberExpr final
1926
1922
SourceLoc getEndLoc () const { return NameLoc.getSourceRange ().End ; }
1927
1923
1928
1924
// / Retrieve the kind of function reference.
1929
- FunctionRefKind getFunctionRefKind () const {
1930
- return static_cast <FunctionRefKind> (
1931
- Bits.UnresolvedMemberExpr .FunctionRefKind );
1925
+ FunctionRefInfo getFunctionRefInfo () const {
1926
+ return FunctionRefInfo::fromOpaque (
1927
+ Bits.UnresolvedMemberExpr .FunctionRefInfo );
1932
1928
}
1933
1929
1934
1930
// / Set the kind of function reference.
1935
- void setFunctionRefKind (FunctionRefKind refKind) {
1936
- Bits.UnresolvedMemberExpr .FunctionRefKind = static_cast <unsigned >(refKind);
1931
+ void setFunctionRefInfo (FunctionRefInfo refKind) {
1932
+ Bits.UnresolvedMemberExpr .FunctionRefInfo = refKind.getOpaqueValue ();
1933
+ ASSERT (refKind == getFunctionRefInfo () && " FunctionRefInfo truncated" );
1937
1934
}
1938
-
1935
+
1939
1936
static bool classof (const Expr *E) {
1940
1937
return E->getKind () == ExprKind::UnresolvedMember;
1941
1938
}
@@ -2627,9 +2624,7 @@ class UnresolvedDotExpr : public Expr {
2627
2624
: Expr(ExprKind::UnresolvedDot, Implicit), SubExpr(subexpr),
2628
2625
DotLoc (dotloc), NameLoc(nameloc), Name(name),
2629
2626
OuterAlternatives(outerAlternatives) {
2630
- Bits.UnresolvedDotExpr .FunctionRefKind =
2631
- static_cast <unsigned >(NameLoc.isCompound () ? FunctionRefKind::Compound
2632
- : FunctionRefKind::Unapplied);
2627
+ setFunctionRefInfo (FunctionRefInfo::unapplied (nameloc));
2633
2628
}
2634
2629
2635
2630
static UnresolvedDotExpr *createImplicit (
@@ -2692,13 +2687,14 @@ class UnresolvedDotExpr : public Expr {
2692
2687
}
2693
2688
2694
2689
// / Retrieve the kind of function reference.
2695
- FunctionRefKind getFunctionRefKind () const {
2696
- return static_cast <FunctionRefKind> (Bits.UnresolvedDotExpr .FunctionRefKind );
2690
+ FunctionRefInfo getFunctionRefInfo () const {
2691
+ return FunctionRefInfo::fromOpaque (Bits.UnresolvedDotExpr .FunctionRefInfo );
2697
2692
}
2698
2693
2699
2694
// / Set the kind of function reference.
2700
- void setFunctionRefKind (FunctionRefKind refKind) {
2701
- Bits.UnresolvedDotExpr .FunctionRefKind = static_cast <unsigned >(refKind);
2695
+ void setFunctionRefInfo (FunctionRefInfo refKind) {
2696
+ Bits.UnresolvedDotExpr .FunctionRefInfo = refKind.getOpaqueValue ();
2697
+ ASSERT (refKind == getFunctionRefInfo () && " FunctionRefInfo truncated" );
2702
2698
}
2703
2699
2704
2700
static bool classof (const Expr *E) {
0 commit comments