Skip to content

Commit d79ba78

Browse files
committed
[Constraint solver] Collapse the three optional-to-optional restriction kinds.
All three of these conversion restriction kinds were handled in exactly the same way, so just treat them as one.
1 parent bbecb33 commit d79ba78

File tree

5 files changed

+7
-34
lines changed

5 files changed

+7
-34
lines changed

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,8 +5528,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
55285528
return result;
55295529
}
55305530

5531-
case ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional:
5532-
case ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional:
55335531
case ConversionRestrictionKind::OptionalToOptional:
55345532
return coerceOptionalToOptional(expr, toType, locator, typeFromPattern);
55355533

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,29 +1209,18 @@ selectOptionalConversionRestriction(Type type1, Type type2,
12091209
kind >= ConstraintKind::Conversion)
12101210
return ConversionRestrictionKind::ForceUnchecked;
12111211

1212-
return llvm::None;
1212+
return None;
12131213
}
12141214

1215-
if (optionalKind1 == optionalKind2)
1216-
return ConversionRestrictionKind::OptionalToOptional;
1217-
12181215
if (optionalKind1 == OTK_None)
12191216
return ConversionRestrictionKind::ValueToOptional;
12201217

1221-
if (optionalKind1 == OTK_Optional) {
1222-
if (kind >= ConstraintKind::Conversion)
1223-
return ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional;
1224-
1225-
assert(optionalKind2 == OTK_ImplicitlyUnwrappedOptional &&
1226-
"Result has unexpected optional kind!");
1227-
1228-
return llvm::None;
1229-
}
1230-
1231-
assert(optionalKind1 == OTK_ImplicitlyUnwrappedOptional &&
1232-
"Source has unexpected optional kind!");
1218+
if (optionalKind1 == OTK_Optional &&
1219+
optionalKind2 == OTK_ImplicitlyUnwrappedOptional &&
1220+
kind < ConstraintKind::Conversion)
1221+
return None;
12331222

1234-
return ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional;
1223+
return ConversionRestrictionKind::OptionalToOptional;
12351224
}
12361225

12371226

@@ -3795,8 +3784,6 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
37953784
// T $< U ===> T! $< U?
37963785
// also:
37973786
// T <c U ===> T? <c U!
3798-
case ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional:
3799-
case ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional:
38003787
case ConversionRestrictionKind::OptionalToOptional: {
38013788
addContextualScore();
38023789
assert(matchKind >= ConstraintKind::Subtype);

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,11 +2199,7 @@ static bool shortCircuitDisjunctionAt(Constraint *constraint,
21992199
if (auto restriction = constraint->getRestriction()) {
22002200
// Non-optional conversions are better than optional-to-optional
22012201
// conversions.
2202-
if (*restriction == ConversionRestrictionKind::OptionalToOptional ||
2203-
*restriction
2204-
== ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional ||
2205-
*restriction
2206-
== ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional)
2202+
if (*restriction == ConversionRestrictionKind::OptionalToOptional)
22072203
return true;
22082204

22092205
// Array-to-pointer conversions are better than inout-to-pointer conversions.

lib/Sema/Constraint.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ StringRef swift::constraints::getName(ConversionRestrictionKind kind) {
364364
return "[value-to-optional]";
365365
case ConversionRestrictionKind::OptionalToOptional:
366366
return "[optional-to-optional]";
367-
case ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional:
368-
return "[unchecked-optional-to-optional]";
369-
case ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional:
370-
return "[optional-to-unchecked-optional]";
371367
case ConversionRestrictionKind::ClassMetatypeToAnyObject:
372368
return "[class-metatype-to-object]";
373369
case ConversionRestrictionKind::ExistentialMetatypeToAnyObject:

lib/Sema/Constraint.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ enum class ConversionRestrictionKind {
188188
ValueToOptional,
189189
/// T? -> U? optional to optional conversion (or unchecked to unchecked).
190190
OptionalToOptional,
191-
/// T! -> U? unchecked-optional to optional conversion
192-
ImplicitlyUnwrappedOptionalToOptional,
193-
/// T? -> U! optional to implicitly unwrapped optional conversion
194-
OptionalToImplicitlyUnwrappedOptional,
195191
/// Implicit forces of implicitly unwrapped optionals to their presumed values
196192
ForceUnchecked,
197193
/// Implicit upcast conversion of array types.

0 commit comments

Comments
 (0)