[Macros] Reproduce issue with peer+extension macro extension's methods not being checked as witnesses (#71717)

Co-authored-by: Pavel Yaskevich <pyaskevich@apple.com>
This commit is contained in:
Konrad `ktoso` Malawski
2024-02-20 17:50:29 +09:00
committed by GitHub
parent b835009744
commit f03ddf728b
6 changed files with 147 additions and 113 deletions

View File

@@ -7,10 +7,7 @@
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t-scratch)
// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking -plugin-path %swift-plugin-dir -I %t -dump-macro-expansions %s -dump-macro-expansions 2>&1 | %FileCheck %s
// FIXME: inheritance tests limited because cannot refer to any generated macro from the same module...
// XFAIL: *
// RUN: %target-swift-frontend -typecheck -verify -disable-availability-checking -plugin-path %swift-plugin-dir -I %t -dump-macro-expansions %s 2>&1 | %FileCheck %s
import Distributed
@@ -19,62 +16,48 @@ typealias System = LocalTestingDistributedActorSystem
@_DistributedProtocol
protocol EmptyBase {}
// TODO: allow this?
//@_DistributedProtocol
//extension EmptyBase {}
// @_DistributedProtocol ->
//
// CHECK: @freestanding(declaration)
// CHECK: macro _distributed_stubs_EmptyBase() =
// CHECK: #distributedStubs(
// CHECK: module: "main", protocolName: "EmptyBase",
// CHECK: stubProtocols: []
// CHECK: )
//
// CHECK: // distributed actor $EmptyBase <ActorSystem>: EmptyBase where SerializationRequirement == any Codable {
// CHECK: distributed actor $EmptyBase : EmptyBase {
// CHECK: typealias ActorSystem = LocalTestingDistributedActorSystem // FIXME: remove this
//
// CHECK: #distributedStubs(
// CHECK: module: "main", protocolName: "EmptyBase",
// CHECK: stubProtocols: []
// CHECK: )
// CHECK: distributed actor $EmptyBase<ActorSystem>: EmptyBase,
// CHECK: Distributed._DistributedActorStub
// CHECK: where ActorSystem: DistributedActorSystem<any Codable>,
// CHECK: ActorSystem.ActorID: Codable
// CHECK: {
// CHECK: }
// CHECK: extension EmptyBase where Self: Distributed._DistributedActorStub {
// CHECK: }
// ==== ------------------------------------------------------------------------
@_DistributedProtocol
protocol G3: DistributedActor, EmptyBase where SerializationRequirement == any Codable {
protocol G3<ActorSystem>: DistributedActor, EmptyBase where ActorSystem: DistributedActorSystem<any Codable> {
distributed func get() -> String
distributed func greet(name: String) -> String
}
// @_DistributedProtocol ->
//
// Since we have also the EmptyBase we don't know what names it will introduce,
// so this stubs macro must be "names: arbitrary":
// CHECK: @freestanding(declaration, names: arbitrary)
// CHECK: macro _distributed_stubs_G3() =
// CHECK: #distributedStubs(
// CHECK: module: "main", protocolName: "G3",
// CHECK: stubProtocols: ["EmptyBase"],
// CHECK: "distributed func get() -> String",
// CHECK: "distributed func greet(name: String) -> String"
// CHECK: )
//
// TODO: distributed actor $G3<ActorSystem>: Greeter where SerializationRequirement == any Codable {
// CHECK: distributed actor $G3: G3, EmptyBase {
// TODO: Preferably, we could refer to our own macro like this: #_distributed_stubs_G3
// WORKAROUND:
// CHECK: #distributedStubs(
// CHECK: module: "main", protocolName: "G3",
// CHECK: stubProtocols: ["EmptyBase"],
// CHECK: "distributed func get() -> String",
// CHECK: "distributed func greet(name: String) -> String"
// CHECK: )
// CHECK:
// FIXME: the below cannot find the macro because it's form the same module
// CHECK: // stub inherited members
// CHECK: #_distributed_stubs_EmptyBase
// CHECK: distributed actor $G3<ActorSystem>: G3
// CHECK: Distributed._DistributedActorStub
// CHECK: where ActorSystem: DistributedActorSystem<any Codable>,
// CHECK: ActorSystem.ActorID: Codable
// CHECK: {
// CHECK: }
// CHECK: extension G3 where Self: Distributed._DistributedActorStub {
// CHECK: func get() -> String {
// CHECK: if #available (SwiftStdlib 5.11, *) {
// CHECK: Distributed._distributedStubFatalError()
// CHECK: } else {
// CHECK: fatalError()
// CHECK: }
// CHECK: }
// CHECK: distributed func greet(name: String) -> String {
// CHECK: if #available (SwiftStdlib 5.11, *) {
// CHECK: Distributed._distributedStubFatalError()
// CHECK: } else {
// CHECK: fatalError()
// CHECK: }
// CHECK: }
// CHECK: }
// ==== ------------------------------------------------------------------------