Skip to content

Commit dadf2b4

Browse files
committed
[ConstraintSystem] Track invalid function builder bodies to avoid duplicate diagnostics
1 parent c17bdaf commit dadf2b4

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/BuilderTransform.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,13 @@ ConstraintSystem::matchFunctionBuilder(
16551655
assert(builder && "Bad function builder type");
16561656
assert(builder->getAttrs().hasAttribute<FunctionBuilderAttr>());
16571657

1658+
if (InvalidFunctionBuilderBodies.count(fn)) {
1659+
(void)recordFix(
1660+
IgnoreInvalidFunctionBuilderBody::duringConstraintGeneration(
1661+
*this, getConstraintLocator(fn.getBody())));
1662+
return getTypeMatchSuccess();
1663+
}
1664+
16581665
// Pre-check the body: pre-check any expressions in it and look
16591666
// for return statements.
16601667
auto request =
@@ -1720,6 +1727,8 @@ ConstraintSystem::matchFunctionBuilder(
17201727
return getTypeMatchFailure(locator);
17211728

17221729
if (transaction.hasErrors()) {
1730+
InvalidFunctionBuilderBodies.insert(fn);
1731+
17231732
if (recordFix(
17241733
IgnoreInvalidFunctionBuilderBody::duringConstraintGeneration(
17251734
*this, getConstraintLocator(fn.getBody()))))

lib/Sema/ConstraintSystem.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,13 @@ class ConstraintSystem {
20252025
/// from declared parameters/result and body.
20262026
llvm::MapVector<const ClosureExpr *, FunctionType *> ClosureTypes;
20272027

2028+
/// This is a *global* list of all function builder bodies that have
2029+
/// been determined to be incorrect by failing constraint generation.
2030+
///
2031+
/// Tracking this information is useful to avoid producing duplicate
2032+
/// diagnostics when function builder has multiple overloads.
2033+
llvm::SmallDenseSet<AnyFunctionRef> InvalidFunctionBuilderBodies;
2034+
20282035
/// Maps node types used within all portions of the constraint
20292036
/// system, instead of directly using the types on the
20302037
/// nodes themselves. This allows us to typecheck and

0 commit comments

Comments
 (0)