Skip to content

Commit f52f0a5

Browse files
committed
Replace SWIFT_SWIFT_PARSER_ROUNDTRIP with an experimental feature.
Remove the CMake configuration option `SWIFT_SWIFT_PARSER_ROUNDTRIP`. Instead, whenever the "early" SwiftSyntax module is built, link the Swift Swift parser into the compiler and related tools. Introduce a new experimental feature `ParserRoundTrip` that can be enabled to perform round-trip testing.
1 parent 9df77e9 commit f52f0a5

File tree

5 files changed

+15
-17
lines changed

5 files changed

+15
-17
lines changed

CMakeLists.txt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -870,18 +870,8 @@ endif()
870870

871871
# When we have the early SwiftSyntax build, we can include its parser.
872872
if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
873-
# An option that specifies how the SwiftSyntax-based Swift parser is
874-
# integrated.
875-
option(SWIFT_SWIFT_PARSER_MODE [=[
876-
How to use the SwiftSyntax-based Swift parser. Possible values are
877-
OFF: do not use this parser at all
878-
ROUNDTRIP: ensure that the SwiftSyntax-based Swift parser round-trips
879-
]=] OFF)
880-
881-
if(SWIFT_SWIFT_PARSER_MODE)
882-
set(SWIFT_SWIFT_PARSER TRUE)
883-
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
884-
endif()
873+
set(SWIFT_SWIFT_PARSER TRUE)
874+
include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake)
885875
endif()
886876

887877

@@ -1091,7 +1081,7 @@ if(SWIFT_INCLUDE_TOOLS)
10911081
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
10921082
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
10931083
message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}")
1094-
message(STATUS " Swift parser: ${SWIFT_SWIFT_PARSER_MODE}")
1084+
message(STATUS " Swift parser: ${SWIFT_SWIFT_PARSER}")
10951085
message(STATUS "")
10961086
else()
10971087
message(STATUS "Not building host Swift tools")

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ EXPERIMENTAL_FEATURE(OpaqueTypeErasure)
126126
/// wrapped type.
127127
EXPERIMENTAL_FEATURE(TypeWrappers)
128128

129+
/// Whether to perform round-trip testing of the Swift Swift parser.
130+
EXPERIMENTAL_FEATURE(ParserRoundTrip)
131+
129132
#undef EXPERIMENTAL_FEATURE
130133
#undef UPCOMING_FEATURE
131134
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,6 +2935,10 @@ static bool usesFeatureTypeWrappers(Decl *decl) {
29352935
return decl->getAttrs().hasAttribute<TypeWrapperAttr>();
29362936
}
29372937

2938+
static bool usesFeatureParserRoundTrip(Decl *decl) {
2939+
return false;
2940+
}
2941+
29382942
static void suppressingFeatureSpecializeAttributeWithAvailability(
29392943
PrintOptions &options,
29402944
llvm::function_ref<void()> action) {

lib/Parse/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if (SWIFT_SWIFT_PARSER)
5959

6060
target_compile_definitions(swiftParse
6161
PRIVATE
62-
SWIFT_SWIFT_PARSER_ROUNDTRIP
62+
SWIFT_SWIFT_PARSER
6363
)
6464
endif()
6565

lib/Parse/ParseRequests.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "swift/Syntax/SyntaxNodes.h"
2727
#include "swift/SyntaxParse/SyntaxTreeCreator.h"
2828

29-
#ifdef SWIFT_SWIFT_PARSER_ROUNDTRIP
29+
#ifdef SWIFT_SWIFT_PARSER
3030
#include "SwiftParserCompilerSupport.h"
3131
#endif
3232

@@ -193,8 +193,9 @@ SourceFileParsingResult ParseSourceFileRequest::evaluate(Evaluator &evaluator,
193193
if (auto tokens = parser.takeTokenReceiver()->finalize())
194194
tokensRef = ctx.AllocateCopy(*tokens);
195195

196-
#ifdef SWIFT_SWIFT_PARSER_ROUNDTRIP
197-
if (ctx.SourceMgr.getCodeCompletionBufferID() != bufferID) {
196+
#ifdef SWIFT_SWIFT_PARSER
197+
if (ctx.LangOpts.hasFeature(Feature::ParserRoundTrip) &&
198+
ctx.SourceMgr.getCodeCompletionBufferID() != bufferID) {
198199
auto bufferRange = ctx.SourceMgr.getRangeForBuffer(*bufferID);
199200
unsigned int flags = SPCC_RoundTrip;
200201

0 commit comments

Comments
 (0)