Skip to content

Commit

Permalink
Breaking: Use C++ 20
Browse files Browse the repository at this point in the history
Summary:
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, but n - 1 is going to be a better long term place than n - 2. I think it is likely everything will be buildable for a while under Clang 10 (released 3.5 years ago), GCC 10 (releaseed 3.5 years ago), and VS 16.11 (released 2 years ago).

Differential Revision: D49261607
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Sep 14, 2023
1 parent b29b393 commit f321d20
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
* LICENSE file in the root directory of this source tree.
*/

#include "YGJNIVanilla.h"
#include <bit>
#include <cstring>
#include <iostream>
#include <memory>

#include <jni.h>
#include <yoga/Yoga-internal.h>

#include "LayoutContext.h"
#include "YGJNI.h"
#include "YGJNIVanilla.h"
#include "YGJTypesVanilla.h"
#include "YogaJniException.h"
#include "common.h"
#include "jni.h"

#include <yoga/Yoga-internal.h>
#include <yoga/bits/BitCast.h>

using namespace facebook;
using namespace facebook::yoga;
Expand Down Expand Up @@ -645,8 +646,8 @@ static YGSize YGJNIMeasureFunc(
uint32_t wBits = 0xFFFFFFFF & (measureResult >> 32);
uint32_t hBits = 0xFFFFFFFF & measureResult;

const float measuredWidth = yoga::bit_cast<float>(wBits);
const float measuredHeight = yoga::bit_cast<float>(hBits);
const float measuredWidth = std::bit_cast<float>(wBits);
const float measuredHeight = std::bit_cast<float>(hBits);

return YGSize{measuredWidth, measuredHeight};
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/ReactCommon/yoga/Yoga.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Pod::Spec.new do |spec|
'-fexceptions',
'-Wall',
'-Werror',
'-std=c++17',
'-std=c++20',
'-fPIC'
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand Down
29 changes: 0 additions & 29 deletions packages/react-native/ReactCommon/yoga/yoga/bits/BitCast.h

This file was deleted.

11 changes: 5 additions & 6 deletions packages/react-native/ReactCommon/yoga/yoga/style/CompactValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

#pragma once

#include <bit>
#include <cmath>
#include <cstdint>
#include <limits>

#include <yoga/YGMacros.h>
#include <yoga/YGValue.h>

#include <yoga/bits/BitCast.h>

static_assert(
std::numeric_limits<float>::is_iec559,
"facebook::yoga::detail::CompactValue only works with IEEE754 floats");
Expand Down Expand Up @@ -64,7 +63,7 @@ class YG_EXPORT CompactValue {
}

uint32_t unitBit = Unit == YGUnitPercent ? PERCENT_BIT : 0;
auto data = yoga::bit_cast<uint32_t>(value);
auto data = std::bit_cast<uint32_t>(value);
data -= BIAS;
data |= unitBit;
return {data};
Expand Down Expand Up @@ -117,7 +116,7 @@ class YG_EXPORT CompactValue {
return YGValue{0.0f, YGUnitPercent};
}

if (std::isnan(yoga::bit_cast<float>(repr_))) {
if (std::isnan(std::bit_cast<float>(repr_))) {
return YGValueUndefined;
}

Expand All @@ -126,14 +125,14 @@ class YG_EXPORT CompactValue {
data += BIAS;

return YGValue{
yoga::bit_cast<float>(data),
std::bit_cast<float>(data),
repr_ & 0x40000000 ? YGUnitPercent : YGUnitPoint};
}

bool isUndefined() const noexcept {
return (
repr_ != AUTO_BITS && repr_ != ZERO_BITS_POINT &&
repr_ != ZERO_BITS_PERCENT && std::isnan(yoga::bit_cast<float>(repr_)));
repr_ != ZERO_BITS_PERCENT && std::isnan(std::bit_cast<float>(repr_)));
}

bool isAuto() const noexcept {
Expand Down

0 comments on commit f321d20

Please sign in to comment.