Skip to content

Commit 3a93147

Browse files
authored
[ClangImporter] Remove now-unnecessary special case for IUO importing (#27265)
Back when IUO could be used anywhere in a type in Swift, we had a special case for imported pointer types that their pointees were never implicitly-unwrapped, even if they weren't nullability-audited on the Objective-C side. Now that IUO can only be used in top-level positions (SE-0054, only fully implemented last year), we don't need a special case for this; all non-top-level optionals are never implicitly-unwrapped. No functionality change.
2 parents b11e8ac + 2b25fe0 commit 3a93147

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,6 @@ namespace {
160160
explicit operator bool() const { return (bool) AbstractType; }
161161
};
162162

163-
static OptionalTypeKind getOptionalKind(ImportTypeKind kind,
164-
OptionalTypeKind OptKind) {
165-
// Import pointee types as true Optional.
166-
if (OptKind == OTK_ImplicitlyUnwrappedOptional &&
167-
kind == ImportTypeKind::Pointee)
168-
return OTK_Optional;
169-
return OptKind;
170-
}
171-
172163
class SwiftTypeConverter :
173164
public clang::TypeVisitor<SwiftTypeConverter, ImportResult>
174165
{
@@ -393,7 +384,7 @@ namespace {
393384
pointeeType = Impl.getNamedSwiftType(Impl.getStdlibModule(), "Void");
394385
else
395386
pointeeType = Impl.importTypeIgnoreIUO(
396-
pointeeQualType, ImportTypeKind::Pointee, AllowNSUIntegerAsInt,
387+
pointeeQualType, ImportTypeKind::Value, AllowNSUIntegerAsInt,
397388
Bridgeability::None);
398389

399390
// If the pointed-to type is unrepresentable in Swift, or its C
@@ -479,7 +470,7 @@ namespace {
479470
// we can cheese static-offset "indexing" using .$n operations.
480471

481472
Type elementType = Impl.importTypeIgnoreIUO(
482-
type->getElementType(), ImportTypeKind::Pointee, AllowNSUIntegerAsInt,
473+
type->getElementType(), ImportTypeKind::Value, AllowNSUIntegerAsInt,
483474
Bridgeability::None);
484475
if (!elementType)
485476
return Type();
@@ -1096,7 +1087,6 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
10961087
case ImportTypeKind::Value:
10971088
case ImportTypeKind::Variable:
10981089
case ImportTypeKind::AuditedVariable:
1099-
case ImportTypeKind::Pointee:
11001090
case ImportTypeKind::Enum:
11011091
case ImportTypeKind::RecordField:
11021092
return false;
@@ -1124,7 +1114,6 @@ static bool isCFAudited(ImportTypeKind importKind) {
11241114
case ImportTypeKind::ObjCCollectionElement:
11251115
case ImportTypeKind::Variable:
11261116
case ImportTypeKind::Result:
1127-
case ImportTypeKind::Pointee:
11281117
case ImportTypeKind::Enum:
11291118
case ImportTypeKind::RecordField:
11301119
return false;
@@ -1398,7 +1387,6 @@ static ImportedType adjustTypeForConcreteImport(
13981387
// optional type.
13991388
bool isIUO = false;
14001389
if (importKind != ImportTypeKind::Typedef && canImportAsOptional(hint)) {
1401-
optKind = getOptionalKind(importKind, optKind);
14021390
isIUO = optKind == OTK_ImplicitlyUnwrappedOptional;
14031391
if (optKind != OTK_None)
14041392
importedType = OptionalType::get(importedType);
@@ -2044,14 +2032,11 @@ ImportedType ClangImporter::Implementation::importMethodType(
20442032
bool paramIsIUO;
20452033
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
20462034
paramTy->isObjCIdType()) {
2047-
auto optKind =
2048-
getOptionalKind(ImportTypeKind::Parameter, optionalityOfParam);
2049-
20502035
swiftParamTy = SwiftContext.getNSCopyingDecl()->getDeclaredType();
2051-
if (optKind != OTK_None)
2036+
if (optionalityOfParam != OTK_None)
20522037
swiftParamTy = OptionalType::get(swiftParamTy);
20532038

2054-
paramIsIUO = optKind == OTK_ImplicitlyUnwrappedOptional;
2039+
paramIsIUO = optionalityOfParam == OTK_ImplicitlyUnwrappedOptional;
20552040
} else {
20562041
ImportTypeKind importKind = ImportTypeKind::Parameter;
20572042
if (param->hasAttr<clang::CFReturnsRetainedAttr>())

lib/ClangImporter/ImporterImpl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@ enum class ImportTypeKind {
152152
/// This ensures that the parameter is not marked as Unmanaged.
153153
CFUnretainedOutParameter,
154154

155-
/// Import the type pointed to by a pointer or reference.
156-
///
157-
/// This provides special treatment for pointer-to-ObjC-pointer
158-
/// types, which get imported as pointers to *checked* optional,
159-
/// *Pointer<NSFoo?>, instead of implicitly unwrapped optional as usual.
160-
Pointee,
161-
162155
/// Import the type of an ObjC property.
163156
///
164157
/// This enables the conversion of bridged types. Properties are always

0 commit comments

Comments
 (0)