Skip to content

Commit 9cc3008

Browse files
committed
[IDE] Report solutions from a result builder transform to a SolutionCallback
1 parent 3022812 commit 9cc3008

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,6 +2365,24 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
23652365
SmallVector<Solution, 4> solutions;
23662366
bool solvingFailed = cs.solve(solutions);
23672367

2368+
auto reportSolutionsToSolutionCallback = [&](const SolutionResult &result) {
2369+
if (!cs.getASTContext().SolutionCallback) {
2370+
return;
2371+
}
2372+
switch (result.getKind()) {
2373+
case SolutionResult::Success:
2374+
cs.getASTContext().SolutionCallback->sawSolution(result.getSolution());
2375+
break;
2376+
case SolutionResult::Ambiguous:
2377+
for (auto &solution : result.getAmbiguousSolutions()) {
2378+
cs.getASTContext().SolutionCallback->sawSolution(solution);
2379+
}
2380+
break;
2381+
default:
2382+
break;
2383+
}
2384+
};
2385+
23682386
if (solvingFailed || solutions.size() != 1) {
23692387
// Try to fix the system or provide a decent diagnostic.
23702388
auto salvagedResult = cs.salvage();
@@ -2376,14 +2394,17 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
23762394

23772395
case SolutionResult::Kind::Error:
23782396
case SolutionResult::Kind::Ambiguous:
2397+
reportSolutionsToSolutionCallback(salvagedResult);
23792398
return nullptr;
23802399

23812400
case SolutionResult::Kind::UndiagnosedError:
2401+
reportSolutionsToSolutionCallback(salvagedResult);
23822402
cs.diagnoseFailureFor(SolutionApplicationTarget(func));
23832403
salvagedResult.markAsDiagnosed();
23842404
return nullptr;
23852405

23862406
case SolutionResult::Kind::TooComplex:
2407+
reportSolutionsToSolutionCallback(salvagedResult);
23872408
func->diagnose(diag::expression_too_complex)
23882409
.highlight(func->getBodySourceRange());
23892410
salvagedResult.markAsDiagnosed();
@@ -2401,6 +2422,13 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
24012422
log << '\n';
24022423
}
24032424

2425+
if (cs.getASTContext().SolutionCallback) {
2426+
for (auto &solution : solutions) {
2427+
cs.getASTContext().SolutionCallback->sawSolution(solution);
2428+
}
2429+
return nullptr;
2430+
}
2431+
24042432
// FIXME: Shouldn't need to do this.
24052433
cs.applySolution(solutions.front());
24062434

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
23722372
auto optBody = TypeChecker::applyResultBuilderBodyTransform(
23732373
func, builderType,
23742374
/*ClosuresInResultBuilderDontParticipateInInference=*/
2375-
ctx.CompletionCallback == nullptr);
2375+
ctx.CompletionCallback == nullptr && ctx.SolutionCallback == nullptr);
23762376
if (optBody && *optBody) {
23772377
// Wire up the function body now.
23782378
func->setBody(*optBody, AbstractFunctionDecl::BodyKind::TypeChecked);

0 commit comments

Comments
 (0)