Skip to content

Commit e2eaad5

Browse files
authored
Merge pull request #68363 from ahoppen/ahoppen/more-cc-cleanup
[Sema] Some more cleanup now that we migrated all of code completion to solver-based
2 parents ce2635b + 66a0b78 commit e2eaad5

File tree

7 files changed

+16
-61
lines changed

7 files changed

+16
-61
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ class SyntacticElementTarget;
7474
// so they could be made friends of ConstraintSystem.
7575
namespace TypeChecker {
7676

77-
llvm::Optional<BraceStmt *> applyResultBuilderBodyTransform(
78-
FuncDecl *func, Type builderType,
79-
bool ClosuresInResultBuilderDontParticipateInInference);
77+
llvm::Optional<BraceStmt *> applyResultBuilderBodyTransform(FuncDecl *func,
78+
Type builderType);
8079

8180
llvm::Optional<constraints::SyntacticElementTarget>
8281
typeCheckExpression(constraints::SyntacticElementTarget &target,
@@ -1815,12 +1814,6 @@ enum class ConstraintSystemFlags {
18151814

18161815
/// Disable macro expansions.
18171816
DisableMacroExpansions = 0x100,
1818-
1819-
/// Non solver-based code completion expects that closures inside result
1820-
/// builders don't participate in inference.
1821-
/// Once all code completion kinds are migrated to solver-based we should be
1822-
/// able to remove this flag.
1823-
ClosuresInResultBuildersDontParticipateInInference = 0x200,
18241817
};
18251818

18261819
/// Options that affect the constraint system as a whole.
@@ -2877,9 +2870,8 @@ class ConstraintSystem {
28772870

28782871
// FIXME: Perhaps these belong on ConstraintSystem itself.
28792872
friend llvm::Optional<BraceStmt *>
2880-
swift::TypeChecker::applyResultBuilderBodyTransform(
2881-
FuncDecl *func, Type builderType,
2882-
bool ClosuresInResultBuilderDontParticipateInInference);
2873+
swift::TypeChecker::applyResultBuilderBodyTransform(FuncDecl *func,
2874+
Type builderType);
28832875

28842876
friend llvm::Optional<SyntacticElementTarget>
28852877
swift::TypeChecker::typeCheckExpression(

lib/Sema/BuilderTransform.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -912,9 +912,8 @@ class ResultBuilderTransform
912912

913913
} // end anonymous namespace
914914

915-
llvm::Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
916-
FuncDecl *func, Type builderType,
917-
bool ClosuresInResultBuilderDontParticipateInInference) {
915+
llvm::Optional<BraceStmt *>
916+
TypeChecker::applyResultBuilderBodyTransform(FuncDecl *func, Type builderType) {
918917
// Pre-check the body: pre-check any expressions in it and look
919918
// for return statements.
920919
//
@@ -970,10 +969,6 @@ llvm::Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
970969
}
971970

972971
ConstraintSystemOptions options = ConstraintSystemFlags::AllowFixes;
973-
if (ClosuresInResultBuilderDontParticipateInInference) {
974-
options |= ConstraintSystemFlags::
975-
ClosuresInResultBuildersDontParticipateInInference;
976-
}
977972
auto resultInterfaceTy = func->getResultInterfaceType();
978973
auto resultContextType = func->mapTypeIntoContext(resultInterfaceTy);
979974

lib/Sema/CSRanking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
10081008
// problems with restating requirements in protocols.
10091009
identical = false;
10101010

1011-
if (cs.Context.CompletionCallback) {
1011+
if (cs.isForCodeCompletion()) {
10121012
// Don't rank based on overload choices of function calls that contain the
10131013
// code completion token.
10141014
ASTNode anchor = simplifyLocatorToAnchor(overload.locator);

lib/Sema/CSStep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
945945

946946
if (Solutions.size() == 1) {
947947
auto score = Solutions.front().getFixedScore();
948-
if (score.Data[SK_Fix] > 0 && !CS.getASTContext().CompletionCallback)
948+
if (score.Data[SK_Fix] > 0 && !CS.isForCodeCompletion())
949949
Producer.markExhausted();
950950
}
951951
} else if (Solutions.size() != 1) {

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7311,24 +7311,13 @@ bool ConstraintSystem::participatesInInference(ClosureExpr *closure) const {
73117311
if (getAppliedResultBuilderTransform(closure))
73127312
return true;
73137313

7314-
if (closure->hasSingleExpressionBody())
7315-
return true;
7316-
73177314
if (Options.contains(ConstraintSystemFlags::LeaveClosureBodyUnchecked))
73187315
return false;
73197316

73207317
if (closure->hasEmptyBody())
73217318
return false;
73227319

7323-
// If body is nested in a parent that has a function builder applied,
7324-
// let's prevent inference until result builders.
7325-
if (Options.contains(
7326-
ConstraintSystemFlags::
7327-
ClosuresInResultBuildersDontParticipateInInference)) {
7328-
return !isInResultBuilderContext(closure);
7329-
} else {
7330-
return true;
7331-
}
7320+
return true;
73327321
}
73337322

73347323
TypeVarBindingProducer::TypeVarBindingProducer(BindingSet &bindings)

lib/Sema/TypeCheckStmt.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,11 +2605,8 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
26052605
if (auto *func = dyn_cast<FuncDecl>(DC)) {
26062606
if (Type builderType = getResultBuilderType(func)) {
26072607
if (func->getBody()) {
2608-
auto optBody = TypeChecker::applyResultBuilderBodyTransform(
2609-
func, builderType,
2610-
/*ClosuresInResultBuilderDontParticipateInInference=*/
2611-
ctx.CompletionCallback == nullptr &&
2612-
ctx.SolutionCallback == nullptr);
2608+
auto optBody =
2609+
TypeChecker::applyResultBuilderBodyTransform(func, builderType);
26132610
if ((ctx.CompletionCallback && ctx.CompletionCallback->gotCallback()) ||
26142611
(ctx.SolutionCallback && ctx.SolutionCallback->gotCallback())) {
26152612
// We already informed the completion callback of solutions found by
@@ -2632,31 +2629,14 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
26322629
}
26332630
}
26342631

2635-
// The enclosing closure might be a single expression closure or a function
2636-
// builder closure. In such cases, the body elements are type checked with
2637-
// the closure itself. So we need to try type checking the enclosing closure
2638-
// signature first unless it has already been type checked.
2632+
// If the context is a closure, type check the entire surrounding closure.
2633+
// Conjunction constraints ensure that statements unrelated to the one that
2634+
// contains the code completion token are not type checked.
26392635
if (auto CE = dyn_cast<ClosureExpr>(DC)) {
26402636
if (CE->getBodyState() == ClosureExpr::BodyState::Parsed) {
26412637
swift::typeCheckASTNodeAtLoc(
26422638
TypeCheckASTNodeAtLocContext::declContext(CE->getParent()),
26432639
CE->getLoc());
2644-
// We need the actor isolation of the closure to be set so that we can
2645-
// annotate results that are on the same global actor.
2646-
// Since we are evaluating TypeCheckASTNodeAtLocRequest for every closure
2647-
// from outermost to innermost, we don't want to call checkActorIsolation,
2648-
// because that would cause actor isolation to be checked multiple times
2649-
// for nested closures. Instead, call determineClosureActorIsolation
2650-
// directly and set the closure's actor isolation manually. We can
2651-
// guarantee of that the actor isolation of enclosing closures have their
2652-
// isolation checked before nested ones are being checked by the way
2653-
// TypeCheckASTNodeAtLocRequest is called multiple times, as described
2654-
// above.
2655-
auto ActorIsolation = determineClosureActorIsolation(
2656-
CE, __Expr_getType, __AbstractClosureExpr_getActorIsolation);
2657-
CE->setActorIsolation(ActorIsolation);
2658-
// Type checking the parent closure also type checked this node.
2659-
// Nothing to do anymore.
26602640
return false;
26612641
}
26622642
}

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,8 @@ void typeCheckASTNode(ASTNode &node, DeclContext *DC,
459459
/// e.g., because of a \c return statement. Otherwise, returns either the
460460
/// fully type-checked body of the function (on success) or a \c nullptr
461461
/// value if an error occurred while type checking the transformed body.
462-
llvm::Optional<BraceStmt *> applyResultBuilderBodyTransform(
463-
FuncDecl *func, Type builderType,
464-
bool ClosuresInResultBuilderDontParticipateInInference = false);
462+
llvm::Optional<BraceStmt *> applyResultBuilderBodyTransform(FuncDecl *func,
463+
Type builderType);
465464

466465
/// Find the return statements within the body of the given function.
467466
std::vector<ReturnStmt *> findReturnStatements(AnyFunctionRef fn);

0 commit comments

Comments
 (0)