Test printing of declarations created by macros on imported decls

This commit is contained in:
Doug Gregor
2024-09-16 14:53:25 -07:00
parent cdcabd05bd
commit f255cf6922
6 changed files with 35 additions and 6 deletions

View File

@@ -38,12 +38,12 @@ enum class IntermoduleDepTrackingMode;
/// Options for controlling the behavior of the frontend.
class FrontendOptions {
friend class ArgsToFrontendOptionsConverter;
public:
/// A list of arbitrary modules to import and make implicitly visible.
std::vector<std::pair<std::string, bool /*testable*/>>
ImplicitImportModuleNames;
public:
FrontendInputsAndOutputs InputsAndOutputs;
void forAllOutputPaths(const InputFile &input,

View File

@@ -1,2 +1,2 @@
void async_divide(double x, double y, void (* _Nonnull completionHandler)(double x))
__attribute__((swift_attr("@ModuleUser.AddAsync")));
__attribute__((swift_attr("@macro_library.AddAsync")));

View File

@@ -53,3 +53,6 @@ public struct declareVarValuePeerShadowed {
@attached(peer, names: named(value))
public macro declareVarValuePeerShadowed() = #externalMacro(module: "MacroDefinition", type: "VarValueMacro")
@attached(peer, names: overloaded)
public macro AddAsync() = #externalMacro(module: "MacroDefinition", type: "AddAsyncMacro")

View File

@@ -3,13 +3,14 @@
// RUN: %empty-directory(%t)
// 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
// Diagnostics testing
// 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
// Build the macro library to give us access to AddAsync.
// 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)
@attached(peer, names: overloaded)
public macro AddAsync() = #externalMacro(module: "MacroDefinition", type: "AddAsyncMacro")
// Diagnostics testing
// 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
import CompletionHandlerGlobals
import macro_library
// Make sure that @AddAsync works at all.
@AddAsync

View File

@@ -0,0 +1,16 @@
// REQUIRES: swift_swift_parser, executable_test
// RUN: %empty-directory(%t)
// 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
// Build the macro library to give us access to AddAsync.
// 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)
// 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
// RUN: %FileCheck -input-file %t/imported.printed.txt %s
import CompletionHandlerGlobals
// CHECK: func async_divide(_ x: Double, _ y: Double, _ completionHandler: @convention(c) (Double) -> Void)
// CHECK: func async_divide(_ x: Double, _ y: Double) async -> Double

View File

@@ -262,6 +262,10 @@ SecondSourceFilename("second-source-filename",
llvm::cl::desc("Name of the second source file"),
llvm::cl::cat(Category));
static llvm::cl::list<std::string>
ImplicitModuleImports("import-module", llvm::cl::desc("Force import of named modules"),
llvm::cl::cat(Category));
static llvm::cl::list<std::string>
InputFilenames(llvm::cl::Positional, llvm::cl::desc("[input files...]"),
llvm::cl::ZeroOrMore, llvm::cl::cat(Category));
@@ -4585,6 +4589,11 @@ int main(int argc, char *argv[]) {
}
InitInvok.setDefaultInProcessPluginServerPathIfNecessary();
for (auto implicitImport : options::ImplicitModuleImports) {
InitInvok.getFrontendOptions().ImplicitImportModuleNames.emplace_back(
implicitImport, /*isTestable=*/false);
}
// Process the clang arguments last and allow them to override previously
// set options.
if (!CCArgs.empty()) {