Skip to content

Commit c301833

Browse files
committed
Reapply: Collapse the three optional-to-optional restriction kinds.
This reapply's Doug's change d79ba78, which had previously been applied on top of 1efafbc, the latter of which resulted in a source compatibility break.
1 parent fc73e79 commit c301833

File tree

5 files changed

+3
-19
lines changed

5 files changed

+3
-19
lines changed

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5545,8 +5545,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
55455545
return result;
55465546
}
55475547

5548-
case ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional:
5549-
case ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional:
55505548
case ConversionRestrictionKind::OptionalToOptional:
55515549
return coerceOptionalToOptional(expr, toType, locator, typeFromPattern);
55525550

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,13 +2009,13 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
20092009
decl1 == TC.Context.getImplicitlyUnwrappedOptionalDecl()) {
20102010
assert(boundGenericType1->getGenericArgs().size() == 1);
20112011
conversionsOrFixes.push_back(
2012-
ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional);
2012+
ConversionRestrictionKind::OptionalToOptional);
20132013
} else if (optionalKind2 == OTK_ImplicitlyUnwrappedOptional &&
20142014
kind >= ConstraintKind::Conversion &&
20152015
decl1 == TC.Context.getOptionalDecl()) {
20162016
assert(boundGenericType1->getGenericArgs().size() == 1);
20172017
conversionsOrFixes.push_back(
2018-
ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional);
2018+
ConversionRestrictionKind::OptionalToOptional);
20192019
}
20202020
}
20212021

@@ -3818,8 +3818,6 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
38183818
// T $< U ===> T! $< U?
38193819
// also:
38203820
// T <c U ===> T? <c U!
3821-
case ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional:
3822-
case ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional:
38233821
case ConversionRestrictionKind::OptionalToOptional: {
38243822
addContextualScore();
38253823
assert(matchKind >= ConstraintKind::Subtype);

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,11 +2223,7 @@ static bool shortCircuitDisjunctionAt(Constraint *constraint,
22232223
if (auto restriction = constraint->getRestriction()) {
22242224
// Non-optional conversions are better than optional-to-optional
22252225
// conversions.
2226-
if (*restriction == ConversionRestrictionKind::OptionalToOptional ||
2227-
*restriction
2228-
== ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional ||
2229-
*restriction
2230-
== ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional)
2226+
if (*restriction == ConversionRestrictionKind::OptionalToOptional)
22312227
return true;
22322228

22332229
// 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
@@ -365,10 +365,6 @@ StringRef swift::constraints::getName(ConversionRestrictionKind kind) {
365365
return "[value-to-optional]";
366366
case ConversionRestrictionKind::OptionalToOptional:
367367
return "[optional-to-optional]";
368-
case ConversionRestrictionKind::ImplicitlyUnwrappedOptionalToOptional:
369-
return "[unchecked-optional-to-optional]";
370-
case ConversionRestrictionKind::OptionalToImplicitlyUnwrappedOptional:
371-
return "[optional-to-unchecked-optional]";
372368
case ConversionRestrictionKind::ClassMetatypeToAnyObject:
373369
return "[class-metatype-to-object]";
374370
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)