46
46
// RUN: %target-codesign %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
47
47
// RUN: %target-run %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
48
48
49
+ ///////////////////////////////////////////////////////////////////////////////
50
+ // Now repeat all of the same tests, but with library evolution enabled:
51
+ ///////////////////////////////////////////////////////////////////////////////
52
+
53
+ // RUN: %empty-directory(%t)
54
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module1)) -DMODULE -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -enable-library-evolution
55
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module2)) -I%t -L%t -lModule1 %target-rpath(%t) -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -DEVOLUTION
56
+ // RUN: %target-build-swift -I%t -L%t -lModule1 -DMAIN -o %t/main %target-rpath(%t) %s -swift-version 5 -DEVOLUTION
57
+ // RUN: %target-codesign %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
58
+ // RUN: %target-run %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
59
+
60
+ // Now the same in optimized mode.
61
+ // RUN: %empty-directory(%t)
62
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module1)) -O -DMODULE -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -enable-library-evolution
63
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module2)) -O -I%t -L%t -lModule1 %target-rpath(%t) -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -DEVOLUTION
64
+ // RUN: %target-build-swift -O -I%t -L%t -lModule1 -DMAIN -o %t/main %target-rpath(%t) %s -swift-version 5 -DEVOLUTION
65
+ // RUN: %target-codesign %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
66
+ // RUN: %target-run %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
67
+
68
+ // Now the same in size mode.
69
+ // RUN: %empty-directory(%t)
70
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module1)) -Osize -DMODULE -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -enable-library-evolution
71
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module2)) -Osize -I%t -L%t -lModule1 %target-rpath(%t) -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -DEVOLUTION
72
+ // RUN: %target-build-swift -Osize -I%t -L%t -lModule1 -DMAIN -o %t/main %target-rpath(%t) %s -swift-version 5 -DEVOLUTION
73
+ // RUN: %target-codesign %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
74
+ // RUN: %target-run %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
75
+
76
+ // Now the same in optimized wholemodule mode.
77
+ // RUN: %empty-directory(%t)
78
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module1)) -O -wmo -DMODULE -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -enable-library-evolution
79
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module2)) -O -wmo -I%t -L%t -lModule1 %target-rpath(%t) -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -DEVOLUTION
80
+ // RUN: %target-build-swift -O -wmo -I%t -L%t -lModule1 -DMAIN -o %t/main %target-rpath(%t) %s -swift-version 5 -DEVOLUTION
81
+ // RUN: %target-codesign %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
82
+ // RUN: %target-run %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
83
+
84
+ // Test the -enable-implicit-dynamic flag.
85
+
86
+ // RUN: %empty-directory(%t)
87
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module1)) -DMODULENODYNAMIC -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -Xfrontend -enable-implicit-dynamic -enable-library-evolution
88
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module2)) -I%t -L%t -lModule1 %target-rpath(%t) -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -DEVOLUTION
89
+ // RUN: %target-build-swift -I%t -L%t -lModule1 -DMAIN -o %t/main %target-rpath(%t) %s -swift-version 5 -DEVOLUTION
90
+ // RUN: %target-codesign %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
91
+ // RUN: %target-run %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
92
+
93
+ // Test the -enable-implicit-dynamic flag in optimized wholemodule mode.
94
+ // RUN: %empty-directory(%t)
95
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module1)) -O -wmo -DMODULENODYNAMIC -module-name Module1 -emit-module -emit-module-path %t/Module1.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -Xfrontend -enable-implicit-dynamic -enable-library-evolution
96
+ // RUN: %target-build-swift-dylib(%t/%target-library-name(Module2)) -O -wmo -I%t -L%t -lModule1 %target-rpath(%t) -DMODULE2 -module-name Module2 -emit-module -emit-module-path %t/Module2.swiftmodule -swift-version 5 %S/Inputs/dynamic_replacement_module.swift -DEVOLUTION
97
+ // RUN: %target-build-swift -O -wmo -I%t -L%t -lModule1 -DMAIN -o %t/main %target-rpath(%t) %s -swift-version 5 -DEVOLUTION
98
+ // RUN: %target-codesign %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
99
+ // RUN: %target-run %t/main %t/%target-library-name(Module1) %t/%target-library-name(Module2)
100
+
49
101
50
102
// REQUIRES: executable_test
51
103
@@ -75,42 +127,51 @@ func expectedResult(_ forOriginalLibrary: Bool, _ expectedOriginalString: Strin
75
127
}
76
128
77
129
func checkExpectedResults( forOriginalLibrary useOrig: Bool ) {
78
- expectTrue ( public_global_var == expectedResult ( useOrig, " public_global_var " ) )
79
-
80
- expectTrue ( public_global_func ( ) ==
81
- expectedResult ( useOrig, " public_global_func " ) )
82
- expectTrue ( public_global_generic_func ( Int . self) ==
83
- expectedResult ( useOrig, " public_global_generic_func " ) )
84
-
85
- expectTrue ( PublicClass ( ) . function ( ) ==
86
- expectedResult ( useOrig, " public_class_func " ) )
87
- expectTrue ( PublicClass ( ) . finalFunction ( ) ==
88
- expectedResult ( useOrig, " public_class_final_func " ) )
89
- expectTrue ( PublicClass ( ) . genericFunction ( Int . self) ==
90
- expectedResult ( useOrig, " public_class_generic_func " ) )
91
-
92
- expectTrue ( PublicStruct ( ) . function ( ) ==
93
- expectedResult ( useOrig, " public_struct_func " ) )
94
- expectTrue ( PublicStruct ( ) . genericFunction ( Int . self) ==
95
- expectedResult ( useOrig, " public_struct_generic_func " ) )
96
- expectTrue ( PublicStruct ( ) . public_stored_property ==
97
- expectedResult ( useOrig, " public_stored_property " ) )
98
- expectTrue ( PublicStruct ( ) [ 0 ] ==
99
- expectedResult ( useOrig, " public_subscript_get " ) )
100
- expectTrue ( PublicStruct ( ) [ y: 0 ] ==
101
- expectedResult ( useOrig, " public_subscript_get_modify_read " ) )
102
- var testSetter = PublicStruct ( )
103
- testSetter [ 0 ] = " public_subscript_set "
104
- expectTrue ( testSetter. str ==
105
- expectedResult ( useOrig, " public_subscript_set " ) )
106
- testSetter [ y: 0 ] = " public_subscript_set_modify_read "
107
- expectTrue ( testSetter. str ==
108
- expectedResult ( useOrig, " public_subscript_set_modify_read " ) )
109
-
110
- expectTrue ( PublicEnumeration< Int> . A. function ( ) ==
111
- expectedResult ( useOrig, " public_enum_func " ) )
112
- expectTrue ( PublicEnumeration< Int> . B. genericFunction ( Int . self) ==
113
- expectedResult ( useOrig, " public_enum_generic_func " ) )
130
+ expectTrue ( public_global_var == expectedResult ( useOrig, " public_global_var " ) )
131
+
132
+ expectTrue ( public_global_func ( ) ==
133
+ expectedResult ( useOrig, " public_global_func " ) )
134
+ expectTrue ( public_global_generic_func ( Int . self) ==
135
+ expectedResult ( useOrig, " public_global_generic_func " ) )
136
+
137
+ // Designated initializers of resilient classes cannot be
138
+ // dynamically replaced.
139
+ #if !EVOLUTION
140
+ expectTrue ( PublicClass ( x: 0 ) . str ==
141
+ expectedResult ( useOrig, " public_class_init " ) )
142
+ #endif
143
+
144
+ expectTrue ( PublicClass ( ) . function ( ) ==
145
+ expectedResult ( useOrig, " public_class_func " ) )
146
+ expectTrue ( PublicClass ( ) . finalFunction ( ) ==
147
+ expectedResult ( useOrig, " public_class_final_func " ) )
148
+ expectTrue ( PublicClass ( ) . genericFunction ( Int . self) ==
149
+ expectedResult ( useOrig, " public_class_generic_func " ) )
150
+
151
+ expectTrue ( PublicStruct ( x: 0 ) . str ==
152
+ expectedResult ( useOrig, " public_struct_init " ) )
153
+ expectTrue ( PublicStruct ( ) . function ( ) ==
154
+ expectedResult ( useOrig, " public_struct_func " ) )
155
+ expectTrue ( PublicStruct ( ) . genericFunction ( Int . self) ==
156
+ expectedResult ( useOrig, " public_struct_generic_func " ) )
157
+ expectTrue ( PublicStruct ( ) . public_stored_property ==
158
+ expectedResult ( useOrig, " public_stored_property " ) )
159
+ expectTrue ( PublicStruct ( ) [ 0 ] ==
160
+ expectedResult ( useOrig, " public_subscript_get " ) )
161
+ expectTrue ( PublicStruct ( ) [ y: 0 ] ==
162
+ expectedResult ( useOrig, " public_subscript_get_modify_read " ) )
163
+ var testSetter = PublicStruct ( )
164
+ testSetter [ 0 ] = " public_subscript_set "
165
+ expectTrue ( testSetter. str ==
166
+ expectedResult ( useOrig, " public_subscript_set " ) )
167
+ testSetter [ y: 0 ] = " public_subscript_set_modify_read "
168
+ expectTrue ( testSetter. str ==
169
+ expectedResult ( useOrig, " public_subscript_set_modify_read " ) )
170
+
171
+ expectTrue ( PublicEnumeration< Int> . A. function ( ) ==
172
+ expectedResult ( useOrig, " public_enum_func " ) )
173
+ expectTrue ( PublicEnumeration< Int> . B. genericFunction ( Int . self) ==
174
+ expectedResult ( useOrig, " public_enum_generic_func " ) )
114
175
}
115
176
116
177
private func target_library_name( _ name: String ) -> String {
@@ -135,7 +196,7 @@ DynamicallyReplaceable.test("DynamicallyReplaceable") {
135
196
#if os(Linux)
136
197
_ = dlopen ( target_library_name ( " Module2 " ) , RTLD_NOW)
137
198
#elseif os(Windows)
138
- _ = LoadLibraryA ( target_library_name ( " Module2 " ) )
199
+ _ = LoadLibraryA ( target_library_name ( " Module2 " ) )
139
200
#else
140
201
_ = dlopen ( executablePath+ target_library_name( " Module2 " ) , RTLD_NOW)
141
202
#endif
0 commit comments