Skip to content

Commit 17f1cf9

Browse files
authored
Merge pull request #40240 from rxwei/string-processing-module
2 parents 52eb046 + 65bffd7 commit 17f1cf9

File tree

25 files changed

+201
-12
lines changed

25 files changed

+201
-12
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
445445
"Enable experimental distributed actors and functions"
446446
FALSE)
447447

448+
option(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING
449+
"Enable experimental string processing"
450+
FALSE)
451+
448452
option(SWIFT_ENABLE_DISPATCH
449453
"Enable use of libdispatch"
450454
TRUE)
@@ -997,6 +1001,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
9971001
message(STATUS "Differentiable Programming Support: ${SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING}")
9981002
message(STATUS "Concurrency Support: ${SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY}")
9991003
message(STATUS "Distributed Support: ${SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED}")
1004+
message(STATUS "String Processing Support: ${SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING}")
10001005
message(STATUS "")
10011006
else()
10021007
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace swift {
145145
version::Version PackageDescriptionVersion;
146146

147147
/// Enable experimental string processing
148-
bool EnableExperimentalRegex = false;
148+
bool EnableExperimentalStringProcessing = false;
149149

150150
/// Disable API availability checking.
151151
bool DisableAvailabilityChecking = false;

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,8 @@ def disable_deserialization_recovery :
475475
Flag<["-"], "disable-deserialization-recovery">,
476476
HelpText<"Don't attempt to recover from missing xrefs (etc) in swiftmodules">;
477477

478-
def enable_experimental_regex :
479-
Flag<["-"], "enable-experimental-regex">,
478+
def enable_experimental_string_processing :
479+
Flag<["-"], "enable-experimental-string-processing">,
480480
HelpText<"Enable experimental string processing">;
481481

482482
def disable_availability_checking : Flag<["-"],

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
473473
}
474474

475475
// Experimental string processing
476-
Opts.EnableExperimentalRegex |=
477-
Args.hasArg(OPT_enable_experimental_regex);
476+
Opts.EnableExperimentalStringProcessing |=
477+
Args.hasArg(OPT_enable_experimental_string_processing);
478478

479479
Opts.DisableAvailabilityChecking |=
480480
Args.hasArg(OPT_disable_availability_checking);

lib/Parse/Lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ void Lexer::diagnoseSingleQuoteStringLiteral(const char *TokStart,
18071807
auto startLoc = Lexer::getSourceLoc(TokStart);
18081808
auto endLoc = Lexer::getSourceLoc(TokEnd);
18091809

1810-
if (LangOpts.EnableExperimentalRegex) {
1810+
if (LangOpts.EnableExperimentalStringProcessing) {
18111811
if (parseRegexStrawperson) {
18121812
auto copy = std::string(TokStart, TokEnd-TokStart);
18131813
auto msg = parseRegexStrawperson(copy.c_str());

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ function(_add_target_variant_swift_compile_flags
285285
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING")
286286
endif()
287287

288+
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
289+
list(APPEND result "-D" "SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING")
290+
endif()
291+
288292
if(SWIFT_STDLIB_OS_VERSIONING)
289293
list(APPEND result "-D" "SWIFT_RUNTIME_OS_VERSIONING")
290294
endif()

stdlib/public/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ if(SWIFT_BUILD_STDLIB)
115115
if(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED)
116116
add_subdirectory(Distributed)
117117
endif()
118+
119+
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
120+
add_subdirectory(MatchingEngine)
121+
add_subdirectory(StringProcessing)
122+
endif()
118123
endif()
119124

120125
if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#===--- CMakeLists.txt - Pattern matching engine support library -----------===#
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
#===------------------------------------------------------------------------===#
12+
13+
set(swift_matching_engine_link_libraries
14+
swiftCore)
15+
16+
17+
add_swift_target_library(swift_MatchingEngine ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
18+
MatchingEngine.swift
19+
20+
SWIFT_MODULE_DEPENDS_LINUX Glibc
21+
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
22+
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
23+
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
24+
SWIFT_MODULE_DEPENDS_HAIKU Glibc
25+
SWIFT_MODULE_DEPENDS_WINDOWS CRT
26+
27+
LINK_LIBRARIES ${swift_matching_engine_link_libraries}
28+
29+
C_COMPILE_FLAGS
30+
-Dswift_MatchingEngine_EXPORTS
31+
SWIFT_COMPILE_FLAGS
32+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
33+
-parse-stdlib
34+
-Xfrontend -enable-experimental-string-processing
35+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
36+
37+
INSTALL_IN_COMPONENT stdlib
38+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Swift
2+
3+
public struct DummyMatchingEngine {
4+
public init() {
5+
fatalError("Unimplemented")
6+
}
7+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#===--- CMakeLists.txt - String processing support library -----------------===#
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2021 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
#===------------------------------------------------------------------------===#
12+
13+
set(swift_string_processing_link_libraries
14+
swiftCore
15+
swift_MatchingEngine)
16+
17+
18+
add_swift_target_library(swift_StringProcessing ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
19+
Regex.swift
20+
21+
SWIFT_MODULE_DEPENDS_LINUX Glibc
22+
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
23+
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
24+
SWIFT_MODULE_DEPENDS_CYGWIN Glibc
25+
SWIFT_MODULE_DEPENDS_HAIKU Glibc
26+
SWIFT_MODULE_DEPENDS_WINDOWS CRT
27+
28+
LINK_LIBRARIES ${swift_string_processing_link_libraries}
29+
30+
C_COMPILE_FLAGS
31+
-Dswift_StringProcessing_EXPORTS
32+
SWIFT_COMPILE_FLAGS
33+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
34+
-parse-stdlib
35+
-Xfrontend -enable-experimental-string-processing
36+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
37+
38+
SWIFT_MODULE_DEPENDS _MatchingEngine
39+
INSTALL_IN_COMPONENT stdlib
40+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Swift
2+
import _MatchingEngine
3+
4+
public struct DummyRegex<Match> {
5+
public init() {
6+
fatalError("Unimplemented")
7+
}
8+
}

test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
193193
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY)
194194
normalize_boolean_spelling(SWIFT_BACK_DEPLOY_CONCURRENCY)
195195
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED)
196+
normalize_boolean_spelling(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
196197
normalize_boolean_spelling(SWIFT_ENABLE_MACCATALYST)
197198
normalize_boolean_spelling(SWIFT_RUN_TESTS_WITH_HOST_COMPILER)
198199
normalize_boolean_spelling(SWIFT_RUNTIME_ENABLE_LEAK_CHECKER)
@@ -385,6 +386,10 @@ foreach(SDK ${SWIFT_SDKS})
385386
list(APPEND LIT_ARGS "--param" "distributed")
386387
endif()
387388

389+
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
390+
list(APPEND LIT_ARGS "--param" "string_processing")
391+
endif()
392+
388393
foreach(test_subset ${TEST_SUBSETS})
389394
set(directories)
390395
set(dependencies ${test_dependencies})

test/ExperimentalRegex/Parse/Strawperson.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-regex
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-string-processing
22
// REQUIRES: libswift
33

44
var s = 'abc'

test/StringProcessing/lit.local.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if 'string_processing' not in config.available_features:
2+
config.unsupported = False
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-frontend -enable-experimental-string-processing -parse-as-library -emit-sil -verify %s
2+
3+
// REQUIRES: string_processing
4+
5+
import _MatchingEngine
6+
import _StringProcessing
7+
8+
func foo() {
9+
_ = DummyMatchingEngine()
10+
_ = DummyRegex<Substring>()
11+
}

test/lit.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,10 @@ differentiable_programming = lit_config.params.get('differentiable_programming',
445445
if differentiable_programming is not None:
446446
config.available_features.add('differentiable_programming')
447447

448+
string_processing = lit_config.params.get('string_processing', None)
449+
if string_processing is not None:
450+
config.available_features.add('string_processing')
451+
448452
config.available_features.add('lld_lto')
449453

450454
test_options = os.environ.get('SWIFT_TEST_OPTIONS')
@@ -1711,6 +1715,13 @@ config.substitutions.append(('%distributed_module', distributed_module))
17111715
config.substitutions.append(('%/distributed_module',
17121716
'/'.join(os.path.normpath(distributed_module).split(os.sep))))
17131717

1718+
# Add 'string_processing_module' as the path to the _StringProcessing .swiftmodule file
1719+
string_processing_module = os.path.join(stdlib_dir, "_StringProcessing.swiftmodule",
1720+
target_specific_module_triple + ".swiftmodule")
1721+
config.substitutions.append(('%string_processing_module', string_processing_module))
1722+
config.substitutions.append(('%/string_processing_module',
1723+
'/'.join(os.path.normpath(string_processing_module).split(os.sep))))
1724+
17141725
# Different OS's require different prefixes for the environment variables to be
17151726
# propagated to the calling contexts.
17161727
# In order to make tests OS-agnostic, names of environment variables should be

test/lit.site.cfg.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ if "@SWIFT_BACK_DEPLOY_CONCURRENCY@" == "TRUE":
138138
config.available_features.add('back_deploy_concurrency')
139139
if "@SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED@" == "TRUE":
140140
config.available_features.add('distributed')
141+
if "@SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING@" == "TRUE":
142+
config.available_features.add('string_processing')
141143

142144
# Let the main config do the real work.
143145
if config.test_exec_root is None:

tools/swift-refactor/swift-refactor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ static llvm::cl::opt<bool> EnableExperimentalConcurrency(
128128
"enable-experimental-concurrency",
129129
llvm::cl::desc("Whether to enable experimental concurrency or not"));
130130

131+
static llvm::cl::opt<bool> EnableExperimentalStringProcessing(
132+
"enable-experimental-string-processing",
133+
llvm::cl::desc("Whether to enable experimental string processing or not"));
134+
131135
static llvm::cl::opt<std::string>
132136
SDK("sdk", llvm::cl::desc("Path to the SDK to build against"));
133137

@@ -311,6 +315,9 @@ int main(int argc, char *argv[]) {
311315
if (options::EnableExperimentalConcurrency)
312316
Invocation.getLangOptions().EnableExperimentalConcurrency = true;
313317

318+
if (options::EnableExperimentalStringProcessing)
319+
Invocation.getLangOptions().EnableExperimentalStringProcessing = true;
320+
314321
for (auto FileName : options::InputFilenames)
315322
Invocation.getFrontendOptions().InputsAndOutputs.addInputFile(FileName);
316323
Invocation.setModuleName(options::ModuleName);

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,7 @@ def create_argument_parser():
11881188

11891189
option('--enable-experimental-differentiable-programming', toggle_true,
11901190
default=True,
1191-
help='Enable experimental Swift differentiable programming language'
1192-
' features.')
1191+
help='Enable experimental Swift differentiable programming.')
11931192

11941193
option('--enable-experimental-concurrency', toggle_true,
11951194
default=True,
@@ -1199,6 +1198,10 @@ def create_argument_parser():
11991198
default=True,
12001199
help='Enable experimental Swift distributed actors.')
12011200

1201+
option('--enable-experimental-string-processing', toggle_true,
1202+
default=True,
1203+
help='Enable experimental Swift string processing.')
1204+
12021205
# -------------------------------------------------------------------------
12031206
in_group('Unsupported options')
12041207

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
'enable_experimental_differentiable_programming': True,
150150
'enable_experimental_concurrency': True,
151151
'enable_experimental_distributed': True,
152+
'enable_experimental_string_processing': True,
152153
'enable_lsan': False,
153154
'enable_sanitize_coverage': False,
154155
'disable_guaranteed_normal_arguments': False,
@@ -540,6 +541,7 @@ class BuildScriptImplOption(_BaseOption):
540541
EnableOption('--enable-experimental-differentiable-programming'),
541542
EnableOption('--enable-experimental-concurrency'),
542543
EnableOption('--enable-experimental-distributed'),
544+
EnableOption('--enable-experimental-string-processing'),
543545
EnableOption('--enable-lsan'),
544546
EnableOption('--enable-sanitize-coverage'),
545547
EnableOption('--enable-tsan'),

utils/refactor-check-compiles.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def parse_args():
3333
- swift-refactor
3434
- temp-dir
3535
- enable-experimental-concurrency (sent to both)
36+
- enable-experimental-string-processing (sent to both)
3637
- I (sent to both)
3738
- sdk (sent to both)
3839
- target (sent to both)
@@ -74,6 +75,14 @@ def parse_args():
7475
swift-frontend
7576
'''
7677
)
78+
parser.add_argument(
79+
'-enable-experimental-string-processing',
80+
action='store_true',
81+
help='''
82+
Whether to enable experimental string processing in both swift-refactor
83+
and swift-frontend
84+
'''
85+
)
7786
parser.add_argument(
7887
'-I',
7988
action='append',
@@ -103,6 +112,8 @@ def main():
103112
extra_both_args = []
104113
if args.enable_experimental_concurrency:
105114
extra_both_args.append('-enable-experimental-concurrency')
115+
if args.enable_experimental_string_processing:
116+
extra_both_args.append('-enable-experimental-string-processing')
106117
if args.I:
107118
for path in args.I:
108119
extra_both_args += ['-I', path]

utils/swift-api-dump.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ def main():
334334
extra_args = extra_args + ['-enable-experimental-concurrency']
335335
if args.enable_experimental_distributed:
336336
extra_args = extra_args + ['-enable-experimental-distributed']
337+
if args.enable_experimental_string_processing:
338+
extra_args = extra_args + ['-enable-experimental-string-processing']
337339
if args.swift_version:
338340
extra_args = extra_args + ['-swift-version', '%s' % args.swift_version]
339341

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
5656
# Add experimental distributed flag.
5757
self.cmake_options.extend(self._enable_experimental_distributed)
5858

59+
# Add experimental string processing flag.
60+
self.cmake_options.extend(self._enable_experimental_string_processing)
61+
5962
@classmethod
6063
def is_build_script_impl_product(cls):
6164
"""is_build_script_impl_product -> bool
@@ -155,6 +158,11 @@ def _enable_experimental_distributed(self):
155158
return [('SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL',
156159
self.args.enable_experimental_distributed)]
157160

161+
@property
162+
def _enable_experimental_string_processing(self):
163+
return [('SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING:BOOL',
164+
self.args.enable_experimental_string_processing)]
165+
158166
@classmethod
159167
def get_dependencies(cls):
160168
return [cmark.CMark,

0 commit comments

Comments
 (0)