Skip to content

Commit bea377f

Browse files
authored
Merge pull request swiftlang#14383 from rudkx/iuo-delete-rename-etc
More IUO removal clean-up.
2 parents cae95c4 + be8defb commit bea377f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+440
-604
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,10 +2986,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
29862986

29872987
void setConformanceLoader(LazyMemberLoader *resolver, uint64_t contextData);
29882988

2989-
/// classifyAsOptionalType - Decide whether this declaration is one
2990-
/// of the library-intrinsic Optional<T> or ImplicitlyUnwrappedOptional<T> types.
2991-
OptionalTypeKind classifyAsOptionalType() const;
2992-
2989+
/// Is this the decl for Optional<T>?
2990+
bool isOptionalDecl() const;
2991+
29932992
private:
29942993
/// Predicate used to filter StoredPropertyRange.
29952994
struct ToStoredProperty {

include/swift/AST/Type.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,8 @@ class CanType : public Type {
389389
static bool isExistentialTypeImpl(CanType type);
390390
static bool isAnyExistentialTypeImpl(CanType type);
391391
static bool isObjCExistentialTypeImpl(CanType type);
392-
static CanType getAnyOptionalObjectTypeImpl(CanType type,
393-
OptionalTypeKind &kind);
394-
static CanType getOptionalObjectTypeImpl(CanType type);
392+
static CanType getOptionalObjectTypeImpl(CanType type,
393+
OptionalTypeKind &kind);
395394
static CanType getReferenceStorageReferentImpl(CanType type);
396395
static CanType getWithoutSpecifierTypeImpl(CanType type);
397396

@@ -459,16 +458,12 @@ class CanType : public Type {
459458
GenericTypeDecl *getAnyGeneric() const;
460459

461460
CanType getOptionalObjectType() const {
462-
return getOptionalObjectTypeImpl(*this);
463-
}
464-
465-
CanType getAnyOptionalObjectType() const {
466461
OptionalTypeKind kind;
467-
return getAnyOptionalObjectTypeImpl(*this, kind);
462+
return getOptionalObjectTypeImpl(*this, kind);
468463
}
469464

470-
CanType getAnyOptionalObjectType(OptionalTypeKind &kind) const {
471-
return getAnyOptionalObjectTypeImpl(*this, kind);
465+
CanType getOptionalObjectType(OptionalTypeKind &kind) const {
466+
return getOptionalObjectTypeImpl(*this, kind);
472467
}
473468

474469
CanType getReferenceStorageReferent() const {

include/swift/AST/TypeNodes.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ ABSTRACT_SUGARED_TYPE(Sugar, Type)
150150
ABSTRACT_SUGARED_TYPE(UnarySyntaxSugar, SyntaxSugarType)
151151
SUGARED_TYPE(ArraySlice, UnarySyntaxSugarType)
152152
SUGARED_TYPE(Optional, UnarySyntaxSugarType)
153-
SUGARED_TYPE(ImplicitlyUnwrappedOptional, UnarySyntaxSugarType)
154-
TYPE_RANGE(UnarySyntaxSugar, ArraySlice, ImplicitlyUnwrappedOptional)
153+
TYPE_RANGE(UnarySyntaxSugar, ArraySlice, Optional)
155154
SUGARED_TYPE(Dictionary, SyntaxSugarType)
156155
TYPE_RANGE(SyntaxSugar, ArraySlice, Dictionary)
157156
TYPE_RANGE(Sugar, Paren, Dictionary)

include/swift/AST/Types.h

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -993,25 +993,22 @@ 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 Optional<T> or ImplicitlyUnwrappedOptional<T>;
997-
/// otherwise, return the null type.
998-
Type getAnyOptionalObjectType(OptionalTypeKind &kind);
999-
Type getAnyOptionalObjectType() {
1000-
OptionalTypeKind ignored;
1001-
return getAnyOptionalObjectType(ignored);
1002-
}
996+
/// Return T if this type is Optional<T>; otherwise, return the null
997+
/// type. Set \p kind to OTK_Optional if it is an optional, OTK_None
998+
/// otherwise.
999+
Type getOptionalObjectType(OptionalTypeKind &kind);
10031000

10041001
// Return type underlying type of a swift_newtype annotated imported struct;
10051002
// otherwise, return the null type.
10061003
Type getSwiftNewtypeUnderlyingType();
10071004

1008-
/// Return the type T after looking through all of the optional or
1009-
/// implicitly-unwrapped optional types.
1010-
Type lookThroughAllAnyOptionalTypes();
1005+
/// Return the type T after looking through all of the optional
1006+
/// types.
1007+
Type lookThroughAllOptionalTypes();
10111008

1012-
/// Return the type T after looking through all of the optional or
1013-
/// implicitly-unwrapped optional types.
1014-
Type lookThroughAllAnyOptionalTypes(SmallVectorImpl<Type> &optionals);
1009+
/// Return the type T after looking through all of the optional
1010+
/// types.
1011+
Type lookThroughAllOptionalTypes(SmallVectorImpl<Type> &optionals);
10151012

10161013
/// Whether this is the AnyObject type.
10171014
bool isAnyObject();
@@ -4105,26 +4102,6 @@ class OptionalType : public UnarySyntaxSugarType {
41054102
}
41064103
};
41074104

4108-
/// The type T!, which is always sugar for a library type.
4109-
class ImplicitlyUnwrappedOptionalType : public UnarySyntaxSugarType {
4110-
ImplicitlyUnwrappedOptionalType(const ASTContext &ctx, Type base,
4111-
RecursiveTypeProperties properties)
4112-
: UnarySyntaxSugarType(TypeKind::ImplicitlyUnwrappedOptional, ctx, base,
4113-
properties) {
4114-
llvm_unreachable(
4115-
"ImplicitlyUnwrappedOptionalType::ImplicitlyUnwrappedOptionalType");
4116-
}
4117-
4118-
public:
4119-
/// Return a uniqued optional type with the specified base type.
4120-
static ImplicitlyUnwrappedOptionalType *get(Type baseTy);
4121-
4122-
// Implement isa/cast/dyncast/etc.
4123-
static bool classof(const TypeBase *T) {
4124-
return T->getKind() == TypeKind::ImplicitlyUnwrappedOptional;
4125-
}
4126-
};
4127-
41284105
/// The dictionary type [K : V], which is syntactic sugar for Dictionary<K, V>.
41294106
///
41304107
/// Example:

include/swift/SIL/AbstractionPattern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ class AbstractionPattern {
10191019

10201020
/// Given that the value being abstracted is optional, return the
10211021
/// abstraction pattern for its object type.
1022-
AbstractionPattern getAnyOptionalObjectType() const;
1022+
AbstractionPattern getOptionalObjectType() const;
10231023

10241024
/// If this pattern refers to a reference storage type, look through
10251025
/// it.

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,8 +2481,8 @@ class KeyPathPatternComponent {
24812481
case Kind::OptionalForce:
24822482
break;
24832483
case Kind::OptionalWrap:
2484-
assert(ty->getAnyOptionalObjectType()
2485-
&& "optional wrap didn't form optional?!");
2484+
assert(ty->getOptionalObjectType() &&
2485+
"optional wrap didn't form optional?!");
24862486
break;
24872487
case Kind::StoredProperty:
24882488
case Kind::GettableProperty:

include/swift/SIL/SILType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ class SILType {
382382
bool isBlockPointerCompatible() const {
383383
// Look through one level of optionality.
384384
SILType ty = *this;
385-
if (auto optPayload = ty.getAnyOptionalObjectType()) {
385+
if (auto optPayload = ty.getOptionalObjectType()) {
386386
ty = optPayload;
387387
}
388388

@@ -481,7 +481,7 @@ class SILType {
481481

482482
/// Returns the lowered type for T if this type is Optional<T>;
483483
/// otherwise, return the null type.
484-
SILType getAnyOptionalObjectType() const;
484+
SILType getOptionalObjectType() const;
485485

486486
/// Unwraps one level of optional type.
487487
/// Returns the lowered T if the given type is Optional<T>.

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
293293
llvm::DenseMap<Type, ArraySliceType*> ArraySliceTypes;
294294
llvm::DenseMap<std::pair<Type, Type>, DictionaryType *> DictionaryTypes;
295295
llvm::DenseMap<Type, OptionalType*> OptionalTypes;
296-
llvm::DenseMap<Type, ImplicitlyUnwrappedOptionalType*> ImplicitlyUnwrappedOptionalTypes;
297296
llvm::DenseMap<std::pair<Type, unsigned>, ParenType*> ParenTypes;
298297
llvm::DenseMap<uintptr_t, ReferenceStorageType*> ReferenceStorageTypes;
299298
llvm::DenseMap<Type, LValueType*> LValueTypes;
@@ -2120,7 +2119,6 @@ size_t ASTContext::Implementation::Arena::getTotalMemory() const {
21202119
llvm::capacity_in_bytes(ArraySliceTypes) +
21212120
llvm::capacity_in_bytes(DictionaryTypes) +
21222121
llvm::capacity_in_bytes(OptionalTypes) +
2123-
llvm::capacity_in_bytes(ImplicitlyUnwrappedOptionalTypes) +
21242122
llvm::capacity_in_bytes(ParenTypes) +
21252123
llvm::capacity_in_bytes(ReferenceStorageTypes) +
21262124
llvm::capacity_in_bytes(LValueTypes) +
@@ -3440,7 +3438,7 @@ ReferenceStorageType *ReferenceStorageType::get(Type T, Ownership ownership,
34403438
return entry = new (C, arena) UnownedStorageType(
34413439
T, T->isCanonical() ? &C : nullptr, properties);
34423440
case Ownership::Weak:
3443-
assert(T->getAnyOptionalObjectType() &&
3441+
assert(T->getOptionalObjectType() &&
34443442
"object of weak storage type is not optional");
34453443
return entry = new (C, arena)
34463444
WeakStorageType(T, T->isCanonical() ? &C : nullptr, properties);
@@ -4033,7 +4031,8 @@ Type OptionalType::get(OptionalTypeKind which, Type valueType) {
40334031
// OTK_None if we made code more convenient to write.
40344032
case OTK_None: llvm_unreachable("building a non-optional type!");
40354033
case OTK_Optional: return OptionalType::get(valueType);
4036-
case OTK_ImplicitlyUnwrappedOptional: return ImplicitlyUnwrappedOptionalType::get(valueType);
4034+
case OTK_ImplicitlyUnwrappedOptional:
4035+
llvm_unreachable("Should no longer have IUOs");
40374036
}
40384037
llvm_unreachable("bad optional type kind");
40394038
}
@@ -4050,18 +4049,6 @@ OptionalType *OptionalType::get(Type base) {
40504049
return entry = new (C, arena) OptionalType(C, base, properties);
40514050
}
40524051

4053-
ImplicitlyUnwrappedOptionalType *ImplicitlyUnwrappedOptionalType::get(Type base) {
4054-
auto properties = base->getRecursiveProperties();
4055-
auto arena = getArena(properties);
4056-
4057-
const ASTContext &C = base->getASTContext();
4058-
4059-
auto *&entry = C.Impl.getArena(arena).ImplicitlyUnwrappedOptionalTypes[base];
4060-
if (entry) return entry;
4061-
4062-
return entry = new (C, arena) ImplicitlyUnwrappedOptionalType(C, base, properties);
4063-
}
4064-
40654052
ProtocolType *ProtocolType::get(ProtocolDecl *D, Type Parent,
40664053
const ASTContext &C) {
40674054
llvm::FoldingSetNodeID id;

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,13 +3222,6 @@ namespace {
32223222
OS << ")";
32233223
}
32243224

3225-
void visitImplicitlyUnwrappedOptionalType(
3226-
ImplicitlyUnwrappedOptionalType *T, StringRef label) {
3227-
printCommon(label, "implicitly_unwrapped_optional_type");
3228-
printRec(T->getBaseType());
3229-
OS << ")";
3230-
}
3231-
32323225
void visitDictionaryType(DictionaryType *T, StringRef label) {
32333226
printCommon(label, "dictionary_type");
32343227
printRec("key", T->getKeyType());

lib/AST/ASTMangler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,10 +754,6 @@ void ASTMangler::appendType(Type type) {
754754
case TypeKind::Dictionary:
755755
return appendSugaredType<SyntaxSugarType>(type);
756756

757-
case TypeKind::ImplicitlyUnwrappedOptional: {
758-
llvm_unreachable("Should no longer have IUOs");
759-
}
760-
761757
case TypeKind::ExistentialMetatype: {
762758
ExistentialMetatypeType *EMT = cast<ExistentialMetatypeType>(tybase);
763759
appendType(EMT->getInstanceType());

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,20 +3785,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
37853785
Printer << "?";
37863786
}
37873787

3788-
void visitImplicitlyUnwrappedOptionalType(ImplicitlyUnwrappedOptionalType *T) {
3789-
auto printAsIUO = Options.PrintOptionalAsImplicitlyUnwrapped;
3790-
3791-
// Printing optionals with a trailing '!' applies only to
3792-
// top-level optionals, not to any nested within.
3793-
const_cast<PrintOptions &>(Options).PrintOptionalAsImplicitlyUnwrapped =
3794-
false;
3795-
printWithParensIfNotSimple(T->getBaseType());
3796-
const_cast<PrintOptions &>(Options).PrintOptionalAsImplicitlyUnwrapped =
3797-
printAsIUO;
3798-
3799-
Printer << "!";
3800-
}
3801-
38023788
void visitProtocolType(ProtocolType *T) {
38033789
printTypeDeclName(T);
38043790
}

lib/AST/ASTVerifier.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,10 +1686,10 @@ class Verifier : public ASTWalker {
16861686
Expr *E) {
16871687
auto optionalRVType = optionalType->getRValueType();
16881688
auto objectRVType = objectType->getRValueType();
1689-
1690-
checkSameType(objectRVType, optionalRVType->getAnyOptionalObjectType(),
1689+
1690+
checkSameType(objectRVType, optionalRVType->getOptionalObjectType(),
16911691
"optional object type");
1692-
1692+
16931693
if (objectType->is<LValueType>() != optionalType->is<LValueType>()) {
16941694
Out << "optional operation must preserve lvalue-ness of base\n";
16951695
E->print(Out);
@@ -1856,7 +1856,7 @@ class Verifier : public ASTWalker {
18561856
PrettyStackTraceExpr debugStack(Ctx, "verifying InjectIntoOptionalExpr",
18571857
E);
18581858

1859-
auto valueType = E->getType()->getAnyOptionalObjectType();
1859+
auto valueType = E->getType()->getOptionalObjectType();
18601860
if (!valueType) {
18611861
Out << "InjectIntoOptionalExpr is not of Optional type";
18621862
abort();
@@ -2320,7 +2320,7 @@ class Verifier : public ASTWalker {
23202320

23212321
// FIXME: Update to look for plain Optional once
23222322
// ImplicitlyUnwrappedOptional is removed
2323-
if (!varTy->getAnyOptionalObjectType()) {
2323+
if (!varTy->getOptionalObjectType()) {
23242324
Out << "implicitly unwrapped optional attribute should only be set on VarDecl "
23252325
"with optional type\n";
23262326
abort();
@@ -2688,7 +2688,7 @@ class Verifier : public ASTWalker {
26882688
CD->getDeclContext()->getDeclaredInterfaceType()->getAnyNominal() !=
26892689
Ctx.getOptionalDecl()) {
26902690
OptionalTypeKind resultOptionality = OTK_None;
2691-
CD->getResultInterfaceType()->getAnyOptionalObjectType(resultOptionality);
2691+
CD->getResultInterfaceType()->getOptionalObjectType(resultOptionality);
26922692
auto declOptionality = CD->getFailability();
26932693

26942694
if ((resultOptionality != OTK_None || declOptionality != OTK_None) &&
@@ -2702,8 +2702,10 @@ class Verifier : public ASTWalker {
27022702
if (auto genericFn
27032703
= CD->getInterfaceType()->getAs<GenericFunctionType>()) {
27042704
resultOptionality = OTK_None;
2705-
genericFn->getResult()->castTo<AnyFunctionType>()->getResult()
2706-
->getAnyOptionalObjectType(resultOptionality);
2705+
genericFn->getResult()
2706+
->castTo<AnyFunctionType>()
2707+
->getResult()
2708+
->getOptionalObjectType(resultOptionality);
27072709
if ((resultOptionality != OTK_None || declOptionality != OTK_None) &&
27082710
(resultOptionality == OTK_None || declOptionality == OTK_None)) {
27092711
Out << "Initializer has result optionality/failability mismatch\n";
@@ -2732,7 +2734,7 @@ class Verifier : public ASTWalker {
27322734

27332735
// FIXME: Update to look for plain Optional once
27342736
// ImplicitlyUnwrappedOptional is removed
2735-
if (!resultTy->getAnyOptionalObjectType()) {
2737+
if (!resultTy->getOptionalObjectType()) {
27362738
Out << "implicitly unwrapped optional attribute should only be set "
27372739
"on constructors with optional return types\n";
27382740
CD->dump(llvm::errs());
@@ -2900,7 +2902,7 @@ class Verifier : public ASTWalker {
29002902

29012903
// FIXME: Update to look for plain Optional once
29022904
// ImplicitlyUnwrappedOptional is removed
2903-
if (!resultTy->getAnyOptionalObjectType()) {
2905+
if (!resultTy->getOptionalObjectType()) {
29042906
Out << "implicitly unwrapped optional attribute should only be set "
29052907
"on functions with optional return types\n";
29062908
abort();

lib/AST/Decl.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ bool PatternBindingDecl::isDefaultInitializable(unsigned i) const {
12401240
if (const auto *varDecl = typedPattern->getSingleVar())
12411241
// Lazy storage is never user accessible.
12421242
if (!varDecl->isUserAccessible())
1243-
if (typedPattern->getTypeLoc().getType()->getAnyOptionalObjectType())
1243+
if (typedPattern->getTypeLoc().getType()->getOptionalObjectType())
12441244
return true;
12451245
}
12461246
}
@@ -1741,10 +1741,10 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
17411741
if (isInitializer) {
17421742
if (auto inOutTy = type->getAs<InOutType>()) {
17431743
if (auto objectType =
1744-
inOutTy->getObjectType()->getAnyOptionalObjectType()) {
1744+
inOutTy->getObjectType()->getOptionalObjectType()) {
17451745
type = InOutType::get(objectType);
17461746
}
1747-
} else if (auto objectType = type->getAnyOptionalObjectType()) {
1747+
} else if (auto objectType = type->getOptionalObjectType()) {
17481748
type = objectType;
17491749
}
17501750
}
@@ -2478,13 +2478,8 @@ void NominalTypeDecl::addExtension(ExtensionDecl *extension) {
24782478
LastExtension = extension;
24792479
}
24802480

2481-
OptionalTypeKind NominalTypeDecl::classifyAsOptionalType() const {
2482-
const ASTContext &ctx = getASTContext();
2483-
if (this == ctx.getOptionalDecl()) {
2484-
return OTK_Optional;
2485-
} else {
2486-
return OTK_None;
2487-
}
2481+
bool NominalTypeDecl::isOptionalDecl() const {
2482+
return this == getASTContext().getOptionalDecl();
24882483
}
24892484

24902485
GenericTypeDecl::GenericTypeDecl(DeclKind K, DeclContext *DC,
@@ -3273,7 +3268,7 @@ findProtocolSelfReferences(const ProtocolDecl *proto, Type type,
32733268
}
32743269

32753270
// Optionals preserve variance.
3276-
if (auto optType = type->getAnyOptionalObjectType()) {
3271+
if (auto optType = type->getOptionalObjectType()) {
32773272
return findProtocolSelfReferences(proto, optType,
32783273
skipAssocTypes);
32793274
}
@@ -4559,7 +4554,7 @@ ObjCSubscriptKind SubscriptDecl::getObjCSubscriptKind(
45594554

45604555
// If the index type is an object type in Objective-C, we have a
45614556
// keyed subscript.
4562-
if (Type objectTy = indexTy->getAnyOptionalObjectType())
4557+
if (Type objectTy = indexTy->getOptionalObjectType())
45634558
indexTy = objectTy;
45644559

45654560
return ObjCSubscriptKind::Keyed;

0 commit comments

Comments
 (0)