Skip to content

Commit

Permalink
<bit> and <concepts>
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/yoga#1497

The lowest common denominator we have had for Yoga has been Clang 12 + MSVC 2017 stdlib. This has allowed Yoga to use C++ 20 language features, but not library features. React Native for mobile has not been bound to this restriction.

Builds using that toolchain are being updated to latest MSVC 2019 stdlib (which has good C++ 20 library support), along with Clang 17 (or maybe a stop at 15) pending projects using `-fcoroutines-ts` being migrated to C++ 20.

This tests out some C++ 20 standard library usages against the current Clang 12 + MSVC 2019 stdlib toolchain that didn't work before, and adds a couple concepts for better constraints/compiler error messages if misused.

This bumps min-tested XCode (and minimum required) version to 14.3, matching a similar change for React Native. This should probably be bumped to 15 sometime before Apple starts requiring 15+ to go out to the iOS app store.

We are approaching a practical support range of:
1. XCode >= 14.3
2. NDK >= 26
3. Clang/libc++ >= 14
4. GCC/libstdc++ >= 11
5. MSVC >= 16.11 (VS 2019)

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D51604487

fbshipit-source-id: d394d0d86672b69781b8ae071d87adcf944ddc72
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Dec 12, 2023
1 parent 86df742 commit 1727ffa
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 196 deletions.
8 changes: 4 additions & 4 deletions packages/react-native/ReactCommon/yoga/yoga/YGMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@
#ifdef __cplusplus
#define YG_DEFINE_ENUM_FLAG_OPERATORS(name) \
extern "C++" { \
constexpr inline name operator~(name a) { \
constexpr name operator~(name a) { \
return static_cast<name>( \
~static_cast<std::underlying_type<name>::type>(a)); \
} \
constexpr inline name operator|(name a, name b) { \
constexpr name operator|(name a, name b) { \
return static_cast<name>( \
static_cast<std::underlying_type<name>::type>(a) | \
static_cast<std::underlying_type<name>::type>(b)); \
} \
constexpr inline name operator&(name a, name b) { \
constexpr name operator&(name a, name b) { \
return static_cast<name>( \
static_cast<std::underlying_type<name>::type>(a) & \
static_cast<std::underlying_type<name>::type>(b)); \
} \
constexpr inline name operator^(name a, name b) { \
constexpr name operator^(name a, name b) { \
return static_cast<name>( \
static_cast<std::underlying_type<name>::type>(a) ^ \
static_cast<std::underlying_type<name>::type>(b)); \
Expand Down
30 changes: 0 additions & 30 deletions packages/react-native/ReactCommon/yoga/yoga/bits/BitCast.h

This file was deleted.

13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Align.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,15 @@ enum class Align : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Align>() {
constexpr int32_t ordinalCount<Align>() {
return 9;
}

template <>
constexpr inline int32_t bitCount<Align>() {
return 4;
}
}

constexpr inline Align scopedEnum(YGAlign unscoped) {
constexpr Align scopedEnum(YGAlign unscoped) {
return static_cast<Align>(unscoped);
}

constexpr inline YGAlign unscopedEnum(Align scoped) {
constexpr YGAlign unscopedEnum(Align scoped) {
return static_cast<YGAlign>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ enum class Dimension : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Dimension>() {
constexpr int32_t ordinalCount<Dimension>() {
return 2;
}

template <>
constexpr inline int32_t bitCount<Dimension>() {
return 1;
}
}

constexpr inline Dimension scopedEnum(YGDimension unscoped) {
constexpr Dimension scopedEnum(YGDimension unscoped) {
return static_cast<Dimension>(unscoped);
}

constexpr inline YGDimension unscopedEnum(Dimension scoped) {
constexpr YGDimension unscopedEnum(Dimension scoped) {
return static_cast<YGDimension>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Direction.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ enum class Direction : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Direction>() {
constexpr int32_t ordinalCount<Direction>() {
return 3;
}

template <>
constexpr inline int32_t bitCount<Direction>() {
return 2;
}
}

constexpr inline Direction scopedEnum(YGDirection unscoped) {
constexpr Direction scopedEnum(YGDirection unscoped) {
return static_cast<Direction>(unscoped);
}

constexpr inline YGDirection unscopedEnum(Direction scoped) {
constexpr YGDirection unscopedEnum(Direction scoped) {
return static_cast<YGDirection>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ enum class Display : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Display>() {
constexpr int32_t ordinalCount<Display>() {
return 2;
}

template <>
constexpr inline int32_t bitCount<Display>() {
return 1;
}
}

constexpr inline Display scopedEnum(YGDisplay unscoped) {
constexpr Display scopedEnum(YGDisplay unscoped) {
return static_cast<Display>(unscoped);
}

constexpr inline YGDisplay unscopedEnum(Display scoped) {
constexpr YGDisplay unscopedEnum(Display scoped) {
return static_cast<YGDisplay>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Edge.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,15 @@ enum class Edge : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Edge>() {
constexpr int32_t ordinalCount<Edge>() {
return 9;
}

template <>
constexpr inline int32_t bitCount<Edge>() {
return 4;
}
}

constexpr inline Edge scopedEnum(YGEdge unscoped) {
constexpr Edge scopedEnum(YGEdge unscoped) {
return static_cast<Edge>(unscoped);
}

constexpr inline YGEdge unscopedEnum(Edge scoped) {
constexpr YGEdge unscopedEnum(Edge scoped) {
return static_cast<YGEdge>(scoped);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Errata.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ enum class Errata : uint32_t {

YG_DEFINE_ENUM_FLAG_OPERATORS(Errata)

constexpr inline Errata scopedEnum(YGErrata unscoped) {
constexpr Errata scopedEnum(YGErrata unscoped) {
return static_cast<Errata>(unscoped);
}

constexpr inline YGErrata unscopedEnum(Errata scoped) {
constexpr YGErrata unscopedEnum(Errata scoped) {
return static_cast<YGErrata>(scoped);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ enum class ExperimentalFeature : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<ExperimentalFeature>() {
constexpr int32_t ordinalCount<ExperimentalFeature>() {
return 2;
}

template <>
constexpr inline int32_t bitCount<ExperimentalFeature>() {
return 1;
}
}

constexpr inline ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) {
constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) {
return static_cast<ExperimentalFeature>(unscoped);
}

constexpr inline YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) {
constexpr YGExperimentalFeature unscopedEnum(ExperimentalFeature scoped) {
return static_cast<YGExperimentalFeature>(scoped);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ enum class FlexDirection : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<FlexDirection>() {
constexpr int32_t ordinalCount<FlexDirection>() {
return 4;
}

template <>
constexpr inline int32_t bitCount<FlexDirection>() {
return 2;
}
}

constexpr inline FlexDirection scopedEnum(YGFlexDirection unscoped) {
constexpr FlexDirection scopedEnum(YGFlexDirection unscoped) {
return static_cast<FlexDirection>(unscoped);
}

constexpr inline YGFlexDirection unscopedEnum(FlexDirection scoped) {
constexpr YGFlexDirection unscopedEnum(FlexDirection scoped) {
return static_cast<YGFlexDirection>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Gutter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ enum class Gutter : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Gutter>() {
constexpr int32_t ordinalCount<Gutter>() {
return 3;
}

template <>
constexpr inline int32_t bitCount<Gutter>() {
return 2;
}
}

constexpr inline Gutter scopedEnum(YGGutter unscoped) {
constexpr Gutter scopedEnum(YGGutter unscoped) {
return static_cast<Gutter>(unscoped);
}

constexpr inline YGGutter unscopedEnum(Gutter scoped) {
constexpr YGGutter unscopedEnum(Gutter scoped) {
return static_cast<YGGutter>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Justify.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,15 @@ enum class Justify : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Justify>() {
constexpr int32_t ordinalCount<Justify>() {
return 6;
}

template <>
constexpr inline int32_t bitCount<Justify>() {
return 3;
}
}

constexpr inline Justify scopedEnum(YGJustify unscoped) {
constexpr Justify scopedEnum(YGJustify unscoped) {
return static_cast<Justify>(unscoped);
}

constexpr inline YGJustify unscopedEnum(Justify scoped) {
constexpr YGJustify unscopedEnum(Justify scoped) {
return static_cast<YGJustify>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/LogLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,15 @@ enum class LogLevel : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<LogLevel>() {
constexpr int32_t ordinalCount<LogLevel>() {
return 6;
}

template <>
constexpr inline int32_t bitCount<LogLevel>() {
return 3;
}
}

constexpr inline LogLevel scopedEnum(YGLogLevel unscoped) {
constexpr LogLevel scopedEnum(YGLogLevel unscoped) {
return static_cast<LogLevel>(unscoped);
}

constexpr inline YGLogLevel unscopedEnum(LogLevel scoped) {
constexpr YGLogLevel unscopedEnum(LogLevel scoped) {
return static_cast<YGLogLevel>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/MeasureMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ enum class MeasureMode : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<MeasureMode>() {
constexpr int32_t ordinalCount<MeasureMode>() {
return 3;
}

template <>
constexpr inline int32_t bitCount<MeasureMode>() {
return 2;
}
}

constexpr inline MeasureMode scopedEnum(YGMeasureMode unscoped) {
constexpr MeasureMode scopedEnum(YGMeasureMode unscoped) {
return static_cast<MeasureMode>(unscoped);
}

constexpr inline YGMeasureMode unscopedEnum(MeasureMode scoped) {
constexpr YGMeasureMode unscopedEnum(MeasureMode scoped) {
return static_cast<YGMeasureMode>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/NodeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,15 @@ enum class NodeType : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<NodeType>() {
constexpr int32_t ordinalCount<NodeType>() {
return 2;
}

template <>
constexpr inline int32_t bitCount<NodeType>() {
return 1;
}
}

constexpr inline NodeType scopedEnum(YGNodeType unscoped) {
constexpr NodeType scopedEnum(YGNodeType unscoped) {
return static_cast<NodeType>(unscoped);
}

constexpr inline YGNodeType unscopedEnum(NodeType scoped) {
constexpr YGNodeType unscopedEnum(NodeType scoped) {
return static_cast<YGNodeType>(scoped);
}

Expand Down
13 changes: 4 additions & 9 deletions packages/react-native/ReactCommon/yoga/yoga/enums/Overflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@ enum class Overflow : uint8_t {
};

template <>
constexpr inline int32_t ordinalCount<Overflow>() {
constexpr int32_t ordinalCount<Overflow>() {
return 3;
}

template <>
constexpr inline int32_t bitCount<Overflow>() {
return 2;
}
}

constexpr inline Overflow scopedEnum(YGOverflow unscoped) {
constexpr Overflow scopedEnum(YGOverflow unscoped) {
return static_cast<Overflow>(unscoped);
}

constexpr inline YGOverflow unscopedEnum(Overflow scoped) {
constexpr YGOverflow unscopedEnum(Overflow scoped) {
return static_cast<YGOverflow>(scoped);
}

Expand Down
Loading

0 comments on commit 1727ffa

Please sign in to comment.