Skip to content

[Macros] Recognize the $e Embedded Swift prefix in MacroDecl::isUniqueMacroName #79403

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 1 commit into from
Feb 24, 2025
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
4 changes: 2 additions & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12071,8 +12071,8 @@ bool MacroDecl::isUniqueNamePlaceholder(DeclName name) {
}

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

// Unique macro names end with fMu<digits>_. Match that.
Expand Down
34 changes: 34 additions & 0 deletions test/Macros/macro_unique_name_embedded.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_Embedded
// REQUIRES: OS=macosx

// RUN: %empty-directory(%t)
// RUN: split-file --leading-lines %s %t

// Create the plugin
// 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

// RUN: %target-swift-frontend -typecheck -swift-version 5 -load-plugin-library %t/%target-library-name(MacroPlugin) -module-name TestModule %t/TestModule.swift \
// RUN: -enable-experimental-feature Embedded -wmo -target arm64-apple-macos14

//--- MacroPlugin.swift
import SwiftSyntax
import SwiftSyntaxBuilder
import SwiftSyntaxMacros

public struct AddMemberMacro: PeerMacro {
public static func expansion(of node: AttributeSyntax, providingPeersOf declaration: some DeclSyntaxProtocol, in context: some MacroExpansionContext) throws -> [DeclSyntax] {
return [
"""
func \(context.makeUniqueName("foo"))() { }
"""
]
}
}

//--- TestModule.swift
@attached(peer)
public macro AddMember() = #externalMacro(module: "MacroPlugin", type: "AddMemberMacro")

@AddMember
struct TestStruct { }