Skip to content

[6.0][CMake] Add option to perform SwiftParser validation by default #73016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ option(SWIFT_ENABLE_GLOBAL_ISEL_ARM64
"Enable global isel on arm64"
FALSE)

option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
"Enable experimental SwiftParser validation by default"
FALSE)

cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
"Build SourceKit" TRUE
"SWIFT_ENABLE_DISPATCH" FALSE)
Expand Down
4 changes: 3 additions & 1 deletion SwiftCompilerSources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ function(add_swift_compiler_modules_library name)
list(APPEND swift_compile_options "-O" "-cross-module-optimization")
endif()

if(NOT LLVM_ENABLE_ASSERTIONS)
if(LLVM_ENABLE_ASSERTIONS)
list(APPEND swift_compile_options "-Xcc" "-UNDEBUG")
else()
list(APPEND swift_compile_options "-Xcc" "-DNDEBUG")
endif()

Expand Down
6 changes: 6 additions & 0 deletions cmake/modules/AddPureSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ function(_add_host_swift_compile_options name)
target_compile_options(${name} PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-color-diagnostics>
)

if(LLVM_ENABLE_ASSERTIONS)
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -UNDEBUG>")
else()
target_compile_options(${name} PRIVATE "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DNDEBUG>")
endif()
endfunction()

function(_set_pure_swift_link_flags name relpath_to_lib_dir)
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@

#cmakedefine01 SWIFT_ENABLE_GLOBAL_ISEL_ARM64

#cmakedefine01 SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION

#endif // SWIFT_CONFIG_H
2 changes: 1 addition & 1 deletion lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
}
}

#ifndef NDEBUG
#if SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
/// Enable round trip parsing via the new swift parser unless it is disabled
/// explicitly. The new Swift parser can have mismatches with C++ parser -
/// rdar://118013482 Use this flag to disable round trip through the new
Expand Down
6 changes: 6 additions & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,7 @@ skstresstester
sourcekit-lsp
install-swiftformat
skip-test-swift=false
enable-experimental-parser-validation=true

[preset: buildbot_swiftsyntax_linux]
mixin-preset=mixin_swiftpm_package_linux_platform
Expand All @@ -1881,6 +1882,7 @@ swiftsyntax-enable-test-fuzzing
sourcekit-lsp
swiftformat
install-swiftformat
enable-experimental-parser-validation=true

#===------------------------------------------------------------------------===#
# Test Swift Format
Expand Down Expand Up @@ -2853,12 +2855,14 @@ mixin-preset=source_compat_suite_macos_base
debug
assertions
cross-compile-hosts=macosx-arm64
enable-experimental-parser-validation=true

[preset: source_compat_suite_macos_RA]
mixin-preset=source_compat_suite_macos_base
release
assertions
cross-compile-hosts=macosx-arm64
enable-experimental-parser-validation=true

[preset: source_compat_suite_macos_R]
mixin-preset=source_compat_suite_macos_base
Expand All @@ -2876,11 +2880,13 @@ cross-compile-hosts=macosx-arm64
mixin-preset=source_compat_suite_linux_base
debug
assertions
enable-experimental-parser-validation=true

[preset: source_compat_suite_linux_RA]
mixin-preset=source_compat_suite_linux_base
release
assertions
enable-experimental-parser-validation=true

[preset: source_compat_suite_linux_R]
mixin-preset=source_compat_suite_linux_base
Expand Down
4 changes: 4 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,10 @@ def create_argument_parser():
default=True,
help='Enable Swift Synchronization.')

option('--enable-experimental-parser-validation', toggle_true,
default=False,
help='Enable experimental Swift Parser validation by default.')

# -------------------------------------------------------------------------
in_group('Unsupported options')

Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
'enable_experimental_nonescapable_types': False,
'enable_experimental_string_processing': True,
'enable_experimental_observation': True,
'enable_experimental_parser_validation': False,
'swift_enable_backtracing': True,
'enable_synchronization': True,
'enable_lsan': False,
Expand Down Expand Up @@ -596,6 +597,7 @@ class BuildScriptImplOption(_BaseOption):
EnableOption('--enable-experimental-nonescapable-types'),
EnableOption('--enable-experimental-string-processing'),
EnableOption('--enable-experimental-observation'),
EnableOption('--enable-experimental-parser-validation'),
EnableOption('--enable-lsan'),
EnableOption('--enable-sanitize-coverage'),
EnableOption('--enable-tsan'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def __init__(self, args, toolchain, source_dir, build_dir):
self.cmake_options.extend(
self._swift_tools_ld64_lto_codegen_only_for_supporting_targets)

self.cmake_options.extend(
self._enable_experimental_parser_validation)

@classmethod
def is_build_script_impl_product(cls):
"""is_build_script_impl_product -> bool
Expand Down Expand Up @@ -238,6 +241,11 @@ def _swift_tools_ld64_lto_codegen_only_for_supporting_targets(self):
return [('SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS:BOOL',
self.args.swift_tools_ld64_lto_codegen_only_for_supporting_targets)]

@property
def _enable_experimental_parser_validation(self):
return [('SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL',
self.args.enable_experimental_parser_validation)]

@classmethod
def get_dependencies(cls):
return [cmark.CMark,
Expand Down
3 changes: 3 additions & 0 deletions utils/swift_build_support/tests/products/test_swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def setUp(self):
enable_experimental_distributed=False,
enable_experimental_nonescapable_types=False,
enable_experimental_observation=False,
enable_experimental_parser_validation=False,
swift_enable_backtracing=False,
enable_synchronization=False,
build_early_swiftsyntax=False,
Expand Down Expand Up @@ -105,6 +106,7 @@ def test_by_default_no_cmake_options(self):
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE',
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
'-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE',
'-DSWIFT_STDLIB_STATIC_PRINT=FALSE',
Expand Down Expand Up @@ -134,6 +136,7 @@ def test_swift_runtime_tsan(self):
'-DSWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_OBSERVATION:BOOL=FALSE',
'-DSWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION:BOOL=FALSE',
'-DSWIFT_ENABLE_BACKTRACING:BOOL=FALSE',
'-DSWIFT_ENABLE_SYNCHRONIZATION:BOOL=FALSE',
'-DSWIFT_STDLIB_STATIC_PRINT=FALSE',
Expand Down