Skip to content

Commit 44be113

Browse files
authored
Merge pull request #64944 from DougGregor/sil-symbol-visitor-aux-decls-5.9
2 parents 4be3c18 + dff4726 commit 44be113

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
390390
void visit(FileUnit *file) {
391391
auto visitFile = [this](FileUnit *file) {
392392
SmallVector<Decl *, 16> decls;
393-
file->getTopLevelDecls(decls);
393+
file->getTopLevelDeclsWithAuxiliaryDecls(decls);
394394

395395
addMainIfNecessary(file);
396396

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,20 @@ public struct DefineStructWithUnqualifiedLookupMacro: DeclarationMacro {
12591259
}
12601260
}
12611261

1262+
extension TupleExprElementListSyntax {
1263+
/// Retrieve the first element with the given label.
1264+
func first(labeled name: String) -> Element? {
1265+
return first { element in
1266+
if let label = element.label, label.text == name {
1267+
return true
1268+
}
1269+
1270+
return false
1271+
}
1272+
}
1273+
}
1274+
1275+
12621276
public struct DefineAnonymousTypesMacro: DeclarationMacro {
12631277
public static func expansion(
12641278
of node: some FreestandingMacroExpansionSyntax,
@@ -1267,13 +1281,22 @@ public struct DefineAnonymousTypesMacro: DeclarationMacro {
12671281
guard let body = node.trailingClosure else {
12681282
throw CustomError.message("#anonymousTypes macro requires a trailing closure")
12691283
}
1284+
1285+
let accessSpecifier: String
1286+
if let _ = node.argumentList.first(labeled: "public") {
1287+
accessSpecifier = "public "
1288+
} else {
1289+
accessSpecifier = ""
1290+
}
12701291
return [
12711292
"""
12721293
1273-
class \(context.makeUniqueName("name")) {
1274-
func hello() -> String {
1294+
\(raw:accessSpecifier)class \(context.makeUniqueName("name")) {
1295+
\(raw:accessSpecifier)func hello() -> String {
12751296
\(body.statements)
12761297
}
1298+
1299+
\(raw:accessSpecifier)func getSelf() -> Any.Type { return Self.self }
12771300
}
12781301
""",
12791302
"""

test/Macros/top_level_freestanding.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func lookupGlobalFreestandingExpansion() {
2525
}
2626

2727
@freestanding(declaration)
28-
macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition", type: "DefineAnonymousTypesMacro")
28+
macro anonymousTypes(public: Bool = false, _: () -> String) = #externalMacro(module: "MacroDefinition", type: "DefineAnonymousTypesMacro")
2929

30-
#anonymousTypes { "hello" }
30+
#anonymousTypes(public: true) { "hello" }
3131

32-
// CHECK-SIL: sil hidden @$s9MacroUser03$s9A71User33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_4namefMu_C5helloSSyF
32+
// CHECK-SIL: sil @$s9MacroUser03$s9A71User33_082AE7CFEFA6960C804A9FE7366EB5A0Ll14anonymousTypesfMf0_4namefMu_C5helloSSyF
3333

3434
@main
3535
struct Main {

test/SourceKit/Macros/macro_basic.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition"
131131
// EXPAND_MACRO_DECL-NEXT: func hello() -> String {
132132
// EXPAND_MACRO_DECL-NEXT: "hello"
133133
// EXPAND_MACRO_DECL-NEXT: }
134+
// EXPAND_MACRO_DECL: func getSelf() -> Any.Type { return Self.self }
134135
// EXPAND_MACRO_DECL-NEXT: }
135136
// EXPAND_MACRO_DECL-NEXT: enum $s9MacroUser33_70D4178875715FB9B8B50C58F66F8D53Ll14anonymousTypesfMf0_4namefMu0_ {
136137
// EXPAND_MACRO_DECL-NEXT: case apple

0 commit comments

Comments
 (0)