From e4c88915abb9aad416d65c053504ae9e583c6999 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 22 Mar 2025 18:58:04 -0600 Subject: [PATCH] LibGC+LibJS+LibWeb: Add workaround for Swift boolean bitfield issue This patch adds a workaround for a Swift issue where boolean bitfields with getters and setters in SWIFT_UNSAFE_REFERENCE types are improperly imported, causing an ICE. --- Libraries/LibGC/CMakeLists.txt | 8 ++++++-- Libraries/LibGC/Cell.h | 18 +++++++++++++----- Libraries/LibJS/Runtime/Shape.h | 6 +++--- Libraries/LibWeb/Bindings/PlatformObject.h | 22 +++++++++++----------- Libraries/LibWeb/CSS/StyleInvalidation.h | 8 ++++---- Libraries/LibWeb/DOM/Element.h | 20 ++++++++++---------- Libraries/LibWeb/Painting/Paintable.h | 12 ++++++------ Meta/CMake/Swift/swift-settings.cmake | 9 +++++++-- 8 files changed, 60 insertions(+), 43 deletions(-) diff --git a/Libraries/LibGC/CMakeLists.txt b/Libraries/LibGC/CMakeLists.txt index e5518077a55..b7e6f880ad4 100644 --- a/Libraries/LibGC/CMakeLists.txt +++ b/Libraries/LibGC/CMakeLists.txt @@ -17,8 +17,12 @@ target_link_libraries(LibGC PRIVATE LibCore) if (ENABLE_SWIFT) generate_clang_module_map(LibGC) target_sources(LibGC PRIVATE - Heap+Swift.swift + Heap+Swift.swift ) target_link_libraries(LibGC PRIVATE AK) - add_swift_target_properties(LibGC LAGOM_LIBRARIES AK) + + # FIXME: https://github.com/swiftlang/swift/issues/80182 + target_compile_options(LibGC PUBLIC $<$:-DLIBGC_WORKAROUND_BOOL_BITFIELD> + SHELL:$<$:-Xcc -DLIBGC_WORKAROUND_BOOL_BITFIELD>) + add_swift_target_properties(LibGC LAGOM_LIBRARIES AK COMPILE_DEFINITIONS LIBGC_WORKAROUND_BOOL_BITFIELD) endif() diff --git a/Libraries/LibGC/Cell.h b/Libraries/LibGC/Cell.h index 60f72f1e74a..45f2da8d5c9 100644 --- a/Libraries/LibGC/Cell.h +++ b/Libraries/LibGC/Cell.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,13 @@ namespace GC { # define IGNORE_GC #endif +// https://github.com/swiftlang/swift/issues/80182 +#if defined(LIBGC_WORKAROUND_BOOL_BITFIELD) +# define BOOL_BITFIELD +#else +# define BOOL_BITFIELD : 1 +#endif + #define GC_CELL(class_, base_class) \ public: \ using Base = base_class; \ @@ -163,7 +171,7 @@ public: protected: virtual void visit_impl(Cell&) = 0; virtual ~Visitor() = default; - }; + } SWIFT_UNSAFE_REFERENCE; virtual void visit_edges(Visitor&) { } @@ -187,10 +195,10 @@ protected: void set_overrides_must_survive_garbage_collection(bool b) { m_overrides_must_survive_garbage_collection = b; } private: - bool m_mark { false }; - bool m_overrides_must_survive_garbage_collection { false }; - State m_state { State::Live }; -}; + bool m_mark BOOL_BITFIELD { false }; + bool m_overrides_must_survive_garbage_collection BOOL_BITFIELD { false }; + State m_state BOOL_BITFIELD { State::Live }; +} SWIFT_UNSAFE_REFERENCE; } diff --git a/Libraries/LibJS/Runtime/Shape.h b/Libraries/LibJS/Runtime/Shape.h index 3ee9fb133e7..7d24b3c77c8 100644 --- a/Libraries/LibJS/Runtime/Shape.h +++ b/Libraries/LibJS/Runtime/Shape.h @@ -142,9 +142,9 @@ private: PropertyAttributes m_attributes { 0 }; TransitionType m_transition_type { TransitionType::Invalid }; - bool m_dictionary : 1 { false }; - bool m_cacheable : 1 { true }; - bool m_is_prototype_shape : 1 { false }; + bool m_dictionary BOOL_BITFIELD { false }; + bool m_cacheable BOOL_BITFIELD { true }; + bool m_is_prototype_shape BOOL_BITFIELD { false }; }; } diff --git a/Libraries/LibWeb/Bindings/PlatformObject.h b/Libraries/LibWeb/Bindings/PlatformObject.h index 99bbc35f0aa..b70ae58c26b 100644 --- a/Libraries/LibWeb/Bindings/PlatformObject.h +++ b/Libraries/LibWeb/Bindings/PlatformObject.h @@ -49,17 +49,17 @@ protected: explicit PlatformObject(JS::Object& prototype, MayInterfereWithIndexedPropertyAccess = MayInterfereWithIndexedPropertyAccess::No); struct LegacyPlatformObjectFlags { - u16 supports_indexed_properties : 1 = false; - u16 supports_named_properties : 1 = false; - u16 has_indexed_property_setter : 1 = false; - u16 has_named_property_setter : 1 = false; - u16 has_named_property_deleter : 1 = false; - u16 has_legacy_unenumerable_named_properties_interface_extended_attribute : 1 = false; - u16 has_legacy_override_built_ins_interface_extended_attribute : 1 = false; - u16 has_global_interface_extended_attribute : 1 = false; - u16 indexed_property_setter_has_identifier : 1 = false; - u16 named_property_setter_has_identifier : 1 = false; - u16 named_property_deleter_has_identifier : 1 = false; + u16 supports_indexed_properties BOOL_BITFIELD = false; + u16 supports_named_properties BOOL_BITFIELD = false; + u16 has_indexed_property_setter BOOL_BITFIELD = false; + u16 has_named_property_setter BOOL_BITFIELD = false; + u16 has_named_property_deleter BOOL_BITFIELD = false; + u16 has_legacy_unenumerable_named_properties_interface_extended_attribute BOOL_BITFIELD = false; + u16 has_legacy_override_built_ins_interface_extended_attribute BOOL_BITFIELD = false; + u16 has_global_interface_extended_attribute BOOL_BITFIELD = false; + u16 indexed_property_setter_has_identifier BOOL_BITFIELD = false; + u16 named_property_setter_has_identifier BOOL_BITFIELD = false; + u16 named_property_deleter_has_identifier BOOL_BITFIELD = false; }; Optional m_legacy_platform_object_flags = {}; diff --git a/Libraries/LibWeb/CSS/StyleInvalidation.h b/Libraries/LibWeb/CSS/StyleInvalidation.h index 8fa8c75fbb6..19d7399d525 100644 --- a/Libraries/LibWeb/CSS/StyleInvalidation.h +++ b/Libraries/LibWeb/CSS/StyleInvalidation.h @@ -11,10 +11,10 @@ namespace Web::CSS { struct RequiredInvalidationAfterStyleChange { - bool repaint : 1 { false }; - bool rebuild_stacking_context_tree : 1 { false }; - bool relayout : 1 { false }; - bool rebuild_layout_tree : 1 { false }; + bool repaint BOOL_BITFIELD { false }; + bool rebuild_stacking_context_tree BOOL_BITFIELD { false }; + bool relayout BOOL_BITFIELD { false }; + bool rebuild_layout_tree BOOL_BITFIELD { false }; void operator|=(RequiredInvalidationAfterStyleChange const& other) { diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index e62f86a5080..9532bf870a3 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -553,16 +553,16 @@ private: Array m_scroll_offset; - bool m_in_top_layer : 1 { false }; - bool m_rendered_in_top_layer : 1 { false }; - bool m_style_uses_css_custom_properties { false }; - bool m_affected_by_has_pseudo_class_in_subject_position : 1 { false }; - bool m_affected_by_has_pseudo_class_in_non_subject_position : 1 { false }; - bool m_affected_by_direct_sibling_combinator : 1 { false }; - bool m_affected_by_indirect_sibling_combinator : 1 { false }; - bool m_affected_by_first_or_last_child_pseudo_class : 1 { false }; - bool m_affected_by_nth_child_pseudo_class : 1 { false }; - bool m_affected_by_has_pseudo_class_with_relative_selector_that_has_sibling_combinator : 1 { false }; + bool m_in_top_layer BOOL_BITFIELD { false }; + bool m_rendered_in_top_layer BOOL_BITFIELD { false }; + bool m_style_uses_css_custom_properties BOOL_BITFIELD { false }; + bool m_affected_by_has_pseudo_class_in_subject_position BOOL_BITFIELD { false }; + bool m_affected_by_has_pseudo_class_in_non_subject_position BOOL_BITFIELD { false }; + bool m_affected_by_direct_sibling_combinator BOOL_BITFIELD { false }; + bool m_affected_by_indirect_sibling_combinator BOOL_BITFIELD { false }; + bool m_affected_by_first_or_last_child_pseudo_class BOOL_BITFIELD { false }; + bool m_affected_by_nth_child_pseudo_class BOOL_BITFIELD { false }; + bool m_affected_by_has_pseudo_class_with_relative_selector_that_has_sibling_combinator BOOL_BITFIELD { false }; size_t m_sibling_invalidation_distance { 0 }; diff --git a/Libraries/LibWeb/Painting/Paintable.h b/Libraries/LibWeb/Painting/Paintable.h index a47211cb64d..f0ec52e5b62 100644 --- a/Libraries/LibWeb/Painting/Paintable.h +++ b/Libraries/LibWeb/Painting/Paintable.h @@ -168,12 +168,12 @@ private: SelectionState m_selection_state { SelectionState::None }; - bool m_positioned : 1 { false }; - bool m_fixed_position : 1 { false }; - bool m_sticky_position : 1 { false }; - bool m_absolutely_positioned : 1 { false }; - bool m_floating : 1 { false }; - bool m_inline : 1 { false }; + bool m_positioned BOOL_BITFIELD { false }; + bool m_fixed_position BOOL_BITFIELD { false }; + bool m_sticky_position BOOL_BITFIELD { false }; + bool m_absolutely_positioned BOOL_BITFIELD { false }; + bool m_floating BOOL_BITFIELD { false }; + bool m_inline BOOL_BITFIELD { false }; }; inline DOM::Node* HitTestResult::dom_node() diff --git a/Meta/CMake/Swift/swift-settings.cmake b/Meta/CMake/Swift/swift-settings.cmake index 4563b4442ec..b1f9779fac2 100644 --- a/Meta/CMake/Swift/swift-settings.cmake +++ b/Meta/CMake/Swift/swift-settings.cmake @@ -40,7 +40,7 @@ function(swizzle_target_properties_for_swift target_name) endfunction() function(add_swift_target_properties target_name) - cmake_parse_arguments(PARSE_ARGV 1 SWIFT_TARGET "" "" "LAGOM_LIBRARIES") + cmake_parse_arguments(PARSE_ARGV 1 SWIFT_TARGET "" "" "LAGOM_LIBRARIES;COMPILE_DEFINITIONS;COMPILE_OPTIONS") target_compile_features(${target_name} PUBLIC cxx_std_${CMAKE_CXX_STANDARD}) target_compile_options(${target_name} PUBLIC "SHELL:$<$:-Xcc -std=c++23 -cxx-interoperability-mode=default>") @@ -60,8 +60,13 @@ function(add_swift_target_properties target_name) get_target_property(_NATIVE_DIRS ${target_name} INCLUDE_DIRECTORIES) list(APPEND _NATIVE_DIRS ${CMAKE_Swift_MODULE_DIRECTORY}) + set(EXTRA_COMPILE_DEFINITIONS "") + foreach (compile_definition IN LISTS SWIFT_TARGET_COMPILE_DEFINITIONS) + list(APPEND EXTRA_COMPILE_DEFINITIONS "-Xcc" "-D${compile_definition}") + endforeach() + _swift_generate_cxx_header(${target_name} "${target_name}-Swift.h" SEARCH_PATHS ${_NATIVE_DIRS} - COMPILE_OPTIONS ${VFS_OVERLAY_OPTIONS} + COMPILE_OPTIONS ${VFS_OVERLAY_OPTIONS} ${EXTRA_COMPILE_DEFINITIONS} ${SWIFT_TARGET_COMPILE_OPTIONS} ) endfunction()