Skip to content

Commit b07139e

Browse files
committed
[ConstraintSystem] Relax the left-over information check in ComponentStep
Instead of crashing in release builds, let's simplify fail the step and let type-checker produce a fallback diagnostic. Maintain a trap in debug builds to make it easier to investigate the root cause of the issue. Resolves: rdar://56167233
1 parent ce660f5 commit b07139e

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

lib/Sema/CSStep.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,22 +362,60 @@ StepResult ComponentStep::take(bool prevFailed) {
362362
return finalize(/*isSuccess=*/false);
363363
}
364364

365+
#ifdef NDEBUG
366+
auto printConstraints = [&](const ConstraintList &constraints) {
367+
for (auto &constraint : constraints)
368+
constraint.print(getDebugLogger(), &CS.getASTContext().SourceMgr);
369+
};
370+
#endif
371+
365372
// If we don't have any disjunction or type variable choices left, we're done
366373
// solving. Make sure we don't have any unsolved constraints left over, using
367-
// report_fatal_error to make sure we trap in release builds instead of
368-
// potentially miscompiling.
374+
// report_fatal_error to make sure we trap in debug builds and fail the step
375+
// in release builds.
369376
if (!CS.ActiveConstraints.empty()) {
377+
#ifndef NDEBUG
370378
CS.print(llvm::errs());
371379
llvm::report_fatal_error("Active constraints left over?");
380+
#else
381+
if (CS.isDebugMode()) {
382+
getDebugLogger() << "(failed due to remaining active constraints:\n";
383+
printConstraints(CS.ActiveConstraints);
384+
getDebugLogger() << ")\n";
385+
}
386+
387+
return finalize(/*isSuccess=*/false);
388+
#endif
372389
}
390+
373391
if (!CS.solverState->allowsFreeTypeVariables()) {
374392
if (!CS.InactiveConstraints.empty()) {
393+
#ifndef NDEBUG
375394
CS.print(llvm::errs());
376395
llvm::report_fatal_error("Inactive constraints left over?");
396+
#else
397+
if (CS.isDebugMode()) {
398+
getDebugLogger() << "(failed due to remaining inactive constraints:\n";
399+
printConstraints(CS.InactiveConstraints);
400+
getDebugLogger() << ")\n";
401+
}
402+
403+
return finalize(/*isSuccess=*/false);
404+
#endif
377405
}
406+
378407
if (CS.hasFreeTypeVariables()) {
408+
#ifndef NDEBUG
379409
CS.print(llvm::errs());
380410
llvm::report_fatal_error("Free type variables left over?");
411+
#else
412+
if (CS.isDebugMode()) {
413+
getDebugLogger() << "(failed due to remaining free type variables)\n";
414+
CS.print(getDebugLogger(/*indent=*/false));
415+
}
416+
417+
return finalize(/*isSuccess=*/false);
418+
#endif
381419
}
382420
}
383421

0 commit comments

Comments
 (0)