From ef6827158b8a66676d4ca4f70da2610416bc5a0b Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 19 Dec 2025 16:00:58 -0800 Subject: [PATCH] [LLDB] Add an opt-out setting for the explicit-only import mode rdar://166747831 --- lldb/include/lldb/Target/Target.h | 2 ++ .../TypeSystem/Swift/SwiftASTContext.cpp | 3 +++ lldb/source/Target/Target.cpp | 13 ++++++++++++ lldb/source/Target/TargetProperties.td | 3 +++ ...estSwiftExplicitModulesImplicitFallback.py | 21 +++++++++++++++++++ 5 files changed, 42 insertions(+) diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 3d92629e4da1f..9834d3f61b724 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -206,6 +206,8 @@ class TargetProperties : public Properties { bool GetSwiftAllowExplicitModules() const; + bool GetSwiftAllowImplicitModules() const; + AutoBool GetSwiftPCMValidation() const; bool GetSwiftUseTasksPlugin() const; diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index 7de8d4bb4cc20..682ff2fea1983 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -9421,6 +9421,9 @@ bool SwiftASTContext::GetCompileUnitImportsImpl( // If EBM is enabled, disable implicit modules during contextual imports. // fixme nullptr! bool turn_off_implicit = m_has_explicit_modules; + if (Target::GetGlobalProperties().GetSwiftAllowImplicitModules()) + turn_off_implicit = false; + auto reset = llvm::make_scope_exit([&] { if (turn_off_implicit) { LOG_PRINTF(GetLog(LLDBLog::Types), "Turning on implicit modules"); diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index c776d5394220d..fcaf215b141fc 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -4708,6 +4708,19 @@ bool TargetProperties::GetSwiftAllowExplicitModules() const { return true; } +bool TargetProperties::GetSwiftAllowImplicitModules() const { + const Property *exp_property = + m_collection_sp->GetPropertyAtIndex(ePropertyExperimental); + OptionValueProperties *exp_values = + exp_property->GetValue()->GetAsProperties(); + if (exp_values) + return exp_values + ->GetPropertyAtIndexAs(ePropertySwiftAllowImplicitModules) + .value_or(false); + + return false; +} + AutoBool TargetProperties::GetSwiftPCMValidation() const { const Property *exp_property = m_collection_sp->GetPropertyAtIndex(ePropertyExperimental); diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index 7d7263ece5c48..796d17b6323f6 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -26,6 +26,9 @@ let Definition = "target_experimental" in { def SwiftAllowExplicitModules: Property<"swift-allow-explicit-modules", "Boolean">, DefaultTrue, Desc<"Allows explicit module flags to be passed through to ClangImporter.">; + def SwiftAllowImplicitModules: Property<"swift-allow-implicit-modules", "Boolean">, + DefaultFalse, + Desc<"Allows implicit module imports in an explicitly-built target.">; def SwiftPCMValidation: Property<"swift-pcm-validation", "Enum">, Global, DefaultEnumValue<"llvm::to_underlying(AutoBool::Auto)">, diff --git a/lldb/test/API/lang/swift/explicit_modules/implicit_fallback/TestSwiftExplicitModulesImplicitFallback.py b/lldb/test/API/lang/swift/explicit_modules/implicit_fallback/TestSwiftExplicitModulesImplicitFallback.py index f9acedd9fee22..66f42bf8cd3b2 100644 --- a/lldb/test/API/lang/swift/explicit_modules/implicit_fallback/TestSwiftExplicitModulesImplicitFallback.py +++ b/lldb/test/API/lang/swift/explicit_modules/implicit_fallback/TestSwiftExplicitModulesImplicitFallback.py @@ -6,6 +6,7 @@ class TestCase(lldbtest.TestBase): + NO_DEBUG_INFO_TESTCASE = True @swiftTest def test_missing_explicit_modules(self): """Test missing explicit Swift modules and fallback to implicit modules.""" @@ -53,3 +54,23 @@ def test_sanity(self): # CHECK-SANITY: Explicit modules : true # CHECK-SANITY: Turning off implicit modules # CHECK-SANITY: Turning on implicit modules + + @swiftTest + def test_setting(self): + """Check the normal behavior.""" + self.build() + + lldbutil.run_to_source_breakpoint( + self, "Set breakpoint here", lldb.SBFileSpec("main.swift") + ) + + log = self.getBuildArtifact("types.log") + self.runCmd(f"log enable lldb types -f '{log}'") + self.expect("settings set target.experimental.swift-allow-implicit-modules true") + + self.expect("expression c") + + self.filecheck(f"platform shell cat {log}", __file__, + '--check-prefix=CHECK-SETTING') + # CHECK-SETTING: Explicit modules : true + # CHECK-SETTING-NOT: Turning {{.*}} implicit modules