mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Allow users to opt-out of implicit Cxx import with -disable-implicit-cxx-module-import
This commit is contained in:
@@ -402,6 +402,9 @@ namespace swift {
|
|||||||
bool DisableImplicitBacktracingModuleImport =
|
bool DisableImplicitBacktracingModuleImport =
|
||||||
!SWIFT_IMPLICIT_BACKTRACING_IMPORT;
|
!SWIFT_IMPLICIT_BACKTRACING_IMPORT;
|
||||||
|
|
||||||
|
/// Disable the implicit import of the Cxx module.
|
||||||
|
bool DisableImplicitCxxModuleImport = false;
|
||||||
|
|
||||||
// Whether to use checked continuations when making an async call from
|
// Whether to use checked continuations when making an async call from
|
||||||
// Swift into ObjC. If false, will use unchecked continuations instead.
|
// Swift into ObjC. If false, will use unchecked continuations instead.
|
||||||
bool UseCheckedAsyncObjCBridging = false;
|
bool UseCheckedAsyncObjCBridging = false;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ using llvm::BCVBR;
|
|||||||
/// Every .moddepcache file begins with these 4 bytes, for easy identification.
|
/// Every .moddepcache file begins with these 4 bytes, for easy identification.
|
||||||
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
|
const unsigned char MODULE_DEPENDENCY_CACHE_FORMAT_SIGNATURE[] = {'I', 'M', 'D','C'};
|
||||||
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR =
|
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MAJOR =
|
||||||
6; // mappedPCMPath
|
7; // isSystem
|
||||||
/// Increment this on every change.
|
/// Increment this on every change.
|
||||||
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1;
|
const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -405,6 +405,9 @@ public:
|
|||||||
/// imported.
|
/// imported.
|
||||||
bool shouldImportSwiftBacktracing() const;
|
bool shouldImportSwiftBacktracing() const;
|
||||||
|
|
||||||
|
/// Whether the CXX module should be implicitly imported.
|
||||||
|
bool shouldImportCxx() const;
|
||||||
|
|
||||||
/// Performs input setup common to these tools:
|
/// Performs input setup common to these tools:
|
||||||
/// sil-opt, sil-func-extractor, sil-llvm-gen, and sil-nm.
|
/// sil-opt, sil-func-extractor, sil-llvm-gen, and sil-nm.
|
||||||
/// Return value includes the buffer so caller can keep it alive.
|
/// Return value includes the buffer so caller can keep it alive.
|
||||||
|
|||||||
@@ -502,6 +502,10 @@ def disable_implicit_backtracing_module_import : Flag<["-"],
|
|||||||
"disable-implicit-backtracing-module-import">,
|
"disable-implicit-backtracing-module-import">,
|
||||||
HelpText<"Disable the implicit import of the _Backtracing module.">;
|
HelpText<"Disable the implicit import of the _Backtracing module.">;
|
||||||
|
|
||||||
|
def disable_implicit_cxx_module_import : Flag<["-"],
|
||||||
|
"disable-implicit-cxx-module-import">,
|
||||||
|
HelpText<"Disable the implicit import of the C++ Standard Library module.">;
|
||||||
|
|
||||||
def disable_arc_opts : Flag<["-"], "disable-arc-opts">,
|
def disable_arc_opts : Flag<["-"], "disable-arc-opts">,
|
||||||
HelpText<"Don't run SIL ARC optimization passes.">;
|
HelpText<"Don't run SIL ARC optimization passes.">;
|
||||||
def disable_ossa_opts : Flag<["-"], "disable-ossa-opts">,
|
def disable_ossa_opts : Flag<["-"], "disable-ossa-opts">,
|
||||||
|
|||||||
@@ -637,6 +637,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
|||||||
Opts.DisableImplicitStringProcessingModuleImport |=
|
Opts.DisableImplicitStringProcessingModuleImport |=
|
||||||
Args.hasArg(OPT_disable_implicit_string_processing_module_import);
|
Args.hasArg(OPT_disable_implicit_string_processing_module_import);
|
||||||
|
|
||||||
|
Opts.DisableImplicitCxxModuleImport |=
|
||||||
|
Args.hasArg(OPT_disable_implicit_cxx_module_import);
|
||||||
|
|
||||||
Opts.DisableImplicitBacktracingModuleImport =
|
Opts.DisableImplicitBacktracingModuleImport =
|
||||||
Args.hasFlag(OPT_disable_implicit_backtracing_module_import,
|
Args.hasFlag(OPT_disable_implicit_backtracing_module_import,
|
||||||
OPT_enable_implicit_backtracing_module_import,
|
OPT_enable_implicit_backtracing_module_import,
|
||||||
|
|||||||
@@ -1094,6 +1094,26 @@ bool CompilerInvocation::shouldImportSwiftBacktracing() const {
|
|||||||
FrontendOptions::ParseInputMode::SwiftModuleInterface;
|
FrontendOptions::ParseInputMode::SwiftModuleInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CompilerInvocation::shouldImportCxx() const {
|
||||||
|
// C++ Interop is disabled
|
||||||
|
if (!getLangOptions().EnableCXXInterop)
|
||||||
|
return false;
|
||||||
|
// Avoid C++ stdlib when building Swift stdlib
|
||||||
|
if (getImplicitStdlibKind() == ImplicitStdlibKind::Builtin)
|
||||||
|
return false;
|
||||||
|
// Avoid importing Cxx when building Cxx itself
|
||||||
|
if (getFrontendOptions().ModuleName == CXX_MODULE_NAME)
|
||||||
|
return false;
|
||||||
|
// Cxx cannot be imported when Library evolution is enabled
|
||||||
|
if (getFrontendOptions().EnableLibraryEvolution)
|
||||||
|
return false;
|
||||||
|
// Implicit import of Cxx is disabled
|
||||||
|
if (getLangOptions().DisableImplicitCxxModuleImport)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// Implicitly import the SwiftOnoneSupport module in non-optimized
|
/// Implicitly import the SwiftOnoneSupport module in non-optimized
|
||||||
/// builds. This allows for use of popular specialized functions
|
/// builds. This allows for use of popular specialized functions
|
||||||
/// from the standard library, which makes the non-optimized builds
|
/// from the standard library, which makes the non-optimized builds
|
||||||
@@ -1286,9 +1306,7 @@ ImplicitImportInfo CompilerInstance::getImplicitImportInfo() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Invocation.getLangOptions().EnableCXXInterop) {
|
if (Invocation.getLangOptions().EnableCXXInterop) {
|
||||||
if (imports.StdlibKind != ImplicitStdlibKind::Builtin &&
|
if (Invocation.shouldImportCxx() && canImportCxx())
|
||||||
Invocation.getFrontendOptions().ModuleName != CXX_MODULE_NAME &&
|
|
||||||
canImportCxx())
|
|
||||||
pushImport(CXX_MODULE_NAME);
|
pushImport(CXX_MODULE_NAME);
|
||||||
if (canImportCxxShim())
|
if (canImportCxxShim())
|
||||||
pushImport(CXX_SHIM_NAME, {ImportFlags::ImplementationOnly});
|
pushImport(CXX_SHIM_NAME, {ImportFlags::ImplementationOnly});
|
||||||
|
|||||||
@@ -1987,6 +1987,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
|
|||||||
compatVersion = "default";
|
compatVersion = "default";
|
||||||
else if (langOpts.cxxInteropCompatVersion[0] == 5)
|
else if (langOpts.cxxInteropCompatVersion[0] == 5)
|
||||||
compatVersion = "swift-5.9";
|
compatVersion = "swift-5.9";
|
||||||
|
else if (langOpts.cxxInteropCompatVersion[0] == 6)
|
||||||
|
compatVersion = "swift-6";
|
||||||
else if (langOpts.cxxInteropCompatVersion[0] ==
|
else if (langOpts.cxxInteropCompatVersion[0] ==
|
||||||
version::getUpcomingCxxInteropCompatVersion())
|
version::getUpcomingCxxInteropCompatVersion())
|
||||||
compatVersion = "upcoming-swift";
|
compatVersion = "upcoming-swift";
|
||||||
|
|||||||
@@ -1031,7 +1031,8 @@ LoadedFile *SerializedModuleLoaderBase::loadAST(
|
|||||||
if (M.hasCxxInteroperability() &&
|
if (M.hasCxxInteroperability() &&
|
||||||
M.getResilienceStrategy() != ResilienceStrategy::Resilient &&
|
M.getResilienceStrategy() != ResilienceStrategy::Resilient &&
|
||||||
!Ctx.LangOpts.EnableCXXInterop &&
|
!Ctx.LangOpts.EnableCXXInterop &&
|
||||||
Ctx.LangOpts.RequireCxxInteropToImportCxxInteropModule) {
|
Ctx.LangOpts.RequireCxxInteropToImportCxxInteropModule &&
|
||||||
|
M.getName().str() != CXX_MODULE_NAME) {
|
||||||
auto loc = diagLoc.value_or(SourceLoc());
|
auto loc = diagLoc.value_or(SourceLoc());
|
||||||
Ctx.Diags.diagnose(loc, diag::need_cxx_interop_to_import_module,
|
Ctx.Diags.diagnose(loc, diag::need_cxx_interop_to_import_module,
|
||||||
M.getName());
|
M.getName());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %empty-directory(%t)
|
// RUN: %empty-directory(%t)
|
||||||
// RUN: split-file %s %t
|
// RUN: split-file %s %t
|
||||||
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -typecheck -enable-library-evolution -enable-experimental-cxx-interop -disable-availability-checking -verify
|
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -typecheck -enable-library-evolution -enable-experimental-cxx-interop -disable-availability-checking -disable-implicit-cxx-module-import -verify
|
||||||
|
|
||||||
//--- Inputs/module.modulemap
|
//--- Inputs/module.modulemap
|
||||||
module CxxModule {
|
module CxxModule {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// RUN: %empty-directory(%t)
|
// RUN: %empty-directory(%t)
|
||||||
// RUN: split-file %s %t
|
// RUN: split-file %s %t
|
||||||
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -typecheck -enable-library-evolution -enable-experimental-cxx-interop -verify
|
// RUN: %target-swift-frontend %t/test.swift -I %t/Inputs -typecheck -enable-library-evolution -enable-experimental-cxx-interop -disable-implicit-cxx-module-import -verify
|
||||||
|
|
||||||
//--- Inputs/module.modulemap
|
//--- Inputs/module.modulemap
|
||||||
module CxxModule {
|
module CxxModule {
|
||||||
|
|||||||
Reference in New Issue
Block a user