Skip to content

[5.10] Update some Distributed tests to be less deployment target sensitive #71133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/Distributed/Inputs/CustomSerialExecutorAvailability.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import Distributed
import FakeDistributedActorSystems

@available(SwiftStdlib 5.7, *)
typealias DefaultDistributedActorSystem = LocalTestingDistributedActorSystem

@available(SwiftStdlib 5.7, *)
distributed actor FiveSevenActor_NothingExecutor {
nonisolated var unownedExecutor: UnownedSerialExecutor {
print("get unowned executor")
return MainActor.sharedUnownedExecutor
}

distributed func test(x: Int) async throws {
print("executed: \(#function)")
defer {
print("done executed: \(#function)")
}
MainActor.assumeIsolated {
// ignore
}
}
}

@available(SwiftStdlib 5.9, *)
distributed actor FiveNineActor_NothingExecutor {
nonisolated var unownedExecutor: UnownedSerialExecutor {
print("get unowned executor")
return MainActor.sharedUnownedExecutor
}

distributed func test(x: Int) async throws {
print("executed: \(#function)")
defer {
print("done executed: \(#function)")
}
MainActor.assumeIsolated {
// ignore
}
}
}

@available(SwiftStdlib 5.7, *)
distributed actor FiveSevenActor_FiveNineExecutor {
@available(SwiftStdlib 5.9, *)
nonisolated var unownedExecutor: UnownedSerialExecutor {
print("get unowned executor")
return MainActor.sharedUnownedExecutor
}

distributed func test(x: Int) async throws {
print("executed: \(#function)")
defer {
print("done executed: \(#function)")
}
MainActor.assumeIsolated {
// ignore
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
// RUN: %target-build-swift -Xfrontend -disable-availability-checking -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-build-swift -parse-as-library -target %target-swift-abi-5.7-triple -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift %S/../Inputs/CustomSerialExecutorAvailability.swift -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out
// RUN: %target-run %t/a.out

// These are the only platforms for which compiling a Swift 5.7 aligned deployment target is possible.
// REQUIRES: OS=macosx || OS=ios || OS=watchos || OS=tvos

// REQUIRES: executable_test
// REQUIRES: concurrency
Expand All @@ -16,65 +19,6 @@

import StdlibUnittest
import Distributed
import FakeDistributedActorSystems

@available(SwiftStdlib 5.7, *)
typealias DefaultDistributedActorSystem = LocalTestingDistributedActorSystem

@available(SwiftStdlib 5.7, *)
distributed actor FiveSevenActor_NothingExecutor {
nonisolated var unownedExecutor: UnownedSerialExecutor {
print("get unowned executor")
return MainActor.sharedUnownedExecutor
}

distributed func test(x: Int) async throws {
print("executed: \(#function)")
defer {
print("done executed: \(#function)")
}
MainActor.assumeIsolated {
// ignore
}
}
}

@available(SwiftStdlib 5.9, *)
distributed actor FiveNineActor_NothingExecutor {
nonisolated var unownedExecutor: UnownedSerialExecutor {
print("get unowned executor")
return MainActor.sharedUnownedExecutor
}

distributed func test(x: Int) async throws {
print("executed: \(#function)")
defer {
print("done executed: \(#function)")
}
MainActor.assumeIsolated {
// ignore
}
}
}

@available(SwiftStdlib 5.7, *)
distributed actor FiveSevenActor_FiveNineExecutor {
@available(SwiftStdlib 5.9, *)
nonisolated var unownedExecutor: UnownedSerialExecutor {
print("get unowned executor")
return MainActor.sharedUnownedExecutor
}

distributed func test(x: Int) async throws {
print("executed: \(#function)")
defer {
print("done executed: \(#function)")
}
MainActor.assumeIsolated {
// ignore
}
}
}

@main struct Main {
static func main() async {
Expand All @@ -83,7 +27,6 @@ distributed actor FiveSevenActor_FiveNineExecutor {

let system = LocalTestingDistributedActorSystem()

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
tests.test("5.7 actor, no availability executor property => no custom executor") {
expectCrashLater(withMessage: "Fatal error: Incorrect actor executor assumption; Expected 'MainActor' executor.")
try! await FiveSevenActor_NothingExecutor(actorSystem: system).test(x: 42)
Expand All @@ -97,22 +40,6 @@ distributed actor FiveSevenActor_FiveNineExecutor {
expectCrashLater(withMessage: "Fatal error: Incorrect actor executor assumption; Expected 'MainActor' executor.")
try! await FiveSevenActor_FiveNineExecutor(actorSystem: system).test(x: 42)
}
#else
// On non-apple platforms the SDK comes with the toolchains,
// so the feature works because we're executing in a 5.9 context already,
// which otherwise could not have been compiled
tests.test("non apple platform: 5.7 actor, no availability executor property => no custom executor") {
try! await FiveSevenActor_NothingExecutor(actorSystem: system).test(x: 42)
}

tests.test("non apple platform: 5.9 actor, no availability executor property => custom executor") {
try! await FiveNineActor_NothingExecutor(actorSystem: system).test(x: 42)
}

tests.test("non apple platform: 5.7 actor, 5.9 executor property => no custom executor") {
try! await FiveSevenActor_FiveNineExecutor(actorSystem: system).test(x: 42)
}
#endif

await runAllTestsAsync()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
// RUN: %target-build-swift -parse-as-library -target %target-swift-abi-5.9-triple -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift %S/../Inputs/CustomSerialExecutorAvailability.swift -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: distributed
// REQUIRES: concurrency_runtime
// UNSUPPORTED: back_deployment_runtime

// UNSUPPORTED: back_deploy_concurrency
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: freestanding

import StdlibUnittest
import Distributed

@main struct Main {
static func main() async {
if #available(SwiftStdlib 5.9, *) {
let tests = TestSuite("DistributedActorExecutorAvailabilitySwift59")

let system = LocalTestingDistributedActorSystem()

// On non-apple platforms the SDK comes with the toolchains,
// so the feature works because we're executing in a 5.9 context already,
// which otherwise could not have been compiled
tests.test("non apple platform: 5.7 actor, no availability executor property => no custom executor") {
try! await FiveSevenActor_NothingExecutor(actorSystem: system).test(x: 42)
}

tests.test("non apple platform: 5.9 actor, no availability executor property => custom executor") {
try! await FiveNineActor_NothingExecutor(actorSystem: system).test(x: 42)
}

tests.test("non apple platform: 5.7 actor, 5.9 executor property => no custom executor") {
try! await FiveSevenActor_FiveNineExecutor(actorSystem: system).test(x: 42)
}

await runAllTestsAsync()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ public distributed actor MyOtherActor {
// CHECK: [[ARG_0_SIZE_ADJ:%.*]] = add i64 %size, 15
// CHECK-NEXT: [[ARG_0_SIZE:%.*]] = and i64 [[ARG_0_SIZE_ADJ]], -16
// CHECK-NEXT: [[ARG_0_VALUE_BUF:%.*]] = call swiftcc ptr @swift_task_alloc(i64 [[ARG_0_SIZE]])
// CHECK-NEXT: [[ENCODABLE_WITNESS:%.*]] = call ptr @swift_conformsToProtocol(ptr %arg_type, ptr @"$sSeMp")
// CHECK-NEXT: [[ENCODABLE_WITNESS:%.*]] = call ptr @swift_conformsToProtocol{{(2)?}}(ptr %arg_type, ptr @"$sSeMp")
// CHECK-NEXT: [[IS_NULL:%.*]] = icmp eq ptr [[ENCODABLE_WITNESS]], null
// CHECK-NEXT: br i1 [[IS_NULL]], label %missing-witness, label [[CONT:%.*]]
// CHECK: missing-witness:
// CHECK-NEXT: call void @llvm.trap()
// CHECK-NEXT: unreachable
// CHECK: [[DECODABLE_WITNESS:%.*]] = call ptr @swift_conformsToProtocol(ptr %arg_type, ptr @"$sSEMp")
// CHECK: [[DECODABLE_WITNESS:%.*]] = call ptr @swift_conformsToProtocol{{(2)?}}(ptr %arg_type, ptr @"$sSEMp")
// CHECK-NEXT: [[IS_NULL:%.*]] = icmp eq ptr [[DECODABLE_WITNESS]], null
// CHECK-NEXT: br i1 [[IS_NULL]], label %missing-witness1, label [[CONT:%.*]]
// CHECK: missing-witness1:
Expand Down