Skip to content

Some cleanup to remove more IUO related things. #14398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,6 @@ class alignas(1 << TypeAlignInBits) TypeBase {
/// Return T if this type is Optional<T>; otherwise, return the null type.
Type getOptionalObjectType();

/// Return T if this type is ImplicitlyUnwrappedOptional<T>; otherwise, return
/// the null type.
Type getImplicitlyUnwrappedOptionalObjectType();

/// Return T if this type is Optional<T> or ImplicitlyUnwrappedOptional<T>;
/// otherwise, return the null type.
Type getAnyOptionalObjectType(OptionalTypeKind &kind);
Expand Down
12 changes: 0 additions & 12 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,18 +1696,6 @@ static Type mapSignatureType(ASTContext &ctx, Type type) {

/// Map a signature type for a parameter.
static Type mapSignatureParamType(ASTContext &ctx, Type type) {
// Translate implicitly unwrapped optionals into strict optionals.
if (auto inOutTy = type->getAs<InOutType>()) {
if (auto uncheckedOptOf =
inOutTy->getObjectType()
->getImplicitlyUnwrappedOptionalObjectType()) {
type = InOutType::get(OptionalType::get(uncheckedOptOf));
}
} else if (auto uncheckedOptOf =
type->getImplicitlyUnwrappedOptionalObjectType()) {
type = OptionalType::get(uncheckedOptOf);
}

return mapSignatureType(ctx, type);
}

Expand Down
18 changes: 0 additions & 18 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,6 @@ Type TypeBase::getOptionalObjectType() {
return Type();
}

Type TypeBase::getImplicitlyUnwrappedOptionalObjectType() {
if (auto boundTy = getAs<BoundGenericEnumType>())
if (boundTy->getDecl()->classifyAsOptionalType() == OTK_ImplicitlyUnwrappedOptional)
return boundTy->getGenericArgs()[0];
return Type();
}

Type TypeBase::getAnyOptionalObjectType(OptionalTypeKind &kind) {
if (auto boundTy = getAs<BoundGenericEnumType>())
if ((kind = boundTy->getDecl()->classifyAsOptionalType()))
Expand Down Expand Up @@ -2309,17 +2302,6 @@ static bool matches(CanType t1, CanType t2, TypeMatchOptions matchMode,
paramsAndResultMatch);
}

if (matchMode.contains(TypeMatchFlags::AllowNonOptionalForIUOParam) &&
(paramPosition == ParameterPosition::Parameter ||
paramPosition == ParameterPosition::ParameterTupleElement) &&
insideOptional == OptionalUnwrapping::None) {
// Allow T to override T! in certain cases.
if (auto obj1 = t1->getImplicitlyUnwrappedOptionalObjectType()) {
t1 = obj1->getCanonicalType();
if (t1 == t2) return true;
}
}

// Class-to-class.
if (matchMode.contains(TypeMatchFlags::AllowOverride))
if (t2->isExactSuperclassOf(t1))
Expand Down
24 changes: 0 additions & 24 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ namespace {
using TypeVisitor::Visit;
ImportResult Visit(clang::QualType type) {
auto IR = Visit(type.getTypePtr());
assert(!IR.AbstractType ||
!IR.AbstractType->getImplicitlyUnwrappedOptionalObjectType());
return IR;
}

Expand Down Expand Up @@ -1161,10 +1159,6 @@ static ImportedType adjustTypeForConcreteImport(
bool allowNSUIntegerAsInt, Bridgeability bridging, OptionalTypeKind optKind,
bool resugarNSErrorPointer) {

// We never expect an IUO type to be passed in.
assert(!importedType ||
!importedType->getImplicitlyUnwrappedOptionalObjectType());

if (importKind == ImportTypeKind::Abstract) {
return {importedType, false};
}
Expand All @@ -1188,8 +1182,6 @@ static ImportedType adjustTypeForConcreteImport(
if (!importedType)
return {Type(), false};

assert(!importedType->getImplicitlyUnwrappedOptionalObjectType());

// Special case AutoreleasingUnsafeMutablePointer<NSError?> parameters.
auto maybeImportNSErrorPointer = [&]() -> Type {
if (importKind != ImportTypeKind::Parameter)
Expand Down Expand Up @@ -1232,7 +1224,6 @@ static ImportedType adjustTypeForConcreteImport(
};

if (Type result = maybeImportNSErrorPointer()) {
assert(!result->getImplicitlyUnwrappedOptionalObjectType());
return {result, false};
}

Expand Down Expand Up @@ -1278,11 +1269,9 @@ static ImportedType adjustTypeForConcreteImport(
resultTy = impl.getNamedSwiftTypeSpecialization(impl.getStdlibModule(),
pointerName,
resultTy);
assert(!resultTy->getImplicitlyUnwrappedOptionalObjectType());
return resultTy;
};
if (Type outParamTy = maybeImportCFOutParameter()) {
assert(!outParamTy->getImplicitlyUnwrappedOptionalObjectType());
importedType = outParamTy;
}

Expand Down Expand Up @@ -1381,9 +1370,6 @@ static ImportedType adjustTypeForConcreteImport(
importedType = OptionalType::get(importedType);
}

// We do not expect to return actual IUO types.
assert(!importedType->getImplicitlyUnwrappedOptionalObjectType());

return {importedType, isIUO};
}

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

// We should never get an actual IUO type back.
assert(!adjustedType ||
!adjustedType.getType()->getImplicitlyUnwrappedOptionalObjectType());

return adjustedType;
}

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

assert(!importedType ||
!importedType.getType()->getImplicitlyUnwrappedOptionalObjectType());

return importedType.getType();
}

Expand Down Expand Up @@ -1569,9 +1548,6 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
switch (getClangASTContext().BuiltinInfo.getTypeString(builtinID)[0]) {
case 'z': // size_t
case 'Y': // ptrdiff_t
assert(!SwiftContext.getIntDecl()
->getDeclaredType()
->getImplicitlyUnwrappedOptionalObjectType());
return {SwiftContext.getIntDecl()->getDeclaredType(), false};
default:
break;
Expand Down
8 changes: 3 additions & 5 deletions lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,10 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
}
#endif

if (!isIUO) {
assert(!ty->getImplicitlyUnwrappedOptionalObjectType());
if (!isIUO)
return;
} else {
assert(ty->getAnyOptionalObjectType());
}

assert(ty->getOptionalObjectType());

auto *IUOAttr = new (SwiftContext)
ImplicitlyUnwrappedOptionalAttr(/* implicit= */ true);
Expand Down
8 changes: 2 additions & 6 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3158,6 +3158,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
// FIXME: consider types convertible to T?.

ExprType = ExprType->getRValueType();
// FIXME: We don't always pass down whether a type is from an
// unforced IUO.
if (isIUO) {
if (Type Unwrapped = ExprType->getAnyOptionalObjectType()) {
lookupVisibleMemberDecls(*this, Unwrapped, CurrDeclContext,
Expand All @@ -3184,12 +3186,6 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
IncludeInstanceMembers);
}
}
} else if (Type Unwrapped = ExprType->getImplicitlyUnwrappedOptionalObjectType()) {
// FIXME: This can go away when IUOs have been removed from the type
// system.
lookupVisibleMemberDecls(*this, Unwrapped, CurrDeclContext,
TypeResolver.get(),
IncludeInstanceMembers);
} else {
return false;
}
Expand Down
7 changes: 0 additions & 7 deletions lib/SILGen/SILGenBridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,6 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF,
loweredBridgedTy.castTo<SILFunctionType>());
}

// Erase IUO at this point, because there aren't any conformances for
// IUO anymore. Note that the value representation stays the same
// because SIL erases the difference.
if (auto obj = nativeType->getImplicitlyUnwrappedOptionalObjectType()) {
nativeType = OptionalType::get(obj)->getCanonicalType();
}

// If the native type conforms to _ObjectiveCBridgeable, use its
// _bridgeToObjectiveC witness.
if (auto conformance =
Expand Down
Loading