-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILOptimizer] Prevent devirtualization of call to distributed witnes… #80373
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
test/Distributed/distributed_actor_adhoc_requirements_optimized_build.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -emit-ir -swift-version 6 -O -I %t %s | ||
// RUN: %target-swift-frontend -emit-sil -swift-version 6 -O -I %t %s | %FileCheck %s | ||
|
||
// REQUIRES: concurrency | ||
// REQUIRES: distributed | ||
|
||
// REQUIRES: OS=macosx || OS=ios | ||
|
||
import Distributed | ||
|
||
// NOTE: None of the ad-hoc protocol requirement implementations | ||
|
||
public protocol Transferable: Sendable {} | ||
|
||
// NOT final on purpose | ||
public class TheSpecificResultHandlerWhichIsANonFinalClass: DistributedTargetInvocationResultHandler { | ||
public typealias SerializationRequirement = Transferable | ||
|
||
public func onReturn<Success>(value: Success) async throws where Success: Transferable { | ||
} | ||
|
||
public func onReturnVoid() async throws { | ||
fatalError() | ||
} | ||
|
||
public func onThrow<Err>(error: Err) async throws where Err : Error { | ||
fatalError() | ||
} | ||
} | ||
|
||
// NOT final on purpose | ||
public class FakeInvocationDecoder: DistributedTargetInvocationDecoder { | ||
public typealias SerializationRequirement = Transferable | ||
|
||
public func decodeGenericSubstitutions() throws -> [Any.Type] { | ||
[] | ||
} | ||
|
||
public func decodeNextArgument<Argument: SerializationRequirement>() throws -> Argument { | ||
fatalError() | ||
} | ||
|
||
public func decodeErrorType() throws -> Any.Type? { | ||
nil | ||
} | ||
|
||
public func decodeReturnType() throws -> Any.Type? { | ||
nil | ||
} | ||
} | ||
|
||
// NOT final on purpose | ||
public class FakeInvocationEncoder : DistributedTargetInvocationEncoder { | ||
public typealias SerializationRequirement = Transferable | ||
|
||
public func recordArgument<Value: SerializationRequirement>( | ||
_ argument: RemoteCallArgument<Value>) throws { | ||
} | ||
|
||
public func recordGenericSubstitution<T>(_ type: T.Type) throws { | ||
} | ||
|
||
public func recordErrorType<E: Error>(_ type: E.Type) throws { | ||
} | ||
|
||
public func recordReturnType<R: SerializationRequirement>(_ type: R.Type) throws { | ||
} | ||
|
||
public func doneRecording() throws { | ||
} | ||
} | ||
|
||
// NOT final on purpose | ||
public class NotFinalActorSystemForAdHocRequirementTest: DistributedActorSystem, @unchecked Sendable { | ||
public typealias ActorID = String | ||
public typealias InvocationEncoder = FakeInvocationEncoder | ||
public typealias InvocationDecoder = FakeInvocationDecoder | ||
public typealias SerializationRequirement = Transferable | ||
public typealias ResultHandler = TheSpecificResultHandlerWhichIsANonFinalClass | ||
|
||
public init() {} | ||
|
||
public func resolve<Act>(id: ActorID, as actorType: Act.Type) | ||
throws -> Act? where Act: DistributedActor { | ||
fatalError() | ||
} | ||
|
||
public func assignID<Act>(_ actorType: Act.Type) -> ActorID | ||
where Act: DistributedActor { | ||
fatalError() | ||
} | ||
|
||
public func actorReady<Act>(_ actor: Act) where Act: DistributedActor, Act.ID == ActorID { | ||
fatalError() | ||
} | ||
|
||
public func resignID(_ id: ActorID) { | ||
fatalError() | ||
} | ||
|
||
public func makeInvocationEncoder() -> InvocationEncoder { | ||
fatalError() | ||
} | ||
|
||
public func remoteCall<Act, Err, Res>( | ||
on actor: Act, | ||
target: RemoteCallTarget, | ||
invocation: inout InvocationEncoder, | ||
throwing errorType: Err.Type, | ||
returning returnType: Res.Type | ||
) async throws -> Res | ||
where Act: DistributedActor, | ||
Act.ID == ActorID, | ||
Err: Error, | ||
Res: SerializationRequirement { | ||
fatalError() | ||
} | ||
|
||
public func remoteCallVoid<Act, Err>( | ||
on actor: Act, | ||
target: RemoteCallTarget, | ||
invocation: inout InvocationEncoder, | ||
throwing errorType: Err.Type | ||
) async throws | ||
where Act: DistributedActor, | ||
Act.ID == ActorID, | ||
Err: Error { | ||
fatalError() | ||
} | ||
} | ||
|
||
// FIXME: This call should be devirtualized but it cannot be done at the moment due to issues with ad-hoc serialization requirement. | ||
|
||
// CHECK-LABEL: sil shared [transparent] [thunk] @$s52distributed_actor_adhoc_requirements_optimized_build42NotFinalActorSystemForAdHocRequirementTestC11Distributed0piJ0AadEP10remoteCall2on6target10invocation8throwing9returningqd_1_qd___AD06RemoteR6TargetV17InvocationEncoderQzzqd_0_mqd_1_mtYaKAD0pI0Rd__s5ErrorRd_0_2IDQyd__0I2IDRtzr1_lFTW | ||
// CHECK: bb0(%0 : $*τ_0_2, %1 : $τ_0_0, %2 : $*RemoteCallTarget, %3 : $*FakeInvocationEncoder, %4 : $@thick τ_0_1.Type, %5 : $@thick τ_0_2.Type, %6 : $*NotFinalActorSystemForAdHocRequirementTest): | ||
// CHECK-NEXT: [[DIST_IMPL:%.*]] = load %6 | ||
// CHECK-NEXT: [[REMOTE_CALL_WITNESS:%.*]] = class_method [[DIST_IMPL]], #NotFinalActorSystemForAdHocRequirementTest.remoteCall | ||
// CHECK-NEXT: try_apply [[REMOTE_CALL_WITNESS]]<τ_0_0, τ_0_1, τ_0_2>(%0, %1, %2, %3, %4, %5, [[DIST_IMPL]]) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ktoso FYI, I restricted this test to macOS and iOS only for now because it fails with availability issues on watch os: