Skip to content

Commit f205f2c

Browse files
committed
[embedded] Add once-dependent.swift test to showcase lazy initializers dependending on other lazy initializers
1 parent 95d5d71 commit f205f2c

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

test/embedded/once-dependent.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// RUN: %target-swift-frontend %s %S/Inputs/print.swift -enable-experimental-feature Embedded -c -o %t/main.o
2+
// RUN: %target-clang %t/main.o -o %t/a.out -dead_strip
3+
// RUN: %target-run %t/a.out | %FileCheck %s
4+
5+
// REQUIRES: executable_test
6+
// REQUIRES: optimized_stdlib
7+
// REQUIRES: VENDOR=apple
8+
// REQUIRES: OS=macosx
9+
10+
public struct MyStructA {
11+
static var singleton = MyStructA()
12+
13+
init() {
14+
print("MyStructA.init")
15+
_ = MyStructB.singleton
16+
print("MyStructA.init done")
17+
}
18+
}
19+
20+
public struct MyStructB {
21+
static var singleton = MyStructB()
22+
23+
init() {
24+
print("MyStructB.init")
25+
_ = MyStructC.singleton
26+
print("MyStructB.init done")
27+
}
28+
}
29+
30+
public struct MyStructC {
31+
static var singleton = MyStructC()
32+
33+
init() {
34+
print("MyStructC.init")
35+
print("MyStructC.init done")
36+
}
37+
}
38+
39+
@main
40+
struct Main {
41+
static func main() {
42+
print("Start")
43+
_ = MyStructA.singleton
44+
45+
// CHECK: Start
46+
// CHECK-NEXT: MyStructA.init
47+
// CHECK-NEXT: MyStructB.init
48+
// CHECK-NEXT: MyStructC.init
49+
// CHECK-NEXT: MyStructC.init done
50+
// CHECK-NEXT: MyStructB.init done
51+
// CHECK-NEXT: MyStructA.init done
52+
}
53+
}

test/embedded/once-multithreaded.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/split_file.py -o %t %s
33

4-
// RUN: %target-swift-frontend %t/Main.swift %S/Inputs/print.swift -import-bridging-header %t/BridgingHeader.h -Rmodule-loading -enable-experimental-feature Embedded -c -o %t/main.o
4+
// RUN: %target-swift-frontend %t/Main.swift %S/Inputs/print.swift -import-bridging-header %t/BridgingHeader.h -enable-experimental-feature Embedded -c -o %t/main.o
55
// RUN: %target-clang %t/main.o -o %t/a.out -dead_strip
66
// RUN: %target-run %t/a.out | %FileCheck %s
77

0 commit comments

Comments
 (0)