Skip to content

Commit 39687f1

Browse files
authored
[Distributed] Carry SPI attribute to stub types (#79987)
* [Distributed] Carry SPI attribute to stub types * Cleaner identifier checking
1 parent 7d15ce0 commit 39687f1

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/Macros/Sources/SwiftMacros/DistributedResolvableMacro.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ extension DistributedResolvableMacro {
4545
return []
4646
}
4747

48+
let attributes = proto.attributes.filter { attr in
49+
attr.as(AttributeSyntax.self)?.attributeName.trimmed.description == "_spi"
50+
}
4851
let accessModifiers = proto.accessControlModifiers
4952

5053
let requirementStubs =
@@ -64,6 +67,7 @@ extension DistributedResolvableMacro {
6467

6568
let extensionDecl: DeclSyntax =
6669
"""
70+
\(raw: attributes.map({$0.description}).joined(separator: "\n"))
6771
extension \(proto.name.trimmed) where Self: Distributed._DistributedActorStub {
6872
\(raw: requirementStubs)
6973
}
@@ -133,6 +137,15 @@ extension DistributedResolvableMacro {
133137
var isGenericOverActorSystem = false
134138
var specificActorSystemRequirement: TypeSyntax?
135139

140+
let attributes = proto.attributes.filter {
141+
guard let attr = $0.as(AttributeSyntax.self) else {
142+
return false
143+
}
144+
guard let ident = attr.attributeName.as(IdentifierTypeSyntax.self) else {
145+
return false
146+
}
147+
return ident.name.text == "_spi"
148+
}
136149
let accessModifiers = proto.accessControlModifiers
137150

138151
for req in proto.genericWhereClause?.requirements ?? [] {
@@ -232,6 +245,7 @@ extension DistributedResolvableMacro {
232245

233246
return [
234247
"""
248+
\(attributes)
235249
\(proto.modifiers) distributed actor $\(proto.name.trimmed)\(raw: typeParamsClause): \(proto.name.trimmed),
236250
Distributed._DistributedActorStub \(raw: whereClause)
237251
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// REQUIRES: swift_swift_parser, asserts
2+
//
3+
// UNSUPPORTED: back_deploy_concurrency
4+
// REQUIRES: concurrency
5+
// REQUIRES: distributed
6+
//
7+
// RUN: %empty-directory(%t)
8+
// RUN: %empty-directory(%t-scratch)
9+
10+
// RUN: %target-swift-frontend -typecheck -verify -target %target-swift-6.0-abi-triple -plugin-path %swift-plugin-dir -I %t -dump-macro-expansions %s -dump-macro-expansions 2>&1 | %FileCheck %s
11+
12+
import Distributed
13+
14+
@Resolvable
15+
@_spi(CoolFeatures)
16+
public protocol Greeter: DistributedActor where ActorSystem: DistributedActorSystem<any Codable> {
17+
distributed func greet(name: String) -> String
18+
}
19+
20+
// @Resolvable ->
21+
22+
// CHECK: @_spi(CoolFeatures)
23+
// CHECK: distributed actor $Greeter<ActorSystem>: Greeter,
24+
// CHECK-NEXT: Distributed._DistributedActorStub
25+
// CHECK-NEXT: where ActorSystem: DistributedActorSystem<any Codable>
26+
// CHECK-NEXT: {
27+
// CHECK: }
28+
29+
// CHECK: @_spi(CoolFeatures)
30+
// CHECK: extension Greeter where Self: Distributed._DistributedActorStub {
31+
// CHECK: distributed func greet(name: String) -> String {
32+
// CHECK-NEXT: if #available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) {
33+
// CHECK-NEXT: Distributed._distributedStubFatalError()
34+
// CHECK-NEXT: } else {
35+
// CHECK-NEXT: fatalError()
36+
// CHECK-NEXT: }
37+
// CHECK-NEXT: }
38+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)