@@ -249,17 +249,8 @@ class alignas(8) Expr {
249249 NumArgLabels : 16
250250 );
251251
252- SWIFT_INLINE_BITFIELD_FULL (UnresolvedMemberExpr, Expr, 1 +1 +1 +16 ,
253- // / Whether the UnresolvedMemberExpr has arguments.
254- HasArguments : 1 ,
255- // / Whether the UnresolvedMemberExpr also has source locations for the
256- // / argument label.
257- HasArgLabelLocs : 1 ,
258- // / Whether the last argument is a trailing closure.
259- HasTrailingClosure : 1 ,
260- : NumPadBits,
261- // / # of argument labels stored after the UnresolvedMemberExpr.
262- NumArgLabels : 16
252+ SWIFT_INLINE_BITFIELD_FULL (UnresolvedMemberExpr, Expr, 2 ,
253+ FunctionRefKind : 2
263254 );
264255
265256 SWIFT_INLINE_BITFIELD (OverloadSetRefExpr, Expr, 2 ,
@@ -1841,71 +1832,49 @@ class DynamicSubscriptExpr final
18411832// / member, which is to be resolved with context sensitive type information into
18421833// / bar.foo. These always have unresolved type.
18431834class UnresolvedMemberExpr final
1844- : public Expr,
1845- public TrailingCallArguments<UnresolvedMemberExpr> {
1835+ : public Expr {
18461836 SourceLoc DotLoc;
18471837 DeclNameLoc NameLoc;
18481838 DeclNameRef Name;
1849- Expr *Argument;
1850-
1851- UnresolvedMemberExpr (SourceLoc dotLoc, DeclNameLoc nameLoc,
1852- DeclNameRef name, Expr *argument,
1853- ArrayRef<Identifier> argLabels,
1854- ArrayRef<SourceLoc> argLabelLocs,
1855- bool hasTrailingClosure,
1856- bool implicit);
18571839
18581840public:
1859- // / Create a new unresolved member expression with no arguments.
1860- static UnresolvedMemberExpr *create (ASTContext &ctx, SourceLoc dotLoc,
1861- DeclNameLoc nameLoc, DeclNameRef name,
1862- bool implicit);
1863-
1864- // / Create a new unresolved member expression.
1865- static UnresolvedMemberExpr *create (ASTContext &ctx, SourceLoc dotLoc,
1866- DeclNameLoc nameLoc, DeclNameRef name,
1867- SourceLoc lParenLoc,
1868- ArrayRef<Expr *> args,
1869- ArrayRef<Identifier> argLabels,
1870- ArrayRef<SourceLoc> argLabelLocs,
1871- SourceLoc rParenLoc,
1872- ArrayRef<TrailingClosure> trailingClosures,
1873- bool implicit);
1841+ UnresolvedMemberExpr (SourceLoc dotLoc, DeclNameLoc nameLoc, DeclNameRef name,
1842+ bool implicit)
1843+ : Expr(ExprKind::UnresolvedMember, implicit), DotLoc(dotLoc),
1844+ NameLoc (nameLoc), Name(name) {
1845+ // FIXME: Really, we should be setting this to `FunctionRefKind::Compound`
1846+ // if `NameLoc` is compound, but this would be a source break for cases like
1847+ // ```
1848+ // struct S {
1849+ // static func makeS(_: Int) -> S! { S() }
1850+ // }
1851+ //
1852+ // let s: S = .makeS(_:)(0)
1853+ // ```
1854+ // Instead, we should store compound-ness as a separate bit from applied/
1855+ // unapplied.
1856+ Bits.UnresolvedMemberExpr .FunctionRefKind =
1857+ static_cast <unsigned >(FunctionRefKind::Unapplied);
1858+ }
18741859
18751860 DeclNameRef getName () const { return Name; }
18761861 DeclNameLoc getNameLoc () const { return NameLoc; }
18771862 SourceLoc getDotLoc () const { return DotLoc; }
1878- Expr *getArgument () const { return Argument; }
1879- void setArgument (Expr *argument) { Argument = argument; }
18801863
1881- // / Whether this reference has arguments.
1882- bool hasArguments () const {
1883- return Bits.UnresolvedMemberExpr .HasArguments ;
1884- }
1885-
1886- unsigned getNumArguments () const {
1887- return Bits.UnresolvedMemberExpr .NumArgLabels ;
1888- }
1889-
1890- bool hasArgumentLabelLocs () const {
1891- return Bits.UnresolvedMemberExpr .HasArgLabelLocs ;
1892- }
1864+ SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
18931865
1894- // / Whether this call with written with a trailing closure.
1895- bool hasTrailingClosure () const {
1896- return Bits.UnresolvedMemberExpr .HasTrailingClosure ;
1897- }
1866+ SourceLoc getStartLoc () const { return DotLoc; }
1867+ SourceLoc getEndLoc () const { return NameLoc.getSourceRange ().End ; }
18981868
1899- // / Return the index of the unlabeled trailing closure argument.
1900- Optional<unsigned > getUnlabeledTrailingClosureIndex () const {
1901- return getArgument ()->getUnlabeledTrailingClosureIndexOfPackedArgument ();
1869+ // / Retrieve the kind of function reference.
1870+ FunctionRefKind getFunctionRefKind () const {
1871+ return static_cast <FunctionRefKind>(
1872+ Bits.UnresolvedMemberExpr .FunctionRefKind );
19021873 }
19031874
1904- SourceLoc getLoc () const { return NameLoc.getBaseNameLoc (); }
1905-
1906- SourceLoc getStartLoc () const { return DotLoc; }
1907- SourceLoc getEndLoc () const {
1908- return (Argument ? Argument->getEndLoc () : NameLoc.getSourceRange ().End );
1875+ // / Set the kind of function reference.
1876+ void setFunctionRefKind (FunctionRefKind refKind) {
1877+ Bits.UnresolvedMemberExpr .FunctionRefKind = static_cast <unsigned >(refKind);
19091878 }
19101879
19111880 static bool classof (const Expr *E) {
@@ -2088,6 +2057,31 @@ class ParenExpr : public IdentityExpr {
20882057
20892058 static bool classof (const Expr *E) { return E->getKind () == ExprKind::Paren; }
20902059};
2060+
2061+ // / Represents the result of a chain of accesses or calls hanging off of an
2062+ // / \c UnresolvedMemberExpr at the root. This is only used during type checking
2063+ // / to give the result type of such a chain representation in the AST. This
2064+ // / expression type is always implicit.
2065+ class UnresolvedMemberChainResultExpr : public IdentityExpr {
2066+ // / The base of this chain of member accesses.
2067+ UnresolvedMemberExpr *ChainBase;
2068+ public:
2069+ UnresolvedMemberChainResultExpr (Expr *subExpr, UnresolvedMemberExpr *base,
2070+ Type ty = Type())
2071+ : IdentityExpr(ExprKind::UnresolvedMemberChainResult, subExpr, ty,
2072+ /* isImplicit=*/ true ),
2073+ ChainBase (base) {
2074+ assert (base);
2075+ }
2076+
2077+ UnresolvedMemberExpr *getChainBase () const { return ChainBase; }
2078+
2079+ SWIFT_FORWARD_SOURCE_LOCS_TO (getSubExpr())
2080+
2081+ static bool classof(const Expr *E) {
2082+ return E->getKind () == ExprKind::UnresolvedMemberChainResult;
2083+ }
2084+ };
20912085
20922086// / AwaitExpr - An 'await' surrounding an expression, marking that the
20932087// / expression contains code which is a coroutine that may block.
0 commit comments