From 93958ed76ba94a2bf97a1ed1dea22c13a30b2387 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 21 Apr 2020 17:59:33 -0700 Subject: [PATCH 1/3] [NFC] Add test case for old arm64e fallback behavior. --- .../arm64-apple-ios.swiftinterface | 4 ++++ .../Modules/DummyFramework.swiftmodule/arm64.swiftinterface | 4 ++++ test/ModuleInterface/arm64e-fallback.swift | 5 +++++ 3 files changed, 13 insertions(+) create mode 100644 test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64-apple-ios.swiftinterface create mode 100644 test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64.swiftinterface create mode 100644 test/ModuleInterface/arm64e-fallback.swift diff --git a/test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64-apple-ios.swiftinterface b/test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64-apple-ios.swiftinterface new file mode 100644 index 0000000000000..cf71c2f1a1e21 --- /dev/null +++ b/test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64-apple-ios.swiftinterface @@ -0,0 +1,4 @@ +// swift-interface-format-version: 1.0 +// swift-compiler-version: Apple Swift version 5.2 +// swift-module-flags: -target arm64-apple-ios13.0 -enable-library-evolution -swift-version 5 -module-name DummyFramework +import Swift diff --git a/test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64.swiftinterface b/test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64.swiftinterface new file mode 100644 index 0000000000000..cf71c2f1a1e21 --- /dev/null +++ b/test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64.swiftinterface @@ -0,0 +1,4 @@ +// swift-interface-format-version: 1.0 +// swift-compiler-version: Apple Swift version 5.2 +// swift-module-flags: -target arm64-apple-ios13.0 -enable-library-evolution -swift-version 5 -module-name DummyFramework +import Swift diff --git a/test/ModuleInterface/arm64e-fallback.swift b/test/ModuleInterface/arm64e-fallback.swift new file mode 100644 index 0000000000000..3e7df2d4b1503 --- /dev/null +++ b/test/ModuleInterface/arm64e-fallback.swift @@ -0,0 +1,5 @@ +// RUN: %target-typecheck-verify-swift %s -target arm64e-apple-ios13.0 -F %S/Inputs + +// REQUIRES: OS=ios + +import DummyFramework From c4134ca45228c40e740fdbca27119d60b4779098 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 21 Apr 2020 18:08:29 -0700 Subject: [PATCH 2/3] [ModuleInterface] Remove fallback behavior for arm64e -> arm64. Addresses rdar://problem/61407215. --- lib/Serialization/SerializedModuleLoader.cpp | 6 +----- test/ModuleInterface/arm64e-fallback.swift | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/Serialization/SerializedModuleLoader.cpp b/lib/Serialization/SerializedModuleLoader.cpp index 59e2d019faa1c..50b923f94a2c5 100644 --- a/lib/Serialization/SerializedModuleLoader.cpp +++ b/lib/Serialization/SerializedModuleLoader.cpp @@ -49,14 +49,10 @@ void forEachTargetModuleBasename(const ASTContext &Ctx, // names checked in "#if arch(...)". Fall back to that name in the one case // where it's different from what Swift 4.2 supported: // - 32-bit ARM platforms (formerly "arm") - // - arm64e (formerly shared with "arm64") // We should be able to drop this once there's an Xcode that supports the // new names. - if (Ctx.LangOpts.Target.getArch() == llvm::Triple::ArchType::arm) + if (Ctx.LangOpts.Target.getArch() == llvm::Triple::ArchType::arm) { body("arm"); - else if (Ctx.LangOpts.Target.getSubArch() == - llvm::Triple::SubArchType::AArch64SubArch_E) { - body("arm64"); } } diff --git a/test/ModuleInterface/arm64e-fallback.swift b/test/ModuleInterface/arm64e-fallback.swift index 3e7df2d4b1503..5085c278124b6 100644 --- a/test/ModuleInterface/arm64e-fallback.swift +++ b/test/ModuleInterface/arm64e-fallback.swift @@ -1,5 +1,6 @@ -// RUN: %target-typecheck-verify-swift %s -target arm64e-apple-ios13.0 -F %S/Inputs +// RUN: not %target-typecheck-verify-swift -target arm64e-apple-ios13.0 -F %S/Inputs 2>&1 | %FileCheck %s // REQUIRES: OS=ios import DummyFramework +// CHECK: no such module 'DummyFramework' From 412ee0a922f701e7b8eede2c65785e9408424ce5 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Tue, 21 Apr 2020 20:18:03 -0700 Subject: [PATCH 3/3] [ModuleLoader] Emit a better diagnostic for swiftinterfaces with wrong arch. Before this change, we would emit the warning only for swiftmodules; however, it may be the case that only a swiftinterface (of a different arch) is present but no swiftmodule is present. Fixes rdar://problem/50905075. --- lib/Serialization/SerializedModuleLoader.cpp | 10 +++++++--- .../force-module-loading-mode-archs.swift | 12 ++++++------ .../force-module-loading-mode-framework.swift | 12 ++++++------ test/ModuleInterface/arm64e-fallback.swift | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/Serialization/SerializedModuleLoader.cpp b/lib/Serialization/SerializedModuleLoader.cpp index 50b923f94a2c5..032b1f8c56623 100644 --- a/lib/Serialization/SerializedModuleLoader.cpp +++ b/lib/Serialization/SerializedModuleLoader.cpp @@ -405,8 +405,12 @@ bool SerializedModuleLoader::maybeDiagnoseTargetMismatch( return false; StringRef filePath = directoryIterator->path(); StringRef extension = llvm::sys::path::extension(filePath); - if (file_types::lookupTypeForExtension(extension) == - file_types::TY_SwiftModuleFile) { + auto fileType = file_types::lookupTypeForExtension(extension); + // We also check for interfaces here, because the SerializedModuleLoader + // is invoked after the ModuleInterfaceLoader; if the ModuleInterfaceLoader + // handled interfaces separately, we could get duplicate diagnostics. + if (fileType == file_types::TY_SwiftModuleFile + || fileType == file_types::TY_SwiftModuleInterfaceFile) { if (!foundArchs.empty()) foundArchs += ", "; foundArchs += llvm::sys::path::stem(filePath).str(); @@ -414,7 +418,7 @@ bool SerializedModuleLoader::maybeDiagnoseTargetMismatch( } if (foundArchs.empty()) { - // Maybe this swiftmodule directory only contains swiftinterfaces, or + // It is strange that there were no swiftmodules or swiftinterfaces here; // maybe something else is going on. Regardless, we shouldn't emit a // possibly incorrect diagnostic. return false; diff --git a/test/ModuleInterface/ModuleCache/force-module-loading-mode-archs.swift b/test/ModuleInterface/ModuleCache/force-module-loading-mode-archs.swift index 280b1a82aa273..34c87a5841a16 100644 --- a/test/ModuleInterface/ModuleCache/force-module-loading-mode-archs.swift +++ b/test/ModuleInterface/ModuleCache/force-module-loading-mode-archs.swift @@ -14,7 +14,7 @@ // RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s // RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s // RUN: env SWIFT_FORCE_MODULE_LOADING=only-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s -// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH-2 -DARCH=%module-target-triple -DTARGET_CPU=%target-cpu %s // (default) // RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -I %t %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s @@ -82,19 +82,19 @@ // 8. Only the interface is present but for the wrong architecture. // (Diagnostics for the module only are tested elsewhere.) -// FIXME: We should improve this to not just say NO-SUCH-MODULE. // RUN: rm %t/Lib.swiftmodule/garbage.swiftmodule -// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s -// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // RUN: env SWIFT_FORCE_MODULE_LOADING=only-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s -// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // (default) -// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -I %t %s 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -I %t %s 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s import Lib // NO-SUCH-MODULE: [[@LINE-1]]:8: error: no such module 'Lib' // BAD-MODULE: [[@LINE-2]]:8: error: malformed compiled module: {{.*}}Lib.swiftmodule // WRONG-ARCH: [[@LINE-3]]:8: error: could not find module 'Lib' for target '[[ARCH]]'; found: garbage +// WRONG-ARCH-2: [[@LINE-4]]:8: error: could not find module 'Lib' for target '[[ARCH]]'; found: [[TARGET_CPU]] struct X {} let _: X = Lib.testValue diff --git a/test/ModuleInterface/ModuleCache/force-module-loading-mode-framework.swift b/test/ModuleInterface/ModuleCache/force-module-loading-mode-framework.swift index cd2a43d5f7fec..4722b6dfb3cfb 100644 --- a/test/ModuleInterface/ModuleCache/force-module-loading-mode-framework.swift +++ b/test/ModuleInterface/ModuleCache/force-module-loading-mode-framework.swift @@ -14,7 +14,7 @@ // RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s // RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s // RUN: env SWIFT_FORCE_MODULE_LOADING=only-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s -// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH-2 -DARCH=%module-target-triple -DTARGET_CPU=%target-cpu %s // (default) // RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -F %t %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s @@ -83,19 +83,19 @@ // 8. Only the interface is present but for the wrong architecture. // (Diagnostics for the module only are tested elsewhere.) -// FIXME: We should improve this to not just say NO-SUCH-MODULE. // RUN: rm %t/Lib.framework/Modules/Lib.swiftmodule/garbage.swiftmodule -// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s -// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=prefer-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // RUN: env SWIFT_FORCE_MODULE_LOADING=only-parseable not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s -// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: env SWIFT_FORCE_MODULE_LOADING=only-serialized not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // (default) -// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -F %t %s 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s +// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -F %t %s 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s import Lib // NO-SUCH-MODULE: [[@LINE-1]]:8: error: no such module 'Lib' // BAD-MODULE: [[@LINE-2]]:8: error: malformed compiled module: {{.*}}Lib.swiftmodule // WRONG-ARCH: [[@LINE-3]]:8: error: could not find module 'Lib' for target '[[ARCH]]'; found: garbage +// WRONG-ARCH-2: [[@LINE-4]]:8: error: could not find module 'Lib' for target '[[ARCH]]'; found: [[TARGET_CPU]] struct X {} let _: X = Lib.testValue diff --git a/test/ModuleInterface/arm64e-fallback.swift b/test/ModuleInterface/arm64e-fallback.swift index 5085c278124b6..d60ccb5e6898c 100644 --- a/test/ModuleInterface/arm64e-fallback.swift +++ b/test/ModuleInterface/arm64e-fallback.swift @@ -3,4 +3,4 @@ // REQUIRES: OS=ios import DummyFramework -// CHECK: no such module 'DummyFramework' +// CHECK: could not find module 'DummyFramework' for target 'arm64e-apple-ios'; found: arm64-apple-ios, arm64