Skip to content

Commit

Permalink
Merge pull request llvm#4440 from augusto2112/enable-bare-slash-regex…
Browse files Browse the repository at this point in the history
…-lazy

[lldb] Add the SwiftEnableBareSlashRegexOnPlayground setting
  • Loading branch information
augusto2112 authored May 9, 2022
2 parents 9776194 + 5ab3967 commit a7b829b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lldb/include/lldb/Target/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class TargetProperties : public Properties {

bool GetSwiftDiscoverImplicitSearchPaths() const;

bool GetSwiftEnableBareSlashRegex() const;

bool GetSwiftAutoImportFrameworks() const;

bool GetEnableAutoImportClangModules() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,11 @@ static llvm::Expected<ParsedExpression> 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)
Expand Down
17 changes: 17 additions & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ class SwiftASTContext : public TypeSystemSwift {
std::unique_ptr<swift::irgen::IRGenerator> m_ir_generator_ap;
std::unique_ptr<swift::irgen::IRGenModule> 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<swift::DiagnosticConsumer> m_diagnostic_consumer_ap;
std::unique_ptr<swift::DependencyTracker> m_dependency_tracker;
/// A collection of (not necessarily fatal) error messages that
Expand Down
11 changes: 11 additions & 0 deletions lldb/source/Target/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions lldb/source/Target/TargetProperties.td
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a7b829b

Please sign in to comment.