Skip to content

[CS] Tweak addExplicitConversionConstraint slightly #30687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2978,8 +2978,8 @@ namespace {

// Add a conversion constraint for the direct conversion between
// types.
CS.addExplicitConversionConstraint(fromType, toType,
/*allowFixes=*/true, locator);
CS.addExplicitConversionConstraint(fromType, toType, RememberChoice,
locator);

// If the result type was declared IUO, add a disjunction for
// bindings for the result of the coercion.
Expand Down
15 changes: 6 additions & 9 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7291,13 +7291,13 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
if (auto fromKeyValue = isDictionaryType(unwrappedFromType)) {
if (auto toKeyValue = isDictionaryType(unwrappedToType)) {
addExplicitConversionConstraint(fromKeyValue->first, toKeyValue->first,
/*allowFixes=*/false,
ForgetChoice,
locator.withPathElement(
LocatorPathElt::GenericArgument(0)));
addExplicitConversionConstraint(fromKeyValue->second, toKeyValue->second,
/*allowFixes=*/false,
ForgetChoice,
locator.withPathElement(
LocatorPathElt::GenericArgument(0)));
LocatorPathElt::GenericArgument(1)));
countOptionalInjections();
return SolutionKind::Solved;
}
Expand Down Expand Up @@ -9701,9 +9701,8 @@ void ConstraintSystem::addFixConstraint(ConstraintFix *fix, ConstraintKind kind,
}

void ConstraintSystem::addExplicitConversionConstraint(
Type fromType, Type toType,
bool allowFixes,
ConstraintLocatorBuilder locator) {
Type fromType, Type toType, RememberChoice_t rememberChoice,
ConstraintLocatorBuilder locator) {
SmallVector<Constraint *, 3> constraints;

auto locatorPtr = getConstraintLocator(locator);
Expand All @@ -9721,9 +9720,7 @@ void ConstraintSystem::addExplicitConversionConstraint(
fromType, toType, locatorPtr);
constraints.push_back(bridgingConstraint);

addDisjunctionConstraint(constraints, locator,
allowFixes ? RememberChoice
: ForgetChoice);
addDisjunctionConstraint(constraints, locator, rememberChoice);
}

ConstraintSystem::SolutionKind
Expand Down
8 changes: 7 additions & 1 deletion lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2855,8 +2855,14 @@ class ConstraintSystem {
}

/// Add an explicit conversion constraint (e.g., \c 'x as T').
///
/// \param fromType The type of the expression being converted.
/// \param toType The type to convert to.
/// \param rememberChoice Whether the conversion disjunction should record its
/// choice.
/// \param locator The locator.
void addExplicitConversionConstraint(Type fromType, Type toType,
bool allowFixes,
RememberChoice_t rememberChoice,
ConstraintLocatorBuilder locator);

/// Add a disjunction constraint.
Expand Down