Skip to content

Commit 82a0549

Browse files
committed
[Pacage CMO] Update and add more tests
1 parent d3c6688 commit 82a0549

7 files changed

+355
-232
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -o %t/IR-nonres.ir
4+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -enable-library-evolution -o %t/IR-res.ir
5+
// RUN: %target-build-swift -module-name=File -package-name Pkg -I%t -emit-ir %s -enable-library-evolution -wmo -Xfrontend -experimental-allow-non-resilient-access -Xfrontend -experimental-package-cmo -o %t/IR-res-package-cmo.ir
6+
7+
// RUN: %FileCheck %s --check-prefix=CHECK-IR-NONRES < %t/IR-nonres.ir
8+
// RUN: %FileCheck %s --check-prefix=CHECK-IR-RES < %t/IR-res.ir
9+
// RUN: %FileCheck %s --check-prefix=CHECK-IR-RES < %t/IR-res-package-cmo.ir
10+
11+
public struct S {
12+
public static let x = "hello world"
13+
package static let y = "dogs cats"
14+
}
15+
16+
public struct R {
17+
package static let a = "foo"
18+
public static let b = "bar"
19+
}
20+
21+
// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1SV1xSSvau"()
22+
// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1SV1ySSvau"()
23+
// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1RV1aSSvau"()
24+
// CHECK-IR-NONRES: define{{( dllexport)?}}{{( protected)?}} swiftcc ptr @"$s4File1RV1bSSvau"()
25+
26+
// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1SV1xSSvau"()
27+
// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1SV1ySSvau"()
28+
// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1RV1aSSvau"()
29+
// CHECK-IR-RES: define hidden swiftcc ptr @"$s4File1RV1bSSvau"()
30+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-silgen %s -enable-library-evolution -wmo -o %t/Lib-no-pcmo-silgen.sil
4+
5+
// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-sil %s -enable-library-evolution -wmo -o %t/Lib-no-pcmo-sil.sil
6+
7+
// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-ir %s -enable-library-evolution -wmo -o %t/Lib-no-pcmo-ir.ll -emit-tbd-path %t/Lib-no-pcmo-tbd.tbd -tbd-install_name Lib
8+
9+
// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-silgen %s -enable-library-evolution -wmo -allow-non-resilient-access -package-cmo -o %t/Lib-silgen.sil
10+
11+
// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-sil %s -enable-library-evolution -wmo -allow-non-resilient-access -package-cmo -o %t/Lib-sil.sil
12+
13+
// RUN: %target-swift-frontend -module-name=Lib -package-name libpkg -emit-ir %s -enable-library-evolution -wmo -allow-non-resilient-access -package-cmo -o %t/Lib-ir.ll -emit-tbd-path %t/Lib-tbd.tbd -tbd-install_name Lib
14+
15+
// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-SILGEN < %t/Lib-no-pcmo-silgen.sil
16+
// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-SIL < %t/Lib-no-pcmo-sil.sil
17+
// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-IR < %t/Lib-no-pcmo-ir.ll
18+
// RUN: %FileCheck %s --check-prefix=CHECK-NO-PCMO-TBD < %t/Lib-no-pcmo-tbd.tbd
19+
// RUN: %FileCheck %s --check-prefix=CHECK-SILGEN < %t/Lib-silgen.sil
20+
// RUN: %FileCheck %s --check-prefix=CHECK-SIL < %t/Lib-sil.sil
21+
// RUN: %FileCheck %s --check-prefix=CHECK-IR < %t/Lib-ir.ll
22+
// RUN: %FileCheck %s --check-prefix=CHECK-TBD < %t/Lib-tbd.tbd
23+
24+
25+
/// TEST that a public (or package) protocol witness thunk gets a shared linkage if Package CMO is enabled.
26+
/// It also gets [serialized] in emit-silgen.
27+
///
28+
// protocol witness for Proto.foo.getter in conformance Pub
29+
30+
// CHECK-NO-PCMO-SILGEN-DAG: sil private [transparent] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {
31+
// CHECK-SILGEN-DAG: sil shared [transparent] [serialized] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {
32+
33+
// CHECK-NO-PCMO-SIL-DAG: sil private [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {
34+
// CHECK-SIL-DAG: sil shared [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW : $@convention(witness_method: Proto) (@in_guaranteed Pub) -> @owned String {
35+
36+
// CHECK-NO-PCMO-IR-DAG: define internal swiftcc { {{i64|i32}}, ptr } @"$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW"
37+
// CHECK-IR-DAG: define linkonce_odr hidden swiftcc { {{i64|i32}}, ptr } @"$s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW"
38+
39+
// protocol witness for Proto.bar(_:) in conformance Pub
40+
41+
// CHECK-NO-PCMO-SILGEN-DAG: sil private [transparent] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {
42+
// CHECK-SILGEN-DAG: sil shared [transparent] [serialized] [thunk] [ossa] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {
43+
44+
// CHECK-NO-PCMO-SIL-DAG: sil private [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {
45+
// CHECK-SIL-DAG: sil shared [transparent] [thunk] @$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW : $@convention(witness_method: Proto) (Int, @in_guaranteed Pub) -> Int {
46+
47+
// CHECK-NO-PCMO-IR-DAG: define internal swiftcc {{i64|i32}} @"$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW"
48+
// CHECK-IR-DAG: define linkonce_odr hidden swiftcc i64 @"$s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW"
49+
50+
// CHECK-NO-PCMO-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW
51+
// CHECK-NO-PCMO-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW
52+
// CHECK-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3fooSSvgTW
53+
// CHECK-TBD-NOT: s3Lib3PubVAA5ProtoA2aDP3baryS2iFTW
54+
55+
public protocol Proto {
56+
var foo: String { get set }
57+
func bar(_ arg: Int) -> Int
58+
}
59+
60+
public struct Pub: Proto {
61+
public var foo = "foo"
62+
public func bar(_ arg: Int) -> Int {
63+
return arg
64+
}
65+
}

test/IRGen/package_global_accessor.swift

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/SILOptimizer/package-cmo-deserialize-for-external-client.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@
2020
/// Test 1: They should be deserialized into Client as Lib and Client are in the same package.
2121
// RUN: %FileCheck -check-prefix=CHECK-INPKG %s < %t/InPkgClient.sil
2222

23-
// Pub.init(_:) is removed after getting lined below.
24-
// CHECK-INPKG-NOT: @$s3Lib3PubCyACSicfc
25-
2623
// Pub.__allocating_init(_:)
2724
// CHECK-INPKG: sil public_external @$s3Lib3PubCyACSicfC : $@convention(method) (Int, @thick Pub.Type) -> @owned Pub {
28-
// Pub.init(_:) is inlined in this block, as its body was deserialized.
29-
// CHECK-INPKG: ref_element_addr {{.*}} : $Pub, #Pub.pubVar
25+
// CHECK-INPKG: function_ref @$s3Lib3PubCyACSicfc
26+
27+
// Pub.init(_:)
28+
// CHECK-INPKG: sil @$s3Lib3PubCyACSicfc : $@convention(method) (Int, @owned Pub) -> @owned Pub
3029

3130
// CHECK-INPKG: sil_vtable Pub {
3231
// CHECK-INPKG: #Pub.pubVar!getter: (Pub) -> () -> Int : @$s3Lib3PubC6pubVarSivg // Pub.pubVar.getter
@@ -72,11 +71,6 @@
7271

7372
// CHECK-LIB: sil [serialized] [exact_self_class] [canonical] @$s3Lib3PubCyACSicfC : $@convention(method) (Int, @thick Pub.Type) -> @owned Pub {
7473
// CHECK-LIB: function_ref @$s3Lib3PubCyACSicfc : $@convention(method) (Int, @owned Pub) -> @owned Pub
75-
// Pub.init(_:)
76-
77-
// CHECK-LIB: sil [serialized_for_package] [canonical] @$s3Lib3PubCyACSicfc : $@convention(method) (Int, @owned Pub) -> @owned Pub {
78-
// CHECK-LIB: ref_element_addr {{.*}} : $Pub, #Pub.pubVar
79-
// Pub.__allocating_init(_:)
8074

8175
// Pub.pkgVar.getter
8276
// CHECK-LIB: sil package [serialized_for_package] [canonical] @$s3Lib3PubC6pkgVarSivg : $@convention(method) (@guaranteed Pub) -> Int {
@@ -106,21 +100,35 @@ public protocol PubProto {
106100
public class Pub: PubProto {
107101
public var pubVar: Int = 1
108102
package var pkgVar: Int = 2
103+
var internalVar: Int = 3
109104
public init(_ arg: Int) {
110105
pubVar = arg
111106
pkgVar = arg
112107
}
108+
public func pubFunc(_ arg: Pub) {
109+
print(arg.pubVar)
110+
}
111+
}
112+
113+
public class SubPub: Pub {
114+
override public func pubFunc(_ arg: Pub) {
115+
print(arg.pubVar, arg.internalVar)
116+
}
113117
}
114118

115119
//--- Client.swift
116120
import Lib
117121

118-
public func test(_ arg: Int) -> Int {
122+
public func test1(_ arg: Int) -> Int {
119123
let x = Pub(arg)
120124
x.pubVar = 3
121125
return x.run()
122126
}
123127

128+
public func test2(_ arg: Int) {
129+
SubPub(arg).pubFunc(Pub(arg))
130+
}
131+
124132
public extension PubProto {
125133
func run() -> Int {
126134
return pubVar
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// RUN: %target-swift-frontend %s \
4+
// RUN: -emit-sil -module-name=Lib -package-name Pkg \
5+
// RUN: -package-cmo -allow-non-resilient-access \
6+
// RUN: -O -wmo -enable-library-evolution \
7+
// RUN: -Xllvm -sil-print-function=s3Lib3fooyS2iF 2>&1 | %FileCheck %s
8+
9+
/// TEST that accessing PkgStruct in the following functions gets inlined after perf inlining pass.
10+
public func bar(_ arg: Int) -> Int {
11+
let p = PkgStruct(1, 2)
12+
return arg > 0 ? p.field1 : p.field2
13+
}
14+
15+
package func foo(_ arg: Int) -> Int {
16+
let p = PkgStruct(1, 2)
17+
return arg > 0 ? p.field1 : p.field2
18+
}
19+
20+
package struct PkgStruct {
21+
package let field1: Int
22+
package let field2: Int
23+
package init(_ arg1: Int, _ arg2: Int) {
24+
field1 = arg1
25+
field2 = arg2
26+
}
27+
}
28+
29+
/// BEFORE perf inlining pass.
30+
// CHECK: sil package @$s3Lib3fooyS2iF : $@convention(thin) (Int) -> Int {
31+
// CHECK: [[PKG_STACK:%.*]] = alloc_stack $PkgStruct
32+
// CHECK: [[FUNC_REF:%.*]] = function_ref @$s3Lib9PkgStructVyACSi_SitcfC : $@convention(method) (Int, Int, @thin PkgStruct.Type) -> @out PkgStruct
33+
// CHECK: apply [[FUNC_REF]]
34+
// CHECK: [[F1:%.*]] = struct_element_addr [[PKG_STACK]] : $*PkgStruct, #PkgStruct.field1
35+
// CHECK: load [[F1]] : $*Int
36+
// CHECK: [[F2:%.*]] = struct_element_addr [[PKG_STACK]] : $*PkgStruct, #PkgStruct.field2
37+
// CHECK: load [[F2]] : $*Int
38+
39+
/// AFTER perf inlining pass; body of `@$s3Lib9PkgStructVyACSi_SitcfC` gets inlined.
40+
// CHECK: *** SIL function after {{.*}} EarlyPerfInliner (early-inline)
41+
// CHECK: sil package @$s3Lib3fooyS2iF : $@convention(thin) (Int) -> Int {
42+
// CHECK: [[PKG_ALLOC:%.*]] = alloc_stack $PkgStruct
43+
// CHECK: [[PKG_INIT:%.*]] = alloc_stack [var_decl] $PkgStruct, var, name "self"
44+
// CHECK: [[FIELD1_IVAR:%.*]] = struct_element_addr [[PKG_INIT]] : $*PkgStruct, #PkgStruct.field1
45+
// CHECK: store {{.*}} to [[FIELD1_IVAR]] : $*Int
46+
// CHECK: [[FIELD2_IVAR:%.*]] = struct_element_addr [[PKG_INIT]] : $*PkgStruct, #PkgStruct.field2
47+
// CHECK: store {{.*}} to [[FIELD2_IVAR]] : $*Int
48+
// CHECK: [[PKG_STR:%.*]] = struct $PkgStruct
49+
// CHECK: store [[PKG_STR]] to [[PKG_ALLOC]] : $*PkgStruct
50+
// CHECK: [[FIELD1:%.*]] = struct_element_addr [[PKG_ALLOC]] : $*PkgStruct, #PkgStruct.field1
51+
// CHECK: load [[FIELD1]] : $*Int
52+
// CHECK: [[FIELD2:%.*]] = struct_element_addr [[PKG_ALLOC]] : $*PkgStruct, #PkgStruct.field2
53+
// CHECK: load [[FIELD2]] : $*Int

0 commit comments

Comments
 (0)