Skip to content

Commit ec32339

Browse files
always use the argNames constructor for macro DeclNames
rdar://110179186
1 parent 5ae4d69 commit ec32339

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,14 +4793,10 @@ class DeclDeserializer {
47934793

47944794
// Resolve the name ids.
47954795
DeclName name;
4796-
if (numArgNames > 0) {
4797-
SmallVector<Identifier, 2> argNames;
4798-
for (auto argNameID : argNameAndDependencyIDs.slice(0, numArgNames))
4799-
argNames.push_back(MF.getIdentifier(argNameID));
4800-
name = DeclName(ctx, baseName, argNames);
4801-
} else {
4802-
name = baseName;
4803-
}
4796+
SmallVector<Identifier, 2> argNames;
4797+
for (auto argNameID : argNameAndDependencyIDs.slice(0, numArgNames))
4798+
argNames.push_back(MF.getIdentifier(argNameID));
4799+
name = DeclName(ctx, baseName, argNames);
48044800
PrettySupplementalDeclNameTrace trace(name);
48054801

48064802
argNameAndDependencyIDs = argNameAndDependencyIDs.slice(numArgNames);

test/SymbolGraph/Symbols/Mixins/DeclarationFragments/Full/Macros.swift

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@
66
// RUN: %target-swift-frontend -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) %s -module-name Macros -emit-module -emit-module-path %t/Macros.swiftmodule -emit-symbol-graph -emit-symbol-graph-dir %t/
77
// RUN: %{python} -m json.tool %t/Macros.symbols.json %t/Macros.formatted.symbols.json
88

9-
// Make sure that the `= #externalMacro(...)` doesn't show up in declaration fragments and in names fragments.
9+
// Make sure that the `= #externalMacro(...)` doesn't show up in declaration fragments and in names
10+
// fragments, and also that macros with no parameters get the `()` in their name.
1011

1112
// RUN: %FileCheck %s --input-file %t/Macros.formatted.symbols.json
1213
// RUN: %FileCheck %s --input-file %t/Macros.formatted.symbols.json --check-prefix NAMES
14+
// RUN: %FileCheck %s --input-file %t/Macros.formatted.symbols.json --check-prefix TITLE
1315

16+
// Now do the same thing with a `swift-symbolgraph-extract`-processed symbol graph.
17+
18+
// RUN: %empty-directory(%t)
19+
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/stringify_macro.swift -g -no-toolchain-stdlib-rpath -swift-version 5
20+
// RUN: %target-swift-frontend -load-plugin-library %t/%target-library-name(MacroDefinition) %s -module-name Macros -emit-module -emit-module-path %t/Macros.swiftmodule
21+
// RUN: %target-swift-symbolgraph-extract -module-name Macros -I %t -pretty-print -output-dir %t
22+
23+
// RUN: %FileCheck %s --input-file %t/Macros.symbols.json
24+
// RUN: %FileCheck %s --input-file %t/Macros.symbols.json --check-prefix NAMES
25+
// RUN: %FileCheck %s --input-file %t/Macros.symbols.json --check-prefix TITLE
1426

1527
@freestanding(expression) public macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro")
1628

29+
@freestanding(expression) public macro stringifySeven() -> (Int, String) = #stringify(7)
30+
31+
// Note that type parameters don't have reference USRs when loading from serialized AST, so the
32+
// following declaration/names dumps are edited to handle both situations.
33+
34+
// CHECK-LABEL: "precise": "s:6Macros9stringifyyx_SStxclufm",
1735
// CHECK: "declarationFragments": [
1836
// CHECK-NEXT: {
1937
// CHECK-NEXT: "kind": "attribute",
@@ -65,18 +83,16 @@
6583
// CHECK-NEXT: },
6684
// CHECK-NEXT: {
6785
// CHECK-NEXT: "kind": "typeIdentifier",
68-
// CHECK-NEXT: "spelling": "T",
69-
// CHECK-NEXT: "preciseIdentifier": "s:6Macros1TL_xmfp"
70-
// CHECK-NEXT: },
86+
// CHECK-NEXT: "spelling": "T"
87+
// CHECK: },
7188
// CHECK-NEXT: {
7289
// CHECK-NEXT: "kind": "text",
7390
// CHECK-NEXT: "spelling": ") -> ("
7491
// CHECK-NEXT: },
7592
// CHECK-NEXT: {
7693
// CHECK-NEXT: "kind": "typeIdentifier",
77-
// CHECK-NEXT: "spelling": "T",
78-
// CHECK-NEXT: "preciseIdentifier": "s:6Macros1TL_xmfp"
79-
// CHECK-NEXT: },
94+
// CHECK-NEXT: "spelling": "T"
95+
// CHECK: },
8096
// CHECK-NEXT: {
8197
// CHECK-NEXT: "kind": "text",
8298
// CHECK-NEXT: "spelling": ", "
@@ -92,6 +108,7 @@
92108
// CHECK-NEXT: }
93109
// CHECK-NEXT: ],
94110

111+
// NAMES-LABEL: "precise": "s:6Macros9stringifyyx_SStxclufm",
95112
// NAMES: "names": {
96113
// NAMES-NEXT: "title": "stringify(_:)",
97114
// NAMES-NEXT: "subHeading": [
@@ -121,18 +138,16 @@
121138
// NAMES-NEXT: },
122139
// NAMES-NEXT: {
123140
// NAMES-NEXT: "kind": "typeIdentifier",
124-
// NAMES-NEXT: "spelling": "T",
125-
// NAMES-NEXT: "preciseIdentifier": "s:6Macros1TL_xmfp"
126-
// NAMES-NEXT: },
141+
// NAMES-NEXT: "spelling": "T"
142+
// NAMES: },
127143
// NAMES-NEXT: {
128144
// NAMES-NEXT: "kind": "text",
129145
// NAMES-NEXT: "spelling": ") -> ("
130146
// NAMES-NEXT: },
131147
// NAMES-NEXT: {
132148
// NAMES-NEXT: "kind": "typeIdentifier",
133-
// NAMES-NEXT: "spelling": "T",
134-
// NAMES-NEXT: "preciseIdentifier": "s:6Macros1TL_xmfp"
135-
// NAMES-NEXT: },
149+
// NAMES-NEXT: "spelling": "T"
150+
// NAMES: },
136151
// NAMES-NEXT: {
137152
// NAMES-NEXT: "kind": "text",
138153
// NAMES-NEXT: "spelling": ", "
@@ -148,3 +163,6 @@
148163
// NAMES-NEXT: }
149164
// NAMES-NEXT: ]
150165
// NAMES-NEXT: },
166+
167+
// TITLE-LABEL: "precise": "s:6Macros14stringifySevenSi_SStycfm",
168+
// TITLE: "title": "stringifySeven()",

0 commit comments

Comments
 (0)