|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | + |
| 4 | +// Library module |
| 5 | + |
| 6 | +// SIL checking |
| 7 | +// RUN: %target-swift-frontend %t/Library.swift -parse-as-library -entry-point-function-name Library_main -enable-experimental-feature Embedded -emit-sil -emit-module-path %t/Modules/Library.swiftmodule -o - | %FileCheck -check-prefix LIBRARY-SIL %s |
| 8 | + |
| 9 | +// IR checking to ensure we get the right weak symbols. |
| 10 | +// RUN: %target-swift-frontend %t/Library.swift -parse-as-library -entry-point-function-name Library_main -enable-experimental-feature Embedded -emit-ir -o - | %FileCheck -check-prefix LIBRARY-IR --dump-input-filter all %s |
| 11 | + |
| 12 | +// Application module |
| 13 | + |
| 14 | +// RUN: %target-swift-frontend %t/Application.swift -I %t/Modules -parse-as-library -entry-point-function-name Application_main -enable-experimental-feature Embedded -emit-sil -o - | %FileCheck -check-prefix APPLICATION-SIL %s |
| 15 | + |
| 16 | +// RUN: %target-swift-frontend %t/Application.swift -I %t/Modules -parse-as-library -entry-point-function-name Application_main -enable-experimental-feature Embedded -emit-ir -o - | %FileCheck -check-prefix APPLICATION-IR %s |
| 17 | + |
| 18 | +// REQUIRES: swift_in_compiler |
| 19 | +// REQUIRES: swift_feature_Embedded |
| 20 | + |
| 21 | +//--- Library.swift |
| 22 | + |
| 23 | +// LIBRARY-IR: define {{(protected |dllexport )?}}swiftcc ptr @"$e7Library5helloSaySiGyF"() |
| 24 | +@_neverEmitIntoClient |
| 25 | +public func hello() -> [Int] { |
| 26 | + getArray() |
| 27 | +} |
| 28 | + |
| 29 | +// LIBRARY-IR: define {{(protected |dllexport )?}}swiftcc ptr @"$e7Library8getArraySaySiGyF"() |
| 30 | +public func getArray() -> [Int] { |
| 31 | + throughInternal() |
| 32 | +} |
| 33 | + |
| 34 | +// LIBRARY-IR: define {{(protected |dllexport )?}}swiftcc ptr @"$e7Library15throughInternalSaySiGyF"() |
| 35 | +func throughInternal() -> [Int] { |
| 36 | + throughPrivate() |
| 37 | +} |
| 38 | + |
| 39 | +// LIBRARY-IR: define {{(protected |dllexport )?}}swiftcc ptr @"$e7Library14throughPrivate |
| 40 | +private func throughPrivate() -> [Int] { |
| 41 | + [5, 6, 7] |
| 42 | +} |
| 43 | + |
| 44 | +// LIBRARY-IR-NOT: unnecessary |
| 45 | +public func unnecessary() -> Int { 5 } |
| 46 | + |
| 47 | +// LIBRARY-IR: define linkonce_odr hidden swiftcc { ptr, ptr } @"$es27_allocateUninitializedArrayySayxG_BptBwlFSi_Tg5" |
| 48 | + |
| 49 | +// LIBRARY-SIL: sil @$e7Library5helloSaySiGyF |
| 50 | +// LIBRARY-SIL: sil @$e7Library8getArraySaySiGyF : $@convention(thin) () -> @owned Array<Int> { |
| 51 | + |
| 52 | +//--- Application.swift |
| 53 | +import Library |
| 54 | + |
| 55 | +@_neverEmitIntoClient |
| 56 | +public func testMe() { |
| 57 | + _ = hello() |
| 58 | + _ = getArray() |
| 59 | +} |
| 60 | + |
| 61 | +// Note: "hello" is emitted only into the object file, so there is no definition |
| 62 | +// here. |
| 63 | + |
| 64 | +// APPLICATION-SIL: sil @$e7Library5helloSaySiGyF : $@convention(thin) () -> @owned Array<Int>{{$}} |
| 65 | +// APPLICATION-IR: declare swiftcc ptr @"$e7Library5helloSaySiGyF"() |
| 66 | + |
| 67 | +// Note: "getArray" is not @_neverEmitIntoClient, so it's definition is |
| 68 | +// available. |
| 69 | + |
| 70 | +// APPLICATION-SIL: sil public_external @$e7Library8getArraySaySiGyF : $@convention(thin) () -> @owned Array<Int> { |
| 71 | +// APPLICATION-IR: define linkonce_odr hidden swiftcc ptr @"$e7Library8getArraySaySiGyF"() |
| 72 | + |
| 73 | +// APPLICATION-IR: define{{.*}}@Application_main |
| 74 | +@main |
| 75 | +struct Main { |
| 76 | + static func main() { |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +// APPLICATION-IR: define linkonce_odr hidden swiftcc { ptr, ptr } @"$es27_allocateUninitializedArrayySayxG_BptBwlFSi_Tg5" |
| 81 | + |
0 commit comments