File: module-recovery-remarks.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (86 lines) | stat: -rw-r--r-- 4,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/sdk)
// RUN: split-file %s %t

/// Compile two library modules A and A_related, and a middle library LibWithXRef with a reference to a type in A.
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/A.swiftmodule -module-name A -I %t
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related
// RUN: %target-swift-frontend %t/LibWithXRef.swift -emit-module-path %t/sdk/LibWithXRef.swiftmodule -module-name LibWithXRef -I %t -swift-version 5 -enable-library-evolution

/// Move MyType from A to A_related, triggering most notes.
// RUN: %target-swift-frontend %t/EmptyOverlay.swift -emit-module-path %t/A.swiftmodule -module-name A -I %t
// RUN: %target-swift-frontend %t/LibOriginal.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related -I %t
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk -swift-version 4 2>&1 \
// RUN:   | %FileCheck --check-prefixes CHECK-MOVED %s

/// Main error downgraded to a remark.
// CHECK-MOVED: 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'

/// Contextual notes about the modules involved.
// CHECK-MOVED: note: the type was expected to be found in module 'A' at '
// CHECK-MOVED-SAME: A.swiftmodule'
// CHECK-MOVED: note: or expected to be found in the underlying module 'A' defined at '
// CHECK-MOVED-SAME: module.modulemap'
// CHECK-MOVED: note: the type was actually found in module 'A_related' at '
// CHECK-MOVED-SAME: A_related.swiftmodule'

/// More notes depending on the context
// CHECK-MOVED: note: the module 'LibWithXRef' was built with a Swift language version set to 5
// CHECK-MOVED-SAME: while the current invocation uses 4

// CHECK-MOVED: note: the module 'LibWithXRef' has enabled library-evolution; the following file may need to be deleted if the SDK was modified: '
// CHECK-MOVED-SAME: LibWithXRef.swiftmodule'
// CHECK-MOVED: note: declarations in the underlying clang module 'A' may be hidden by clang preprocessor macros
// CHECK-MOVED: note: the distributed module 'LibWithXRef' refers to the local module 'A'; this may be caused by header maps or search paths
// CHECK-MOVED: note: the type 'MyType' moved between related modules; clang preprocessor macros may affect headers shared between these modules
// CHECK-MOVED: note: could not deserialize type for 'foo()'
// CHECK-MOVED: error: cannot find 'foo' in scope

/// Move A to the SDK, triggering a different note about layering.
// RUN: mv %t/A.swiftmodule %t/sdk/A.swiftmodule
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk 2>&1 \
// RUN:   | %FileCheck --check-prefixes CHECK-LAYERING-FOUND %s
// CHECK-LAYERING-FOUND: note: the reference may break layering; the candidate was found in the local module 'A_related' for a reference from the distributed module 'LibWithXRef'
// CHECK-LAYERING-FOUND: error: cannot find 'foo' in scope

/// Delete A, keep only the underlying clangmodule for notes about clang modules.
// RUN: rm %t/sdk/A.swiftmodule
// RUN: %target-swift-frontend %t/Empty.swift -emit-module-path %t/A_related.swiftmodule -module-name A_related
// RUN: not %target-swift-frontend -c -O %t/Client.swift -I %t -I %t/sdk -Rmodule-recovery -sdk %t/sdk 2>&1 \
// RUN:   | %FileCheck --check-prefixes CHECK-CLANG %s
// CHECK-CLANG: note: declarations in the clang module 'A' may be hidden by clang preprocessor macros
// CHECK-CLANG: error: cannot find 'foo' in scope


//--- module.modulemap
module A {
    header "A.h"
}

//--- A.h
void foo() {}

//--- Empty.swift

//--- EmptyOverlay.swift
@_exported import A

//--- LibOriginal.swift
@_exported import A

public struct MyType {
    public init() {}
}

//--- LibWithXRef.swift
import A
import A_related

public func foo() -> MyType {
    fatalError()
}

//--- Client.swift
import LibWithXRef

foo()