Skip to content

Commit c83caf5

Browse files
authored
Merge pull request #73016 from rintaro/6.0-cmake-parservalidatoin
[6.0][CMake] Add option to perform SwiftParser validation by default
2 parents 2325cf1 + 2f7a474 commit c83caf5

File tree

10 files changed

+39
-2
lines changed

10 files changed

+39
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,10 @@ option(SWIFT_ENABLE_GLOBAL_ISEL_ARM64
691691
"Enable global isel on arm64"
692692
FALSE)
693693

694+
option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
695+
"Enable experimental SwiftParser validation by default"
696+
FALSE)
697+
694698
cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
695699
"Build SourceKit" TRUE
696700
"SWIFT_ENABLE_DISPATCH" FALSE)

SwiftCompilerSources/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ function(add_swift_compiler_modules_library name)
129129
list(APPEND swift_compile_options "-O" "-cross-module-optimization")
130130
endif()
131131

132-
if(NOT LLVM_ENABLE_ASSERTIONS)
132+
if(LLVM_ENABLE_ASSERTIONS)
133+
list(APPEND swift_compile_options "-Xcc" "-UNDEBUG")
134+
else()
133135
list(APPEND swift_compile_options "-Xcc" "-DNDEBUG")
134136
endif()
135137

cmake/modules/AddPureSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ function(_add_host_swift_compile_options name)
7575
target_compile_options(${name} PRIVATE
7676
$<$<COMPILE_LANGUAGE:Swift>:-color-diagnostics>
7777
)
78+
79+
if(LLVM_ENABLE_ASSERTIONS)
80+
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -UNDEBUG>")
81+
else()
82+
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DNDEBUG>")
83+
endif()
7884
endfunction()
7985

8086
function(_set_pure_swift_link_flags name relpath_to_lib_dir)

include/swift/Config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616

1717
#cmakedefine01 SWIFT_ENABLE_GLOBAL_ISEL_ARM64
1818

19+
#cmakedefine01 SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
20+
1921
#endif // SWIFT_CONFIG_H

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
15131513
}
15141514
}
15151515

1516-
#ifndef NDEBUG
1516+
#if SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
15171517
/// Enable round trip parsing via the new swift parser unless it is disabled
15181518
/// explicitly. The new Swift parser can have mismatches with C++ parser -
15191519
/// rdar://118013482 Use this flag to disable round trip through the new

utils/build-presets.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,7 @@ skstresstester
18701870
sourcekit-lsp
18711871
install-swiftformat
18721872
skip-test-swift=false
1873+
enable-experimental-parser-validation=true
18731874

18741875
[preset: buildbot_swiftsyntax_linux]
18751876
mixin-preset=mixin_swiftpm_package_linux_platform
@@ -1881,6 +1882,7 @@ swiftsyntax-enable-test-fuzzing
18811882
sourcekit-lsp
18821883
swiftformat
18831884
install-swiftformat
1885+
enable-experimental-parser-validation=true
18841886

18851887
#===------------------------------------------------------------------------===#
18861888
# Test Swift Format
@@ -2853,12 +2855,14 @@ mixin-preset=source_compat_suite_macos_base
28532855
debug
28542856
assertions
28552857
cross-compile-hosts=macosx-arm64
2858+
enable-experimental-parser-validation=true
28562859

28572860
[preset: source_compat_suite_macos_RA]
28582861
mixin-preset=source_compat_suite_macos_base
28592862
release
28602863
assertions
28612864
cross-compile-hosts=macosx-arm64
2865+
enable-experimental-parser-validation=true
28622866

28632867
[preset: source_compat_suite_macos_R]
28642868
mixin-preset=source_compat_suite_macos_base
@@ -2876,11 +2880,13 @@ cross-compile-hosts=macosx-arm64
28762880
mixin-preset=source_compat_suite_linux_base
28772881
debug
28782882
assertions
2883+
enable-experimental-parser-validation=true
28792884

28802885
[preset: source_compat_suite_linux_RA]
28812886
mixin-preset=source_compat_suite_linux_base
28822887
release
28832888
assertions
2889+
enable-experimental-parser-validation=true
28842890

28852891
[preset: source_compat_suite_linux_R]
28862892
mixin-preset=source_compat_suite_linux_base

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,10 @@ def create_argument_parser():
13691369
default=True,
13701370
help='Enable Swift Synchronization.')
13711371

1372+
option('--enable-experimental-parser-validation', toggle_true,
1373+
default=False,
1374+
help='Enable experimental Swift Parser validation by default.')
1375+
13721376
# -------------------------------------------------------------------------
13731377
in_group('Unsupported options')
13741378

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
'enable_experimental_nonescapable_types': False,
173173
'enable_experimental_string_processing': True,
174174
'enable_experimental_observation': True,
175+
'enable_experimental_parser_validation': False,
175176
'swift_enable_backtracing': True,
176177
'enable_synchronization': True,
177178
'enable_lsan': False,
@@ -596,6 +597,7 @@ class BuildScriptImplOption(_BaseOption):
596597
EnableOption('--enable-experimental-nonescapable-types'),
597598
EnableOption('--enable-experimental-string-processing'),
598599
EnableOption('--enable-experimental-observation'),
600+
EnableOption('--enable-experimental-parser-validation'),
599601
EnableOption('--enable-lsan'),
600602
EnableOption('--enable-sanitize-coverage'),
601603
EnableOption('--enable-tsan'),

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
8484
self.cmake_options.extend(
8585
self._swift_tools_ld64_lto_codegen_only_for_supporting_targets)
8686

87+
self.cmake_options.extend(
88+
self._enable_experimental_parser_validation)
89+
8790
@classmethod
8891
def is_build_script_impl_product(cls):
8992
"""is_build_script_impl_product -> bool
@@ -238,6 +241,11 @@ def _swift_tools_ld64_lto_codegen_only_for_supporting_targets(self):
238241
return [('SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL',
239242
self.args.swift_tools_ld64_lto_codegen_only_for_supporting_targets)]
240243

244+
@property
245+
def _enable_experimental_parser_validation(self):
246+
return [('SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL',
247+
self.args.enable_experimental_parser_validation)]
248+
241249
@classmethod
242250
def get_dependencies(cls):
243251
return [cmark.CMark,

utils/swift_build_support/tests/products/test_swift.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def setUp(self):
6060
enable_experimental_distributed=False,
6161
enable_experimental_nonescapable_types=False,
6262
enable_experimental_observation=False,
63+
enable_experimental_parser_validation=False,
6364
swift_enable_backtracing=False,
6465
enable_synchronization=False,
6566
build_early_swiftsyntax=False,
@@ -105,6 +106,7 @@ def test_by_default_no_cmake_options(self):
105106
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
106107
'-DSWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES:BOOL=FALSE',
107108
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
109+
'-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE',
108110
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
109111
'-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE',
110112
'-DSWIFT_STDLIB_STATIC_PRINT=FALSE',
@@ -134,6 +136,7 @@ def test_swift_runtime_tsan(self):
134136
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
135137
'-DSWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES:BOOL=FALSE',
136138
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
139+
'-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE',
137140
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
138141
'-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE',
139142
'-DSWIFT_STDLIB_STATIC_PRINT=FALSE',

0 commit comments

Comments
 (0)