Skip to content

Commit be2466c

Browse files
committed
Updates for new freestanding macro discriminators
1 parent b31133e commit be2466c

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

lib/AST/ASTVerifier.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,10 @@ class Verifier : public ASTWalker {
24722472
}
24732473

24742474
void verifyChecked(MacroExpansionExpr *expansion) {
2475+
// If there is a substitute decl, we'll end up checking that instead.
2476+
if (expansion->getSubstituteDecl())
2477+
return;
2478+
24752479
MacroExpansionDiscriminatorKey key{
24762480
MacroDiscriminatorContext::getParentOf(expansion).getOpaqueValue(),
24772481
expansion->getMacroName().getBaseName().getIdentifier()

test/Macros/freestanding_multifile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ macro anonymousTypes(public: Bool, _: () -> String) = #externalMacro(module: "Ma
1111
// CHECK-IR: $s9MacroUser33{{.*}}14anonymousTypesfMf_4namefMu_
1212
// CHECK-IR-NOT: $s9MacroUser33{{.*}}14anonymousTypesfMf0_4namefMu_
1313
// CHECK-IR: $s9MacroUser33{{.*}}14anonymousTypesfMf_4namefMu_
14-
// CHECK-IR: $s9MacroUser33{{.*}}14anonymousTypesfMf0_4namefMu_
14+
// CHECK-IR-NOT: $s9MacroUser33{{.*}}14anonymousTypesfMf0_4namefMu_

test/Macros/macro_expand.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct MemberNotCovered {
7171
// expected-note@-1 {{in expansion of macro 'NotCovered' here}}
7272

7373
// CHECK-DIAGS: error: declaration name 'value' is not covered by macro 'NotCovered'
74-
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser16MemberNotCoveredV33_4361AD9339943F52AE6186DD51E04E91Ll0dE0fMf0_.swift
74+
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser16MemberNotCoveredV33_4361AD9339943F52AE6186DD51E04E91Ll0dE0fMf_.swift
7575
// CHECK-DIAGS: var value: Int
7676
// CHECK-DIAGS: END CONTENTS OF FILE
7777
}
@@ -137,7 +137,7 @@ macro AccidentalCodeItem() = #externalMacro(module: "MacroDefinition", type: "Fa
137137
func invalidDeclarationMacro() {
138138
#accidentalCodeItem
139139
// expected-note@-1 {{in expansion of macro 'accidentalCodeItem' here}}
140-
// CHECK-DIAGS: @__swiftmacro_9MacroUser018invalidDeclarationA0yyF18accidentalCodeItemfMf0_.swift:1:1: error: expected macro expansion to produce a declaration
140+
// CHECK-DIAGS: @__swiftmacro_9MacroUser018invalidDeclarationA0yyF18accidentalCodeItemfMf_.swift:1:1: error: expected macro expansion to produce a declaration
141141

142142
@AccidentalCodeItem struct S {}
143143
// expected-note@-1 {{in expansion of macro 'AccidentalCodeItem' on struct 'S' here}}
@@ -373,7 +373,7 @@ func testNestedDeclInExpr() {
373373
macro defineDeclsWithKnownNames() = #externalMacro(module: "MacroDefinition", type: "DefineDeclsWithKnownNamesMacro")
374374

375375
// Freestanding macros are not in inlined scopes.
376-
// CHECK-SIL: sil_scope {{.*}} { loc "@__swiftmacro_9MacroUser016testFreestandingA9ExpansionyyF4Foo2L_V25defineDeclsWithKnownNamesfMf0_.swift"{{.*}} -> Int }
376+
// CHECK-SIL: sil_scope {{.*}} { loc "@__swiftmacro_9MacroUser016testFreestandingA9ExpansionyyF4Foo2L_V25defineDeclsWithKnownNamesfMf_.swift"{{.*}} -> Int }
377377

378378
// FIXME: Macros producing arbitrary names are not supported yet
379379
#if false
@@ -436,10 +436,10 @@ func testFreestandingMacroExpansion() {
436436
struct Foo3 {
437437
#bitwidthNumberedStructs("BUG", blah: false)
438438
// expected-note@-1 4{{in expansion of macro 'bitwidthNumberedStructs' here}}
439-
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf0_.swift
439+
// CHECK-DIAGS: CONTENTS OF FILE @__swiftmacro_9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf_.swift
440440
// CHECK-DIAGS: struct BUG {
441-
// CHECK-DIAGS: func $s9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf0_6methodfMu_()
442-
// CHECK-DIAGS: func $s9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf0_6methodfMu0{{_?}}()
441+
// CHECK-DIAGS: func $s9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf_6methodfMu_()
442+
// CHECK-DIAGS: func $s9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf_6methodfMu0{{_?}}()
443443
}
444444
#endif
445445

test/Macros/macro_expand_codeitems.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func testFreestandingMacroExpansion() {
2121
// CHECK: from stmt
2222
// CHECK: from usedInExpandedStmt
2323
// CHECK: from expr
24-
// CHECK-DIAGS: struct $s9MacroUser016testFreestandingA9ExpansionyyF9codeItemsfMf0_3foofMu_ {
24+
// CHECK-DIAGS: struct $s9MacroUser016testFreestandingA9ExpansionyyF9codeItemsfMf_3foofMu_ {
2525
// CHECK-DIAGS: END CONTENTS OF FILE
2626
#codeItems
2727

test/Macros/top_level_freestanding.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func testGlobalVariable() {
9797

9898
// expected-note @+1 6 {{in expansion of macro 'anonymousTypes' here}}
9999
#anonymousTypes(causeErrors: true) { "foo" }
100-
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser33{{.*}}anonymousTypesfMf2_{{.*}}error: use of protocol 'Equatable' as a type must be written 'any Equatable'
101-
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser03{{.*}}anonymousTypes{{.*}}introduceTypeCheckingErrorsfMf0_{{.*}}error: use of protocol 'Hashable' as a type must be written 'any Hashable'
100+
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser33{{.*}}anonymousTypesfMf0_{{.*}}error: use of protocol 'Equatable' as a type must be written 'any Equatable'
101+
// DIAG_BUFFERS-DAG: @__swiftmacro_9MacroUser03{{.*}}anonymousTypes{{.*}}introduceTypeCheckingErrorsfMf_{{.*}}error: use of protocol 'Hashable' as a type must be written 'any Hashable'
102102

103103
// expected-note @+1 2 {{in expansion of macro 'anonymousTypes' here}}
104104
#anonymousTypes { () -> String in

test/SourceKit/Macros/macro_semantic_token.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ macro anonymousTypes(_: () -> String) = #externalMacro(module: "MacroDefinition"
1212
// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/../../Macros/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath
1313

1414
// Check the output of the the `#anonymousTypes` macro
15-
// RUN: %sourcekitd-test -req=semantic-tokens @__swiftmacro_9MacroUser33_8C2BB8A10AE555140C0EDFDEB4A9572DLl14anonymousTypesfMf0_.swift -primary-file %s -- -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser %s | %FileCheck %s --check-prefix IN_BUFFER
15+
// RUN: %sourcekitd-test -req=semantic-tokens @__swiftmacro_9MacroUser33_8C2BB8A10AE555140C0EDFDEB4A9572DLl14anonymousTypesfMf_.swift -primary-file %s -- -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser %s | %FileCheck %s --check-prefix IN_BUFFER
1616

1717
// Check that we get some semantic tokens. Checking exact offsets is brittle.
1818
// IN_BUFFER: source.lang.swift.ref.struct

0 commit comments

Comments
 (0)