Skip to content

[ClangImporter] Remove support for Swift 3 mode #17722

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 1 commit into from
Jul 17, 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
40 changes: 2 additions & 38 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,7 @@ shouldSuppressGenericParamsImport(const LangOptions &langOpts,
return module->getTopLevelModuleName() == "Foundation";
};

if (langOpts.isSwiftVersion3() || isFromFoundationModule(decl)) {
if (isFromFoundationModule(decl)) {
// In Swift 3 we used a hardcoded list of declarations, and made all of
// their subclasses drop their generic parameters when imported.
while (decl) {
Expand Down Expand Up @@ -7552,41 +7552,6 @@ void ClangImporter::Implementation::importAttributes(
PlatformAgnostic, /*Implicit=*/false);

MappedDecl->getAttrs().add(AvAttr);

// For enum cases introduced in the 2017 SDKs, add
// @_downgrade_exhaustivity_check in Swift 3.
if (C.LangOpts.isSwiftVersion3() && isa<EnumElementDecl>(MappedDecl)) {
bool downgradeExhaustivity = false;
switch (*platformK) {
case PlatformKind::OSX:
case PlatformKind::OSXApplicationExtension:
downgradeExhaustivity = (introduced.getMajor() == 10 &&
introduced.getMinor() &&
*introduced.getMinor() == 13);
break;

case PlatformKind::iOS:
case PlatformKind::iOSApplicationExtension:
case PlatformKind::tvOS:
case PlatformKind::tvOSApplicationExtension:
downgradeExhaustivity = (introduced.getMajor() == 11);
break;

case PlatformKind::watchOS:
case PlatformKind::watchOSApplicationExtension:
downgradeExhaustivity = (introduced.getMajor() == 4);
break;

case PlatformKind::none:
break;
}

if (downgradeExhaustivity) {
auto attr =
new (C) DowngradeExhaustivityCheckAttr(/*isImplicit=*/true);
MappedDecl->getAttrs().add(attr);
}
}
}
}

Expand Down Expand Up @@ -7717,8 +7682,7 @@ ClangImporter::Implementation::importDeclImpl(const clang::NamedDecl *ClangDecl,
}
}
if (auto method = dyn_cast<clang::ObjCMethodDecl>(ClangDecl)) {
if (!SwiftContext.LangOpts.isSwiftVersion3() &&
method->isDesignatedInitializerForTheInterface()) {
if (method->isDesignatedInitializerForTheInterface()) {
const clang::ObjCInterfaceDecl *theClass = method->getClassInterface();
assert(theClass && "cannot be a protocol method here");
// Only allow this to affect declarations in the same top-level module
Expand Down
28 changes: 3 additions & 25 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,10 +884,7 @@ namespace {
}
importedTypeArg = subresult.AbstractType;
} else if (typeParam->getSuperclass() &&
(Impl.SwiftContext.isSwiftVersion3() ||
typeParam->getConformingProtocols().empty())) {
// In Swift 3 mode, discard the protocol bounds if there is
// a superclass bound.
typeParam->getConformingProtocols().empty()) {
importedTypeArg = typeParam->getSuperclass();
} else {
SmallVector<Type, 4> memberTypes;
Expand Down Expand Up @@ -1039,10 +1036,7 @@ namespace {
}
}

// Swift 3 compatibility -- don't import subclass existentials
if (!type->qual_empty() &&
(importedType->isAnyObject() ||
!Impl.SwiftContext.isSwiftVersion3())) {
if (!type->qual_empty()) {
SmallVector<Type, 4> members;
if (!importedType->isAnyObject())
members.push_back(importedType);
Expand Down Expand Up @@ -1555,23 +1549,7 @@ ImportedType ClangImporter::Implementation::importFunctionReturnType(
bool allowNSUIntegerAsInt) {

// Hardcode handling of certain result types for builtins.
auto builtinID = clangDecl->getBuiltinID();
switch (builtinID) {
case clang::Builtin::NotBuiltin:
break;
case clang::Builtin::BIstrxfrm:
case clang::Builtin::BIstrcspn:
case clang::Builtin::BIstrspn:
case clang::Builtin::BIstrlen:
case clang::Builtin::BIstrlcpy:
case clang::Builtin::BIstrlcat:
// This is a list of all built-ins with a result type of 'size_t' that
// existed in Swift 3. We didn't have special handling for builtins at
// that time, and so these had a result type of UInt.
if (SwiftContext.isSwiftVersion3())
break;
LLVM_FALLTHROUGH;
default:
if (auto builtinID = clangDecl->getBuiltinID()) {
switch (getClangASTContext().BuiltinInfo.getTypeString(builtinID)[0]) {
case 'z': // size_t
case 'Y': // ptrdiff_t
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/availability_open_enums.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -I %S/Inputs/custom-modules -swift-version 4 -enable-nonfrozen-enum-exhaustivity-diagnostics %s
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -I %S/Inputs/custom-modules -enable-nonfrozen-enum-exhaustivity-diagnostics %s

// REQUIRES: objc_interop

Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/clang_builtins.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: not %target-swift-frontend -swift-version 4 -typecheck %s 2>&1 | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-%target-runtime %s
// RUN: not %target-swift-frontend -typecheck %s 2>&1 | %FileCheck -check-prefix=CHECK -check-prefix=CHECK-%target-runtime %s

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
import Darwin
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/subclass_existentials.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -o - -primary-file %s -swift-version 4 -I %S/Inputs/custom-modules/
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -o - -primary-file %s -I %S/Inputs/custom-modules/

// REQUIRES: objc_interop

Expand Down