Skip to content

Commit f255cf6

Browse files
committed
Test printing of declarations created by macros on imported decls
1 parent cdcabd0 commit f255cf6

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

include/swift/Frontend/FrontendOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ enum class IntermoduleDepTrackingMode;
3838
/// Options for controlling the behavior of the frontend.
3939
class FrontendOptions {
4040
friend class ArgsToFrontendOptionsConverter;
41+
public:
4142

4243
/// A list of arbitrary modules to import and make implicitly visible.
4344
std::vector<std::pair<std::string, bool /*testable*/>>
4445
ImplicitImportModuleNames;
4546

46-
public:
4747
FrontendInputsAndOutputs InputsAndOutputs;
4848

4949
void forAllOutputPaths(const InputFile &input,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x))
2-
__attribute__((swift_attr("@ModuleUser.AddAsync")));
2+
__attribute__((swift_attr("@macro_library.AddAsync")));

test/Macros/Inputs/macro_library.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ public struct declareVarValuePeerShadowed {
5353

5454
@attached(peer, names: named(value))
5555
public macro declareVarValuePeerShadowed() = #externalMacro(module: "MacroDefinition", type: "VarValueMacro")
56+
57+
@attached(peer, names: overloaded)
58+
public macro AddAsync() = #externalMacro(module: "MacroDefinition", type: "AddAsyncMacro")

test/Macros/expand_on_imported.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
// RUN: %empty-directory(%t)
44
// RUN: %host-build-swift -swift-version 5 -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
55

6-
// Diagnostics testing
7-
// 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
6+
// Build the macro library to give us access to AddAsync.
7+
// 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-
@attached(peer, names: overloaded)
10-
public macro AddAsync() = #externalMacro(module: "MacroDefinition", type: "AddAsyncMacro")
9+
// 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
1111

1212
import CompletionHandlerGlobals
13+
import macro_library
1314

1415
// Make sure that @AddAsync works at all.
1516
@AddAsync
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// REQUIRES: swift_swift_parser, executable_test
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %host-build-swift -swift-version 5 -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
5+
6+
// Build the macro library to give us access to AddAsync.
7+
// 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)
8+
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
10+
// RUN: %FileCheck -input-file %t/imported.printed.txt %s
11+
12+
import CompletionHandlerGlobals
13+
14+
// CHECK: func async_divide(_ x: Double, _ y: Double, _ completionHandler: @convention(c) (Double) -> Void)
15+
// CHECK: func async_divide(_ x: Double, _ y: Double) async -> Double
16+

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ SecondSourceFilename("second-source-filename",
262262
llvm::cl::desc("Name of the second source file"),
263263
llvm::cl::cat(Category));
264264

265+
static llvm::cl::list<std::string>
266+
ImplicitModuleImports("import-module", llvm::cl::desc("Force import of named modules"),
267+
llvm::cl::cat(Category));
268+
265269
static llvm::cl::list<std::string>
266270
InputFilenames(llvm::cl::Positional, llvm::cl::desc("[input files...]"),
267271
llvm::cl::ZeroOrMore, llvm::cl::cat(Category));
@@ -4585,6 +4589,11 @@ int main(int argc, char *argv[]) {
45854589
}
45864590
InitInvok.setDefaultInProcessPluginServerPathIfNecessary();
45874591

4592+
for (auto implicitImport : options::ImplicitModuleImports) {
4593+
InitInvok.getFrontendOptions().ImplicitImportModuleNames.emplace_back(
4594+
implicitImport, /*isTestable=*/false);
4595+
}
4596+
45884597
// Process the clang arguments last and allow them to override previously
45894598
// set options.
45904599
if (!CCArgs.empty()) {

0 commit comments

Comments
 (0)