Skip to content

Commit 2328132

Browse files
authored
Merge pull request #34832 from xymus/rmodule-loading
[Frontend] Intro flag to remark on loaded modules location
2 parents 87c9cd8 + 92a1615 commit 2328132

File tree

6 files changed

+32
-0
lines changed

6 files changed

+32
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,10 @@ REMARK(cross_import_added,none,
908908
"import of %0 and %1 triggered a cross-import of %2",
909909
(Identifier, Identifier, Identifier))
910910

911+
REMARK(module_loaded,none,
912+
"loaded module at %0",
913+
(StringRef))
914+
911915
// Operator decls
912916
ERROR(ambiguous_operator_decls,none,
913917
"ambiguous operator declarations found for operator", ())

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ namespace swift {
129129
/// overlay.
130130
bool EnableCrossImportRemarks = false;
131131

132+
/// Emit a remark after loading a module.
133+
bool EnableModuleLoadingRemarks = false;
134+
132135
///
133136
/// Support for alternate usage modes
134137
///

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ def emit_cross_import_remarks : Flag<["-"], "Rcross-import">,
336336
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
337337
HelpText<"Emit a remark if a cross-import of a module is triggered.">;
338338

339+
def remark_loading_module : Flag<["-"], "Rmodule-loading">,
340+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
341+
HelpText<"Emit a remark and file path of each loaded module">;
342+
339343
def emit_tbd : Flag<["-"], "emit-tbd">,
340344
HelpText<"Emit a TBD file">,
341345
Flags<[FrontendOption, NoInteractiveOption, SupplementaryOutput]>;

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,6 +1921,11 @@ ASTContext::getModule(ImportPath::Module ModulePath) {
19211921
auto moduleID = ModulePath[0];
19221922
for (auto &importer : getImpl().ModuleLoaders) {
19231923
if (ModuleDecl *M = importer->loadModule(moduleID.Loc, ModulePath)) {
1924+
if (LangOpts.EnableModuleLoadingRemarks) {
1925+
Diags.diagnose(ModulePath.getSourceRange().Start,
1926+
diag::module_loaded,
1927+
M->getModuleFilename());
1928+
}
19241929
return M;
19251930
}
19261931
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
577577

578578
Opts.EnableCrossImportRemarks = Args.hasArg(OPT_emit_cross_import_remarks);
579579

580+
Opts.EnableModuleLoadingRemarks = Args.hasArg(OPT_remark_loading_module);
581+
580582
llvm::Triple Target = Opts.Target;
581583
StringRef TargetArg;
582584
std::string TargetArgScratch;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// Test the -Rmodule-loading flag.
2+
// RUN: %empty-directory(%t)
3+
4+
/// Create a simple module and interface.
5+
// RUN: echo 'public func publicFunction() {}' > %t/TestModule.swift
6+
// RUN: %target-swift-frontend -typecheck %t/TestModule.swift -emit-module-interface-path %t/TestModule.swiftinterface -swift-version 5
7+
8+
/// Use -Rmodule-loading in a client and look for the diagnostics output.
9+
// RUN: %target-swift-frontend -typecheck %s -I %t -Rmodule-loading 2>&1 | %FileCheck %s
10+
11+
import TestModule
12+
// CHECK: remark: loaded module at {{.*}}SwiftShims-{{.*}}.pcm
13+
// CHECK: remark: loaded module at {{.*}}Swift.swiftmodule{{.*}}.swiftmodule
14+
// CHECK: remark: loaded module at {{.*}}TestModule.swiftinterface

0 commit comments

Comments
 (0)