Skip to content

Commit 3321c32

Browse files
committed
Pass all the tests!
There were some tests that relied on the top-level code not being an asynchronous context to emit certain error messages. Now that it is, those tests weren't emitting the expected error message. In other cases, the issue was that they were trying to initialize a global variable and weren't really using top-level code as top-level code, so adding `-parse-as-library` was sufficient for the testing purposes. To fix the objc_async test, parsing as a library was nearly sufficient. Unfortunately, the little `if #available` trick that I was using stopped working since it relied on being in top-level code. So that we emit the unavailableFromAsync error message, I had to set the availability on everything correctly because we can't just disable availability checking.
1 parent c34f705 commit 3321c32

File tree

7 files changed

+49
-22
lines changed

7 files changed

+49
-22
lines changed

test/ClangImporter/objc_async.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules %s -verify -verify-additional-file %swift_src_root/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h -warn-concurrency
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -I %S/Inputs/custom-modules %s -verify -verify-additional-file %swift_src_root/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h -warn-concurrency -parse-as-library
22

33
// REQUIRES: objc_interop
44
// REQUIRES: concurrency
55
import Foundation
66
import ObjCConcurrency
77
// expected-remark@-1{{add '@preconcurrency' to suppress 'Sendable'-related warnings from module 'ObjCConcurrency'}}
88

9-
if #available(SwiftStdlib 5.5, *) {
10-
9+
@available(SwiftStdlib 5.5, *)
1110
@MainActor func onlyOnMainActor() { }
1211

12+
@available(SwiftStdlib 5.5, *)
1313
func testSlowServer(slowServer: SlowServer) async throws {
1414
let _: Int = await slowServer.doSomethingSlow("mail")
1515
let _: Bool = await slowServer.checkAvailability()
@@ -62,6 +62,7 @@ func testSlowServer(slowServer: SlowServer) async throws {
6262
_ = await slowServer.runOnMainThread()
6363
}
6464

65+
@available(SwiftStdlib 5.5, *)
6566
func testSlowServerSynchronous(slowServer: SlowServer) {
6667
// synchronous version
6768
let _: Int = slowServer.doSomethingConflicted("thinking")
@@ -88,6 +89,7 @@ func testSlowServerSynchronous(slowServer: SlowServer) {
8889
let _: Int = slowServer.overridableButRunsOnMainThread // expected-error{{cannot convert value of type '(((String) -> Void)?) -> Void' to specified type 'Int'}}
8990
}
9091

92+
@available(SwiftStdlib 5.5, *)
9193
func testSlowServerOldSchool(slowServer: SlowServer) {
9294
slowServer.doSomethingSlow("mail") { i in
9395
_ = i
@@ -96,6 +98,7 @@ func testSlowServerOldSchool(slowServer: SlowServer) {
9698
_ = slowServer.allOperations
9799
}
98100

101+
@available(SwiftStdlib 5.5, *)
99102
func testSendable(fn: () -> Void) {
100103
doSomethingConcurrently(fn) // okay, due to implicit @preconcurrency
101104
doSomethingConcurrentlyButUnsafe(fn) // okay, @Sendable not part of the type
@@ -107,6 +110,7 @@ func testSendable(fn: () -> Void) {
107110
}
108111
}
109112

113+
@available(SwiftStdlib 5.5, *)
110114
func testSendableInAsync() async {
111115
var x = 17
112116
doSomethingConcurrentlyButUnsafe {
@@ -115,6 +119,7 @@ func testSendableInAsync() async {
115119
print(x)
116120
}
117121

122+
@available(SwiftStdlib 5.5, *)
118123
func testSendableAttrs(
119124
sendableClass: SendableClass, nonSendableClass: NonSendableClass,
120125
sendableEnum: SendableEnum, nonSendableEnum: NonSendableEnum,
@@ -150,8 +155,10 @@ func testSendableAttrs(
150155
}
151156

152157
// Check import of attributes
158+
@available(SwiftStdlib 5.5, *)
153159
func globalAsync() async { }
154160

161+
@available(SwiftStdlib 5.5, *)
155162
actor MySubclassCheckingSwiftAttributes : ProtocolWithSwiftAttributes {
156163
func syncMethod() { } // expected-note 2{{calls to instance method 'syncMethod()' from outside of its actor context are implicitly asynchronous}}
157164

@@ -177,13 +184,16 @@ func testCV(r: NSRange) {
177184

178185
// Global actor (unsafe) isolation.
179186

187+
@available(SwiftStdlib 5.5, *)
180188
actor SomeActor { }
181189

190+
@available(SwiftStdlib 5.5, *)
182191
@globalActor
183192
struct SomeGlobalActor {
184193
static let shared = SomeActor()
185194
}
186195

196+
@available(SwiftStdlib 5.5, *)
187197
class MyButton : NXButton {
188198
@MainActor func testMain() {
189199
onButtonPress() // okay
@@ -198,17 +208,19 @@ class MyButton : NXButton {
198208
}
199209
}
200210

211+
@available(SwiftStdlib 5.5, *)
201212
func testButtons(mb: MyButton) {
202213
mb.onButtonPress()
203214
}
204215

205-
216+
@available(SwiftStdlib 5.5, *)
206217
func testMirrored(instance: ClassWithAsync) async {
207218
await instance.instanceAsync()
208219
await instance.protocolMethod()
209220
await instance.customAsyncName()
210221
}
211222

223+
@available(SwiftStdlib 5.5, *)
212224
@MainActor class MyToolbarButton : NXButton {
213225
var count = 5
214226

@@ -220,6 +232,7 @@ func testMirrored(instance: ClassWithAsync) async {
220232
}
221233
}
222234

235+
@available(SwiftStdlib 5.5, *)
223236
@MainActor class MyView: NXView {
224237
func f() {
225238
Task {
@@ -231,13 +244,17 @@ func testMirrored(instance: ClassWithAsync) async {
231244
}
232245

233246

247+
248+
@available(SwiftStdlib 5.5, *)
234249
@MainActor func mainActorFn() {}
250+
@available(SwiftStdlib 5.5, *)
235251
@SomeGlobalActor func sgActorFn() {}
236252

237253
// Check inferred isolation for overridden decls from ObjC.
238254
// Note that even if the override is not present, it
239255
// can have an affect. -- rdar://87217618 / SR-15694
240256
@MainActor
257+
@available(SwiftStdlib 5.5, *)
241258
class FooFrame: PictureFrame {
242259
init() {
243260
super.init(size: 0)
@@ -252,6 +269,7 @@ class FooFrame: PictureFrame {
252269
}
253270
}
254271

272+
@available(SwiftStdlib 5.5, *)
255273
class BarFrame: PictureFrame {
256274
init() {
257275
super.init(size: 0)
@@ -266,6 +284,7 @@ class BarFrame: PictureFrame {
266284
}
267285
}
268286

287+
@available(SwiftStdlib 5.5, *)
269288
@SomeGlobalActor
270289
class BazFrame: NotIsolatedPictureFrame {
271290
init() {
@@ -285,6 +304,7 @@ class BazFrame: NotIsolatedPictureFrame {
285304
class BazFrameIso: PictureFrame { // expected-error {{global actor 'SomeGlobalActor'-isolated class 'BazFrameIso' has different actor isolation from main actor-isolated superclass 'PictureFrame'}}
286305
}
287306

307+
@available(SwiftStdlib 5.5, *)
288308
func check() async {
289309
_ = await BarFrame()
290310
_ = await FooFrame()
@@ -347,5 +367,3 @@ func testSender(
347367
sender.sendPtr(ptr)
348368
sender.sendStringArray(stringArray)
349369
}
350-
351-
} // SwiftStdlib 5.5

test/Concurrency/actor_call_implicitly_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency -parse-as-library
22
// REQUIRES: concurrency
33

44

test/Concurrency/actor_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/OtherActors.swiftmodule -module-name OtherActors %S/Inputs/OtherActors.swift -disable-availability-checking
3-
// RUN: %target-typecheck-verify-swift -I %t -disable-availability-checking -warn-concurrency
3+
// RUN: %target-typecheck-verify-swift -I %t -disable-availability-checking -warn-concurrency -parse-as-library
44
// REQUIRES: concurrency
55

66
import OtherActors // expected-remark{{add '@preconcurrency' to suppress 'Sendable'-related warnings from module 'OtherActors'}}{{1-1=@preconcurrency }}

test/Concurrency/concurrency_warnings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -warn-concurrency
1+
// RUN: %target-typecheck-verify-swift -warn-concurrency -parse-as-library
22
// REQUIRES: concurrency
33

44
class GlobalCounter {

test/Concurrency/concurrent_value_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -warn-concurrency -parse-as-library
22
// REQUIRES: concurrency
33

44
class NotConcurrent { } // expected-note 27{{class 'NotConcurrent' does not conform to the 'Sendable' protocol}}

test/Concurrency/property_initializers_swift6.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33

44
// REQUIRES: asserts
55

6-
@MainActor
7-
func mainActorFn() -> Int { return 0 } // expected-note 2 {{calls to global function 'mainActorFn()' from outside of its actor context are implicitly asynchronous}}
6+
@globalActor
7+
actor GlobalActor {
8+
static let shared = GlobalActor()
9+
}
10+
11+
@GlobalActor
12+
func globalActorFn() -> Int { return 0 } // expected-note 2 {{calls to global function 'globalActorFn()' from outside of its actor context are implicitly asynchronous}}
813

9-
@MainActor
14+
@GlobalActor
1015
class C {
11-
var x: Int = mainActorFn() // expected-error {{call to main actor-isolated global function 'mainActorFn()' in a synchronous nonisolated context}}
16+
var x: Int = globalActorFn() // expected-error {{call to global actor 'GlobalActor'-isolated global function 'globalActorFn()' in a synchronous nonisolated context}}
1217

13-
lazy var y: Int = mainActorFn()
18+
lazy var y: Int = globalActorFn()
1419

15-
static var z: Int = mainActorFn()
20+
static var z: Int = globalActorFn()
1621
}
1722

18-
@MainActor
19-
var x: Int = mainActorFn() // expected-error {{call to main actor-isolated global function 'mainActorFn()' in a synchronous nonisolated context}}
23+
var x: Int = globalActorFn() // expected-error {{call to global actor 'GlobalActor'-isolated global function 'globalActorFn()' in a synchronous main actor-isolated context}}

test/stmt/async.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
// REQUIRES: concurrency
44

5-
func f() async -> Int { 0 }
5+
@_silgen_name("omnomInt")
6+
func omnom(_ x: Int)
67

7-
_ = await f() // expected-error{{'async' call in a function that does not support concurrency}}
8+
func f() async -> Int { 0 }
89

9-
async let y = await f() // expected-error{{'async let' in a function that does not support concurrency}}
10-
// expected-error@-1{{'async' call in a function that does not support concurrency}}
10+
func syncContext() { // expected-note 4 {{add 'async' to function 'syncContext()' to make it asynchronous}}
11+
_ = await f() // expected-error{{'async' call in a function that does not support concurrency}}
12+
async let y = await f() // expected-error{{'async let' in a function that does not support concurrency}}
13+
// expected-error@-1{{'async' call in a function that does not support concurrency}}
14+
await omnom(y) // expected-error{{'async let' in a function that does not support concurrency}}
15+
}

0 commit comments

Comments
 (0)