Skip to content

Commit ad43c81

Browse files
committed
add test to catch regressions in ABI stability of actor inits
it should not matter whether an initializer is delegating or not when importing a library. this test helps make sure that stays true.
1 parent 535166d commit ad43c81

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// This input is useful to ensure the delegation status of
3+
// an actor's initializer does not affect ABI stability
4+
public actor BigFoot {
5+
6+
public let name: String
7+
8+
private init(withName name: String) {
9+
self.name = name
10+
}
11+
12+
public init?() {
13+
#if DELEGATES
14+
self.init(withName: "Sasquatch")
15+
#else
16+
return nil
17+
#endif
18+
}
19+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// NOTE: the two tests below look like a lot of copy-pasting, but the only thing that's varying between
4+
// the two checks is whether "-D DELEGATES" is passed when compiling MysteryInit and whether the check-prefix when running the executable matches that or not.
5+
6+
/// -----------------------------------------------------------------------
7+
/// Check if the actor init in the library can change from delegating to non-delegating
8+
/// -----------------------------------------------------------------------
9+
10+
// ------> first library DOES delegate
11+
// RUN: %target-build-swift-dylib(%t/%target-library-name(MysteryInit)) -D DELEGATES -Xfrontend -disable-availability-checking -enable-library-evolution %S/Inputs/MysteryInit.swift -emit-module -emit-module-path %t/MysteryInit.swiftmodule -module-name MysteryInit
12+
// RUN: %target-codesign %t/%target-library-name(MysteryInit)
13+
14+
15+
// ------> make sure that works
16+
// RUN: %target-build-swift -parse-as-library -Xfrontend -disable-availability-checking %s -lMysteryInit -I %t -L %t -o %t/main %target-rpath(%t)
17+
// RUN: %target-codesign %t/main
18+
// RUN: %target-run %t/main %t/%target-library-name(MysteryInit) | %FileCheck --check-prefix=CHECK-DELEGATES %s
19+
20+
// ------> do a little internal sanity check on this test itself
21+
// RUN: %target-run %t/main %t/%target-library-name(MysteryInit) | not %FileCheck --check-prefix=CHECK-NO-DELEGATES %s
22+
23+
// ------> now recompile that library's init so it DOES NOT delegate, without recompiling executable
24+
// RUN: %target-build-swift-dylib(%t/%target-library-name(MysteryInit)) -Xfrontend -disable-availability-checking -enable-library-evolution %S/Inputs/MysteryInit.swift -emit-module -emit-module-path %t/MysteryInit.swiftmodule -module-name MysteryInit
25+
// RUN: %target-codesign %t/%target-library-name(MysteryInit)
26+
27+
// ------> re-run executable
28+
// RUN: %target-run %t/main %t/%target-library-name(MysteryInit) | %FileCheck --check-prefix=CHECK-NO-DELEGATES %s
29+
30+
31+
/// -----------------------------------------------------------------------
32+
/// now, other direction: Check if the actor init can change from non-delegating to delegating
33+
/// -----------------------------------------------------------------------
34+
35+
// ------> library currently DOES NOT delegate. recompile executable to match.
36+
// RUN: %target-build-swift -parse-as-library -Xfrontend -disable-availability-checking %s -lMysteryInit -I %t -L %t -o %t/main %target-rpath(%t)
37+
// RUN: %target-codesign %t/main
38+
// RUN: %target-run %t/main %t/%target-library-name(MysteryInit) | %FileCheck --check-prefix=CHECK-NO-DELEGATES %s
39+
40+
// ------> now recompile that library's init so it DOES delegate, without recompiling executable
41+
// RUN: %target-build-swift-dylib(%t/%target-library-name(MysteryInit)) -D DELEGATES -Xfrontend -disable-availability-checking -enable-library-evolution %S/Inputs/MysteryInit.swift -emit-module -emit-module-path %t/MysteryInit.swiftmodule -module-name MysteryInit
42+
// RUN: %target-codesign %t/%target-library-name(MysteryInit)
43+
44+
// ------> re-run executable
45+
// RUN: %target-run %t/main %t/%target-library-name(MysteryInit) | %FileCheck --check-prefix=CHECK-DELEGATES %s
46+
47+
48+
// REQUIRES: executable_test
49+
// REQUIRES: concurrency
50+
51+
// rdar://76038845
52+
// REQUIRES: concurrency_runtime
53+
// UNSUPPORTED: back_deployment_runtime
54+
55+
import MysteryInit
56+
57+
@main
58+
struct Main {
59+
static func main() {
60+
switch BigFoot() {
61+
case .none:
62+
print("bigfoot is myth")
63+
// CHECK-NO-DELEGATES: bigfoot is myth
64+
default:
65+
print("bigfoot is real")
66+
// CHECK-DELEGATES: bigfoot is real
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)