-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathmodule-alias-emit-sil.swift
90 lines (71 loc) · 3.46 KB
/
module-alias-emit-sil.swift
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
87
88
89
90
/// Test emit sil with module aliasing.
///
/// Module 'Lib' imports module 'XLogging', and 'XLogging' is aliased 'AppleLogging'.
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s
/// Create AppleLogging.swiftmodule by aliasing XLogging
// RUN: %target-swift-frontend -module-name AppleLogging -module-alias XLogging=AppleLogging %t/FileLogging.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule
// RUN: test -f %t/AppleLogging.swiftmodule
/// Verify generated SIL only contains AppleLogging
// RUN: %target-swift-frontend -Xllvm -sil-print-types -emit-sil %t/FileLib.swift -module-alias XLogging=AppleLogging -I %t > %t/result-sil.output
// RUN: %FileCheck %s -input-file %t/result-sil.output
// RUN: not %FileCheck %s -input-file %t/result-sil.output -check-prefix CHECK-NOT-FOUND
// CHECK-NOT-FOUND: XLogging
// CHECK: sil_stage canonical
// CHECK: import Builtin
// CHECK: import Swift
// CHECK: import SwiftShims
// CHECK: import AppleLogging
// CHECK: public struct MyLib : Loggable {
// CHECK: public var verbosity: Int { get }
// CHECK: init()
// CHECK: }
// CHECK: public func start() -> (any Loggable)?
// CHECK: public func end(_ arg: Logger)
// CHECK: // protocol witness for Loggable.verbosity.getter in conformance MyLib
// CHECK: sil shared [transparent] [thunk] @$s7FileLib02MyB0V12AppleLogging8LoggableAadEP9verbositySivgTW : $@convention(witness_method: Loggable) (@in_guaranteed MyLib) -> Int {
// CHECK: // %0 // user: %1
// CHECK: bb0(%0 : $*MyLib):
// CHECK: %1 = load %0 : $*MyLib // user: %3
// CHECK: // function_ref MyLib.verbosity.getter
// CHECK: %2 = function_ref @$s7FileLib02MyB0V9verbositySivg : $@convention(method) (MyLib) -> Int // user: %3
// CHECK: %3 = apply %2(%1) : $@convention(method) (MyLib) -> Int // user: %4
// CHECK: return %3 : $Int // id: %4
// CHECK: } // end sil function '$s7FileLib02MyB0V12AppleLogging8LoggableAadEP9verbositySivgTW'
// CHECK: // start()
// CHECK: sil @$s7FileLib5start12AppleLogging8Loggable_pSgyF : $@convention(thin) () -> @out Optional<any Loggable> {
// CHECK: // %0 "$return_value" // user: %2
// CHECK: bb0(%0 : $*Optional<any Loggable>):
// CHECK: // function_ref setup()
// CHECK: %1 = function_ref @$s12AppleLogging5setupAA8Loggable_pSgyF : $@convention(thin) () -> @out Optional<any Loggable> // user: %2
// CHECK: %2 = apply %1(%0) : $@convention(thin) () -> @out Optional<any Loggable>
// CHECK: %3 = tuple () // user: %4
// CHECK: return %3 : $() // id: %4
// CHECK: } // end sil function '$s7FileLib5start12AppleLogging8Loggable_pSgyF'
// CHECK: // setup()
// CHECK: sil @$s12AppleLogging5setupAA8Loggable_pSgyF : $@convention(thin) () -> @out Optional<any Loggable>
// CHECK: // end(_:)
// CHECK: sil @$s7FileLib3endyy12AppleLogging6LoggerVF : $@convention(thin) (Logger) -> () {
// CHECK: } // end sil function '$s7FileLib3endyy12AppleLogging6LoggerVF'
// BEGIN FileLogging.swift
public protocol Loggable {
var verbosity: Int { get }
}
public struct Logger {
public init() {}
}
public func setup() -> XLogging.Loggable? {
return nil
}
// BEGIN FileLib.swift
import XLogging
public struct MyLib: Loggable {
public var verbosity: Int {
return 3
}
}
public func start() -> XLogging.Loggable? {
return XLogging.setup()
}
public func end(_ arg: XLogging.Logger) {
}