Skip to content

Commit 64f2c8e

Browse files
committed
Address a few comments about the specialization arguments constraint.
1 parent e6ed154 commit 64f2c8e

File tree

2 files changed

+15
-25
lines changed

2 files changed

+15
-25
lines changed

lib/Sema/CSGen.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,9 @@ namespace {
16451645

16461646
/// Given a set of specialization arguments, resolve those arguments and
16471647
/// introduce them as an explicit generic arguments constraint.
1648-
void addSpecializationConstraint(
1648+
///
1649+
/// \returns true if resolving any of the specialization types failed.
1650+
bool addSpecializationConstraint(
16491651
ConstraintLocator *locator, Type boundType,
16501652
ArrayRef<TypeRepr *> specializationArgs) {
16511653
// Resolve each type.
@@ -1658,13 +1660,17 @@ namespace {
16581660
// Introduce type variables for unbound generics.
16591661
OpenUnboundGenericType(CS, locator),
16601662
HandlePlaceholderType(CS, locator));
1663+
if (result->hasError())
1664+
return true;
1665+
16611666
specializationArgTypes.push_back(result);
16621667
}
16631668

16641669
CS.addConstraint(
16651670
ConstraintKind::ExplicitGenericArguments, boundType,
16661671
PackType::get(CS.getASTContext(), specializationArgTypes),
16671672
locator);
1673+
return false;
16681674
}
16691675

16701676
Type visitUnresolvedSpecializeExpr(UnresolvedSpecializeExpr *expr) {
@@ -3710,9 +3716,10 @@ namespace {
37103716

37113717
// Add explicit generic arguments, if there were any.
37123718
if (expr->getGenericArgsRange().isValid()) {
3713-
addSpecializationConstraint(
3714-
CS.getConstraintLocator(expr), macroRefType,
3715-
expr->getGenericArgs());
3719+
if (addSpecializationConstraint(
3720+
CS.getConstraintLocator(expr), macroRefType,
3721+
expr->getGenericArgs()))
3722+
return Type();
37163723
}
37173724

37183725
// For non-calls, the type variable is the result.

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12671,30 +12671,13 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1267112671
if (simplifiedBoundType->isTypeVariableOrMember())
1267212672
return formUnsolved();
1267312673

12674-
// Determine the overload locator for this constraint.
12675-
ConstraintLocator *overloadLocator = nullptr;
12676-
if (auto anchorExpr = locator.getAnchor().dyn_cast<Expr *>()) {
12677-
if (auto expansion = dyn_cast<MacroExpansionExpr>(anchorExpr)) {
12678-
overloadLocator = getConstraintLocator(expansion);
12679-
} else if (auto specialize =
12680-
dyn_cast<UnresolvedSpecializeExpr>(anchorExpr)) {
12681-
overloadLocator = getConstraintLocator(
12682-
specialize->getSubExpr()->getSemanticsProvidingExpr());
12683-
}
12684-
} else if (auto anchorDecl = locator.getAnchor().dyn_cast<Decl *>()) {
12685-
if (auto expansion = dyn_cast<MacroExpansionDecl>(anchorDecl)) {
12686-
overloadLocator = getConstraintLocator(expansion);
12687-
}
12688-
}
12689-
assert(overloadLocator && "Specialize expression has the wrong form");
12690-
1269112674
// If the overload hasn't been resolved, we can't simplify this constraint.
12692-
auto resolvedOverloadIter = getResolvedOverloads().find(overloadLocator);
12693-
if (resolvedOverloadIter == getResolvedOverloads().end())
12675+
auto overloadLocator = getCalleeLocator(getConstraintLocator(locator));
12676+
auto selectedOverload = findSelectedOverloadFor(overloadLocator);
12677+
if (!selectedOverload)
1269412678
return formUnsolved();
1269512679

12696-
auto selectedOverload = resolvedOverloadIter->second;
12697-
auto overloadChoice = selectedOverload.choice;
12680+
auto overloadChoice = selectedOverload->choice;
1269812681
if (!overloadChoice.isDecl()) {
1269912682
return SolutionKind::Error;
1270012683
}

0 commit comments

Comments
 (0)