Skip to content

Commit aaee1c4

Browse files
authored
Merge pull request #42140 from artemcm/EnableRegexLiteralFlag
Add support for `-enable-regex-literals` flag
2 parents 16d204b + b04ae26 commit aaee1c4

File tree

7 files changed

+25
-2
lines changed

7 files changed

+25
-2
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ namespace swift {
561561
/// Enables dumping type witness systems from associated type inference.
562562
bool DumpTypeWitnessSystems = false;
563563

564+
/// Enables `/.../` syntax regular-expression literals
565+
bool EnableForwardSlashRegexLiterals = false;
566+
564567
/// Sets the target we are building for and updates platform conditions
565568
/// to match.
566569
///

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ def disable_actor_data_race_checks :
676676
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,
677677
HelpText<"Disable runtime checks for actor data races">;
678678

679+
def enable_regex_literals : Flag<["-"], "enable-regex-literals">,
680+
Flags<[FrontendOption, ModuleInterfaceOptionIgnorable]>,
681+
HelpText<"Enable the use of regular-expression literals">;
682+
679683
def warn_implicit_overrides :
680684
Flag<["-"], "warn-implicit-overrides">,
681685
Flags<[FrontendOption, DoesNotAffectIncrementalBuild]>,

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
298298
options::OPT_verify_incremental_dependencies);
299299
inputArgs.AddLastArg(arguments, options::OPT_access_notes_path);
300300
inputArgs.AddLastArg(arguments, options::OPT_library_level);
301+
inputArgs.AddLastArg(arguments, options::OPT_enable_regex_literals);
301302

302303
// Pass on any build config options
303304
inputArgs.AddAllArgs(arguments, options::OPT_D);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
10041004
if (Args.hasArg(OPT_disable_requirement_machine_reuse))
10051005
Opts.EnableRequirementMachineReuse = false;
10061006

1007+
if (Args.hasArg(OPT_enable_regex_literals))
1008+
Opts.EnableForwardSlashRegexLiterals = true;
1009+
10071010
if (Args.hasArg(OPT_enable_requirement_machine_opaque_archetypes))
10081011
Opts.EnableRequirementMachineOpaqueArchetypes = true;
10091012

lib/Option/features.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
},
2121
{
2222
"name": "empty-abi-descriptor"
23-
}
23+
},
24+
{
25+
"name": "enable-regex-literals"
26+
}
2427
]
2528
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swiftc_driver -enable-regex-literals -disallow-use-new-driver -driver-print-jobs %s 2>^1 | %FileCheck %s
2+
// The new driver has its own test for this
3+
// REQUIRES: cplusplus_driver
4+
// CHECK: {{.*}}/swift-frontend -frontend{{.*}}-enable-regex-literals
5+
6+
public func foo() -> Int {
7+
return 42
8+
}

test/ModuleInterface/option-preservation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -enable-library-evolution -emit-module-interface-path %t.swiftinterface -module-name t %s -target-min-inlining-version 42 -emit-module -o /dev/null -Onone -enforce-exclusivity=unchecked -autolink-force-load
3+
// RUN: %target-swift-frontend -enable-library-evolution -emit-module-interface-path %t.swiftinterface -module-name t %s -target-min-inlining-version 42 -emit-module -o /dev/null -Onone -enforce-exclusivity=unchecked -autolink-force-load -enable-regex-literals
44
// RUN: %FileCheck %s < %t.swiftinterface -check-prefix=CHECK-SWIFTINTERFACE
55
//
66
// CHECK-SWIFTINTERFACE: swift-module-flags:
@@ -10,6 +10,7 @@
1010
// CHECK-SWIFTINTERFACE-SAME: -autolink-force-load
1111
// CHECK-SWIFTINTERFACE: swift-module-flags-ignorable:
1212
// CHECK-SWIFTINTERFACE-SAME: -target-min-inlining-version 42
13+
// CHECK-SWIFTINTERFACE-SAME: -enable-regex-literals
1314

1415
// Make sure flags show up when filelists are enabled
1516

0 commit comments

Comments
 (0)