Skip to content

Commit 3cf576d

Browse files
committed
Refactor bare slash regex literals as a future feature
1 parent 72c9289 commit 3cf576d

File tree

8 files changed

+22
-33
lines changed

8 files changed

+22
-33
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(NoAsyncAvailability, 340, "@available(*, noasync)"
9191

9292
FUTURE_FEATURE(ConciseMagicFile, 274, 6)
9393
FUTURE_FEATURE(ForwardTrailingClosures, 286, 6)
94+
FUTURE_FEATURE(BareSlashRegexLiterals, 354, 6)
9495

9596
EXPERIMENTAL_FEATURE(StaticAssert)
9697
EXPERIMENTAL_FEATURE(VariadicGenerics)

include/swift/Basic/LangOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,6 @@ namespace swift {
529529
/// Enables dumping type witness systems from associated type inference.
530530
bool DumpTypeWitnessSystems = false;
531531

532-
/// Enables `/.../` syntax regular-expression literals. This requires
533-
/// experimental string processing. Note this does not affect `#/.../#`.
534-
bool EnableBareSlashRegexLiterals = false;
535-
536532
/// Sets the target we are building for and updates platform conditions
537533
/// to match.
538534
///

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,6 +3003,14 @@ static bool usesFeatureConciseMagicFile(Decl *decl) {
30033003
return false;
30043004
}
30053005

3006+
static bool usesFeatureForwardTrailingClosures(Decl *decl) {
3007+
return false;
3008+
}
3009+
3010+
static bool usesFeatureBareSlashRegexLiterals(Decl *decl) {
3011+
return false;
3012+
}
3013+
30063014
static bool usesFeatureVariadicGenerics(Decl *decl) {
30073015
return false;
30083016
}
@@ -3027,10 +3035,6 @@ static bool usesFeatureTypeWitnessSystemInference(Decl *decl) {
30273035
return false;
30283036
}
30293037

3030-
static bool usesFeatureForwardTrailingClosures(Decl *decl) {
3031-
return false;
3032-
}
3033-
30343038
static void
30353039
suppressingFeatureNoAsyncAvailability(PrintOptions &options,
30363040
llvm::function_ref<void()> action) {

lib/Frontend/CompilerInvocation.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -486,25 +486,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
486486
= A->getOption().matches(OPT_enable_deserialization_recovery);
487487
}
488488

489-
// Whether '/.../' regex literals are enabled. This implies experimental
490-
// string processing.
491-
if (Args.hasArg(OPT_enable_bare_slash_regex)) {
492-
Opts.EnableBareSlashRegexLiterals = true;
493-
Opts.EnableExperimentalStringProcessing = true;
494-
}
495-
496-
// Experimental string processing.
497-
if (auto A = Args.getLastArg(OPT_enable_experimental_string_processing,
498-
OPT_disable_experimental_string_processing)) {
499-
Opts.EnableExperimentalStringProcessing =
500-
A->getOption().matches(OPT_enable_experimental_string_processing);
501-
502-
// When experimental string processing is explicitly disabled, also disable
503-
// forward slash regex `/.../`.
504-
if (!Opts.EnableExperimentalStringProcessing)
505-
Opts.EnableBareSlashRegexLiterals = false;
506-
}
507-
508489
Opts.EnableExperimentalBoundGenericExtensions |=
509490
Args.hasArg(OPT_enable_experimental_bound_generic_extensions);
510491

@@ -632,6 +613,12 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
632613
Opts.addCustomConditionalCompilationFlag(A->getValue());
633614
}
634615

616+
// Determine whether string processing is enabled
617+
Opts.EnableExperimentalStringProcessing =
618+
Args.hasFlag(OPT_enable_experimental_string_processing,
619+
OPT_disable_experimental_string_processing,
620+
Args.hasArg(OPT_enable_bare_slash_regex));
621+
635622
// Add a future feature if it is not already implied by the language version.
636623
auto addFutureFeatureIfNotImplied = [&](Feature feature) {
637624
// Check if this feature was introduced already in this language version.
@@ -646,6 +633,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
646633
// Map historical flags over to future features.
647634
if (Args.hasArg(OPT_enable_experimental_concise_pound_file))
648635
addFutureFeatureIfNotImplied(Feature::ConciseMagicFile);
636+
if (Args.hasArg(OPT_enable_bare_slash_regex))
637+
addFutureFeatureIfNotImplied(Feature::BareSlashRegexLiterals);
649638

650639
for (const Arg *A : Args.filtered(OPT_enable_experimental_feature)) {
651640
// If this is a known experimental feature, allow it in +Asserts

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ UnresolvedDeclRefExpr *Parser::parseExprOperator() {
881881
}
882882

883883
void Parser::tryLexRegexLiteral(bool forUnappliedOperator) {
884-
if (!Context.LangOpts.EnableBareSlashRegexLiterals)
884+
if (!Context.LangOpts.hasFeature(Feature::BareSlashRegexLiterals) ||
885+
!Context.LangOpts.EnableExperimentalStringProcessing)
885886
return;
886887

887888
// Check to see if we have a regex literal `/.../`, optionally with a prefix

tools/libSwiftSyntaxParser/libSwiftSyntaxParser.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,7 @@ swiftparse_client_node_t SynParser::parse(const char *source, size_t len) {
512512

513513
// Always enable bare /.../ regex literal in syntax parser.
514514
langOpts.EnableExperimentalStringProcessing = true;
515-
if (EnableBareSlashRegexLiteral && *EnableBareSlashRegexLiteral) {
516-
langOpts.EnableBareSlashRegexLiterals = true;
517-
}
515+
langOpts.Features.insert(Feature::BareSlashRegexLiterals);
518516
if (EffectiveLanguageVersion) {
519517
langOpts.EffectiveLanguageVersion = *EffectiveLanguageVersion;
520518
}

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4305,7 +4305,7 @@ int main(int argc, char *argv[]) {
43054305
InitInvok.getLangOptions().EnableExperimentalStringProcessing = true;
43064306
}
43074307
if (options::EnableBareSlashRegexLiterals) {
4308-
InitInvok.getLangOptions().EnableBareSlashRegexLiterals = true;
4308+
InitInvok.getLangOptions().Features.insert(Feature::BareSlashRegexLiterals);
43094309
InitInvok.getLangOptions().EnableExperimentalStringProcessing = true;
43104310
}
43114311

tools/swift-syntax-test/swift-syntax-test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ int parseFile(
592592
Invocation.getLangOptions().VerifySyntaxTree = options::VerifySyntaxTree;
593593
Invocation.getLangOptions().DisablePoundIfEvaluation = true;
594594
Invocation.getLangOptions().EnableExperimentalStringProcessing = true;
595-
Invocation.getLangOptions().EnableBareSlashRegexLiterals = true;
595+
Invocation.getLangOptions().Features.insert(Feature::BareSlashRegexLiterals);
596596

597597
Invocation.getFrontendOptions().InputsAndOutputs.addInputFile(InputFileName);
598598

0 commit comments

Comments
 (0)