Skip to content

Make iOS Color default constructor constexpr - #59044

Open
christophpurrer wants to merge 1 commit into
react:mainfrom
christophpurrer:export-D124952738
Open

christophpurrer wants to merge 1 commit into
react:mainfrom
christophpurrer:export-D124952738

Conversation

@christophpurrer

Copy link
Copy Markdown
Contributor

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 <React/Graphics.h> 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

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 `<React/Graphics.h>` 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
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 13, 2026
@meta-codesync

meta-codesync Bot commented Oct 13, 2026

Copy link
Copy Markdown

@christophpurrer has exported this pull request. If you are a Meta employee, you can view the originating Diff in D124952738.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant