|
| 1 | +/// Test emit sil with module aliasing. |
| 2 | +/// |
| 3 | +/// Module 'Lib' imports module 'XLogging', and 'XLogging' is aliased 'AppleLogging'. |
| 4 | + |
| 5 | +// RUN: %empty-directory(%t) |
| 6 | +// RUN: %{python} %utils/split_file.py -o %t %s |
| 7 | + |
| 8 | +/// Create AppleLogging.swiftmodule by aliasing XLogging |
| 9 | +// RUN: %target-swift-frontend -module-name AppleLogging -module-alias XLogging=AppleLogging %t/FileLogging.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule |
| 10 | +// RUN: test -f %t/AppleLogging.swiftmodule |
| 11 | + |
| 12 | +/// Verify generated SIL only contains AppleLogging |
| 13 | +// RUN: %target-swift-frontend -emit-sil %t/FileLib.swift -module-alias XLogging=AppleLogging -I %t > %t/result-sil.output |
| 14 | +// RUN: %FileCheck %s -input-file %t/result-sil.output |
| 15 | +// RUN: not %FileCheck %s -input-file %t/result-sil.output -check-prefix CHECK-NOT-FOUND |
| 16 | +// CHECK-NOT-FOUND: XLogging |
| 17 | + |
| 18 | + |
| 19 | +// CHECK: sil_stage canonical |
| 20 | + |
| 21 | +// CHECK: import Builtin |
| 22 | +// CHECK: import Swift |
| 23 | +// CHECK: import SwiftShims |
| 24 | + |
| 25 | +// CHECK: import AppleLogging |
| 26 | + |
| 27 | +// CHECK: public struct MyLib : Loggable { |
| 28 | +// CHECK: public var verbosity: Int { get } |
| 29 | +// CHECK: init() |
| 30 | +// CHECK: } |
| 31 | + |
| 32 | +// CHECK: public func start() -> Loggable? |
| 33 | + |
| 34 | +// CHECK: public func end(_ arg: Logger) |
| 35 | + |
| 36 | +// CHECK: // main |
| 37 | +// CHECK: sil @main : $@convention(c) (Int32, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>) -> Int32 { |
| 38 | +// CHECK: bb0(%0 : $Int32, %1 : $UnsafeMutablePointer<Optional<UnsafeMutablePointer<Int8>>>): |
| 39 | +// CHECK: %2 = integer_literal $Builtin.Int32, 0 // user: %3 |
| 40 | +// CHECK: %3 = struct $Int32 (%2 : $Builtin.Int32) // user: %4 |
| 41 | +// CHECK: return %3 : $Int32 // id: %4 |
| 42 | +// CHECK: // end sil function 'main' |
| 43 | + |
| 44 | +// CHECK: // MyLib.verbosity.getter |
| 45 | +// CHECK: sil @$s7FileLib02MyB0V9verbositySivg : $@convention(method) (MyLib) -> Int { |
| 46 | +// CHECK: // %0 "self" // user: %1 |
| 47 | +// CHECK: bb0(%0 : $MyLib): |
| 48 | +// CHECK: debug_value %0 : $MyLib, let, name "self", argno 1, implicit // id: %1 |
| 49 | +// CHECK: %2 = integer_literal $Builtin.Int64, 3 // user: %3 |
| 50 | +// CHECK: %3 = struct $Int (%2 : $Builtin.Int64) // user: %4 |
| 51 | +// CHECK: return %3 : $Int // id: %4 |
| 52 | +// CHECK: } // end sil function '$s7FileLib02MyB0V9verbositySivg' |
| 53 | + |
| 54 | +// CHECK: // Int.init(_builtinIntegerLiteral:) |
| 55 | +// CHECK: sil public_external [transparent] @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int { |
| 56 | +// CHECK: // %0 // user: %2 |
| 57 | +// CHECK: bb0(%0 : $Builtin.IntLiteral, %1 : $@thin Int.Type): |
| 58 | +// CHECK: %2 = builtin "s_to_s_checked_trunc_IntLiteral_Int64"(%0 : $Builtin.IntLiteral) : $(Builtin.Int64, Builtin.Int1) // user: %3 |
| 59 | +// CHECK: %3 = tuple_extract %2 : $(Builtin.Int64, Builtin.Int1), 0 // user: %4 |
| 60 | +// CHECK: %4 = struct $Int (%3 : $Builtin.Int64) // user: %5 |
| 61 | +// CHECK: return %4 : $Int // id: %5 |
| 62 | +// CHECK: } // end sil function '$sSi22_builtinIntegerLiteralSiBI_tcfC' |
| 63 | + |
| 64 | +// CHECK: // protocol witness for Loggable.verbosity.getter in conformance MyLib |
| 65 | +// CHECK: sil shared [transparent] [thunk] @$s7FileLib02MyB0V12AppleLogging8LoggableAadEP9verbositySivgTW : $@convention(witness_method: Loggable) (@in_guaranteed MyLib) -> Int { |
| 66 | +// CHECK: // %0 // user: %1 |
| 67 | +// CHECK: bb0(%0 : $*MyLib): |
| 68 | +// CHECK: %1 = load %0 : $*MyLib // user: %3 |
| 69 | +// CHECK: // function_ref MyLib.verbosity.getter |
| 70 | +// CHECK: %2 = function_ref @$s7FileLib02MyB0V9verbositySivg : $@convention(method) (MyLib) -> Int // user: %3 |
| 71 | +// CHECK: %3 = apply %2(%1) : $@convention(method) (MyLib) -> Int // user: %4 |
| 72 | +// CHECK: return %3 : $Int // id: %4 |
| 73 | +// CHECK: } // end sil function '$s7FileLib02MyB0V12AppleLogging8LoggableAadEP9verbositySivgTW' |
| 74 | + |
| 75 | +// CHECK: // start() |
| 76 | +// CHECK: sil @$s7FileLib5start12AppleLogging8Loggable_pSgyF : $@convention(thin) () -> @out Optional<Loggable> { |
| 77 | +// CHECK: // %0 "$return_value" // user: %2 |
| 78 | +// CHECK: bb0(%0 : $*Optional<Loggable>): |
| 79 | +// CHECK: // function_ref setup() |
| 80 | +// CHECK: %1 = function_ref @$s12AppleLogging5setupAA8Loggable_pSgyF : $@convention(thin) () -> @out Optional<Loggable> // user: %2 |
| 81 | +// CHECK: %2 = apply %1(%0) : $@convention(thin) () -> @out Optional<Loggable> |
| 82 | +// CHECK: %3 = tuple () // user: %4 |
| 83 | +// CHECK: return %3 : $() // id: %4 |
| 84 | +// CHECK: } // end sil function '$s7FileLib5start12AppleLogging8Loggable_pSgyF' |
| 85 | + |
| 86 | +// CHECK: // setup() |
| 87 | +// CHECK: sil @$s12AppleLogging5setupAA8Loggable_pSgyF : $@convention(thin) () -> @out Optional<Loggable> |
| 88 | + |
| 89 | +// CHECK: // end(_:) |
| 90 | +// CHECK: sil @$s7FileLib3endyy12AppleLogging6LoggerVF : $@convention(thin) (Logger) -> () { |
| 91 | +// CHECK: // %0 "arg" // user: %1 |
| 92 | +// CHECK: bb0(%0 : $Logger): |
| 93 | +// CHECK: debug_value %0 : $Logger, let, name "arg", argno 1 // id: %1 |
| 94 | +// CHECK: %2 = tuple () // user: %3 |
| 95 | +// CHECK: return %2 : $() // id: %3 |
| 96 | +// CHECK: } // end sil function '$s7FileLib3endyy12AppleLogging6LoggerVF' |
| 97 | + |
| 98 | +// CHECK: sil_witness_table MyLib: Loggable module FileLib { |
| 99 | +// CHECK: method #Loggable.verbosity!getter: <Self where Self : Loggable> (Self) -> () -> Int : @$s7FileLib02MyB0V12AppleLogging8LoggableAadEP9verbositySivgTW // protocol witness for Loggable.verbosity.getter in conformance MyLib |
| 100 | +// CHECK: } |
| 101 | + |
| 102 | +// CHECK: sil_property #MyLib.verbosity () |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +// BEGIN FileLogging.swift |
| 107 | +public protocol Loggable { |
| 108 | + var verbosity: Int { get } |
| 109 | +} |
| 110 | +public struct Logger { |
| 111 | + public init() {} |
| 112 | +} |
| 113 | +public func setup() -> XLogging.Loggable? { |
| 114 | + return nil |
| 115 | +} |
| 116 | + |
| 117 | +// BEGIN FileLib.swift |
| 118 | +import XLogging |
| 119 | + |
| 120 | +public struct MyLib: Loggable { |
| 121 | + public var verbosity: Int { |
| 122 | + return 3 |
| 123 | + } |
| 124 | +} |
| 125 | +public func start() -> XLogging.Loggable? { |
| 126 | + return XLogging.setup() |
| 127 | +} |
| 128 | + |
| 129 | +public func end(_ arg: XLogging.Logger) { |
| 130 | +} |
0 commit comments