Skip to content

Commit 24e204a

Browse files
committed
Clean up
1 parent d1705a5 commit 24e204a

File tree

8 files changed

+45
-42
lines changed

8 files changed

+45
-42
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ namespace swift {
109109
class VarDecl;
110110
class OpaqueReturnTypeRepr;
111111
class Witness;
112-
class MacroExpansionExpr;
113112

114113
namespace ast_scope {
115114
class AbstractPatternEntryScope;

include/swift/AST/FileUnit.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,13 @@ class FileUnit : public DeclContext, public ASTAllocated<FileUnit> {
210210
/// The order of the results is not guaranteed to be meaningful.
211211
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const {}
212212

213-
/// Finds all top-level decls in this file with all macros recursively
214-
/// expanded.
213+
/// Finds all top-level decls in this file with their auxiliary decls such as
214+
/// macro expansions.
215215
///
216216
/// This does a simple local lookup, not recursively looking through imports.
217217
/// The order of the results is not guaranteed to be meaningful.
218-
void getExpandedTopLevelDecls(SmallVectorImpl<Decl*> &results) const;
218+
void getTopLevelDeclsWithAuxiliaryDecls(
219+
SmallVectorImpl<Decl*> &results) const;
219220

220221
virtual void
221222
getExportedPrespecializations(SmallVectorImpl<Decl *> &results) const {}

lib/AST/Module.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,18 +3911,16 @@ void FileUnit::getTopLevelDeclsWhereAttributesMatch(
39113911
Results.erase(newEnd, Results.end());
39123912
}
39133913

3914-
void FileUnit::getExpandedTopLevelDecls(SmallVectorImpl<Decl*> &results) const {
3914+
void FileUnit::getTopLevelDeclsWithAuxiliaryDecls(
3915+
SmallVectorImpl<Decl*> &results) const {
39153916
SmallVector<Decl *, 32> nonExpandedDecls;
39163917
nonExpandedDecls.reserve(results.capacity());
39173918
getTopLevelDecls(nonExpandedDecls);
39183919
for (auto *decl : nonExpandedDecls) {
3919-
if (auto *med = dyn_cast<MacroExpansionDecl>(decl)) {
3920-
med->visitAuxiliaryDecls([&](Decl *decl) {
3921-
results.push_back(decl);
3922-
});
3923-
} else {
3924-
results.push_back(decl);
3925-
}
3920+
decl->visitAuxiliaryDecls([&](Decl *auxDecl) {
3921+
results.push_back(auxDecl);
3922+
});
3923+
results.push_back(decl);
39263924
}
39273925
}
39283926

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3727,8 +3727,7 @@ ASTWalker::PreWalkResult<Expr *> VarDeclUsageChecker::walkToExprPre(Expr *E) {
37273727
return Action::SkipChildren(E);
37283728
}
37293729

3730-
#warning "fix me"
3731-
// assert(AllExprsSeen.insert(E).second && "duplicate traversal");
3730+
assert(AllExprsSeen.insert(E).second && "duplicate traversal");
37323731

37333732
// If this is a DeclRefExpr found in a random place, it is a load of the
37343733
// vardecl.

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6133,7 +6133,7 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
61336133

61346134
// FIXME: Switch to a visitor interface?
61356135
SmallVector<Decl *, 32> fileDecls;
6136-
nextFile->getExpandedTopLevelDecls(fileDecls);
6136+
nextFile->getTopLevelDeclsWithAuxiliaryDecls(fileDecls);
61376137

61386138
for (auto D : fileDecls) {
61396139
if (isa<ImportDecl>(D) || isa<IfConfigDecl>(D) ||

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,8 @@ public struct DefineAnonymousTypesMacro: DeclarationMacro {
11771177
"""
11781178
11791179
class \(context.createUniqueName("name")) {
1180-
func hello() {
1180+
func hello() -> String {
1181+
\(body.statements)
11811182
}
11821183
}
11831184
""",
@@ -1187,7 +1188,8 @@ public struct DefineAnonymousTypesMacro: DeclarationMacro {
11871188
case apple
11881189
case banana
11891190
1190-
func hello() {
1191+
func hello() -> String {
1192+
\(body.statements)
11911193
}
11921194
}
11931195
"""

test/Macros/macro_expand.swift

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// UN: %empty-directory(%t)
2-
// UN: %target-build-swift -swift-version 5 -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath -swift-version 5
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -swift-version 5 -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath -swift-version 5
33
// RUNx: %target-swift-frontend -dump-ast -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser 2>&1 | %FileCheck --check-prefix CHECK-AST %s
44

55
// Diagnostics testing
@@ -12,14 +12,14 @@
1212

1313
// RUN: %FileCheck %s --check-prefix CHECK-MACRO-PRINTED < %t/macro-printing.txt
1414

15-
// FIXME(rdar://106053984) Debug info SIL testing (re-enable -g)
16-
// UN: %target-swift-frontend -swift-version 5 -emit-sil -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser -o - | %FileCheck --check-prefix CHECK-SIL %s
15+
// Debug info SIL testing
16+
// RUN: %target-swift-frontend -swift-version 5 -emit-sil -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser -o - -g | %FileCheck --check-prefix CHECK-SIL %s
1717

18-
// FIXME(rdar://106053984) Debug info IR testing (re-enable -g)
19-
// UN: %target-swift-frontend -swift-version 5 -emit-ir -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser -o - | %FileCheck --check-prefix CHECK-IR %s
18+
// Debug info IR testing
19+
// RUN: %target-swift-frontend -swift-version 5 -emit-ir -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir %s -module-name MacroUser -o - -g | %FileCheck --check-prefix CHECK-IR %s
2020

2121
// Execution testing
22-
// RUN: %target-build-swift -swift-version 5 -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -L %swift-host-lib-dir %s -o %t/main -module-name MacroUser
22+
// RUN: %target-build-swift -swift-version 5 -g -enable-experimental-feature FreestandingMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -L %swift-host-lib-dir %s -o %t/main -module-name MacroUser
2323
// RUN: %target-run %t/main | %FileCheck %s
2424
// REQUIRES: executable_test
2525

@@ -83,10 +83,10 @@ struct Bad {}
8383
func testFileID(a: Int, b: Int) {
8484
// CHECK: MacroUser/macro_expand.swift
8585
print("Result is \(#customFileID)")
86-
// HECK-SIL: sil_scope [[MACRO_SCOPE:[0-9]+]] { loc "{{.*}}":1:1 parent @$s9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_ {{.*}} }
87-
// HECK-SIL: sil_scope [[SRC_SCOPE:[0-9]+]] { loc "{{.*}}macro_expand.swift":[[@LINE-2]]
88-
// HECK-SIL: sil_scope {{[0-9]+}} { loc "{{.*}}":1:1 parent [[MACRO_SCOPE]] inlined_at [[SRC_SCOPE]] }
89-
// HECK-IR: !DISubprogram(name: "customFileID", linkageName: "$s9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_"
86+
// CHECK-SIL: sil_scope [[MACRO_SCOPE:[0-9]+]] { loc "{{.*}}":1:1 parent @$s9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_ {{.*}} }
87+
// CHECK-SIL: sil_scope [[SRC_SCOPE:[0-9]+]] { loc "{{.*}}macro_expand.swift":[[@LINE-2]]
88+
// CHECK-SIL: sil_scope {{[0-9]+}} { loc "{{.*}}":1:1 parent [[MACRO_SCOPE]] inlined_at [[SRC_SCOPE]] }
89+
// CHECK-IR: !DISubprogram(name: "customFileID", linkageName: "$s9MacroUser10testFileID1a1bySi_SitF06customdE0fMf_"
9090
9191
9292
// CHECK: Builtin result is MacroUser/macro_expand.swift
@@ -230,26 +230,32 @@ func testNestedDeclInExpr() {
230230
@freestanding(declaration, names: named(A), named(B), named(foo), named(addOne))
231231
macro defineDeclsWithKnownNames() = #externalMacro(module: "MacroDefinition", type: "DefineDeclsWithKnownNamesMacro")
232232

233-
//#bitwidthNumberedStructs("MyIntGlobal")
234-
//
235-
//#bitwidthNumberedStructs("MyIntGlobalTwo", blah: false)
236-
//
237-
//let blah = false
238-
//#bitwidthNumberedStructs("MyIntGlobalThree", blah: blah)
233+
// FIXME: Macros producing arbitrary names are not supported yet
234+
#if false
235+
#bitwidthNumberedStructs("MyIntGlobal")
236+
237+
#bitwidthNumberedStructs("MyIntGlobalTwo", blah: false)
238+
239+
let blah = false
240+
#bitwidthNumberedStructs("MyIntGlobalThree", blah: blah)
241+
#endif
239242

240243
// Test unqualified lookup from within a macro expansion
241244
@freestanding(declaration, names: named(StructWithUnqualifiedLookup))
242245
macro structWithUnqualifiedLookup() = #externalMacro(module: "MacroDefinition", type: "DefineStructWithUnqualifiedLookupMacro")
243-
let world = 3 // to be used by the macro expansion below
244-
#structWithUnqualifiedLookup()
245-
_ = StructWithUnqualifiedLookup().foo()
246246

247247
@freestanding(declaration)
248248
macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition", type: "DefineAnonymousTypesMacro")
249249

250-
#anonymousTypes { "hello" }
251250

252-
// CECK-SIL: $s9MacroUser14anonymousTypesfMf0_4namefMu_
251+
// FIXME: Global freestanding macros not yet supported in script mode.
252+
#if false
253+
let world = 3 // to be used by the macro expansion below
254+
#structWithUnqualifiedLookup()
255+
_ = StructWithUnqualifiedLookup().foo()
256+
257+
#anonymousTypes { "hello" }
258+
#endif
253259

254260
func testFreestandingMacroExpansion() {
255261
// Explicit structs to force macros to be parsed as decl.
@@ -309,7 +315,5 @@ func testFreestandingMacroExpansion() {
309315
// print(MyIntGlobal64.self)
310316

311317
#anonymousTypes { "hello" }
312-
// expected-note @-1 2 {{in expansion of macro 'anonymousTypes' here}}
313-
// HECK-SIL: $s9MacroUser016testFreestandingA9ExpansionyyF14anonymousTypesfMf1_4namefMu_
314318
}
315319
testFreestandingMacroExpansion()

test/Macros/macro_expand_synthesized_members.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public macro ExtendableEnum() = #externalMacro(module: "MacroDefinition", type:
7474

7575
@ExtendableEnum
7676
enum ElementType {
77-
case paper
77+
case paper
7878
}
7979

8080
print(ElementType.paper.unknown())

0 commit comments

Comments
 (0)