Skip to content

Commit b507894

Browse files
committed
Sema: Fix a few places where we built AST that had to go through SanitizeExpr before type checking
1 parent b663c9b commit b507894

9 files changed

+35
-62
lines changed

lib/Sema/DerivedConformanceAdditiveArithmetic.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,10 @@ deriveBodyMathOperator(AbstractFunctionDecl *funcDecl, MathOperator op) {
126126
confRef.getConcrete()->getWitnessDecl(operatorReq))
127127
memberOpDecl = concreteMemberMethodDecl;
128128
assert(memberOpDecl && "Member operator declaration must exist");
129-
auto memberOpDRE =
130-
new (C) DeclRefExpr(memberOpDecl, DeclNameLoc(), /*Implicit*/ true);
131129
auto *memberTypeExpr = TypeExpr::createImplicit(memberType, C);
132130
auto memberOpExpr =
133-
new (C) DotSyntaxCallExpr(memberOpDRE, SourceLoc(), memberTypeExpr);
131+
new (C) MemberRefExpr(memberTypeExpr, SourceLoc(), memberOpDecl,
132+
DeclNameLoc(), /*Implicit*/ true);
134133

135134
// Create expression `lhs.member <op> rhs.member`.
136135
// NOTE(TF-1054): create new `DeclRefExpr`s per loop iteration to avoid

lib/Sema/DerivedConformanceCaseIterable.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ deriveCaseIterable_enum_getter(AbstractFunctionDecl *funcDecl, void *) {
4848

4949
SmallVector<Expr *, 8> elExprs;
5050
for (EnumElementDecl *elt : parentEnum->getAllElements()) {
51-
auto *ref = new (C) DeclRefExpr(elt, DeclNameLoc(), /*implicit*/true);
5251
auto *base = TypeExpr::createImplicit(enumTy, C);
53-
auto *apply = new (C) DotSyntaxCallExpr(ref, SourceLoc(), base);
52+
auto *apply = new (C) MemberRefExpr(base, SourceLoc(),
53+
elt, DeclNameLoc(), /*implicit*/true);
5454
elExprs.push_back(apply);
5555
}
5656
auto *arrayExpr = ArrayExpr::create(C, SourceLoc(), elExprs, {}, SourceLoc());

lib/Sema/DerivedConformanceCodable.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,9 @@ deriveBodyEncodable_encode(AbstractFunctionDecl *encodeDecl, void *) {
619619
DeclNameLoc(), /*Implicit=*/true);
620620

621621
// CodingKeys.x
622-
auto *eltRef = new (C) DeclRefExpr(elt, DeclNameLoc(), /*implicit=*/true);
623622
auto *metaTyRef = TypeExpr::createImplicit(codingKeysType, C);
624-
auto *keyExpr = new (C) DotSyntaxCallExpr(eltRef, SourceLoc(), metaTyRef);
623+
auto *keyExpr = new (C) MemberRefExpr(metaTyRef, SourceLoc(), elt,
624+
DeclNameLoc(), /*Implicit=*/true);
625625

626626
// encode(_:forKey:)/encodeIfPresent(_:forKey:)
627627
auto methodName = useIfPresentVariant ? C.Id_encodeIfPresent : C.Id_encode;
@@ -901,9 +901,9 @@ deriveBodyDecodable_init(AbstractFunctionDecl *initDecl, void *) {
901901
SourceLoc(), varType);
902902

903903
// CodingKeys.x
904-
auto *eltRef = new (C) DeclRefExpr(elt, DeclNameLoc(), /*implicit=*/true);
905904
metaTyRef = TypeExpr::createImplicit(codingKeysType, C);
906-
auto *keyExpr = new (C) DotSyntaxCallExpr(eltRef, SourceLoc(), metaTyRef);
905+
auto *keyExpr = new (C) MemberRefExpr(metaTyRef, SourceLoc(),
906+
elt, DeclNameLoc(), /*Implicit=*/true);
907907

908908
// decode(_:forKey:)/decodeIfPresent(_:forKey:)
909909
SmallVector<Identifier, 2> argNames{Identifier(), C.Id_forKey};

lib/Sema/DerivedConformanceCodingKey.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ deriveBodyCodingKey_init_stringValue(AbstractFunctionDecl *initDecl, void *) {
284284

285285
auto labelItem = CaseLabelItem(litPat);
286286

287-
auto *eltRef = new (C) DeclRefExpr(elt, DeclNameLoc(), /*Implicit=*/true);
288287
auto *metaTyRef = TypeExpr::createImplicit(enumType, C);
289-
auto *valueExpr = new (C) DotSyntaxCallExpr(eltRef, SourceLoc(), metaTyRef);
288+
auto *valueExpr = new (C) MemberRefExpr(metaTyRef, SourceLoc(), elt,
289+
DeclNameLoc(), /*Implicit=*/true);
290290

291291
auto *assignment = new (C) AssignExpr(selfRef, SourceLoc(), valueExpr,
292292
/*Implicit=*/true);

lib/Sema/DerivedConformanceComparable.cpp

+6-24
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,21 @@ deriveBodyComparable_enum_noAssociatedValues_lt(AbstractFunctionDecl *ltDecl,
7474
FuncDecl *cmpFunc = C.getLessThanIntDecl();
7575
assert(cmpFunc && "should have a < for int as we already checked for it");
7676

77-
auto fnType = cmpFunc->getInterfaceType()->castTo<FunctionType>();
78-
79-
Expr *cmpFuncExpr;
80-
if (cmpFunc->getDeclContext()->isTypeContext()) {
81-
auto contextTy = cmpFunc->getDeclContext()->getSelfInterfaceType();
82-
Expr *base = TypeExpr::createImplicitHack(SourceLoc(), contextTy, C);
83-
Expr *ref = new (C) DeclRefExpr(cmpFunc, DeclNameLoc(), /*Implicit*/ true,
84-
AccessSemantics::Ordinary, fnType);
85-
86-
fnType = fnType->getResult()->castTo<FunctionType>();
87-
cmpFuncExpr = new (C) DotSyntaxCallExpr(ref, SourceLoc(), base, fnType);
88-
cmpFuncExpr->setImplicit();
89-
} else {
90-
cmpFuncExpr = new (C) DeclRefExpr(cmpFunc, DeclNameLoc(),
91-
/*implicit*/ true,
92-
AccessSemantics::Ordinary,
93-
fnType);
94-
}
77+
Expr *cmpFuncExpr = new (C) DeclRefExpr(cmpFunc, DeclNameLoc(),
78+
/*implicit*/ true,
79+
AccessSemantics::Ordinary);
9580

96-
TupleTypeElt abTupleElts[2] = { aIndex->getType(), bIndex->getType() };
9781
TupleExpr *abTuple = TupleExpr::create(C, SourceLoc(), { aIndex, bIndex },
9882
{ }, { }, SourceLoc(),
9983
/*HasTrailingClosure*/ false,
100-
/*Implicit*/ true,
101-
TupleType::get(abTupleElts, C));
84+
/*Implicit*/ true);
10285

10386
auto *cmpExpr = new (C) BinaryExpr(
104-
cmpFuncExpr, abTuple, /*implicit*/ true,
105-
fnType->castTo<FunctionType>()->getResult());
87+
cmpFuncExpr, abTuple, /*implicit*/ true);
10688
statements.push_back(new (C) ReturnStmt(SourceLoc(), cmpExpr));
10789

10890
BraceStmt *body = BraceStmt::create(C, SourceLoc(), statements, SourceLoc());
109-
return { body, /*isTypeChecked=*/true };
91+
return { body, /*isTypeChecked=*/false };
11092
}
11193

11294
/// Derive the body for an '==' operator for an enum where at least one of the

lib/Sema/DerivedConformanceDifferentiable.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,14 @@ deriveBodyDifferentiable_move(AbstractFunctionDecl *funcDecl, void *) {
268268
if (auto *witness = confRef.getConcrete()->getWitnessDecl(requirement))
269269
memberWitnessDecl = witness;
270270
assert(memberWitnessDecl && "Member witness declaration must exist");
271-
auto *memberMethodDRE = new (C)
272-
DeclRefExpr(memberWitnessDecl, DeclNameLoc(), /*Implicit*/ true);
273-
memberMethodDRE->setFunctionRefKind(FunctionRefKind::SingleApply);
274271

275272
// Create reference to member method: `self.<member>.move(along:)`.
276273
Expr *memberExpr =
277274
new (C) MemberRefExpr(selfDRE, SourceLoc(), member, DeclNameLoc(),
278275
/*Implicit*/ true);
279276
auto *memberMethodExpr =
280-
new (C) DotSyntaxCallExpr(memberMethodDRE, SourceLoc(), memberExpr);
277+
new (C) MemberRefExpr(memberExpr, SourceLoc(), memberWitnessDecl,
278+
DeclNameLoc(), /*Implicit*/ true);
281279

282280
// Create reference to parameter member: `direction.<member>`.
283281
VarDecl *paramMember = nullptr;

lib/Sema/DerivedConformanceEquatableHashable.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,17 @@ deriveBodyEquatable_struct_eq(AbstractFunctionDecl *eqDecl, void *) {
386386
if (!propertyDecl->isUserAccessible())
387387
continue;
388388

389-
auto aPropertyRef = new (C) DeclRefExpr(propertyDecl, DeclNameLoc(),
390-
/*implicit*/ true);
391389
auto aParamRef = new (C) DeclRefExpr(aParam, DeclNameLoc(),
392390
/*implicit*/ true);
393-
auto aPropertyExpr = new (C) DotSyntaxCallExpr(aPropertyRef, SourceLoc(),
394-
aParamRef);
391+
auto aPropertyExpr = new (C) MemberRefExpr(aParamRef, SourceLoc(),
392+
propertyDecl, DeclNameLoc(),
393+
/*implicit*/ true);
395394

396-
auto bPropertyRef = new (C) DeclRefExpr(propertyDecl, DeclNameLoc(),
397-
/*implicit*/ true);
398395
auto bParamRef = new (C) DeclRefExpr(bParam, DeclNameLoc(),
399396
/*implicit*/ true);
400-
auto bPropertyExpr = new (C) DotSyntaxCallExpr(bPropertyRef, SourceLoc(),
401-
bParamRef);
397+
auto bPropertyExpr = new (C) MemberRefExpr(bParamRef, SourceLoc(),
398+
propertyDecl, DeclNameLoc(),
399+
/*implicit*/ true);
402400

403401
auto guardStmt = DerivedConformance::returnFalseIfNotEqualGuard(C,
404402
aPropertyExpr, bPropertyExpr);
@@ -873,12 +871,12 @@ deriveBodyHashable_struct_hashInto(AbstractFunctionDecl *hashIntoDecl, void *) {
873871
if (!propertyDecl->isUserAccessible())
874872
continue;
875873

876-
auto propertyRef = new (C) DeclRefExpr(propertyDecl, DeclNameLoc(),
877-
/*implicit*/ true);
878874
auto selfRef = new (C) DeclRefExpr(selfDecl, DeclNameLoc(),
879875
/*implicit*/ true);
880-
auto selfPropertyExpr = new (C) DotSyntaxCallExpr(propertyRef, SourceLoc(),
881-
selfRef);
876+
auto selfPropertyExpr = new (C) MemberRefExpr(selfRef, SourceLoc(),
877+
propertyDecl, DeclNameLoc(),
878+
/*implicit*/ true);
879+
882880
// Generate: hasher.combine(self.<property>)
883881
auto combineExpr = createHasherCombineCall(C, hasherParam, selfPropertyExpr);
884882
statements.emplace_back(ASTNode(combineExpr));

lib/Sema/DerivedConformanceRawRepresentable.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ deriveBodyRawRepresentable_init(AbstractFunctionDecl *initDecl, void *) {
332332
// Create a statement which assigns the case to self.
333333

334334
// valueExpr = "\(enumType).\(elt)"
335-
auto eltRef = new (C) DeclRefExpr(elt, DeclNameLoc(), /*implicit*/true);
336335
auto metaTyRef = TypeExpr::createImplicit(enumType, C);
337-
auto valueExpr = new (C) DotSyntaxCallExpr(eltRef, SourceLoc(), metaTyRef);
336+
auto valueExpr = new (C) MemberRefExpr(metaTyRef, SourceLoc(),
337+
elt, DeclNameLoc(), /*implicit*/true);
338338

339339
// assignment = "self = \(valueExpr)"
340340
auto selfRef = new (C) DeclRefExpr(selfDecl, DeclNameLoc(),

lib/Sema/TypeCheckAttr.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -1900,17 +1900,13 @@ void AttributeChecker::visitMainTypeAttr(MainTypeAttr *attr) {
19001900
}
19011901

19021902
auto funcDeclRef = ConcreteDeclRef(mainFunction, substitutionMap);
1903-
auto *funcDeclRefExpr = new (context) DeclRefExpr(
1904-
funcDeclRef, DeclNameLoc(location), /*Implicit*/ true);
1905-
funcDeclRefExpr->setImplicit(true);
1906-
funcDeclRefExpr->setType(mainFunction->getInterfaceType());
19071903

1908-
auto *dotSyntaxCallExpr = new (context) DotSyntaxCallExpr(
1909-
funcDeclRefExpr, /*DotLoc*/ SourceLoc(), typeExpr, voidToVoidFunctionType);
1910-
dotSyntaxCallExpr->setImplicit(true);
1911-
dotSyntaxCallExpr->setThrows(mainFunctionThrows);
1904+
auto *memberRefExpr = new (context) MemberRefExpr(
1905+
typeExpr, SourceLoc(), funcDeclRef, DeclNameLoc(location),
1906+
/*Implicit*/ true);
1907+
memberRefExpr->setImplicit(true);
19121908

1913-
auto *callExpr = CallExpr::createImplicit(context, dotSyntaxCallExpr, {}, {});
1909+
auto *callExpr = CallExpr::createImplicit(context, memberRefExpr, {}, {});
19141910
callExpr->setImplicit(true);
19151911
callExpr->setThrows(mainFunctionThrows);
19161912
callExpr->setType(context.TheEmptyTupleType);

0 commit comments

Comments
 (0)