Skip to content

Commit de42b1f

Browse files
committed
[Frontend] Optional remarks on loaded modules location
Passing the frontend flag -Rmodule-loading makes the compiler emit remarks with the path of every module loaded. The path for Swift modules is either the swiftinterface file for modules built with library evolution or the binary swiftmodule otherwise. The path for clangmodules is always in the cache which could be improved as it may be less useful. Here's an extract of the output for a simple SwiftUI app: <unknown>:0: remark: loaded module from /Users/xymus/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/2VJP7CNCGWRF0/SwiftShims-18ZF6992O9H75.pcm <unknown>:0: remark: loaded module from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/usr/lib/swift/Swift.swiftmodule/x86_64-apple-ios-simulator.swiftinterface <unknown>:0: remark: loaded module from /Users/xymus/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/2VJP7CNCGWRF0/os-1HVC6DNXVU37C.pcm <unknown>:0: remark: loaded module from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/usr/lib/swift/os.swiftmodule/x86_64-apple-ios-simulator.swiftinterface <unknown>:0: remark: loaded module from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/x86_64-apple-ios-simulator.swiftinterface
1 parent 73d5f01 commit de42b1f

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 from %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(nullptr,
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 from {{.*}}SwiftShims-{{.*}}.pcm
13+
// CHECK: remark: loaded module from {{.*}}Swift.swiftmodule{{.*}}.swiftmodule
14+
// CHECK: remark: loaded module from {{.*}}TestModule.swiftinterface

0 commit comments

Comments
 (0)