Skip to content

Commit 47f18d4

Browse files
committed
[ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
ASTGen always builds with the host Swift compiler, without requiring bootstrapping, and is enabled in more places. Move the regex literal parsing logic there so it is enabled in more host environments, and makes use of CMake's Swift support. Enable all of the regex literal tests when ASTGen is built, to ensure everything is working. Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources, because they are no longer needed.
1 parent 23effda commit 47f18d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+144
-331
lines changed

SwiftCompilerSources/CMakeLists.txt

-3
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,8 @@ else()
245245
#define COMPILED_WITH_SWIFT
246246
247247
#include \"Basic/BasicBridging.h\"
248-
#include \"AST/ASTBridging.h\"
249248
#include \"SIL/SILBridging.h\"
250249
#include \"SILOptimizer/OptimizerBridging.h\"
251-
252-
#include \"Parse/RegexParserBridging.h\"
253250
")
254251
add_custom_command(
255252
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"

SwiftCompilerSources/Package.swift

+2-19
Original file line numberDiff line numberDiff line change
@@ -67,39 +67,22 @@ let package = Package(
6767
.library(
6868
name: "swiftCompilerModules",
6969
type: .static,
70-
targets: ["Basic", "AST", "Parse", "SIL", "Optimizer", "_CompilerRegexParser"]),
70+
targets: ["Basic", "SIL", "Optimizer"]),
7171
],
7272
dependencies: [
7373
],
7474
// Note that targets and their dependencies must align with
7575
// 'SwiftCompilerSources/Sources/CMakeLists.txt'
7676
targets: [
77-
.compilerModuleTarget(
78-
name: "_CompilerRegexParser",
79-
dependencies: [],
80-
path: "_RegexParser_Sources",
81-
swiftSettings: [
82-
// Workaround until `_CompilerRegexParser` is imported as implementation-only
83-
// by `_StringProcessing`.
84-
.unsafeFlags([
85-
"-Xfrontend",
86-
"-disable-implicit-string-processing-module-import"
87-
])]),
8877
.compilerModuleTarget(
8978
name: "Basic",
9079
dependencies: []),
91-
.compilerModuleTarget(
92-
name: "AST",
93-
dependencies: ["Basic"]),
94-
.compilerModuleTarget(
95-
name: "Parse",
96-
dependencies: ["Basic", "AST", "_CompilerRegexParser"]),
9780
.compilerModuleTarget(
9881
name: "SIL",
9982
dependencies: ["Basic"]),
10083
.compilerModuleTarget(
10184
name: "Optimizer",
102-
dependencies: ["Basic", "SIL", "Parse"]),
85+
dependencies: ["Basic", "SIL"]),
10386
],
10487
cxxLanguageStandard: .cxx17
10588
)

SwiftCompilerSources/Sources/AST/CMakeLists.txt

-14
This file was deleted.

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

-130
This file was deleted.

SwiftCompilerSources/Sources/Basic/SourceLoc.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import ASTBridging
13+
import BasicBridging
1414

1515
public struct SourceLoc {
1616
/// Points into a source file.

SwiftCompilerSources/Sources/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
# NOTE: Subdirectories must be added in dependency order.
1010

11-
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
12-
add_subdirectory(_RegexParser)
13-
endif()
1411
add_subdirectory(Basic)
15-
add_subdirectory(AST)
16-
add_subdirectory(Parse)
1712
add_subdirectory(SIL)
1813
add_subdirectory(Optimizer)

SwiftCompilerSources/Sources/Optimizer/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
set(dependencies)
10-
list(APPEND dependencies Basic SIL Parse)
10+
list(APPEND dependencies Basic SIL)
1111

1212
add_swift_compiler_module(Optimizer DEPENDS ${dependencies})
1313

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import AST
1413
import SIL
1514
import OptimizerBridging
1615

@@ -41,12 +40,6 @@ extension Context {
4140
}
4241
}
4342

44-
extension Context {
45-
var diagnosticEngine: DiagnosticEngine {
46-
return DiagnosticEngine(bridged: _bridged.getDiagnosticEngine())
47-
}
48-
}
49-
5043
/// A context which allows mutation of a function's SIL.
5144
protocol MutatingContext : Context {
5245
// Called by all instruction mutations, including inserted new instructions.

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212

1313
import SIL
1414
import OptimizerBridging
15-
import Parse
1615

1716
@_cdecl("initializeSwiftModules")
1817
public func initializeSwiftModules() {
1918
registerSILClasses()
2019
registerSwiftAnalyses()
2120
registerSwiftPasses()
22-
initializeSwiftParseModules()
2321
registerOptimizerTests()
2422
}
2523

SwiftCompilerSources/Sources/Parse/CMakeLists.txt

-19
This file was deleted.

SwiftCompilerSources/Sources/Parse/Parse.swift

-16
This file was deleted.

SwiftCompilerSources/Sources/_RegexParser/CMakeLists.txt

-20
This file was deleted.

SwiftCompilerSources/_RegexParser_Sources

-1
This file was deleted.

SwiftCompilerSources/stubs.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
extern "C" {
1414

1515
void initializeSwiftModules();
16-
void initializeSwiftParseModules();
17-
1816
}
1917

2018
void initializeSwiftModules() {}
21-
void initializeSwiftParseModules() {}

include/swift/AST/DiagnosticsParse.def

-7
Original file line numberDiff line numberDiff line change
@@ -2073,13 +2073,6 @@ ERROR(expected_closure_literal,none,
20732073
ERROR(expected_multiple_closures_block_rbrace,none,
20742074
"expected '}' at the end of a trailing closures block", ())
20752075

2076-
//------------------------------------------------------------------------------
2077-
// MARK: diagnostics emitted by Swift libraries
2078-
//------------------------------------------------------------------------------
2079-
2080-
ERROR(foreign_diagnostic,none,
2081-
"%0", (StringRef))
2082-
20832076
//------------------------------------------------------------------------------
20842077
// MARK: macros
20852078
//------------------------------------------------------------------------------

include/swift/Basic/InitializeSwiftModules.h

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern "C" {
1818
#endif
1919

2020
void initializeSwiftModules();
21-
void initializeSwiftParseModules();
2221

2322
#ifdef __cplusplus
2423
}

include/swift/Bridging/ASTGen.h

+14
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,20 @@ swift::Stmt *_Nullable swift_ASTGen_buildStmt(
134134
BridgedASTContext astContext, BridgedLegacyParser legacyParser,
135135
BridgedSourceLoc *_Nonnull endSourceLoc);
136136

137+
// MARK: - Regex parsing
138+
139+
bool swift_ASTGen_lexRegexLiteral(const char *_Nonnull *_Nonnull curPtrPtr,
140+
const char *_Nonnull bufferEndPtr,
141+
bool mustBeRegex,
142+
BridgedNullableDiagnosticEngine diagEngine);
143+
144+
bool swift_ASTGen_parseRegexLiteral(BridgedStringRef inputPtr,
145+
size_t *_Nonnull versionOut,
146+
void *_Nonnull UnsafeMutableRawPointer,
147+
size_t captureStructureSize,
148+
BridgedSourceLoc diagLoc,
149+
BridgedDiagnosticEngine diagEngine);
150+
137151
#ifdef __cplusplus
138152
}
139153
#endif

0 commit comments

Comments
 (0)