Skip to content

Commit 5d93b99

Browse files
committed
[CSClosure] Move participatesInInference check to Constraint Generator
1 parent 8257cc1 commit 5d93b99

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

lib/AST/Module.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3497,7 +3497,8 @@ ArrayRef<OpaqueTypeDecl *> SourceFile::getOpaqueReturnTypeDecls() {
34973497
for (auto *vd : UnvalidatedDeclsWithOpaqueReturnTypes.takeVector()) {
34983498
if (auto opaqueDecl = vd->getOpaqueResultTypeDecl()) {
34993499
auto inserted = ValidatedOpaqueReturnTypes.insert(
3500-
{opaqueDecl->getOpaqueReturnTypeIdentifier().str(), opaqueDecl});
3500+
{opaqueDecl->getOpaqueReturnTypeIdentifier().str(),
3501+
opaqueDecl});
35013502
if (inserted.second) {
35023503
OpaqueReturnTypes.push_back(opaqueDecl);
35033504
}

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7234,13 +7234,13 @@ Parser::parseDeclVar(ParseDeclOptions Flags,
72347234

72357235
pattern = patternRes.get();
72367236
}
7237-
7237+
72387238
bool hasOpaqueReturnTy = false;
72397239
if (auto typedPattern = dyn_cast<TypedPattern>(pattern)) {
72407240
hasOpaqueReturnTy = typedPattern->getTypeRepr()->hasOpaque();
72417241
}
72427242
auto sf = CurDeclContext->getParentSourceFile();
7243-
7243+
72447244
// Configure all vars with attributes, 'static' and parent pattern.
72457245
pattern->forEachVariable([&](VarDecl *VD) {
72467246
VD->setStatic(StaticLoc.isValid());
@@ -7543,12 +7543,13 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
75437543
CurDeclContext);
75447544

75457545
// Let the source file track the opaque return type mapping, if any.
7546-
if (FuncRetTy && FuncRetTy->hasOpaque() && !InInactiveClauseEnvironment) {
7546+
if (FuncRetTy && FuncRetTy->hasOpaque() &&
7547+
!InInactiveClauseEnvironment) {
75477548
if (auto sf = CurDeclContext->getParentSourceFile()) {
75487549
sf->addUnvalidatedDeclWithOpaqueResultType(FD);
75497550
}
75507551
}
7551-
7552+
75527553
// Parse a 'where' clause if present.
75537554
if (Tok.is(tok::kw_where)) {
75547555
ContextChange CC(*this, FD);
@@ -8511,7 +8512,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
85118512
Context, name, StaticLoc, StaticSpelling, SubscriptLoc, Indices.get(),
85128513
ArrowLoc, ElementTy.get(), CurDeclContext, GenericParams);
85138514
Subscript->getAttrs() = Attributes;
8514-
8515+
85158516
// Let the source file track the opaque return type mapping, if any.
85168517
if (ElementTy.get() && ElementTy.get()->hasOpaque() &&
85178518
!InInactiveClauseEnvironment) {

lib/Sema/CSSyntacticElement.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,7 @@ class SyntacticElementConstraintGenerator
907907
void visitBraceStmt(BraceStmt *braceStmt) {
908908
auto &ctx = cs.getASTContext();
909909

910-
if (auto closure = cast<ClosureExpr>(context.getAbstractClosureExpr());
911-
context.getBody() == braceStmt) {
910+
if (auto closure = cast<ClosureExpr>(context.getAsAbstractClosureExpr().getPtrOrNull()); context.getBody() == braceStmt) {
912911
// If this closure has an empty body and no explicit result type
913912
// let's bind result type to `Void` since that's the only type empty body
914913
// can produce. Otherwise, if (multi-statement) closure doesn't have
@@ -924,6 +923,8 @@ class SyntacticElementConstraintGenerator
924923
ctx.TheEmptyTupleType,
925924
cs.getConstraintLocator(closure, ConstraintLocator::ClosureResult));
926925
}
926+
if (!cs.participatesInInference(closure))
927+
return;
927928
}
928929

929930
if (context.isSingleExpressionClosure(cs)) {
@@ -1147,20 +1148,7 @@ bool ConstraintSystem::generateConstraints(AnyFunctionRef fn, BraceStmt *body) {
11471148
if (auto *func = fn.getAbstractFunctionDecl()) {
11481149
locator = getConstraintLocator(func);
11491150
} else {
1150-
auto closure = cast<ClosureExpr>(fn.getAbstractClosureExpr());
1151-
locator = getConstraintLocator(closure);
1152-
1153-
if (participatesInInference(closure)) {
1154-
SyntacticElementConstraintGenerator generator(
1155-
*this, closure, getConstraintLocator(closure));
1156-
1157-
generator.visit(closure->getBody());
1158-
1159-
if (closure->hasSingleExpressionBody())
1160-
return generator.hadError;
1161-
}
1162-
1163-
return false;
1151+
locator = getConstraintLocator(fn.getAbstractClosureExpr());
11641152
}
11651153

11661154
SyntacticElementConstraintGenerator generator(

0 commit comments

Comments
 (0)