Skip to content

Add -Rcross-import option #30782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
# define FIXIT(ID, Text, Signature)
#endif

#ifndef REMARK
# define REMARK(ID,Options,Text,Signature) \
DIAG(REMARK,ID,Options,Text,Signature)
#endif

NOTE(decl_declared_here,none,
"%0 declared here", (DeclName))
NOTE(kind_declared_here,none,
Expand Down Expand Up @@ -864,6 +869,9 @@ WARNING(module_not_compiled_with_library_evolution,none,
"using it means binary compatibility for %1 can't be guaranteed",
(Identifier, Identifier))

REMARK(cross_import_added,none,
"import of %0 and %1 triggered a cross-import of %2",
(Identifier, Identifier, Identifier))

// Operator decls
ERROR(ambiguous_operator_decls,none,
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ namespace swift {
/// Detect and automatically import modules' cross-import overlays.
bool EnableCrossImportOverlays = false;

/// Emit a remark when import resolution implicitly adds a cross-import
/// overlay.
bool EnableCrossImportRemarks = false;

///
/// Support for alternate usage modes
///
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ def emit_loaded_module_trace_path : Separate<["-"], "emit-loaded-module-trace-pa
def emit_loaded_module_trace_path_EQ : Joined<["-"], "emit-loaded-module-trace-path=">,
Flags<[FrontendOption, NoInteractiveOption, ArgumentIsPath]>,
Alias<emit_loaded_module_trace_path>;
def emit_cross_import_remarks : Flag<["-"], "Rcross-import">,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
HelpText<"Emit a remark if a cross-import of a module is triggered.">;

def emit_tbd : Flag<["-"], "emit-tbd">,
HelpText<"Emit a TBD file">,
Expand Down
2 changes: 2 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
OPT_disable_cross_import_overlays,
Opts.EnableCrossImportOverlays);

Opts.EnableCrossImportRemarks = Args.hasArg(OPT_emit_cross_import_remarks);

llvm::Triple Target = Opts.Target;
StringRef TargetArg;
if (const Arg *A = Args.getLastArg(OPT_target)) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Sema/ImportResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@ void ImportResolver::findCrossImports(
declaringImport.module.second->getName(),
bystandingImport.module.second->getName(), name);

if (ctx.LangOpts.EnableCrossImportRemarks)
ctx.Diags.diagnose(I.importLoc, diag::cross_import_added,
declaringImport.module.second->getName(),
bystandingImport.module.second->getName(), name);

LLVM_DEBUG({
auto &crossImportOptions = unboundImports.back().options;
llvm::dbgs() << " ";
Expand Down
9 changes: 9 additions & 0 deletions test/CrossImport/remark-option.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This file tests that the -Rcross-import option causes an appropriate remark to be emitted
// RUN: %empty-directory(%t)
// RUN: cp -r %S/Inputs/lib-templates/* %t/
// RUN: %target-typecheck-verify-swift -enable-cross-import-overlays -Rcross-import -I %t/include -I %t/lib/swift -F %t/Frameworks

import DeclaringLibrary
// FIXME: Similarly to horrible.swift, ideally we would emit this remark on DelcaringLibrary
// decl, since the cross-import overlay actually belongs to the DeclaringLibrary. (SR-12223)
import BystandingLibrary // expected-remark {{import of 'DeclaringLibrary' and 'BystandingLibrary' triggered a cross-import of '_OverlayLibrary'}}