Skip to content

Commit 777969a

Browse files
Add test suites for module summary serialization
1 parent 42bd8bb commit 777969a

File tree

5 files changed

+183
-0
lines changed

5 files changed

+183
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-sib -emit-module-summary-path %t/empty.swiftmodulesummary -module-name empty %s
3+
// RUN: llvm-bcanalyzer -dump %t/empty.swiftmodulesummary | %FileCheck %s -check-prefix BCANALYZER
4+
5+
// BCANALYZER-NOT: UnknownCode
6+
7+
// RUN: %swift-module-summary-test --to-yaml %t/empty.swiftmodulesummary -o - | %FileCheck %s
8+
9+
// CHECK: module_name: empty
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-sib -emit-module-summary-path %t/function_summary.swiftmodulesummary -module-name function_summary -Xllvm -module-summary-embed-debug-name %s
3+
// RUN: llvm-bcanalyzer -dump %t/function_summary.swiftmodulesummary | %FileCheck %s -check-prefix BCANALYZER
4+
5+
// BCANALYZER-NOT: UnknownCode
6+
7+
// RUN: %swift-module-summary-test --to-yaml %t/function_summary.swiftmodulesummary -o %t/function_summary.summary.yaml
8+
9+
// `bar` references `foo` directly
10+
// RUN: cat %t/function_summary.summary.yaml | %FileCheck %s -check-prefix DIRECT-CALL
11+
12+
// DIRECT-CALL: 15904760426814321987:
13+
// DIRECT-CALL-NEXT: name: '$s16function_summary3baryyF'
14+
// DIRECT-CALL-NEXT: guid: 15904760426814321987
15+
// DIRECT-CALL-NEXT: live: false
16+
// DIRECT-CALL-NEXT: preserved: false
17+
// DIRECT-CALL-NEXT: calls:
18+
// DIRECT-CALL-NEXT: - callee_name: '$s16function_summary3fooyyF'
19+
// DIRECT-CALL-NEXT: callee_guid: 3365867516365370991
20+
// DIRECT-CALL-NEXT: kind: direct
21+
func foo() {}
22+
23+
func bar() {
24+
foo()
25+
}
26+
27+
// `useGenericP` and `useExistentialP` reference `#P.protoMember` through witness table
28+
// RUN: cat %t/function_summary.summary.yaml | %FileCheck %s -check-prefix WITNESS-CALL
29+
30+
// WITNESS-CALL: 2534322708691595658:
31+
// WITNESS-CALL-NEXT: name: '$s16function_summary15useExistentialPyyAA1P_pF'
32+
// WITNESS-CALL-NEXT: guid: 2534322708691595658
33+
// WITNESS-CALL-NEXT: live: false
34+
// WITNESS-CALL-NEXT: preserved: false
35+
// WITNESS-CALL-NEXT: calls:
36+
// WITNESS-CALL-NEXT: - callee_name: '$s16function_summary1PP11protoMemberyyF'
37+
// WITNESS-CALL-NEXT: callee_guid: 12061107285276415735
38+
// WITNESS-CALL-NEXT: kind: witness
39+
40+
protocol P {
41+
func protoMember()
42+
}
43+
44+
func useExistentialP(_ v: P) {
45+
v.protoMember()
46+
}
47+
48+
// `useClassC` reference `#P.classMember` through vtable
49+
// RUN: cat %t/function_summary.summary.yaml | %FileCheck %s -check-prefix VTABLE-CALL
50+
51+
// VTABLE-CALL: 6451800047657108456:
52+
// VTABLE-CALL-NEXT: name: '$s16function_summary9useClassCyyAA1CCF'
53+
// VTABLE-CALL-NEXT: guid: 6451800047657108456
54+
// VTABLE-CALL-NEXT: live: false
55+
// VTABLE-CALL-NEXT: preserved: false
56+
// VTABLE-CALL-NEXT: calls:
57+
// VTABLE-CALL-NEXT: - callee_name: '$s16function_summary1CC11classMemberyyF'
58+
// VTABLE-CALL-NEXT: callee_guid: 7506985369146111998
59+
// VTABLE-CALL-NEXT: kind: vtable
60+
61+
class C {
62+
func classMember() {}
63+
}
64+
65+
class D : C {
66+
override func classMember() {}
67+
}
68+
69+
func useClassC(_ v: C) {
70+
v.classMember()
71+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sib -emit-module-summary-path %t/preserved.swiftmodulesummary -module-name preserved -Xllvm -module-summary-embed-debug-name %s
3+
// RUN: %swift-module-summary-test --to-yaml %t/preserved.swiftmodulesummary -o %t/preserved.summary.yaml
4+
// RUN: cat %t/preserved.summary.yaml | %FileCheck %s -check-prefix REPLACABLE
5+
6+
// REQUIRES: objc_interop
7+
8+
// REPLACABLE: 909315153062346157:
9+
// REPLACABLE-NEXT: name: '$s9preserved12replaceable1SiyF'
10+
// REPLACABLE-NEXT: guid: 909315153062346157
11+
// REPLACABLE-NEXT: live: false
12+
// REPLACABLE-NEXT: preserved: true
13+
14+
// REPLACABLE: 3380283816534000009:
15+
// REPLACABLE-NEXT: name: '$s9preserved14replaceable1_rSiyF'
16+
// REPLACABLE-NEXT: guid: 3380283816534000009
17+
// REPLACABLE-NEXT: live: false
18+
// REPLACABLE-NEXT: preserved: false
19+
20+
dynamic func replaceable1() -> Int {
21+
return 0
22+
}
23+
24+
@_dynamicReplacement(for: replaceable1())
25+
func replaceable1_r() -> Int {
26+
return 3
27+
}
28+
29+
30+
// RUN: cat %t/preserved.summary.yaml | %FileCheck %s -check-prefix CDECL
31+
// CDECL: 401177591854398425:
32+
// CDECL-NEXT: name: callableFromC2
33+
// CDECL-NEXT: guid: 401177591854398425
34+
// CDECL-NEXT: live: false
35+
// CDECL-NEXT: preserved: true
36+
// CDECL-NEXT: calls: []
37+
// CDECL: 2609850307322683057:
38+
// CDECL-NEXT: name: callableFromC1
39+
// CDECL-NEXT: guid: 2609850307322683057
40+
// CDECL-NEXT: live: false
41+
// CDECL-NEXT: preserved: true
42+
@_cdecl("callableFromC1")
43+
func callableFromC1(x: Int) -> Int {
44+
return 1
45+
}
46+
47+
@_silgen_name("callableFromC2")
48+
func callableFromC2(x: Int) -> Int {
49+
return 2
50+
}
51+
52+
// RUN: cat %t/preserved.summary.yaml | %FileCheck %s -check-prefix OBJC
53+
// OBJC: 3149498140227613915:
54+
// OBJC-NEXT: name: '$s9preserved1AC11objcMethod1yyFTo'
55+
// OBJC-NEXT: guid: 3149498140227613915
56+
// OBJC-NEXT: live: false
57+
// OBJC-NEXT: preserved: true
58+
import Foundation
59+
60+
class A: NSObject {
61+
@objc func objcMethod1() {}
62+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-sib -emit-module-summary-path %t/tables.swiftmodulesummary -module-name tables -Xllvm -module-summary-embed-debug-name %s
3+
// RUN: llvm-bcanalyzer -dump %t/tables.swiftmodulesummary | %FileCheck %s -check-prefix BCANALYZER
4+
5+
// BCANALYZER-NOT: UnknownCode
6+
7+
// RUN: %swift-module-summary-test --to-yaml %t/tables.swiftmodulesummary -o - | %FileCheck %s
8+
9+
10+
// CHECK: 767048646313834908:
11+
// CHECK-NEXT: name: '$s6tables1SVAA1PA2aDP11protoMemberyyFTW'
12+
// CHECK: 11756327503593502600:
13+
// CHECK-NEXT: name: '$s6tables1DC11classMemberyyF'
14+
// CHECK: 17602567966448237004:
15+
// CHECK-NEXT: name: '$s6tables1CC11classMemberyyF'
16+
17+
// `protoMember` witness is recorded on the table
18+
// CHECK: witness_tables:
19+
// CHECK: 2682576275888919121: [ 767048646313834908 ]
20+
// `classMember` impls are recorded on the table
21+
// CHECK: vtables:
22+
// CHECK: 17602567966448237004: [ 17602567966448237004, 11756327503593502600 ]
23+
24+
protocol P {
25+
func protoMember()
26+
}
27+
28+
struct S : P {
29+
func protoMember() {}
30+
}
31+
32+
33+
class C {
34+
func classMember() {}
35+
}
36+
37+
class D : C {
38+
override func classMember() {}
39+
}

test/lit.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ config.sil_passpipeline_dumper = inferSwiftBinary('sil-passpipeline-dumper')
260260
config.lldb_moduleimport_test = inferSwiftBinary('lldb-moduleimport-test')
261261
config.swift_ide_test = inferSwiftBinary('swift-ide-test')
262262
config.swift_dependency_tool = inferSwiftBinary('swift-dependency-tool')
263+
config.swift_module_summary_test = inferSwiftBinary('swift-module-summary-test')
263264
config.swift_syntax_test = inferSwiftBinary('swift-syntax-test')
264265
if 'syntax_parser_lib' in config.available_features:
265266
config.swift_syntax_parser_test = inferSwiftBinary('swift-syntax-parser-test')
@@ -428,6 +429,7 @@ config.substitutions.append( ('%swift-dump-pcm', "%r -dump-pcm" % config.swiftc)
428429
config.substitutions.append( ('%swift-ide-test_plain', config.swift_ide_test) )
429430
config.substitutions.append( ('%swift-ide-test', "%r %s %s -swift-version %s" % (config.swift_ide_test, mcp_opt, ccp_opt, swift_version)) )
430431
config.substitutions.append( ('%swift-dependency-tool', config.swift_dependency_tool) )
432+
config.substitutions.append( ('%swift-module-summary-test', config.swift_module_summary_test) )
431433
config.substitutions.append( ('%swift-syntax-test', config.swift_syntax_test) )
432434
if 'syntax_parser_lib' in config.available_features:
433435
config.substitutions.append( ('%swift-syntax-parser-test', config.swift_syntax_parser_test) )

0 commit comments

Comments
 (0)