Skip to content

Commit 123490e

Browse files
committed
Address a few comments about the specialization arguments constraint.
1 parent 0e70364 commit 123490e

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) {
@@ -3707,9 +3713,10 @@ namespace {
37073713

37083714
// Add explicit generic arguments, if there were any.
37093715
if (expr->getGenericArgsRange().isValid()) {
3710-
addSpecializationConstraint(
3711-
CS.getConstraintLocator(expr), macroRefType,
3712-
expr->getGenericArgs());
3716+
if (addSpecializationConstraint(
3717+
CS.getConstraintLocator(expr), macroRefType,
3718+
expr->getGenericArgs()))
3719+
return Type();
37133720
}
37143721

37153722
// 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
@@ -12668,30 +12668,13 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1266812668
if (simplifiedBoundType->isTypeVariableOrMember())
1266912669
return formUnsolved();
1267012670

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

12693-
auto selectedOverload = resolvedOverloadIter->second;
12694-
auto overloadChoice = selectedOverload.choice;
12677+
auto overloadChoice = selectedOverload->choice;
1269512678
if (!overloadChoice.isDecl()) {
1269612679
return SolutionKind::Error;
1269712680
}

0 commit comments

Comments
 (0)