mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Make sure we flush the diagnostics consumers to prevent the new diagnostic style to buffer the deserialization errors without printing them. These errors may be printed right before an `abort()`, which would bypass the actual printing of the errors. Take advantage of the new style to make these diagnostics more readable as well. ``` .../LibWithXRef.swiftmodule:1:1: remark: reference to type 'MyType' broken by a context change; 'MyType' was expected to be in 'A', but now a candidate is found only in 'A_related' 1 │ A.MyType │ ├─ remark: reference to type 'MyType' broken by a context change; 'MyType' was expected to be in 'A', but now a candidate is found only in 'A_related' │ ├─ note: the type was expected to be found in module 'A' at ‘.../A.swiftmodule' │ ├─ note: or expected to be found in the underlying module 'A' defined at ‘.../module.modulemap' │ ├─ note: the type was actually found in module 'A_related' at ‘.../A_related.swiftmodule' │ ├─ note: the module 'LibWithXRef' was built with a Swift language version set to 5.10 while the current invocation uses 4.1.50; APINotes may change how clang declarations are imported │ ├─ note: the module 'LibWithXRef' has enabled library-evolution; the following file may need to be deleted if the SDK was modified: ‘.../LibWithXRef.swiftmodule' │ ├─ note: declarations in the underlying clang module 'A' may be hidden by clang preprocessor macros │ ├─ note: the distributed module 'LibWithXRef' refers to the local module 'A'; this may be caused by header maps or search paths │ ╰─ note: the type 'MyType' moved between related modules; clang preprocessor macros may affect headers shared between these modules .../LibWithXRef.swiftmodule:1:1: note: could not deserialize type for 'foo()' 1 │ A.MyType │ ╰─ note: could not deserialize type for 'foo()' ``` rdar://124700605
73 lines
4.4 KiB
Swift
73 lines
4.4 KiB
Swift
/// Simulate typical modularization issues using Swift modules.
|
|
// RUN: %empty-directory(%t)
|
|
// RUN: split-file %s %t
|
|
|
|
/// Compile two library modules A and B, and a client.
|
|
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/A.swiftmodule -module-name A
|
|
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/B.swiftmodule -module-name B
|
|
// RUN: %target-swift-frontend %t/LibWithXRef.swift -emit-module-path %t/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t
|
|
|
|
/// Move MyType from A to B.
|
|
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A.swiftmodule -module-name A
|
|
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/B.swiftmodule -module-name B
|
|
// RUN: not %target-swift-frontend -emit-sil %t/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t -diagnostic-style llvm 2>&1 \
|
|
// RUN: | %FileCheck --check-prefixes CHECK,CHECK-MOVED %s
|
|
// CHECK-MOVED: LibWithXRef.swiftmodule:1:1: error: reference to type 'MyType' broken by a context change; 'MyType' was expected to be in 'A', but now a candidate is found only in 'B'
|
|
|
|
/// Force working around the broken modularization to get a result and no errors.
|
|
// RUN: %target-swift-frontend -emit-sil %t/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t \
|
|
// RUN: -experimental-force-workaround-broken-modules -diagnostic-style llvm 2>&1 \
|
|
// RUN: | %FileCheck --check-prefixes CHECK-WORKAROUND %s
|
|
// CHECK-WORKAROUND: LibWithXRef.swiftmodule:1:1: warning: reference to type 'MyType' broken by a context change; 'MyType' was expected to be in 'A', but now a candidate is found only in 'B'
|
|
// CHECK-WORKAROUND-NEXT: A.MyType
|
|
// CHECK-WORKAROUND-NEXT: ^
|
|
// CHECK-WORKAROUND: note: the type was expected to be found in module 'A' at '
|
|
// CHECK-WORKAROUND-SAME: A.swiftmodule'
|
|
// CHECK-WORKAROUND: note: the type was actually found in module 'B' at '
|
|
// CHECK-WORKAROUND-SAME: B.swiftmodule'
|
|
// CHECK-WORKAROUND: note: attempting forced recovery enabled by -experimental-force-workaround-broken-modules
|
|
// CHECK-WORKAROUND: func foo() -> some Proto
|
|
|
|
/// Change MyType into a function.
|
|
// RUN: %target-swift-frontend %t/LibTypeChanged.swift -emit-module-path %t/A.swiftmodule -module-name A
|
|
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/B.swiftmodule -module-name B
|
|
// RUN: not %target-swift-frontend -emit-sil %t/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t -diagnostic-style llvm 2>&1 \
|
|
// RUN: | %FileCheck --check-prefixes CHECK,CHECK-KIND-CHANGED %s
|
|
// CHECK-KIND-CHANGED: LibWithXRef.swiftmodule:1:1: error: reference to type 'MyType' broken by a context change; the declaration kind of 'MyType' from 'A' changed since building 'LibWithXRef'
|
|
|
|
/// Change MyType into a function and move it.
|
|
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A.swiftmodule -module-name A
|
|
// RUN: %target-swift-frontend %t/LibTypeChanged.swift -emit-module-path %t/B.swiftmodule -module-name B
|
|
// RUN: not %target-swift-frontend -emit-sil %t/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t -diagnostic-style llvm 2>&1 \
|
|
// RUN: | %FileCheck --check-prefixes CHECK,CHECK-KIND-CHANGED-AND-MOVED %s
|
|
// CHECK-KIND-CHANGED-AND-MOVED: LibWithXRef.swiftmodule:1:1: error: reference to type 'MyType' broken by a context change; the declaration kind of 'MyType' changed since building 'LibWithXRef', it was in 'A' and now a candidate is found only in 'B'
|
|
|
|
/// Remove MyType from all imported modules.
|
|
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A.swiftmodule -module-name A
|
|
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/B.swiftmodule -module-name B
|
|
// RUN: not %target-swift-frontend -emit-sil %t/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t -diagnostic-style llvm 2>&1 \
|
|
// RUN: | %FileCheck --check-prefixes CHECK,CHECK-NOT-FOUND %s
|
|
// CHECK-NOT-FOUND: LibWithXRef.swiftmodule:1:1: error: reference to type 'MyType' broken by a context change; 'MyType' is not found, it was expected to be in 'A'
|
|
|
|
// CHECK: LibWithXRef.swiftmodule:1:1: note: could not deserialize extension
|
|
|
|
//--- Empty.swift
|
|
//--- LibOriginal.swift
|
|
public struct MyType {
|
|
public init() {}
|
|
}
|
|
|
|
//--- LibTypeChanged.swift
|
|
/// Make it a function to fail filtering.
|
|
public func MyType() {}
|
|
|
|
//--- LibWithXRef.swift
|
|
import A
|
|
import B
|
|
|
|
public protocol Proto {}
|
|
extension MyType : Proto {}
|
|
|
|
@available(SwiftStdlib 5.1, *)
|
|
public func foo() -> some Proto { return MyType() }
|