Skip to content

Commit 810a94c

Browse files
committed
[CMake] Add option to perform SwiftParser validation by default
Disabled by default. We'll enable it for some build presets. rdar://121545713
1 parent 991a6de commit 810a94c

File tree

9 files changed

+33
-2
lines changed

9 files changed

+33
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ option(SWIFT_ENABLE_GLOBAL_ISEL_ARM64
663663
"Enable global isel on arm64"
664664
FALSE)
665665

666+
option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
667+
"Enable experimental SwiftParser validation by default"
668+
FALSE)
669+
666670
cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
667671
"Build SourceKit" TRUE
668672
"SWIFT_ENABLE_DISPATCH" FALSE)

SwiftCompilerSources/CMakeLists.txt

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

119-
if(NOT LLVM_ENABLE_ASSERTIONS)
119+
if(LLVM_ENABLE_ASSERTIONS)
120+
list(APPEND swift_compile_options "-Xcc" "-UNDEBUG")
121+
else()
120122
list(APPEND swift_compile_options "-Xcc" "-DNDEBUG")
121123
endif()
122124

cmake/modules/AddPureSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ function(_add_host_swift_compile_options name)
6565
target_compile_options(${name} PRIVATE
6666
$<$<COMPILE_LANGUAGE:Swift>:-color-diagnostics>
6767
)
68+
69+
if(LLVM_ENABLE_ASSERTIONS)
70+
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -UNDEBUG>")
71+
else()
72+
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DNDEBUG>")
73+
endif()
6874
endfunction()
6975

7076
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
@@ -18,4 +18,6 @@
1818

1919
#cmakedefine01 SWIFT_ENABLE_GLOBAL_ISEL_ARM64
2020

21+
#cmakedefine01 SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
22+
2123
#endif // SWIFT_CONFIG_H

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
13981398
}
13991399
}
14001400

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

utils/build_swift/build_swift/driver_arguments.py

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

1353+
option('--enable-experimental-parser-validation', toggle_true,
1354+
default=False,
1355+
help='Enable experimental Swift Parser validation by default.')
1356+
13531357
# -------------------------------------------------------------------------
13541358
in_group('Unsupported options')
13551359

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
'enable_experimental_noncopyable_generics': False,
168168
'enable_experimental_string_processing': True,
169169
'enable_experimental_observation': True,
170+
'enable_experimental_parser_validation': False,
170171
'swift_enable_backtracing': True,
171172
'enable_synchronization': True,
172173
'enable_lsan': False,
@@ -587,6 +588,7 @@ class BuildScriptImplOption(_BaseOption):
587588
EnableOption('--enable-experimental-noncopyable-generics'),
588589
EnableOption('--enable-experimental-string-processing'),
589590
EnableOption('--enable-experimental-observation'),
591+
EnableOption('--enable-experimental-parser-validation'),
590592
EnableOption('--enable-lsan'),
591593
EnableOption('--enable-sanitize-coverage'),
592594
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_noncopyable_generics=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_NONCOPYABLE_GENERICS: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_NONCOPYABLE_GENERICS: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)