Skip to content

Commit 70980b9

Browse files
committed
Add experimental feature MacrosOnImporters for applying macro to imported decl
This is still very much experimental and we don't want to accidentally enable it everywhere.
1 parent 5fb8b5f commit 70980b9

File tree

7 files changed

+8
-5
lines changed

7 files changed

+8
-5
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ EXPERIMENTAL_FEATURE(NamedOpaqueTypes, false)
230230
EXPERIMENTAL_FEATURE(FlowSensitiveConcurrencyCaptures, false)
231231
EXPERIMENTAL_FEATURE(CodeItemMacros, false)
232232
EXPERIMENTAL_FEATURE(PreambleMacros, false)
233+
EXPERIMENTAL_FEATURE(MacrosOnImports, true)
233234
EXPERIMENTAL_FEATURE(TupleConformances, false)
234235
EXPERIMENTAL_FEATURE(FullTypedThrows, false)
235236
EXPERIMENTAL_FEATURE(SameElementRequirements, false)

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ UNINTERESTING_FEATURE(Embedded)
121121
UNINTERESTING_FEATURE(Volatile)
122122
UNINTERESTING_FEATURE(SuppressedAssociatedTypes)
123123
UNINTERESTING_FEATURE(StructLetDestructuring)
124+
UNINTERESTING_FEATURE(MacrosOnImports)
124125

125126
static bool usesFeatureNonescapableTypes(Decl *decl) {
126127
auto containsNonEscapable =

lib/AST/NameLookup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,8 @@ SmallVector<MacroDecl *, 1> namelookup::lookupMacros(DeclContext *dc,
17221722

17231723
// When resolving macro names for imported entities, we look for any
17241724
// loaded module.
1725-
if (!moduleDecl && isa<ClangModuleUnit>(moduleScopeDC)) {
1725+
if (!moduleDecl && isa<ClangModuleUnit>(moduleScopeDC) &&
1726+
ctx.LangOpts.hasFeature(Feature::MacrosOnImports)) {
17261727
moduleDecl = ctx.getLoadedModule(moduleName.getBaseIdentifier());
17271728
moduleScopeDC = moduleDecl;
17281729
}

test/Macros/expand_on_imported.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/macro_library.swiftmodule %S/Inputs/macro_library.swift -module-name macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
88

99
// Diagnostics testing
10-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -swift-version 5 -enable-experimental-feature CodeItemMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name ModuleUser %s -I %t
10+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -swift-version 5 -enable-experimental-feature MacrosOnImports -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name ModuleUser %s -I %t
1111

1212
import CompletionHandlerGlobals
1313
import macro_library

test/Macros/expand_on_imported_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/macro_library.swiftmodule %S/Inputs/macro_library.swift -module-name macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
88

99
// Diagnostics testing
10-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -swift-version 5 -enable-experimental-feature CodeItemMacros -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name ModuleUser %s -I %t
10+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify -swift-version 5 -enable-experimental-feature MacrosOnImports -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name ModuleUser %s -I %t
1111

1212
import CompletionHandlerGlobals
1313
import macro_library

test/Macros/print_clang_expand_on_imported.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Build the macro library to give us access to AddAsync.
77
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/macro_library.swiftmodule %S/Inputs/macro_library.swift -module-name macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
88

9-
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -print-implicit-attrs -source-filename %s -module-to-print=CompletionHandlerGlobals -I %t -function-definitions=false -load-plugin-library %t/%target-library-name(MacroDefinition) -import-module macro_library > %t/imported.printed.txt
9+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -print-implicit-attrs -source-filename %s -module-to-print=CompletionHandlerGlobals -I %t -function-definitions=false -load-plugin-library %t/%target-library-name(MacroDefinition) -import-module macro_library -enable-experimental-feature MacrosOnImports > %t/imported.printed.txt
1010
// RUN: %FileCheck -input-file %t/imported.printed.txt %s
1111

1212
import CompletionHandlerGlobals

test/Macros/print_clang_expand_on_imported_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Build the macro library to give us access to AddAsync.
77
// RUN: %target-swift-frontend -swift-version 5 -emit-module -o %t/macro_library.swiftmodule %S/Inputs/macro_library.swift -module-name macro_library -load-plugin-library %t/%target-library-name(MacroDefinition)
88

9-
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -print-implicit-attrs -source-filename %s -module-to-print=CompletionHandlerGlobals -I %t -function-definitions=false -load-plugin-library %t/%target-library-name(MacroDefinition) -import-module macro_library > %t/imported.printed.txt
9+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -print-implicit-attrs -source-filename %s -module-to-print=CompletionHandlerGlobals -I %t -function-definitions=false -load-plugin-library %t/%target-library-name(MacroDefinition) -import-module macro_library -enable-experimental-feature MacrosOnImports > %t/imported.printed.txt
1010
// RUN: %FileCheck -input-file %t/imported.printed.txt %s
1111

1212
import CompletionHandlerGlobals

0 commit comments

Comments
 (0)