@@ -3776,30 +3776,26 @@ namespace {
3776
3776
}
3777
3777
};
3778
3778
3779
- // / AST walker that "sanitizes" an expression for the
3780
- // / constraint-based type checker .
3779
+ // / AST walker that "sanitizes" an expression for re-typechecking during
3780
+ // / code completion .
3781
3781
// /
3782
- // / This is necessary because Sema fills in too much type information before
3783
- // / the type-checker runs, causing redundant work, and for expression that
3784
- // / have already been typechecked and may contain unhandled AST nodes.
3785
- // /
3786
- // / FIXME: Remove this one we no longer re-type check expressions during
3787
- // / diagnostics and code completion.
3782
+ // / FIXME: Remove this.
3788
3783
class SanitizeExpr : public ASTWalker {
3789
- ConstraintSystem &CS;
3784
+ ASTContext &C;
3785
+ bool ShouldReusePrecheckedType;
3790
3786
llvm::SmallDenseMap<OpaqueValueExpr *, Expr *, 4 > OpenExistentials;
3791
3787
3792
3788
public:
3793
- SanitizeExpr (ConstraintSystem &cs) : CS(cs){ }
3794
-
3795
- ASTContext & getASTContext () const { return CS. getASTContext (); }
3789
+ SanitizeExpr (ASTContext &C,
3790
+ bool shouldReusePrecheckedType)
3791
+ : C(C), ShouldReusePrecheckedType(shouldReusePrecheckedType) { }
3796
3792
3797
3793
std::pair<bool , Expr *> walkToExprPre (Expr *expr) override {
3798
3794
while (true ) {
3799
3795
3800
3796
// If we should reuse pre-checked types, don't sanitize the expression
3801
3797
// if it's already type-checked.
3802
- if (CS. shouldReusePrecheckedType () && expr->getType ())
3798
+ if (ShouldReusePrecheckedType && expr->getType ())
3803
3799
return { false , expr };
3804
3800
3805
3801
// OpenExistentialExpr contains OpaqueValueExpr in its sub expression.
@@ -3892,7 +3888,7 @@ namespace {
3892
3888
};
3893
3889
3894
3890
if (TE->isImplicit () && TE->getNumElements () == 1 &&
3895
- TE->getElementName (0 ) == getASTContext () .Id_dynamicMember &&
3891
+ TE->getElementName (0 ) == C .Id_dynamicMember &&
3896
3892
isImplicitKeyPathExpr (TE->getElement (0 ))) {
3897
3893
auto *keyPathExpr = cast<KeyPathExpr>(TE->getElement (0 ));
3898
3894
auto *componentExpr = keyPathExpr->getParsedPath ();
@@ -3957,15 +3953,15 @@ namespace {
3957
3953
argList.labels [0 ].empty () &&
3958
3954
!isa<VarargExpansionExpr>(argList.args [0 ])) {
3959
3955
auto *result =
3960
- new (getASTContext () ) ParenExpr (argList.lParenLoc ,
3961
- argList.args [0 ],
3962
- argList.rParenLoc ,
3963
- argList.hasTrailingClosure );
3956
+ new (C ) ParenExpr (argList.lParenLoc ,
3957
+ argList.args [0 ],
3958
+ argList.rParenLoc ,
3959
+ argList.hasTrailingClosure );
3964
3960
result->setImplicit ();
3965
3961
return result;
3966
3962
}
3967
3963
3968
- return TupleExpr::create (getASTContext () ,
3964
+ return TupleExpr::create (C ,
3969
3965
argList.lParenLoc ,
3970
3966
argList.args ,
3971
3967
argList.labels ,
@@ -3976,32 +3972,18 @@ namespace {
3976
3972
}
3977
3973
3978
3974
Expr *walkToExprPost (Expr *expr) override {
3979
- if (CS.hasType (expr)) {
3980
- Type type = CS.getType (expr);
3981
- if (type->hasOpenedExistential ()) {
3982
- type = type.transform ([&](Type type) -> Type {
3983
- if (auto archetype = type->getAs <OpenedArchetypeType>())
3984
- return archetype->getOpenedExistentialType ();
3985
- return type;
3986
- });
3987
- CS.setType (expr, type);
3988
- // Set new type to the expression directly.
3989
- expr->setType (type);
3990
- }
3991
- }
3992
-
3993
3975
assert (!isa<ImplicitConversionExpr>(expr) &&
3994
3976
" ImplicitConversionExpr should be eliminated in walkToExprPre" );
3995
3977
3996
3978
auto buildMemberRef = [&](Type memberType, Expr *base, SourceLoc dotLoc,
3997
3979
ConcreteDeclRef member, DeclNameLoc memberLoc,
3998
3980
bool implicit) -> Expr * {
3999
- auto *memberRef = new (getASTContext () )
3981
+ auto *memberRef = new (C )
4000
3982
MemberRefExpr (base, dotLoc, member, memberLoc, implicit);
4001
3983
4002
3984
if (memberType) {
4003
3985
memberRef->setType (memberType);
4004
- return CS. cacheType ( memberRef) ;
3986
+ return memberRef;
4005
3987
}
4006
3988
4007
3989
return memberRef;
@@ -4188,7 +4170,8 @@ namespace {
4188
4170
static Expr *generateConstraintsFor (ConstraintSystem &cs, Expr *expr,
4189
4171
DeclContext *DC) {
4190
4172
// Remove implicit conversions from the expression.
4191
- expr = expr->walk (SanitizeExpr (cs));
4173
+ expr = expr->walk (SanitizeExpr (cs.getASTContext (),
4174
+ cs.shouldReusePrecheckedType ()));
4192
4175
4193
4176
// Walk the expression, generating constraints.
4194
4177
ConstraintGenerator cg (cs, DC);
0 commit comments