From 1bf66af4d39a07c104fe51321c8c3da56780e818 Mon Sep 17 00:00:00 2001 From: Autopilot Bot Date: Tue, 13 Oct 2026 08:34:30 -0700 Subject: [PATCH] Make iOS Color default constructor constexpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: WARNING: Generated by Autopilot (alpha) — review carefully, verify the underlying claim before accepting. Agent: PRE Agent | Trajectory: https://www.internalfb.com/intern/devai/devmate/inspector/865a7ddc-4190-4005-a3f5-2b8db052633f/ | SC job: https://www.internalfb.com/intern/sandcastle/instance/67553995153430156/ --- ## The issue - On iOS, `HostPlatformColor.h` defines `NO_DESTROY static const Color UndefinedColor = Color();` at namespace scope. `Color()` is not `constexpr`, and it leaves `uiColorHashValue_` uninitialized, so every Objective-C++ translation unit that includes the header emits its own dynamic static initializer, which runs before `main`. - The header now reaches more translation units through the `` umbrella, and each new includer adds one more pre-main initializer. ## The fix - Make `Color()` `constexpr` and zero-initialize `uiColorHashValue_`, so `UndefinedColor` is constant-initialized and no longer emits an initializer. - This also gives the undefined color a defined hash value instead of an indeterminate one. - Update the Apple C++ API snapshots for the `constexpr` constructor. Changelog: [Internal] Differential Revision: D124952738 --- .../platform/ios/react/renderer/graphics/HostPlatformColor.h | 4 +++- scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api | 2 +- scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api | 2 +- scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api | 2 +- scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h index 80d61ff89d05..0e6efef455c2 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h +++ b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.h @@ -26,7 +26,9 @@ struct Color { Color(int32_t color); Color(const DynamicColor &dynamicColor); Color(const ColorComponents &components); - Color() : uiColor_(nullptr) {}; + // constexpr so `UndefinedColor` below is constant-initialized instead of + // emitting a static initializer in every translation unit that includes it. + constexpr Color() : uiColor_(nullptr), uiColorHashValue_(0) {}; int32_t getColor() const; std::size_t getUIColorHash() const; diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index adcf6293970e..2e990d9c5301 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -5325,7 +5325,7 @@ struct facebook::react::Bridging { } struct facebook::react::Color { - public Color(); + public constexpr Color(); public Color(const facebook::react::ColorComponents& components); public Color(const facebook::react::DynamicColor& dynamicColor); public Color(int32_t color); diff --git a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api index 2cb413c7e92c..75062b3527d2 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api @@ -8150,7 +8150,7 @@ struct facebook::react::CallbackWithId { } struct facebook::react::Color { - public Color(); + public constexpr Color(); public Color(const facebook::react::ColorComponents& components); public Color(const facebook::react::DynamicColor& dynamicColor); public Color(int32_t color); diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index 273b4a58578d..2badec9926eb 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -5310,7 +5310,7 @@ struct facebook::react::Bridging { } struct facebook::react::Color { - public Color(); + public constexpr Color(); public Color(const facebook::react::ColorComponents& components); public Color(const facebook::react::DynamicColor& dynamicColor); public Color(int32_t color); diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 3be7fbb556a1..05276aaff02b 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -5318,7 +5318,7 @@ struct facebook::react::Bridging { } struct facebook::react::Color { - public Color(); + public constexpr Color(); public Color(const facebook::react::ColorComponents& components); public Color(const facebook::react::DynamicColor& dynamicColor); public Color(int32_t color);