Skip to content

Commit a16ad9c

Browse files
authored
Merge pull request #71173 from rintaro/cmake-parservalidatoin
[CMake] Add option to perform SwiftParser validation by default
2 parents e2e6d6a + a8db220 commit a16ad9c

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
@@ -693,6 +693,10 @@ option(SWIFT_ENABLE_GLOBAL_ISEL_ARM64
693693
"Enable global isel on arm64"
694694
FALSE)
695695

696+
option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
697+
"Enable experimental SwiftParser validation by default"
698+
FALSE)
699+
696700
cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
697701
"Build SourceKit" TRUE
698702
"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
@@ -1892,6 +1892,7 @@ skstresstester
18921892
sourcekit-lsp
18931893
install-swiftformat
18941894
skip-test-swift=false
1895+
enable-experimental-parser-validation=true
18951896

18961897
[preset: buildbot_swiftsyntax_linux]
18971898
mixin-preset=mixin_swiftpm_package_linux_platform
@@ -1903,6 +1904,7 @@ swiftsyntax-enable-test-fuzzing
19031904
sourcekit-lsp
19041905
swiftformat
19051906
install-swiftformat
1907+
enable-experimental-parser-validation=true
19061908

19071909
#===------------------------------------------------------------------------===#
19081910
# Test Swift Format
@@ -2875,12 +2877,14 @@ mixin-preset=source_compat_suite_macos_base
28752877
debug
28762878
assertions
28772879
cross-compile-hosts=macosx-arm64
2880+
enable-experimental-parser-validation=true
28782881

28792882
[preset: source_compat_suite_macos_RA]
28802883
mixin-preset=source_compat_suite_macos_base
28812884
release
28822885
assertions
28832886
cross-compile-hosts=macosx-arm64
2887+
enable-experimental-parser-validation=true
28842888

28852889
[preset: source_compat_suite_macos_R]
28862890
mixin-preset=source_compat_suite_macos_base
@@ -2898,11 +2902,13 @@ cross-compile-hosts=macosx-arm64
28982902
mixin-preset=source_compat_suite_linux_base
28992903
debug
29002904
assertions
2905+
enable-experimental-parser-validation=true
29012906

29022907
[preset: source_compat_suite_linux_RA]
29032908
mixin-preset=source_compat_suite_linux_base
29042909
release
29052910
assertions
2911+
enable-experimental-parser-validation=true
29062912

29072913
[preset: source_compat_suite_linux_R]
29082914
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
@@ -1365,6 +1365,10 @@ def create_argument_parser():
13651365
default=True,
13661366
help='Enable Swift Synchronization.')
13671367

1368+
option('--enable-experimental-parser-validation', toggle_true,
1369+
default=False,
1370+
help='Enable experimental Swift Parser validation by default.')
1371+
13681372
# -------------------------------------------------------------------------
13691373
in_group('Unsupported options')
13701374

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
'enable_experimental_nonescapable_types': False,
172172
'enable_experimental_string_processing': True,
173173
'enable_experimental_observation': True,
174+
'enable_experimental_parser_validation': False,
174175
'swift_enable_backtracing': True,
175176
'enable_synchronization': True,
176177
'enable_lsan': False,
@@ -594,6 +595,7 @@ class BuildScriptImplOption(_BaseOption):
594595
EnableOption('--enable-experimental-nonescapable-types'),
595596
EnableOption('--enable-experimental-string-processing'),
596597
EnableOption('--enable-experimental-observation'),
598+
EnableOption('--enable-experimental-parser-validation'),
597599
EnableOption('--enable-lsan'),
598600
EnableOption('--enable-sanitize-coverage'),
599601
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)