Skip to content

Commit 0d10132

Browse files
authored
Merge pull request #30782 from artemcm/Rcross-import
Add -Rcross-import option
2 parents 76881a3 + b679fd8 commit 0d10132

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
# define FIXIT(ID, Text, Signature)
4242
#endif
4343

44+
#ifndef REMARK
45+
# define REMARK(ID,Options,Text,Signature) \
46+
DIAG(REMARK,ID,Options,Text,Signature)
47+
#endif
48+
4449
NOTE(decl_declared_here,none,
4550
"%0 declared here", (DeclName))
4651
NOTE(kind_declared_here,none,
@@ -864,6 +869,9 @@ WARNING(module_not_compiled_with_library_evolution,none,
864869
"using it means binary compatibility for %1 can't be guaranteed",
865870
(Identifier, Identifier))
866871

872+
REMARK(cross_import_added,none,
873+
"import of %0 and %1 triggered a cross-import of %2",
874+
(Identifier, Identifier, Identifier))
867875

868876
// Operator decls
869877
ERROR(ambiguous_operator_decls,none,

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ namespace swift {
112112
/// Detect and automatically import modules' cross-import overlays.
113113
bool EnableCrossImportOverlays = false;
114114

115+
/// Emit a remark when import resolution implicitly adds a cross-import
116+
/// overlay.
117+
bool EnableCrossImportRemarks = false;
118+
115119
///
116120
/// Support for alternate usage modes
117121
///

include/swift/Option/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ def emit_loaded_module_trace_path : Separate<["-"], "emit-loaded-module-trace-pa
338338
def emit_loaded_module_trace_path_EQ : Joined<["-"], "emit-loaded-module-trace-path=">,
339339
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath]>,
340340
Alias<emit_loaded_module_trace_path>;
341+
def emit_cross_import_remarks : Flag<["-"], "Rcross-import">,
342+
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
343+
HelpText<"Emit a remark if a cross-import of a module is triggered.">;
341344

342345
def emit_tbd : Flag<["-"], "emit-tbd">,
343346
HelpText<"Emit a TBD file">,

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
546546
OPT_disable_cross_import_overlays,
547547
Opts.EnableCrossImportOverlays);
548548

549+
Opts.EnableCrossImportRemarks = Args.hasArg(OPT_emit_cross_import_remarks);
550+
549551
llvm::Triple Target = Opts.Target;
550552
StringRef TargetArg;
551553
if (const Arg *A = Args.getLastArg(OPT_target)) {

lib/Sema/ImportResolution.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,11 @@ void ImportResolver::findCrossImports(
914914
declaringImport.module.second->getName(),
915915
bystandingImport.module.second->getName(), name);
916916

917+
if (ctx.LangOpts.EnableCrossImportRemarks)
918+
ctx.Diags.diagnose(I.importLoc, diag::cross_import_added,
919+
declaringImport.module.second->getName(),
920+
bystandingImport.module.second->getName(), name);
921+
917922
LLVM_DEBUG({
918923
auto &crossImportOptions = unboundImports.back().options;
919924
llvm::dbgs() << " ";

test/CrossImport/remark-option.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This file tests that the -Rcross-import option causes an appropriate remark to be emitted
2+
// RUN: %empty-directory(%t)
3+
// RUN: cp -r %S/Inputs/lib-templates/* %t/
4+
// RUN: %target-typecheck-verify-swift -enable-cross-import-overlays -Rcross-import -I %t/include -I %t/lib/swift -F %t/Frameworks
5+
6+
import DeclaringLibrary
7+
// FIXME: Similarly to horrible.swift, ideally we would emit this remark on DelcaringLibrary
8+
// decl, since the cross-import overlay actually belongs to the DeclaringLibrary. (SR-12223)
9+
import BystandingLibrary // expected-remark {{import of 'DeclaringLibrary' and 'BystandingLibrary' triggered a cross-import of '_OverlayLibrary'}}

0 commit comments

Comments
 (0)