Skip to content

Commit 393eae2

Browse files
authored
Merge pull request #14364 from rudkx/typealias-for-iuo
Make ImplicitlyUnwrappedOptional<T> an unavailable typealias.
2 parents 2134f9f + 2008674 commit 393eae2

31 files changed

+219
-432
lines changed

include/swift/AST/ASTContext.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class ASTContext {
410410
DECL_CLASS *get##NAME##Decl() const;
411411
#include "swift/AST/KnownStdlibTypes.def"
412412

413-
/// Retrieve the declaration of Swift.Optional or ImplicitlyUnwrappedOptional.
413+
/// Retrieve the declaration of Swift.Optional.
414414
EnumDecl *getOptionalDecl(OptionalTypeKind kind) const;
415415

416416
/// Retrieve the declaration of Swift.Optional<T>.Some.
@@ -419,12 +419,6 @@ class ASTContext {
419419
/// Retrieve the declaration of Swift.Optional<T>.None.
420420
EnumElementDecl *getOptionalNoneDecl() const;
421421

422-
/// Retrieve the declaration of Swift.ImplicitlyUnwrappedOptional<T>.Some.
423-
EnumElementDecl *getImplicitlyUnwrappedOptionalSomeDecl() const;
424-
425-
/// Retrieve the declaration of Swift.ImplicitlyUnwrappedOptional<T>.None.
426-
EnumElementDecl *getImplicitlyUnwrappedOptionalNoneDecl() const;
427-
428422
EnumElementDecl *getOptionalSomeDecl(OptionalTypeKind kind) const;
429423
EnumElementDecl *getOptionalNoneDecl(OptionalTypeKind kind) const;
430424

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ ERROR(iboutlet_non_optional,none,
10561056
NOTE(note_make_optional,none,
10571057
"add '?' to form the optional type %0", (Type))
10581058
NOTE(note_make_implicitly_unwrapped_optional,none,
1059-
"add '!' to form the implicitly unwrapped optional type %0", (Type))
1059+
"add '!' to form an implicitly unwrapped optional", ())
10601060

10611061
ERROR(invalid_ibdesignable_extension,none,
10621062
"@IBDesignable can only be applied to classes and extensions "
@@ -3129,32 +3129,11 @@ ERROR(tuple_single_element,none,
31293129
ERROR(tuple_ellipsis,none,
31303130
"cannot create a variadic tuple", ())
31313131

3132-
WARNING(implicitly_unwrapped_optional_spelling_deprecated,none,
3133-
"the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use an explicit type followed by '!'", ())
3134-
3135-
WARNING(implicitly_unwrapped_optional_spelling_deprecated_with_fixit,none,
3136-
"the spelling 'ImplicitlyUnwrappedOptional' is deprecated; use '!' after the type name", ())
3137-
3138-
WARNING(implicitly_unwrapped_optional_spelling_suggest_optional,none,
3139-
"using 'ImplicitlyUnwrappedOptional' in this location is deprecated and will be removed in a future release; consider changing this to 'Optional' instead", ())
3140-
3141-
WARNING(implicitly_unwrapped_optional_in_illegal_position_suggest_optional,none,
3142-
"using '!' in this location is deprecated and will be removed in a future release; consider changing this to '?' instead", ())
3143-
3144-
ERROR(implicitly_unwrapped_optional_spelling_error,none,
3145-
"the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use an explicit type followed by '!'", ())
3146-
3147-
ERROR(implicitly_unwrapped_optional_spelling_error_with_bang_fixit,none,
3148-
"the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use '!' after the type name", ())
3149-
3150-
ERROR(implicitly_unwrapped_optional_spelling_error_with_optional_fixit,none,
3151-
"the spelling 'ImplicitlyUnwrappedOptional' is unsupported; use 'Optional' instead", ())
3152-
3153-
ERROR(implicitly_unwrapped_optional_spelling_in_illegal_position,none,
3154-
"'ImplicitlyUnwrappedOptional' is not allowed here; perhaps 'Optional' was intended?", ())
3132+
WARNING(implicitly_unwrapped_optional_in_illegal_position_interpreted_as_optional,none,
3133+
"using '!' is not allowed here; treating this as '?' instead", ())
31553134

31563135
ERROR(implicitly_unwrapped_optional_in_illegal_position,none,
3157-
"'!' is not allowed here; perhaps '?' was intended?", ())
3136+
"using '!' is not allowed here; perhaps '?' was intended?", ())
31583137

31593138
// Ownership
31603139
ERROR(invalid_ownership_type,none,

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ IDENTIFIER(forKey)
5757
IDENTIFIER(from)
5858
IDENTIFIER(fromRaw)
5959
IDENTIFIER(hashValue)
60-
IDENTIFIER(ImplicitlyUnwrappedOptional)
6160
IDENTIFIER(init)
6261
IDENTIFIER(initialize)
6362
IDENTIFIER(initStorage)

include/swift/AST/KnownStdlibTypes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ KNOWN_STDLIB_TYPE_DECL(WritableKeyPath, NominalTypeDecl, 2)
5858
KNOWN_STDLIB_TYPE_DECL(ReferenceWritableKeyPath, NominalTypeDecl, 2)
5959

6060
KNOWN_STDLIB_TYPE_DECL(Optional, EnumDecl, 1)
61-
KNOWN_STDLIB_TYPE_DECL(ImplicitlyUnwrappedOptional, EnumDecl, 1)
6261

6362
KNOWN_STDLIB_TYPE_DECL(OptionSet, NominalTypeDecl, 1)
6463

include/swift/AST/Types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4115,7 +4115,8 @@ class ImplicitlyUnwrappedOptionalType : public UnarySyntaxSugarType {
41154115
RecursiveTypeProperties properties)
41164116
: UnarySyntaxSugarType(TypeKind::ImplicitlyUnwrappedOptional, ctx, base,
41174117
properties) {
4118-
//llvm_unreachable("ImplicitlyUnwrappedOptionalType::ImplicitlyUnwrappedOptionalType");
4118+
llvm_unreachable(
4119+
"ImplicitlyUnwrappedOptionalType::ImplicitlyUnwrappedOptionalType");
41194120
}
41204121

41214122
public:

include/swift/Serialization/ModuleFormat.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 393; // SILLinkage::PublicNonABI
57+
const uint16_t VERSION_MINOR = 394; // Remove IUO serialization and decl
5858

5959
using DeclIDField = BCFixed<31>;
6060

@@ -790,8 +790,6 @@ namespace decls_block {
790790

791791
using ArraySliceTypeLayout = SyntaxSugarTypeLayout<ARRAY_SLICE_TYPE>;
792792
using OptionalTypeLayout = SyntaxSugarTypeLayout<OPTIONAL_TYPE>;
793-
using ImplicitlyUnwrappedOptionalTypeLayout =
794-
SyntaxSugarTypeLayout<UNCHECKED_OPTIONAL_TYPE>;
795793

796794
using DictionaryTypeLayout = BCRecordLayout<
797795
DICTIONARY_TYPE,

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ EnumDecl *ASTContext::getOptionalDecl(OptionalTypeKind kind) const {
650650
case OTK_None:
651651
llvm_unreachable("not optional");
652652
case OTK_ImplicitlyUnwrappedOptional:
653-
return getImplicitlyUnwrappedOptionalDecl();
653+
llvm_unreachable("Should no longer have IUOs");
654654
case OTK_Optional:
655655
return getOptionalDecl();
656656
}
@@ -663,7 +663,7 @@ EnumElementDecl *ASTContext::getOptionalSomeDecl(OptionalTypeKind kind) const {
663663
case OTK_Optional:
664664
return getOptionalSomeDecl();
665665
case OTK_ImplicitlyUnwrappedOptional:
666-
return getImplicitlyUnwrappedOptionalSomeDecl();
666+
llvm_unreachable("Should not have IUOs.");
667667
case OTK_None:
668668
llvm_unreachable("getting Some decl for non-optional type?");
669669
}
@@ -675,7 +675,7 @@ EnumElementDecl *ASTContext::getOptionalNoneDecl(OptionalTypeKind kind) const {
675675
case OTK_Optional:
676676
return getOptionalNoneDecl();
677677
case OTK_ImplicitlyUnwrappedOptional:
678-
return getImplicitlyUnwrappedOptionalNoneDecl();
678+
llvm_unreachable("Should not have IUOs.");
679679
case OTK_None:
680680
llvm_unreachable("getting None decl for non-optional type?");
681681
}
@@ -694,20 +694,6 @@ EnumElementDecl *ASTContext::getOptionalNoneDecl() const {
694694
return Impl.OptionalNoneDecl;
695695
}
696696

697-
EnumElementDecl *ASTContext::getImplicitlyUnwrappedOptionalSomeDecl() const {
698-
if (!Impl.ImplicitlyUnwrappedOptionalSomeDecl)
699-
Impl.ImplicitlyUnwrappedOptionalSomeDecl =
700-
getImplicitlyUnwrappedOptionalDecl()->getUniqueElement(/*hasVal*/true);
701-
return Impl.ImplicitlyUnwrappedOptionalSomeDecl;
702-
}
703-
704-
EnumElementDecl *ASTContext::getImplicitlyUnwrappedOptionalNoneDecl() const {
705-
if (!Impl.ImplicitlyUnwrappedOptionalNoneDecl)
706-
Impl.ImplicitlyUnwrappedOptionalNoneDecl =
707-
getImplicitlyUnwrappedOptionalDecl()->getUniqueElement(/*hasVal*/false);
708-
return Impl.ImplicitlyUnwrappedOptionalNoneDecl;
709-
}
710-
711697
static VarDecl *getPointeeProperty(VarDecl *&cache,
712698
NominalTypeDecl *(ASTContext::*getNominal)() const,
713699
const ASTContext &ctx) {

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,11 +756,7 @@ void ASTMangler::appendType(Type type) {
756756
return appendSugaredType<SyntaxSugarType>(type);
757757

758758
case TypeKind::ImplicitlyUnwrappedOptional: {
759-
assert(DWARFMangling && "sugared types are only legal for the debugger");
760-
auto *IUO = cast<ImplicitlyUnwrappedOptionalType>(tybase);
761-
auto implDecl = tybase->getASTContext().getImplicitlyUnwrappedOptionalDecl();
762-
auto GenTy = BoundGenericType::get(implDecl, Type(), IUO->getBaseType());
763-
return appendType(GenTy);
759+
llvm_unreachable("Should no longer have IUOs");
764760
}
765761

766762
case TypeKind::ExistentialMetatype: {

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,11 +3337,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
33373337
Printer << "?";
33383338
return;
33393339
}
3340-
if (NT == Ctx.getImplicitlyUnwrappedOptionalDecl()) {
3341-
printWithParensIfNotSimple(T->getGenericArgs()[0]);
3342-
Printer << "!";
3343-
return;
3344-
}
33453340
}
33463341
if (auto ParentType = T->getParent()) {
33473342
visit(ParentType);

lib/AST/ASTVerifier.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2684,11 +2684,9 @@ class Verifier : public ASTWalker {
26842684

26852685
// Verify that the optionality of the result type of the
26862686
// initializer matches the failability of the initializer.
2687-
if (!CD->isInvalid() &&
2688-
CD->getDeclContext()->getDeclaredInterfaceType()->getAnyNominal()
2689-
!= Ctx.getOptionalDecl() &&
2690-
CD->getDeclContext()->getDeclaredInterfaceType()->getAnyNominal()
2691-
!= Ctx.getImplicitlyUnwrappedOptionalDecl()) {
2687+
if (!CD->isInvalid() &&
2688+
CD->getDeclContext()->getDeclaredInterfaceType()->getAnyNominal() !=
2689+
Ctx.getOptionalDecl()) {
26922690
OptionalTypeKind resultOptionality = OTK_None;
26932691
CD->getResultInterfaceType()->getAnyOptionalObjectType(resultOptionality);
26942692
auto declOptionality = CD->getFailability();

0 commit comments

Comments
 (0)