Skip to content

Commit a7b829b

Browse files
authored
Merge pull request llvm#4440 from augusto2112/enable-bare-slash-regex-lazy
[lldb] Add the SwiftEnableBareSlashRegexOnPlayground setting
2 parents 9776194 + 5ab3967 commit a7b829b

File tree

6 files changed

+39
-0
lines changed

6 files changed

+39
-0
lines changed

lldb/include/lldb/Target/Target.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ class TargetProperties : public Properties {
179179

180180
bool GetSwiftDiscoverImplicitSearchPaths() const;
181181

182+
bool GetSwiftEnableBareSlashRegex() const;
183+
182184
bool GetSwiftAutoImportFrameworks() const;
183185

184186
bool GetEnableAutoImportClangModules() const;

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,11 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
13591359
invocation.getFrontendOptions().ModuleName = expr_name_buf;
13601360
invocation.getIRGenOptions().ModuleName = expr_name_buf;
13611361

1362+
invocation.getLangOptions().EnableBareSlashRegexLiterals =
1363+
sc.target_sp->GetSwiftEnableBareSlashRegex();
1364+
invocation.getLangOptions().EnableExperimentalStringProcessing =
1365+
sc.target_sp->GetSwiftEnableBareSlashRegex();
1366+
13621367
auto should_use_prestable_abi = [&]() {
13631368
lldb::StackFrameSP this_frame_sp(stack_frame_wp.lock());
13641369
if (!this_frame_sp)

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,6 +3378,23 @@ SwiftASTContext::CreateModule(const SourceModule &module, Status &error,
33783378
return nullptr;
33793379
}
33803380

3381+
// FIXME: the correct thing to do would be to get the modules by calling
3382+
// CompilerInstance::getImplicitImportInfo, instead of explicitly loading this
3383+
// module. However, we currently don't have access to a CompilerInstance,
3384+
// which is why this function is needed.
3385+
auto pushImportIfAvailable = [&](StringRef moduleStr) {
3386+
swift::ImportPath path =
3387+
swift::ImportPath::Builder(ast->getIdentifier(moduleStr)).copyTo(*ast);
3388+
if (!ast->canImportModule(path.getModulePath(swift::ImportKind::Module)))
3389+
return;
3390+
swift::UnloadedImportedModule import(path, /*isScoped=*/false);
3391+
importInfo.AdditionalUnloadedImports.emplace_back(
3392+
import, swift::SourceLoc(), swift::ImportOptions());
3393+
};
3394+
// Implicitly import additional "stdlib-like" modules.
3395+
pushImportIfAvailable(swift::SWIFT_CONCURRENCY_NAME);
3396+
pushImportIfAvailable(swift::SWIFT_STRING_PROCESSING_NAME);
3397+
33813398
swift::Identifier module_id(
33823399
ast->getIdentifier(module.path.front().GetCString()));
33833400
auto *module_decl = swift::ModuleDecl::create(module_id, *ast, importInfo);

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,7 @@ class SwiftASTContext : public TypeSystemSwift {
840840
std::unique_ptr<swift::irgen::IRGenerator> m_ir_generator_ap;
841841
std::unique_ptr<swift::irgen::IRGenModule> m_ir_gen_module_ap;
842842
llvm::once_flag m_ir_gen_module_once;
843+
llvm::once_flag m_load_string_processing_lib_once;
843844
std::unique_ptr<swift::DiagnosticConsumer> m_diagnostic_consumer_ap;
844845
std::unique_ptr<swift::DependencyTracker> m_dependency_tracker;
845846
/// A collection of (not necessarily fatal) error messages that

lldb/source/Target/Target.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4223,6 +4223,17 @@ bool TargetProperties::GetSwiftDiscoverImplicitSearchPaths() const {
42234223
return true;
42244224
}
42254225

4226+
bool TargetProperties::GetSwiftEnableBareSlashRegex() const {
4227+
const Property *exp_property = m_collection_sp->GetPropertyAtIndex(
4228+
nullptr, false, ePropertyExperimental);
4229+
OptionValueProperties *exp_values =
4230+
exp_property->GetValue()->GetAsProperties();
4231+
if (exp_values)
4232+
return exp_values->GetPropertyAtIndexAsBoolean(
4233+
nullptr, ePropertySwiftEnableBareSlashRegex, true);
4234+
4235+
return true;
4236+
}
42264237
bool TargetProperties::GetSwiftAutoImportFrameworks() const {
42274238
const uint32_t idx = ePropertySwiftAutoImportFrameworks;
42284239
return m_collection_sp->GetPropertyAtIndexAsBoolean(

lldb/source/Target/TargetProperties.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ let Definition = "target_experimental" in {
1919
def SwiftDiscoverImplicitSearchPaths: Property<"swift-discover-implicit-search-paths", "Boolean">,
2020
DefaultTrue,
2121
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.">;
22+
def SwiftEnableBareSlashRegex: Property<"swift-enable-bare-slash-regex", "Boolean">,
23+
DefaultFalse,
24+
Desc<"Passes the -enable-bare-slash-regex compiler flag to the swift compiler.">;
2225
}
2326

2427
let Definition = "target" in {

0 commit comments

Comments
 (0)