Commit Graph

2291 Commits

Author SHA1 Message Date
Nick Gerleman
557d2a76fe Breaking: Use C++ 20 (#1382)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1382

X-link: https://github.com/facebook/react-native/pull/39437

Have been running into places where C++ 20 makes life easier for use like `std::bit_cast` (that one is easy to polyfill), in-class member initializer support for bitfields, designated initializers, defaulted comparison operator, concepts instead of SFINAE, and probably more.

Our other infra is in the process of making this jump, or already has. This tests it out everywhere, across the various reference builds, to see if we have any issues.

This is a bit more aggressive than I had previously communicated, but n - 1 is going to be a better long term place than n - 2.

If we wanted to use `std::bit_cast` we would need one of:
1. GCC 11+ (~2.5 years old)
1. Clang 14 (~2.5 years old)
1. VS 16.11 (~2 years old)

For mobile this means:
1. NDK 26 (still in Beta 😭)
1. XCode 14.3.0 (~6 months old)

https://en.cppreference.com/w/cpp/compiler_support/20

That isn't quite doable yet, but we can start taking advantage of language features in the meantime. More of these will be supported in older toolchains.

Anyone needing support for older C++ versions can lag behind on more recent changes. E.g. Yoga 2.0 supports C++ 14.

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D49261607

fbshipit-source-id: ceb06eac20dfe93352d7b796d6847a7314069cf3
2023-09-19 01:28:35 -07:00
Nick Gerleman
ed406f0b55 C++ style enums 7/N: MeasureMode (#1389)
Summary:
X-link: https://github.com/facebook/react-native/pull/39452

Pull Request resolved: https://github.com/facebook/yoga/pull/1389

This converts usages of YGMeasureMode to MeasureMode

Reviewed By: rozele

Differential Revision: D49271165

fbshipit-source-id: 273c9ed0a61c3965e469548d29d37e4566c974dc
2023-09-14 23:06:34 -07:00
Nick Gerleman
383b325d06 C++ style enums 6/N: PrintOptions (#1385)
Summary:
X-link: https://github.com/facebook/react-native/pull/39449

Pull Request resolved: https://github.com/facebook/yoga/pull/1385

This converts usages of YGPrintOptions to PrintOptions

Reviewed By: rozele

Differential Revision: D49270929

fbshipit-source-id: ad98dd25865138808d25b48eff22fbe81ccdd352
2023-09-14 23:06:34 -07:00
Nick Gerleman
70954bbda5 C++ style enums 5/N: LogLevel (#1387)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1387

X-link: https://github.com/facebook/react-native/pull/39447

This converts usages of YGLogLevel to LogLevel

Reviewed By: rozele

Differential Revision: D49270695

fbshipit-source-id: 2ba5b4f2b0af93fef89dbbb2ce54c2f486670aac
2023-09-14 23:06:34 -07:00
Nick Gerleman
6f5eaefc51 C++ style enums 4/N: Errata (#1388)
Summary:
X-link: https://github.com/facebook/react-native/pull/39451

Pull Request resolved: https://github.com/facebook/yoga/pull/1388

This converts usages of YGErrata to Errata

Reviewed By: rozele

Differential Revision: D49270354

fbshipit-source-id: 39c0d26a1609cca0a96da843796ab41c81e3af93
2023-09-14 23:06:34 -07:00
Nick Gerleman
42e1f2c737 C++ style enums 3/N: ExperimentalFeature (#1386)
Summary:
X-link: https://github.com/facebook/react-native/pull/39448

Pull Request resolved: https://github.com/facebook/yoga/pull/1386

This converts usages of YGExperimentalFeature to ExperimentalFeature

Reviewed By: rozele

Differential Revision: D49269440

fbshipit-source-id: 0fcb4f380e214a6aadcac457df5a989789bb05d2
2023-09-14 23:06:34 -07:00
Nick Gerleman
9129a0af87 C++ style enums 2/N: NodeType (#1383)
Summary:
X-link: https://github.com/facebook/react-native/pull/39450

Pull Request resolved: https://github.com/facebook/yoga/pull/1383

This converts usages of YGNodeType to NodeType

Reviewed By: rozele

Differential Revision: D49269117

fbshipit-source-id: 27318279fe555c28c605625a160d5be781b662b8
2023-09-14 23:06:34 -07:00
Nick Gerleman
4cd45ac5d5 C++ style enums 1/N: Generator (#1384)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1384

X-link: https://github.com/facebook/react-native/pull/39446

This adds logic to the enum generator to generate C++ style scoped enums.

This gives us a few nicities over C enums, even if both must exist:
1. We can add types and keep unsgined enums directly in bitfields
2. Style/readability
3. Avoiding implicit int conversion

Reviewed By: rozele

Differential Revision: D49267996

fbshipit-source-id: 1c41164c377b317c1fef97811c46cbc00b5a837e
2023-09-14 23:06:34 -07:00
Nick Gerleman
c60050d0cb Fixup hack for flex line size calculation (#1380)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1380

X-link: https://github.com/facebook/react-native/pull/39433

Back when rolling out flex gap, we encountered a bug where gap was added to the end of the main axis when a size was not specified.

During flex line justification/sizing, we calculate the amount of space that should be in between children. We erroneously add this, even after the last child element.

For `justify-content`, this space between children is derived from free space along the axis. The only time we have free space is if we had a dimension/dimension constraint already set on the parent. In this case, the extra space added to the end of the flex line is usually never noticed, because we bound `maxLineMainDim` to container dimension constraints at the end of layout, and the error doesn't effect how any children are positioned or sized.

There was at least one screenshot test where this issue showed up though, and I was able to add a slightly different repro where we may have free space without a definite dimension by enforcing a min dimension and not stretching.

{F1091401183}

The new reference is correct, and looking back at diffs, is what this seemed to originally look like when added three years ago. Seems like there may have been a potential regression, but I didn't spot anything suspicious when I looked around the code history.

`betweenMainDim` may still be set for `gap` even if we don't have a sized parent, which makes the extra space propagated to `maxLineMainDim` effect parent size.

Because we were in a code freeze, I opted to have us go with a solution just effecting flex gap, instead of the right one, in case there were any side effects. This cleans up the code to use the right calculation everywhere, and fixes a separate bug, where `endOfLineIndex` and `startOfLineIndex` may not be the last/first in the line if they are out of the layout flow (absolutely positioned, or display: none_

See the original conversation on https://github.com/facebook/yoga/pull/1188

Reviewed By: javache

Differential Revision: D49260049

fbshipit-source-id: 218552c5ff938668b9f257df7a1493e13ded4d0d
2023-09-14 20:26:31 -07:00
Nick Gerleman
f9c2c27d33 Use fbsource clang-format config
Summary:
This mirrors the clang-format config used by fbsource to Yoga.

They are pretty similar, except for an annoying habit where Yoga's previous forced small functions in headers to be a a single line, so you would get a combination of multiline and single line functions next to each other which are hard to read. That is what motivated this change.

It also enforces header ordering (yay). I don't think we have any side-effect causing headers, so this should be safe.

Reviewed By: yungsters

Differential Revision: D49248994

fbshipit-source-id: 66998395e7c0158ff9d9fb1bee44e8401bdd8f21
2023-09-13 20:12:55 -07:00
Nick Gerleman
9d21e3e300 Remove config drilling (#1378)
Summary:
X-link: https://github.com/facebook/react-native/pull/39404

Pull Request resolved: https://github.com/facebook/yoga/pull/1378

We thread a config through the root node, to every function, that we don't actually use (with the exception of `canUseCachedMeasurement` in the previous diff which was passing root `pointScaleFactor`).

Since the model is currently per-node config, this only creates redundancy/confusion.

I do think we might want to make some more global/layout-pass scoped configuration in the future, but likely not with this sort of drilling.

Reviewed By: yungsters

Differential Revision: D49180385

fbshipit-source-id: 91248042df7d3cea1fc316b47b8137fcb790b521
2023-09-13 20:12:55 -07:00
Nick Gerleman
66cc95f932 Breaking: per-node pointScaleFactor (#1379)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1379

X-link: https://github.com/facebook/react-native/pull/39403

Right now we have a `pointScaleFactor` per-node, but only ever read the one off the root node. In most cases where config is global, these will be the same, but it is possible for these to differ.

This... doesn't make much sense from an API perspective, and there are edge cases where we may want to allow laying out a subtree with a different DPI then the rest of the tree (though I think there might be other solutions to that).

We should rethink some of what is currently on config being allowed per-node (do we really need each node to be able to have a separate logger?), but this makes the model consistent in the meantime.

This change is breaking to any users relying on setting `pointScaleFactor` on the config of the root node, but not other nodes.

Reviewed By: yungsters

Differential Revision: D49181131

fbshipit-source-id: f1363ca242094f04b995fd50c1e56834d5003425
2023-09-13 14:11:25 -07:00
Nick Gerleman
0a90b16ac6 Remove layoutContext Drilling (#1376)
Summary:
X-link: https://github.com/facebook/react-native/pull/39401

Pull Request resolved: https://github.com/facebook/yoga/pull/1376

kill_with_fire_flamethrower

Reviewed By: rshest

Differential Revision: D49179244

fbshipit-source-id: 9a827e1bd29205254fee5725449191726d6bcf5a
2023-09-12 19:08:55 -07:00
Nick Gerleman
b1e0140aaa Remove JNI Binding usage of layoutContext (#1377)
Summary:
X-link: https://github.com/facebook/react-native/pull/39402

Pull Request resolved: https://github.com/facebook/yoga/pull/1377

To avoid keeping a per-node mapping on native Yoga nodes to Java nodes, a per-layout context was added, to be able to pass information from the start of the layout, to measure functions, log functions, etc.

The way this was done was super invasive, and added quite a few private APIs used only by the JNI functions.

This change removes the context-using functions from the JNI bindings in favor of it managing its own context. Next diff removes all the cruft.

Reviewed By: javache

Differential Revision: D49179243

fbshipit-source-id: 7e4944bead864e6b73fd2208a47c5725c18ff2b0
2023-09-12 19:08:55 -07:00
Nick Gerleman
700be8c8ad Extract isBaselineLayout() (#1375)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1375

X-link: https://github.com/facebook/react-native/pull/39400

Moves `isBaselineLayout` out of `CalculateLayout` into `Baseline.h`. This function is called by flex line justification code, which I have been looking at extracting.

Reviewed By: yungsters

Differential Revision: D49177937

fbshipit-source-id: 02c13aa0b02b26cb60ef197473b90e06d53d5f8d
2023-09-12 19:08:55 -07:00
Nick Gerleman
62ba8ebb3d Replace dim and pos arrays (#1373)
Summary:
X-link: https://github.com/facebook/react-native/pull/39397

Pull Request resolved: https://github.com/facebook/yoga/pull/1373

These are used to get the position origin edge from axis (same as leading edge), and dimension from axis.

Replace them with function usage, so that we can call into them from other files than `CalculateLayout.cpp`, and so that we can later use scoped enums not implicitly convertible to ints.

Reviewed By: rshest

Differential Revision: D49134566

fbshipit-source-id: cb806539ba0733a5773c594713720d465987e469
2023-09-11 19:51:40 -07:00
Nick Gerleman
a4f36bdb51 Separate FlexLine functionality (#1374)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1374

X-link: https://github.com/facebook/react-native/pull/39396

Yoga today has a struct `CollectFlexItemsRowValues`, and function `calculateFlexItemsRowValues()`. These names have evolved over time into something not making much sense.

The job of `calculateFlexItemsRowValues()` is a flex-wrap container into lines (i.e. line-breaking main-axis content, which may be row or column). It returns line-breaking results, but some other fields on `calculateFlexItemsRowValues()` are set much later in the process, and the struct is acting effectivelty as a holder for the line-specific values.

This change:
1. Does some renaming (mainly to FlexLine)
2. Reconciles the count `itemsOnLine` and list `relativeChildren` to list `itemsInFlow` (`relativeChildren` is a lie, as it can include elements with `YGPositionTypeStatic` and exclude relative elements which have `display: "none"`. It really just means children which are included in the layout flow for the line)
3. Makes non-changing algorithm outputs const for clarity of what is a running value, and what is a result of line-breaking values with flex basis.
4. Moves working layout values to a substructure `flexLine.layout`
5. Replaces some dishonest documentation about `endOfLineIndex`.
6. Extracts this logic out of `CalculateLayout()` to a separate file
7. Extracts `boundAxis` wholesale into a separate file, to be usable outside of `CalculateLayout.cpp`

Reviewed By: rshest

Differential Revision: D49133837

fbshipit-source-id: ec68c5a3d2f01e7c9bd8d26e28298331a3fe2475
2023-09-11 19:51:40 -07:00
Nick Gerleman
241c5e4baf Cleanup visibility macros (#1372)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1372

X-link: https://github.com/facebook/react-native/pull/39375

D18029030 added `-fvisibility-hidden`, and a corresponding `YOGA_EXPORT` macro for defining shared library visibility. This is used inline next to function and class definitions that should be exported out of the binary.

There was already a `WIN_EXPORT` macro doing the same thing when building a DLL, defined in the headers instead of CPP files, and it seems like sometimes folks forgot to add it to new public APIs after?

This reconciles the redundant macros into a single visibility macro, that we always place with declaration instead of definition. We also rename `YOGA_EXPORT` to `YG_EXPORT` to match the naming convention of other Yoga macros.

Reviewed By: rshest

Differential Revision: D49132643

fbshipit-source-id: cafa6de0c300788a72d9a446ce07c5ac89a20a8e
2023-09-11 19:51:40 -07:00
Nick Gerleman
0720e0b22a Breaking: YGConfigRef related const-correctness fixes (#1371)
Summary:
X-link: https://github.com/facebook/react-native/pull/39374

Pull Request resolved: https://github.com/facebook/yoga/pull/1371

Right now `YGConfigGetDefault` and `YGNodeGetConfig` both return mutable, freeable, configs, which is bad, since the former points to a global singleton config, and the latter usually does too. Mutating this is not thread safe, and it should never be freed.

This change makes these functions return `YGConfigConstRef` to prevent mutation, and also lets us allow `YGConfigNewWithConfig` to accept a const config. If a caller does want to mutate a config (such as to free it), it must be tracked manually.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D49132476

fbshipit-source-id: ac9ce61149e69c6c25cadb99711435b0a5b9f38a
2023-09-11 19:51:40 -07:00
Nick Gerleman
a003c09a4c Cleanup Android logger code (#1367)
Summary:
X-link: https://github.com/facebook/react-native/pull/39373

Pull Request resolved: https://github.com/facebook/yoga/pull/1367

Moves some messiness around conditionally using Android's logger to `Log.cpp`, isolated to within a single function.

Reviewed By: rshest

Differential Revision: D49131964

fbshipit-source-id: cdff8af1d4df6ae28f00eecfed1920c71eec24d0
2023-09-11 19:51:40 -07:00
Nick Gerleman
c35f8819ae Breaking: Remove "UseLegacyStretchBehaviour" functions (#1368)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1368

X-link: https://github.com/facebook/react-native/pull/39372

These were marked as deprecated as part of the public Yoga 2.0 release, and were alredy emitting deprecation warnings. Remove them.

Reviewed By: javache

Differential Revision: D49131250

fbshipit-source-id: cc1d4e8b179697b9a11a685f4fc4e9d36e1a26a0
2023-09-11 19:51:40 -07:00
Nick Gerleman
a2d3fc6a3c Breaking: Remove YGConfigGetInstanceCount (#1370)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1370

X-link: https://github.com/facebook/react-native/pull/39369

This was added in https://github.com/facebook/yoga/pull/497 specifically for tests related to memory leaks in the C# bindings to count how often YGConfigFree.

This is the wrong layer for this check, we don't have officially supported C# bindings anymore, and this API is not safe when Yoga runs on multiple threads. This removes it, similar to a global node instance count that was also previously removed.

Reviewed By: rshest

Differential Revision: D49131207

fbshipit-source-id: 58537ed635ed455ff065471bdf77061a4bf826f4
2023-09-11 19:51:40 -07:00
Nick Gerleman
776065d7c7 Breaking: size_t indices (#1366)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1366

X-link: https://github.com/facebook/react-native/pull/39371

Yoga's public API exposes indices most often as `uint32_t`, with exception of clone callbacks which are `int32_t`. Yoga internally represents these indices as `size_t` when dealing with the child vector, and this is the true index.

This changes the API to consistently be `size_t`. This should not be breaking for most users, but will cause breaks where:

1. Users set a clone node callback (I think this should be rare. RN uses it, but only because it relies on a separate private API).
2. Callers of `YGNodeGetChildCount()` are assigning to an int with less width than `size_t` and have strong warnings enabled.
3. Using a newer Yoga binary with older source, since we are not preserving ABI compatibility (Yoga in general does not aim to be ABI stable between major versions, only ABI safe for a given set of sources).

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D49130914

fbshipit-source-id: 6a004c160c4c50f68047b108508fd437156f5fac
2023-09-11 19:51:40 -07:00
Nick Gerleman
26f2b28eca Breaking: Fix callback const-correctness (#1369)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1369

X-link: https://github.com/facebook/react-native/pull/39370

This fixes const-correctness of callbacks (e.g. not letting a logger function modify nodes during layout). This helps us to continue to fix const-correctness issues inside of Yoga.

This change is breaking to the public API, since it requires a change in signature passed to Yoga.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49130714

fbshipit-source-id: 4305f8882d89f296e45b78497a51716a0dbb3b2d
2023-09-11 19:51:40 -07:00
Nick Gerleman
b12a6a340c Non-breaking const-correctness fixes (#1365)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1365

X-link: https://github.com/facebook/react-native/pull/39368

This changes public Yoga API to in more places accept const structures where before they required mutable ones.

`resolveRef` is added as a quick way to resolve overloaded opaque refs for different types which is a bit easier to read than static_casting, and which will propagate const-ness. We also add `YGConfigConstRef`, similar to `YGNodeConstRef`. I was a bit iffy on whether we should add something to make it easier to convert to private interface,  but this doesn't seem any easier to misuse than someone who looks at the internals to find the `static_cast`.

This tries to avoid more breaking changes yet, e.g. changing callbacks to require clients do not modify nodes when they are passed for logging. We also don't have const variants for returning child structures which would allow mutation of dependencies of the const object. These would need new names under the public API, since we do not have operator overloading in C.

Reviewed By: rshest

Differential Revision: D49130412

fbshipit-source-id: ee6b31b47f4622031c63dd52d8ac133d21bf29b7
2023-09-11 19:51:40 -07:00
Nick Gerleman
3cb29e60a8 Fix Running Java UTs with CXX Platform
Reviewed By: rshest

Differential Revision: D49131492

fbshipit-source-id: 80b2f108b2a5d80b92c1a11c573a61520b345ac2
2023-09-11 16:15:46 -07:00
Nick Gerleman
26d2a2682f yoga::bit_cast
Summary:
X-link: https://github.com/facebook/react-native/pull/39358

This adds a function polyfilling C++ 20's `std::bit_cast`, using `memcpy()` to be safe with strict aliasing rules.

This replaces the conditional code in CompactValue for type punning, an unsafe place in YGJNI where we do it unsafely, and is used in ValuePool. The polyfill can be switched to `std::bit_cast` whenever we adopt C++ 20.

Note that this doesn't actually call into `memcpy()`, as verified by Godbolt. Compilers are aware of the memcpy type punning pattern and optimize it, but it's ugly and confusing to folks who haven't seen it before.

Reviewed By: javache

Differential Revision: D49082997

fbshipit-source-id: b848775a68286bdb11b2a3a95bef8069364ac9b5
2023-09-08 13:03:48 -07:00
Nick Gerleman
f8e2bc0875 Add copyright header to ld version script (#1360)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1360

Fixes a ShipIt warning about this.

Reviewed By: yungsters

Differential Revision: D48992315

fbshipit-source-id: 20b6ba86abc27599e5f7dc12471344295151db66
2023-09-06 09:50:43 -07:00
Nick Gerleman
aee43a53bc Enable -Wconversion (#1359)
Summary:
X-link: https://github.com/facebook/react-native/pull/39291

Pull Request resolved: https://github.com/facebook/yoga/pull/1359

This enables clang warnings around potentially unsafe conversions, such as those with mismatched signedness, or ones which may lead to truncation.

This should catch issues in local development which create errors for MSVC (e.g. Dash), who's default `/W3` includes warnings akin to `-Wshorten-64-to-32`.

This full set of warnings here is a tad spammy, but probably more useful than not.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D48954777

fbshipit-source-id: 1ccc07b99d09d1c2d428158149698ffd04025605
2023-09-06 08:16:42 -07:00
Nick Gerleman
95a7b4497e Enable GitHub Actions Yarn Caching (#1332)
Summary:
We sometimes see workflows fail due to network flakiness, almost always being Windows agents doing a `yarn install`. This change enables storing and reusing Yarn's package cache, and makes `yarn install` more permissive when it does hit the network. https://stackoverflow.com/questions/51508364/yarn-there-appears-to-be-trouble-with-your-network-connection-retrying

Pull Request resolved: https://github.com/facebook/yoga/pull/1332

Test Plan: Workflows succeed, and we see cache being restored before yarn install step.

Reviewed By: lunaleaps

Differential Revision: D48967590

Pulled By: NickGerleman

fbshipit-source-id: 55ce6f05496f014512e0153b6646a7ca0ab964d9
2023-09-05 10:27:27 -07:00
Nick Gerleman
65ae809d5d C++ Cleanup 10/N: YGNodeCalculateLayout (#1352)
Summary:
X-link: https://github.com/facebook/react-native/pull/39195

Pull Request resolved: https://github.com/facebook/yoga/pull/1352

## This diff

This splits out all of the logic under `YGNodeCalculateLayout` to a couple of different files, does some mechanical renaming, and starts to split up the implementation a tiny bit. After this, core layout functions are all C++ convention and namespaced.

Each new file is marked as a move for the sake of blame history. It means Phabricator has a very inaccurate count of lines removed though.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48770478

fbshipit-source-id: 2a74b86441c3352de03ae193c98fc3a3573047ed
2023-09-05 05:24:54 -07:00
Nick Gerleman
7d8b9176fd C++ Cleanup 9/N: YGAssert (#1353)
Summary:
X-link: https://github.com/facebook/react-native/pull/39201

Pull Request resolved: https://github.com/facebook/yoga/pull/1353

## This diff

This moves and renames `YGAssert`, and removes it from the public API, since external users should not need to call into internal Yoga assert functions, and the current API prevents us from making this a macro later to include the condition in the message.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48769809

fbshipit-source-id: b5480ac54781bc01b00c158b07d2d751fac87d37
2023-09-04 11:20:17 -07:00
Nick Gerleman
7be985d97c C++ Cleanup 8/N: Yoga-internal (#1355)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1355

X-link: https://github.com/facebook/react-native/pull/39198

## This diff

This splits up `Yoga-internal.h` which has become a grab bag. The actual header is left, with the purpose of being a private C ABI for bindings, but everything else is moved to a place more appropriate or removed.

A few notes:
1. `yoga::isUndefined` is replaced with `std::isnan` to avoid a layer of indirection (we will never be able to change its representation anyway). Internal usages of `YGFloatIsUndefined` are also replaced with `std::isnan` since the previous being at a library boundary means I'm not sure it can be inlined/.
2. `leading`, `trailing` arrays are factored into proper functions
3. `Values` is replaced entirely with `std::array`, since most of it was unused.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48769241

fbshipit-source-id: 5b8e2192309539e7c133c3b3b29b445b59dd5835
2023-09-04 11:20:17 -07:00
Nick Gerleman
31b6c0ddc9 C++ Cleanup 7/N: BitUtils (#1351)
Summary:
X-link: https://github.com/facebook/react-native/pull/39223

X-link: https://github.com/facebook/react-native/pull/39200

Pull Request resolved: https://github.com/facebook/yoga/pull/1351

## This diff

This splits up `BitUtils.h`, does some minor renaming, and namespace consistency fixes.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847255

fbshipit-source-id: 4b9722303372f43e936118f8187c0127bceeb1d4
2023-08-31 01:17:39 -07:00
Nick Gerleman
989f352e03 C++ Cleanup 6/N: YGFloatOptional (#1356)
Summary:
X-link: https://github.com/facebook/react-native/pull/39224

Pull Request resolved: https://github.com/facebook/yoga/pull/1356

X-link: https://github.com/facebook/react-native/pull/39196

## This diff

This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847256

fbshipit-source-id: ab9729a4a02ab90d974183425935f4d274db5732
2023-08-31 01:17:39 -07:00
Nick Gerleman
c029041707 C++ Cleanup 5/N: Reorganize Utils (#1357)
Summary:
X-link: https://github.com/facebook/react-native/pull/39222

Pull Request resolved: https://github.com/facebook/yoga/pull/1357

X-link: https://github.com/facebook/react-native/pull/39199

## This diff

This splits `Utils.h` and `Utils.cpp`, and tweaks naming and namespaces.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847260

fbshipit-source-id: b99df3029cd66257a7ae64de28c13e8751ceb20c
2023-08-31 01:17:39 -07:00
Nick Gerleman
b959774af7 C++ Cleanup 4/N: Reorganize Log and YGNodePrint (#1354)
Summary:
X-link: https://github.com/facebook/react-native/pull/39220

Pull Request resolved: https://github.com/facebook/yoga/pull/1354

X-link: https://github.com/facebook/react-native/pull/39197

## This diff

Moves these files to a `yoga/debug` subdirectory and does some mild renaming, namespace adjustment, and removes Yoga internal log function from list of library exports.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847259

fbshipit-source-id: c1607b1c6457d5a47039c735cdb7c365a301ebc0
2023-08-31 01:17:39 -07:00
Nick Gerleman
992f073746 C++ Cleanup 3/N: Reorganize YGNode (#1350)
Summary:
X-link: https://github.com/facebook/react-native/pull/39219

Pull Request resolved: https://github.com/facebook/yoga/pull/1350

X-link: https://github.com/facebook/react-native/pull/39170

## This diff

This diff adds a top level `node` directory for code related to Yoga nodes and data structures on them (inc moving `YGLayout` to `LayoutResults`).

The public API for config handles is `YGNodeRef`, which is forward declared to be a pointer to a struct named `YGNode`. The existing `YGNode` is split into `yoga::Node`, as the private C++ implementation, inheriting from `YGNode`, a marker type represented as an empty struct. The public API continues to accept `YGNodeRef`, which continues to be `YGNode *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it.

This change ends up needing to touch quite a bit, due to the amount of code that mixed and matched private and public APIs. Don't be scared though, because these changes are very mechanical, and Phabricator's line-count is 3x the actual amount due to mirrors and dirsyncs.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

bypass-github-export-checks

Reviewed By: shwanton

Differential Revision: D48847258

fbshipit-source-id: fc560893533b55a5c2d52c37d8e9a59f7369f174
2023-08-30 19:57:16 -07:00
Nick Gerleman
f82babba8a C++ Cleanup 2/N: Reorganize YGConfig (#1348)
Summary:
X-link: https://github.com/facebook/react-native/pull/39218

X-link: https://github.com/facebook/react-native/pull/39169

Pull Request resolved: https://github.com/facebook/yoga/pull/1348

## This diff

This diff adds a top level `config` directory for code related to configuring Yoga and Yoga Nodes.

The public API for config handles is `YGConfigRef`, which is forward declared to be a pointer to a struct named `YGConfig`. The existing `YGConfig` is split into `yoga::Config`, as the private C++ implementation, inheriting from `YGConfig`, a marker type represented as an empty struct. The public API continues to accept `YGConfigRef`, which continues to be `YGConfig *`, but it must be cast to its concrete internal representation at the API boundary before doing work on it.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: shwanton

Differential Revision: D48847257

fbshipit-source-id: 7a2157d169ba80a6f79620693ae45bb10dfca5a3
2023-08-30 16:27:32 -07:00
Nick Gerleman
65d7f95901 C++ Cleanup 1/N: Reorganize YGStyle (#1349)
Summary:
X-link: https://github.com/facebook/react-native/pull/39221

Pull Request resolved: https://github.com/facebook/yoga/pull/1349

X-link: https://github.com/facebook/react-native/pull/39171

## This diff

This diff adds a `style` directory for code related to storing and manipulating styles. `YGStyle`, which is not a public API, is renamed to `yoga::Style` and moved into this folder, alongside `CompactValue`. We will eventually add `ValuePool` alongside this for the next generation style representation.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: shwanton

Differential Revision: D48847261

fbshipit-source-id: 0fc8c6991e19079f3f0d55d368574757e453fe93
2023-08-30 16:27:32 -07:00
Zhiyao Zhou
2a32637c56 Revert D48710084: C++ Cleanup 1/N: Reorganize YGStyle
Differential Revision:
D48710084

Original commit changeset: 20961aee30d5

Original Phabricator Diff: D48710084

fbshipit-source-id: 79cda4f13979b8d0cdf87dabbfc13cbd17abe488
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
13c5ce2234 Revert D48710796: C++ Cleanup 2/N: Reorganize YGConfig
Differential Revision:
D48710796

Original commit changeset: d548553f7ce8

Original Phabricator Diff: D48710796

fbshipit-source-id: c8b2de245f3894f6a87c262ec70d313020aa228e
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
ea7f61a3db Revert D48712710: C++ Cleanup 3/N: Reorganize YGNode
Differential Revision:
D48712710

Original commit changeset: d28eae38469a

Original Phabricator Diff: D48712710

fbshipit-source-id: 7a10b071edcf045ce98bbf8f9deca0d0e2e80a14
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
6ca56e87ce Revert D48763820: C++ Cleanup 4/N: Reorganize Log and YGNodePrint
Differential Revision:
D48763820

Original commit changeset: 7e3ed7354497

Original Phabricator Diff: D48763820

fbshipit-source-id: 1bea996374f14481160aba8f87940c00e229aa69
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
4c0e89e492 Revert D48767465: C++ Cleanup 5/N: Reorganize Utils
Differential Revision:
D48767465

Original commit changeset: da7157953292

Original Phabricator Diff: D48767465

fbshipit-source-id: 0dd948e2c4e6b3aaeb6e197b28b565c0b385d033
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
7cf0483b17 Revert D48767992: C++ Cleanup 6/N: YGFloatOptional
Differential Revision:
D48767992

Original commit changeset: afaff0234359

Original Phabricator Diff: D48767992

fbshipit-source-id: 4666bdbb83aebbf2f7373b3a10a8c1dd0a03f92c
2023-08-29 23:27:25 -07:00
Zhiyao Zhou
8a95b785a8 Revert D48768374: C++ Cleanup 7/N: BitUtils
Differential Revision:
D48768374

Original commit changeset: 921a22ec88bd

Original Phabricator Diff: D48768374

fbshipit-source-id: 59106ab3d03619940023dac1c2af62fd88566773
2023-08-29 23:27:25 -07:00
Nick Gerleman
866b4f7d62 C++ Cleanup 7/N: BitUtils (#1351)
Summary:
X-link: https://github.com/facebook/react-native/pull/39200

Pull Request resolved: https://github.com/facebook/yoga/pull/1351

## This diff

This splits up `BitUtils.h`, does some minor renaming, and namespace consistency fixes.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48768374

fbshipit-source-id: 921a22ec88bd470da1ef9b51f8954afc073d327d
2023-08-29 21:32:56 -07:00
Nick Gerleman
20fd7695e1 C++ Cleanup 6/N: YGFloatOptional (#1356)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1356

X-link: https://github.com/facebook/react-native/pull/39196

## This diff

This renames YGFloatOptional to FloatOptional, adds it to a namespace, and moves it to a subdirectory. This needs Fabric updates because Fabric uses Yoga internals for props storage.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D48767992

fbshipit-source-id: afaff023435915dbd5e571fd1ee2e695e4f59a5c
2023-08-29 21:32:56 -07:00
Nick Gerleman
8fd4d290e6 C++ Cleanup 5/N: Reorganize Utils (#1357)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1357

X-link: https://github.com/facebook/react-native/pull/39199

## This diff

This splits `Utils.h` and `Utils.cpp`, and tweaks naming and namespaces.

## This stack

The organization of the C++ internals of Yoga are in need of attention.
1. Some of the C++ internals are namespaced, but others not.
2. Some of the namespaces include `detail`, but are meant to be used outside of the translation unit (FB Clang Tidy rules warn on any usage of these)
2. Most of the files are in a flat hierarchy, except for event tracing in its own folder
3. Some files and functions begin with YG, others don’t
4. Some functions are uppercase, others are not
5. Almost all of the interesting logic is in Yoga.cpp, and the file is too large to reason about
6. There are multiple grab bag files where folks put random functions they need in (Utils, BitUtils, Yoga-Internal.h)
7. There is no clear indication from file structure or type naming what is private vs not
8. Handles like `YGNodeRef` and `YGConfigRef` can be used to access internals just by importing headers

This stack does some much needed spring cleaning:
1. All non-public headers and C++ implementation details are in separate folders from the root level `yoga`. This will give us room to split up logic and add more files without too large a flat hierarchy
3. All private C++ internals are under the `facebook::yoga` namespace. Details namespaces are only ever used within the same header, as they are intended
4. Utils files are split
5. Most C++ internals drop the YG prefix
6. Most C++ internal function names are all lower camel case
7. We start to split up Yoga.cpp
8. Every header beginning with YG or at the top-level directory is public and C only, with the exception of Yoga-Internal.h which has non-public functions for bindings
9. It is not possible to use private APIs without static casting handles to internal classes

This will give us more leeway to continue splitting monolithic files, and consistent guidelines for style in new files as well.

These changes should not be breaking to any project using only public Yoga headers. This includes every usage of Yoga in fbsource except for RN Fabric which is currently tied to internals. This refactor should make that boundary clearer.

Reviewed By: rshest

Differential Revision: D48767465

fbshipit-source-id: da71579532924b3a912454163fe281c481770a77
2023-08-29 21:32:56 -07:00