Repository navigation
Conversation
8d6cb13 to
46faf17
Compare
6a2ed1a to
5058ed1
Compare
chrfalch
left a comment
There was a problem hiding this comment.
The design is sound. A consteval RawPropName makes the lifetime of names stored in the parser a compile-time guarantee, and atRuntime plus the shared owned-key storage fixes a real dangling view: before this change the prefix and suffix overload of RawProps::at stored a view of a temporary std::string in keys_. All in-repo callers and the codegen output pass literals, so the repository itself compiles unchanged. This is a source-breaking change for third-party Fabric components whose C++ passes a const char* or std::string_view name to convertRawProp or RawProps::at, so the description needs a changelog entry tagged [General] [Breaking] that names the atRuntime replacement; it currently has no changelog section.
The classic Fabric props parser registers each name a component reads and keeps a view of its bytes for later lookups. A `const char*` name leaves that lifetime requirement unstated, and every lookup measures a length the compiler already knows. This change adds `RawPropName` and uses it for the single-name `RawProps::at` and for `convertRawProp`. Its `consteval` constructor accepts string literals and static `constexpr` character arrays, so the compiler computes the length and the name has static storage. A name ends at its first NUL, or at the end of an array that has none. Generated code and calls that pass a literal keep their syntax. Names built at run time go through the new `RawProps::atRuntime`. The parser copies such a name when it registers it, and later lookups compare against the argument without copying it. The deprecated three-argument prefix and suffix overload of `RawProps::at` uses `atRuntime`, so the parser no longer keeps a view of the temporary string that overload composes. A Props constructor that reads its props only under a condition that was false while the parser was prepared leaves the parser with no registered names. A lookup in such a parser now returns `nullptr` instead of reading the first element of an empty name list. C++ code that passes a `const char*` or `std::string_view` name to `convertRawProp` or `RawProps::at` no longer compiles. A helper that forwards a declared name takes a `RawPropName` instead; code that builds a name at run time calls `RawProps::atRuntime` and converts the returned `RawValue`. react#60541 proposes making the iterator-based setter the default for components that support it. That path hashes each supplied name and calls `setProp` without the registered names, so this change does not affect it. Components that use the classic constructor keep the registered-name path. `react_renderer_core_tests --gtest_filter='RawPropsTest.*:PropsConceptsTest.*:ComponentDescriptorTest.*'` passes in Debug. New tests look up a name without a terminating NUL, check that the parser copies composed names while it prepares, and look up a name in a parser that registered none. Compile-time checks accept string literals and reject `std::string`, `const char*` and `std::string_view` names. The Debug View and TextInput prop tests pass. The generated Safe Area props compile, and the Android NDK compiles the TextInput and View prop sources. `FANTOM_FORCE_OSS_BUILD=1 yarn fantom --maxWorkers=4` passes, including the View tests with the iterator flag on and off. `python -m scripts.cxx-api.parser --validate` passes with Doxygen 1.16.1. In an optimized build on an Apple M6, cloning `ViewProps` with six supplied props retires a median of 38,462 instructions on `075deb0d98` and 31,095 with this change on the classic path, 19.15% fewer. With the iterator flag on, the same clone retires 6,924 and 6,905. Signed-off-by: James Ide <ide@expo.dev>
5058ed1 to
5241193
Compare
|
Thanks for the review. The description already had a |
Summary:
The classic Fabric props parser registers each name a component reads and keeps a view of its bytes for later lookups. A
const char*name leaves that lifetime requirement unstated, and every lookup measures a length the compiler already knows.This change adds
RawPropNameand uses it for the single-nameRawProps::atand forconvertRawProp. Itsconstevalconstructor accepts string literals and staticconstexprcharacter arrays, so the compiler computes the length and the name has static storage. A name ends at its first NUL, or at the end of an array that has none. Generated code and calls that pass a literal keep their syntax.Names built at run time go through the new
RawProps::atRuntime. The parser copies such a name when it registers it, and later lookups compare against the argument without copying it. The deprecated three-argument prefix and suffix overload ofRawProps::atusesatRuntime, so the parser no longer keeps a view of the temporary string that overload composes.A Props constructor that reads its props only under a condition that was false while the parser was prepared leaves the parser with no registered names. A lookup in such a parser now returns
nullptrinstead of reading the first element of an empty name list.C++ code that passes a
const char*orstd::string_viewname toconvertRawProporRawProps::atno longer compiles. A helper that forwards a declared name takes aRawPropNameinstead; code that builds a name at run time callsRawProps::atRuntimeand converts the returnedRawValue.#60541 proposes making the iterator-based setter the default for components that support it. That path hashes each supplied name and calls
setPropwithout the registered names, so this change does not affect it. Components that use the classic constructor keep the registered-name path.Changelog:
[General] [Breaking] - Require string literal or static
constexprnames inconvertRawPropandRawProps::at; pass a name built at run time toRawProps::atRuntimeinsteadTest Plan:
react_renderer_core_tests --gtest_filter='RawPropsTest.*:PropsConceptsTest.*:ComponentDescriptorTest.*'passes in Debug. New tests look up a name without a terminating NUL, check that the parser copies composed names while it prepares, and look up a name in a parser that registered none. Compile-time checks accept string literals and rejectstd::string,const char*andstd::string_viewnames.The Debug View and TextInput prop tests pass. The generated Safe Area props compile, and the Android NDK compiles the TextInput and View prop sources.
FANTOM_FORCE_OSS_BUILD=1 yarn fantom --maxWorkers=4passes, including the View tests with the iterator flag on and off.python -m scripts.cxx-api.parser --validatepasses with Doxygen 1.16.1.In an optimized build on an Apple M6, cloning
ViewPropswith six supplied props retires a median of 38,462 instructions on075deb0d98and 31,095 with this change on the classic path, 19.15% fewer. With the iterator flag on, the same clone retires 6,924 and 6,905.