Skip to content

Commit 874c625

Browse files
authored
Merge pull request #79403 from kubamracek/embedded-unique-macro-names
[Macros] Recognize the $e Embedded Swift prefix in MacroDecl::isUniqueMacroName
2 parents 1e4cec9 + e037aaa commit 874c625

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12110,8 +12110,8 @@ bool MacroDecl::isUniqueNamePlaceholder(DeclName name) {
1211012110
}
1211112111

1211212112
bool MacroDecl::isUniqueMacroName(StringRef name) {
12113-
// Unique macro names are mangled names, which always start with "$s".
12114-
if (!name.starts_with("$s"))
12113+
// Unique macro names are mangled names, which always start with "$s" or "$e".
12114+
if (!name.starts_with("$s") && !name.starts_with("$e"))
1211512115
return false;
1211612116

1211712117
// Unique macro names end with fMu<digits>_. Match that.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// REQUIRES: swift_swift_parser
2+
// REQUIRES: swift_feature_Embedded
3+
// REQUIRES: OS=macosx
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: split-file --leading-lines %s %t
7+
8+
// Create the plugin
9+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroPlugin) -module-name=MacroPlugin %t/MacroPlugin.swift -g -no-toolchain-stdlib-rpath
10+
11+
// RUN: %target-swift-frontend -typecheck -swift-version 5 -load-plugin-library %t/%target-library-name(MacroPlugin) -module-name TestModule %t/TestModule.swift \
12+
// RUN: -enable-experimental-feature Embedded -wmo -target arm64-apple-macos14
13+
14+
//--- MacroPlugin.swift
15+
import SwiftSyntax
16+
import SwiftSyntaxBuilder
17+
import SwiftSyntaxMacros
18+
19+
public struct AddMemberMacro: PeerMacro {
20+
public static func expansion(of node: AttributeSyntax, providingPeersOf declaration: some DeclSyntaxProtocol, in context: some MacroExpansionContext) throws -> [DeclSyntax] {
21+
return [
22+
"""
23+
func \(context.makeUniqueName("foo"))() { }
24+
"""
25+
]
26+
}
27+
}
28+
29+
//--- TestModule.swift
30+
@attached(peer)
31+
public macro AddMember() = #externalMacro(module: "MacroPlugin", type: "AddMemberMacro")
32+
33+
@AddMember
34+
struct TestStruct { }

0 commit comments

Comments
 (0)