diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index 9d2f7641185c0f..4719767f73c973 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -179,6 +179,8 @@ class TargetProperties : public Properties { bool GetSwiftDiscoverImplicitSearchPaths() const; + bool GetSwiftEnableBareSlashRegex() const; + bool GetSwiftAutoImportFrameworks() const; bool GetEnableAutoImportClangModules() const; diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp index d2230a00552995..abd1c66e769855 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp @@ -1359,6 +1359,11 @@ static llvm::Expected ParseAndImport( invocation.getFrontendOptions().ModuleName = expr_name_buf; invocation.getIRGenOptions().ModuleName = expr_name_buf; + invocation.getLangOptions().EnableBareSlashRegexLiterals = + sc.target_sp->GetSwiftEnableBareSlashRegex(); + invocation.getLangOptions().EnableExperimentalStringProcessing = + sc.target_sp->GetSwiftEnableBareSlashRegex(); + auto should_use_prestable_abi = [&]() { lldb::StackFrameSP this_frame_sp(stack_frame_wp.lock()); if (!this_frame_sp) diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp index d5ab8b759f5ffe..18ae74870a11ab 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp @@ -3378,6 +3378,23 @@ SwiftASTContext::CreateModule(const SourceModule &module, Status &error, return nullptr; } + // FIXME: the correct thing to do would be to get the modules by calling + // CompilerInstance::getImplicitImportInfo, instead of explicitly loading this + // module. However, we currently don't have access to a CompilerInstance, + // which is why this function is needed. + auto pushImportIfAvailable = [&](StringRef moduleStr) { + swift::ImportPath path = + swift::ImportPath::Builder(ast->getIdentifier(moduleStr)).copyTo(*ast); + if (!ast->canImportModule(path.getModulePath(swift::ImportKind::Module))) + return; + swift::UnloadedImportedModule import(path, /*isScoped=*/false); + importInfo.AdditionalUnloadedImports.emplace_back( + import, swift::SourceLoc(), swift::ImportOptions()); + }; + // Implicitly import additional "stdlib-like" modules. + pushImportIfAvailable(swift::SWIFT_CONCURRENCY_NAME); + pushImportIfAvailable(swift::SWIFT_STRING_PROCESSING_NAME); + swift::Identifier module_id( ast->getIdentifier(module.path.front().GetCString())); auto *module_decl = swift::ModuleDecl::create(module_id, *ast, importInfo); diff --git a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h index b8630cf5eb2fc0..02979aa534fcc7 100644 --- a/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h +++ b/lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h @@ -840,6 +840,7 @@ class SwiftASTContext : public TypeSystemSwift { std::unique_ptr m_ir_generator_ap; std::unique_ptr m_ir_gen_module_ap; llvm::once_flag m_ir_gen_module_once; + llvm::once_flag m_load_string_processing_lib_once; std::unique_ptr m_diagnostic_consumer_ap; std::unique_ptr m_dependency_tracker; /// A collection of (not necessarily fatal) error messages that diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 2982a30df2733e..b6756692ef0335 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -4223,6 +4223,17 @@ bool TargetProperties::GetSwiftDiscoverImplicitSearchPaths() const { return true; } +bool TargetProperties::GetSwiftEnableBareSlashRegex() const { + const Property *exp_property = m_collection_sp->GetPropertyAtIndex( + nullptr, false, ePropertyExperimental); + OptionValueProperties *exp_values = + exp_property->GetValue()->GetAsProperties(); + if (exp_values) + return exp_values->GetPropertyAtIndexAsBoolean( + nullptr, ePropertySwiftEnableBareSlashRegex, true); + + return true; +} bool TargetProperties::GetSwiftAutoImportFrameworks() const { const uint32_t idx = ePropertySwiftAutoImportFrameworks; return m_collection_sp->GetPropertyAtIndexAsBoolean( diff --git a/lldb/source/Target/TargetProperties.td b/lldb/source/Target/TargetProperties.td index 41224baffb46c1..93c7a0bac67851 100644 --- a/lldb/source/Target/TargetProperties.td +++ b/lldb/source/Target/TargetProperties.td @@ -19,6 +19,9 @@ let Definition = "target_experimental" in { def SwiftDiscoverImplicitSearchPaths: Property<"swift-discover-implicit-search-paths", "Boolean">, DefaultTrue, Desc<"Discover implicit search paths from all implicitly imported Swift modules and make them available to the expression context. A Swift module built with -serialize-debugging-options can contain additional search paths which are discovered as the module is imported. This optiondoes an eager import of all modules first to make sure all implicit search paths are availableto the expression evaluator. If the build system registers all Swift modules with the linker (Darwin: via -add_ast_path, Other platforms: -module-wrap), turning this on is not necessary.">; + def SwiftEnableBareSlashRegex: Property<"swift-enable-bare-slash-regex", "Boolean">, + DefaultFalse, + Desc<"Passes the -enable-bare-slash-regex compiler flag to the swift compiler.">; } let Definition = "target" in {