Skip to content

Commit 3654dcc

Browse files
committed
Remove getImplicitlyUnwrappedOptionalObjectType.
1 parent 3f9689e commit 3654dcc

15 files changed

+12
-166
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
993993
/// Return T if this type is Optional<T>; otherwise, return the null type.
994994
Type getOptionalObjectType();
995995

996-
/// Return T if this type is ImplicitlyUnwrappedOptional<T>; otherwise, return
997-
/// the null type.
998-
Type getImplicitlyUnwrappedOptionalObjectType();
999-
1000996
/// Return T if this type is Optional<T> or ImplicitlyUnwrappedOptional<T>;
1001997
/// otherwise, return the null type.
1002998
Type getAnyOptionalObjectType(OptionalTypeKind &kind);

lib/AST/Decl.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,18 +1696,6 @@ static Type mapSignatureType(ASTContext &ctx, Type type) {
16961696

16971697
/// Map a signature type for a parameter.
16981698
static Type mapSignatureParamType(ASTContext &ctx, Type type) {
1699-
// Translate implicitly unwrapped optionals into strict optionals.
1700-
if (auto inOutTy = type->getAs<InOutType>()) {
1701-
if (auto uncheckedOptOf =
1702-
inOutTy->getObjectType()
1703-
->getImplicitlyUnwrappedOptionalObjectType()) {
1704-
type = InOutType::get(OptionalType::get(uncheckedOptOf));
1705-
}
1706-
} else if (auto uncheckedOptOf =
1707-
type->getImplicitlyUnwrappedOptionalObjectType()) {
1708-
type = OptionalType::get(uncheckedOptOf);
1709-
}
1710-
17111699
return mapSignatureType(ctx, type);
17121700
}
17131701

lib/AST/Type.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,6 @@ Type TypeBase::getOptionalObjectType() {
502502
return Type();
503503
}
504504

505-
Type TypeBase::getImplicitlyUnwrappedOptionalObjectType() {
506-
if (auto boundTy = getAs<BoundGenericEnumType>())
507-
if (boundTy->getDecl()->classifyAsOptionalType() == OTK_ImplicitlyUnwrappedOptional)
508-
return boundTy->getGenericArgs()[0];
509-
return Type();
510-
}
511-
512505
Type TypeBase::getAnyOptionalObjectType(OptionalTypeKind &kind) {
513506
if (auto boundTy = getAs<BoundGenericEnumType>())
514507
if ((kind = boundTy->getDecl()->classifyAsOptionalType()))
@@ -2309,17 +2302,6 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
23092302
paramsAndResultMatch);
23102303
}
23112304

2312-
if (matchMode.contains(TypeMatchFlags::AllowNonOptionalForIUOParam) &&
2313-
(paramPosition == ParameterPosition::Parameter ||
2314-
paramPosition == ParameterPosition::ParameterTupleElement) &&
2315-
insideOptional == OptionalUnwrapping::None) {
2316-
// Allow T to override T! in certain cases.
2317-
if (auto obj1 = t1->getImplicitlyUnwrappedOptionalObjectType()) {
2318-
t1 = obj1->getCanonicalType();
2319-
if (t1 == t2) return true;
2320-
}
2321-
}
2322-
23232305
// Class-to-class.
23242306
if (matchMode.contains(TypeMatchFlags::AllowOverride))
23252307
if (t2->isExactSuperclassOf(t1))

lib/ClangImporter/ImportType.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ namespace {
177177
using TypeVisitor::Visit;
178178
ImportResult Visit(clang::QualType type) {
179179
auto IR = Visit(type.getTypePtr());
180-
assert(!IR.AbstractType ||
181-
!IR.AbstractType->getImplicitlyUnwrappedOptionalObjectType());
182180
return IR;
183181
}
184182

@@ -1161,10 +1159,6 @@ static ImportedType adjustTypeForConcreteImport(
11611159
bool allowNSUIntegerAsInt, Bridgeability bridging, OptionalTypeKind optKind,
11621160
bool resugarNSErrorPointer) {
11631161

1164-
// We never expect an IUO type to be passed in.
1165-
assert(!importedType ||
1166-
!importedType->getImplicitlyUnwrappedOptionalObjectType());
1167-
11681162
if (importKind == ImportTypeKind::Abstract) {
11691163
return {importedType, false};
11701164
}
@@ -1188,8 +1182,6 @@ static ImportedType adjustTypeForConcreteImport(
11881182
if (!importedType)
11891183
return {Type(), false};
11901184

1191-
assert(!importedType->getImplicitlyUnwrappedOptionalObjectType());
1192-
11931185
// Special case AutoreleasingUnsafeMutablePointer<NSError?> parameters.
11941186
auto maybeImportNSErrorPointer = [&]() -> Type {
11951187
if (importKind != ImportTypeKind::Parameter)
@@ -1232,7 +1224,6 @@ static ImportedType adjustTypeForConcreteImport(
12321224
};
12331225

12341226
if (Type result = maybeImportNSErrorPointer()) {
1235-
assert(!result->getImplicitlyUnwrappedOptionalObjectType());
12361227
return {result, false};
12371228
}
12381229

@@ -1278,11 +1269,9 @@ static ImportedType adjustTypeForConcreteImport(
12781269
resultTy = impl.getNamedSwiftTypeSpecialization(impl.getStdlibModule(),
12791270
pointerName,
12801271
resultTy);
1281-
assert(!resultTy->getImplicitlyUnwrappedOptionalObjectType());
12821272
return resultTy;
12831273
};
12841274
if (Type outParamTy = maybeImportCFOutParameter()) {
1285-
assert(!outParamTy->getImplicitlyUnwrappedOptionalObjectType());
12861275
importedType = outParamTy;
12871276
}
12881277

@@ -1381,9 +1370,6 @@ static ImportedType adjustTypeForConcreteImport(
13811370
importedType = OptionalType::get(importedType);
13821371
}
13831372

1384-
// We do not expect to return actual IUO types.
1385-
assert(!importedType->getImplicitlyUnwrappedOptionalObjectType());
1386-
13871373
return {importedType, isIUO};
13881374
}
13891375

@@ -1437,10 +1423,6 @@ ImportedType ClangImporter::Implementation::importType(
14371423
*this, type, importResult.AbstractType, importKind, importResult.Hint,
14381424
allowNSUIntegerAsInt, bridging, optionality, resugarNSErrorPointer);
14391425

1440-
// We should never get an actual IUO type back.
1441-
assert(!adjustedType ||
1442-
!adjustedType.getType()->getImplicitlyUnwrappedOptionalObjectType());
1443-
14441426
return adjustedType;
14451427
}
14461428

@@ -1452,9 +1434,6 @@ Type ClangImporter::Implementation::importTypeIgnoreIUO(
14521434
auto importedType = importType(type, importKind, allowNSUIntegerAsInt,
14531435
bridging, optionality, resugarNSErrorPointer);
14541436

1455-
assert(!importedType ||
1456-
!importedType.getType()->getImplicitlyUnwrappedOptionalObjectType());
1457-
14581437
return importedType.getType();
14591438
}
14601439

@@ -1569,9 +1548,6 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
15691548
switch (getClangASTContext().BuiltinInfo.getTypeString(builtinID)[0]) {
15701549
case 'z': // size_t
15711550
case 'Y': // ptrdiff_t
1572-
assert(!SwiftContext.getIntDecl()
1573-
->getDeclaredType()
1574-
->getImplicitlyUnwrappedOptionalObjectType());
15751551
return {SwiftContext.getIntDecl()->getDeclaredType(), false};
15761552
default:
15771553
break;

lib/ClangImporter/ImporterImpl.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,10 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
639639
}
640640
#endif
641641

642-
if (!isIUO) {
643-
assert(!ty->getImplicitlyUnwrappedOptionalObjectType());
642+
if (!isIUO)
644643
return;
645-
} else {
646-
assert(ty->getAnyOptionalObjectType());
647-
}
644+
645+
assert(ty->getOptionalObjectType());
648646

649647
auto *IUOAttr = new (SwiftContext)
650648
ImplicitlyUnwrappedOptionalAttr(/* implicit= */ true);

lib/IDE/CodeCompletion.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
31583158
// FIXME: consider types convertible to T?.
31593159

31603160
ExprType = ExprType->getRValueType();
3161+
// FIXME: We don't always pass down whether a type is from an
3162+
// unforced IUO.
31613163
if (isIUO) {
31623164
if (Type Unwrapped = ExprType->getAnyOptionalObjectType()) {
31633165
lookupVisibleMemberDecls(*this, Unwrapped, CurrDeclContext,
@@ -3184,12 +3186,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
31843186
IncludeInstanceMembers);
31853187
}
31863188
}
3187-
} else if (Type Unwrapped = ExprType->getImplicitlyUnwrappedOptionalObjectType()) {
3188-
// FIXME: This can go away when IUOs have been removed from the type
3189-
// system.
3190-
lookupVisibleMemberDecls(*this, Unwrapped, CurrDeclContext,
3191-
TypeResolver.get(),
3192-
IncludeInstanceMembers);
31933189
} else {
31943190
return false;
31953191
}

lib/SILGen/SILGenBridging.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,6 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF,
631631
loweredBridgedTy.castTo<SILFunctionType>());
632632
}
633633

634-
// Erase IUO at this point, because there aren't any conformances for
635-
// IUO anymore. Note that the value representation stays the same
636-
// because SIL erases the difference.
637-
if (auto obj = nativeType->getImplicitlyUnwrappedOptionalObjectType()) {
638-
nativeType = OptionalType::get(obj)->getCanonicalType();
639-
}
640-
641634
// If the native type conforms to _ObjectiveCBridgeable, use its
642635
// _bridgeToObjectiveC witness.
643636
if (auto conformance =

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4484,8 +4484,6 @@ namespace {
44844484
void diagnoseOptionalInjection(InjectIntoOptionalExpr *injection) {
44854485
// Don't diagnose when we're injecting into
44864486
auto toOptionalType = cs.getType(injection);
4487-
if (toOptionalType->getImplicitlyUnwrappedOptionalObjectType())
4488-
return;
44894487

44904488
// Check whether we have a forced downcast.
44914489
auto &tc = cs.getTypeChecker();
@@ -6248,10 +6246,7 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
62486246
return coerceOptionalToOptional(expr, toType, locator, typeFromPattern);
62496247

62506248
case ConversionRestrictionKind::ForceUnchecked: {
6251-
auto valueTy = fromType->getImplicitlyUnwrappedOptionalObjectType();
6252-
assert(valueTy);
6253-
expr = coerceImplicitlyUnwrappedOptionalToValue(expr, valueTy);
6254-
return coerceToType(expr, toType, locator);
6249+
llvm_unreachable("should never see ForceUnchecked");
62556250
}
62566251

62576252
case ConversionRestrictionKind::ArrayUpcast: {

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5399,12 +5399,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
53995399
callExpr->setFn(operatorRef);
54005400
};
54015401

5402-
auto getFuncType = [](Type type) -> Type {
5403-
auto fnType = type->getRValueType();
5404-
if (auto objectType = fnType->getImplicitlyUnwrappedOptionalObjectType())
5405-
return objectType;
5406-
return fnType;
5407-
};
5402+
auto getFuncType = [](Type type) -> Type { return type->getRValueType(); };
54085403

54095404
auto fnType = getFuncType(CS.getType(fnExpr));
54105405

lib/Sema/CSRanking.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,32 +1026,11 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
10261026
continue;
10271027
}
10281028

1029-
// If one type is an implicitly unwrapped optional of the other,
1030-
// prefer the non-optional.
1031-
bool type1Better = false;
1032-
bool type2Better = false;
1033-
if (auto type1Obj = type1->getImplicitlyUnwrappedOptionalObjectType()) {
1034-
if (type1Obj->isEqual(type2))
1035-
type2Better = true;
1036-
}
1037-
if (auto type2Obj = type2->getImplicitlyUnwrappedOptionalObjectType()) {
1038-
if (type2Obj->isEqual(type1))
1039-
type1Better = true;
1040-
}
1041-
1042-
if (type1Better || type2Better) {
1043-
if (type1Better)
1044-
++score1;
1045-
if (type2Better)
1046-
++score2;
1047-
continue;
1048-
}
1049-
10501029
// If one type is a subtype of the other, but not vice-versa,
10511030
// we prefer the system with the more-constrained type.
10521031
// FIXME: Collapse this check into the second check.
1053-
type1Better = tc.isSubtypeOf(type1, type2, cs.DC);
1054-
type2Better = tc.isSubtypeOf(type2, type1, cs.DC);
1032+
auto type1Better = tc.isSubtypeOf(type1, type2, cs.DC);
1033+
auto type2Better = tc.isSubtypeOf(type2, type1, cs.DC);
10551034
if (type1Better || type2Better) {
10561035
if (type1Better)
10571036
++score1;

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,14 +2292,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
22922292
conversionsOrFixes.push_back(Fix::getForcedDowncast(*this, type2));
22932293
}
22942294

2295-
// Look through IUO's.
2296-
auto type1WithoutIUO = objectType1;
2297-
if (auto elt = type1WithoutIUO->getImplicitlyUnwrappedOptionalObjectType())
2298-
type1WithoutIUO = elt;
2299-
23002295
// If we could perform a bridging cast, try it.
23012296
if (auto bridged =
2302-
TC.getDynamicBridgedThroughObjCClass(DC, type1WithoutIUO, type2)) {
2297+
TC.getDynamicBridgedThroughObjCClass(DC, objectType1, type2)) {
23032298
// Note: don't perform this recovery for NSNumber;
23042299
bool useFix = true;
23052300
if (auto classType = bridged->getAs<ClassType>()) {
@@ -3529,17 +3524,6 @@ ConstraintSystem::simplifyBridgingConstraint(Type type1,
35293524
return SolutionKind::Solved;
35303525
}
35313526

3532-
// Unwrap one extra level of implicitly-unwrapped optional on the source,
3533-
// if needed.
3534-
if (numFromOptionals == numToOptionals + 1 &&
3535-
!type1->getImplicitlyUnwrappedOptionalObjectType().isNull()) {
3536-
--numFromOptionals;
3537-
increaseScore(SK_ForceUnchecked);
3538-
if (worseThanBestSolution()) {
3539-
return SolutionKind::Error;
3540-
}
3541-
}
3542-
35433527
// The source cannot be more optional than the destination, because bridging
35443528
// conversions don't allow us to implicitly check for a value in the optional.
35453529
if (numFromOptionals > numToOptionals) {

lib/Sema/CalleeCandidateInfo.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ UncurriedCandidate::UncurriedCandidate(ValueDecl *decl, unsigned level)
3838
->getForwardingSubstitutions();
3939
entityType = GFT->substGenericArgs(subs);
4040
} else {
41-
if (auto objType =
42-
entityType->getImplicitlyUnwrappedOptionalObjectType())
43-
entityType = objType;
44-
41+
// FIXME: look through unforced IUOs here?
42+
4543
entityType = DC->mapTypeIntoContext(entityType);
4644
}
4745
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,22 +1812,6 @@ Type simplifyTypeImpl(ConstraintSystem &cs, Type type, Fn getFixedTypeFn) {
18121812

18131813
auto *module = cs.DC->getParentModule();
18141814

1815-
// "Force" the IUO for substitution purposes. We can end up in
1816-
// this situation if we use the results of overload resolution
1817-
// as a generic type and the overload resolution resulted in an
1818-
// IUO-typed entity.
1819-
while (auto objectType =
1820-
lookupBaseType->getImplicitlyUnwrappedOptionalObjectType()) {
1821-
// If we're accessing a type member of the IUO itself,
1822-
// stop here. Ugh...
1823-
if (module->lookupConformance(lookupBaseType,
1824-
assocType->getProtocol())) {
1825-
break;
1826-
}
1827-
1828-
lookupBaseType = objectType;
1829-
}
1830-
18311815
if (lookupBaseType->mayHaveMembers()) {
18321816
auto subs = lookupBaseType->getContextSubstitutionMap(
18331817
cs.DC->getParentModule(),

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,6 @@ getTypesToCompare(ValueDecl *reqt, Type reqtType, bool reqtTypeIsIUO,
224224
// have information in the protocol.
225225
break;
226226
}
227-
} else {
228-
// FIXME: Until IUOs are removed from the type system, make
229-
// sure we turn these both into optionals for the purpose of
230-
// comparing types since we could be producing IUOs in some
231-
// places and optionals in others.
232-
if (auto objTy = reqtType->getImplicitlyUnwrappedOptionalObjectType())
233-
reqtType = OptionalType::get(objTy);
234-
if (auto objTy = witnessType->getImplicitlyUnwrappedOptionalObjectType())
235-
witnessType = OptionalType::get(objTy);
236227
}
237228

238229
return std::make_tuple(reqtType, witnessType, optAdjustment);

lib/Sema/TypeCheckStmt.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -599,16 +599,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
599599
return nullptr;
600600
}
601601

602-
// If the sequence is an implicitly unwrapped optional, force it.
603602
Expr *sequence = S->getSequence();
604-
if (auto objectTy
605-
= sequence->getType()->getImplicitlyUnwrappedOptionalObjectType()) {
606-
sequence = new (TC.Context) ForceValueExpr(sequence,
607-
sequence->getEndLoc());
608-
sequence->setType(objectTy);
609-
sequence->setImplicit();
610-
S->setSequence(sequence);
611-
}
612603

613604
// Invoke iterator() to get an iterator from the sequence.
614605
Type generatorTy;

0 commit comments

Comments
 (0)