Stop using RTTI features in Fabric core and components

Summary:
These dynamic_casts aren't really giving us much (they have never fired once in dev! and don't run in prod anyway). They also prevent us from disabling RTTI. So, let's get rid of them.

Changelog: [Internal]

Reviewed By: philIip

Differential Revision: D31634895

fbshipit-source-id: 4a9b259837127feb324f64fa3e9e23eb1cc481a6
This commit is contained in:
Joshua Gross 2021-10-14 19:21:44 -07:00 коммит произвёл Facebook GitHub Bot
Родитель f7a33e3501
Коммит 6525f9b082
16 изменённых файлов: 17 добавлений и 54 удалений

Просмотреть файл

@ -11,6 +11,8 @@ rn_xplat_cxx_library(
], ],
prefix = "react/fabric", prefix = "react/fabric",
), ),
compiler_flags_enable_exceptions = True,
compiler_flags_enable_rtti = True, # dynamic_cast used within Binding.cpp
fbandroid_allow_jni_merging = True, fbandroid_allow_jni_merging = True,
labels = ["supermodule:xplat/default/public.react_native.infra"], labels = ["supermodule:xplat/default/public.react_native.infra"],
platforms = ANDROID, platforms = ANDROID,

Просмотреть файл

@ -646,16 +646,19 @@ inline local_ref<ReadableArray::javaobject> castReadableArray(
// TODO: this method will be removed when binding for components are code-gen // TODO: this method will be removed when binding for components are code-gen
local_ref<JString> getPlatformComponentName(const ShadowView &shadowView) { local_ref<JString> getPlatformComponentName(const ShadowView &shadowView) {
local_ref<JString> componentName; static std::string scrollViewComponentName = std::string("ScrollView");
auto newViewProps =
std::dynamic_pointer_cast<const ScrollViewProps>(shadowView.props);
if (newViewProps && local_ref<JString> componentName;
newViewProps->getProbablyMoreHorizontalThanVertical_DEPRECATED()) { if (scrollViewComponentName.compare(shadowView.componentName) == 0) {
componentName = make_jstring("AndroidHorizontalScrollView"); auto newViewProps =
} else { std::static_pointer_cast<const ScrollViewProps>(shadowView.props);
componentName = make_jstring(shadowView.componentName); if (newViewProps->getProbablyMoreHorizontalThanVertical_DEPRECATED()) {
componentName = make_jstring("AndroidHorizontalScrollView");
return componentName;
}
} }
componentName = make_jstring(shadowView.componentName);
return componentName; return componentName;
} }

Просмотреть файл

@ -38,6 +38,8 @@ rn_xplat_cxx_library(
"-Wno-pessimizing-move", "-Wno-pessimizing-move",
"-Wno-inconsistent-missing-override", "-Wno-inconsistent-missing-override",
], ],
compiler_flags_enable_exceptions = True,
compiler_flags_enable_rtti = True, # dynamic_cast used within ReadableNative*
fbandroid_allow_jni_merging = True, fbandroid_allow_jni_merging = True,
labels = ["supermodule:xplat/default/public.react_native.infra"], labels = ["supermodule:xplat/default/public.react_native.infra"],
platforms = ANDROID, platforms = ANDROID,

Просмотреть файл

@ -7,7 +7,6 @@
#pragma once #pragma once
#include <react/debug/react_native_assert.h>
#include <react/renderer/components/image/ImageShadowNode.h> #include <react/renderer/components/image/ImageShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
#include <react/renderer/imagemanager/ImageManager.h> #include <react/renderer/imagemanager/ImageManager.h>
@ -29,7 +28,6 @@ class ImageComponentDescriptor final
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode); ConcreteComponentDescriptor::adopt(shadowNode);
react_native_assert(std::dynamic_pointer_cast<ImageShadowNode>(shadowNode));
auto imageShadowNode = auto imageShadowNode =
std::static_pointer_cast<ImageShadowNode>(shadowNode); std::static_pointer_cast<ImageShadowNode>(shadowNode);

Просмотреть файл

@ -23,13 +23,9 @@ class InputAccessoryComponentDescriptor final
using ConcreteComponentDescriptor::ConcreteComponentDescriptor; using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
react_native_assert(
std::dynamic_pointer_cast<InputAccessoryShadowNode>(shadowNode));
auto concreteShadowNode = auto concreteShadowNode =
std::static_pointer_cast<InputAccessoryShadowNode>(shadowNode); std::static_pointer_cast<InputAccessoryShadowNode>(shadowNode);
react_native_assert(std::dynamic_pointer_cast<YogaLayoutableShadowNode>(
concreteShadowNode));
auto layoutableShadowNode = auto layoutableShadowNode =
std::static_pointer_cast<YogaLayoutableShadowNode>(concreteShadowNode); std::static_pointer_cast<YogaLayoutableShadowNode>(concreteShadowNode);

Просмотреть файл

@ -8,7 +8,6 @@
#pragma once #pragma once
#include <glog/logging.h> #include <glog/logging.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/components/modal/ModalHostViewShadowNode.h> #include <react/renderer/components/modal/ModalHostViewShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
@ -25,13 +24,9 @@ class ModalHostViewComponentDescriptor final
using ConcreteComponentDescriptor::ConcreteComponentDescriptor; using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
react_native_assert(
std::dynamic_pointer_cast<ModalHostViewShadowNode>(shadowNode));
auto modalShadowNode = auto modalShadowNode =
std::static_pointer_cast<ModalHostViewShadowNode>(shadowNode); std::static_pointer_cast<ModalHostViewShadowNode>(shadowNode);
react_native_assert(
std::dynamic_pointer_cast<YogaLayoutableShadowNode>(modalShadowNode));
auto layoutableShadowNode = auto layoutableShadowNode =
std::static_pointer_cast<YogaLayoutableShadowNode>(modalShadowNode); std::static_pointer_cast<YogaLayoutableShadowNode>(modalShadowNode);

Просмотреть файл

@ -7,7 +7,6 @@
#pragma once #pragma once
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
#include "AndroidProgressBarMeasurementsManager.h" #include "AndroidProgressBarMeasurementsManager.h"
#include "AndroidProgressBarShadowNode.h" #include "AndroidProgressBarShadowNode.h"
@ -31,8 +30,6 @@ class AndroidProgressBarComponentDescriptor final
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode); ConcreteComponentDescriptor::adopt(shadowNode);
react_native_assert(
std::dynamic_pointer_cast<AndroidProgressBarShadowNode>(shadowNode));
auto androidProgressBarShadowNode = auto androidProgressBarShadowNode =
std::static_pointer_cast<AndroidProgressBarShadowNode>(shadowNode); std::static_pointer_cast<AndroidProgressBarShadowNode>(shadowNode);

Просмотреть файл

@ -7,7 +7,6 @@
#pragma once #pragma once
#include <react/debug/react_native_assert.h>
#include <react/renderer/components/slider/SliderMeasurementsManager.h> #include <react/renderer/components/slider/SliderMeasurementsManager.h>
#include <react/renderer/components/slider/SliderShadowNode.h> #include <react/renderer/components/slider/SliderShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
@ -32,8 +31,6 @@ class SliderComponentDescriptor final
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode); ConcreteComponentDescriptor::adopt(shadowNode);
react_native_assert(
std::dynamic_pointer_cast<SliderShadowNode>(shadowNode));
auto sliderShadowNode = auto sliderShadowNode =
std::static_pointer_cast<SliderShadowNode>(shadowNode); std::static_pointer_cast<SliderShadowNode>(shadowNode);

Просмотреть файл

@ -10,7 +10,6 @@
#include "AndroidSwitchMeasurementsManager.h" #include "AndroidSwitchMeasurementsManager.h"
#include "AndroidSwitchShadowNode.h" #include "AndroidSwitchShadowNode.h"
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
namespace facebook { namespace facebook {
@ -31,8 +30,6 @@ class AndroidSwitchComponentDescriptor final
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode); ConcreteComponentDescriptor::adopt(shadowNode);
react_native_assert(
std::dynamic_pointer_cast<AndroidSwitchShadowNode>(shadowNode));
auto androidSwitchShadowNode = auto androidSwitchShadowNode =
std::static_pointer_cast<AndroidSwitchShadowNode>(shadowNode); std::static_pointer_cast<AndroidSwitchShadowNode>(shadowNode);

Просмотреть файл

@ -7,7 +7,6 @@
#pragma once #pragma once
#include <react/debug/react_native_assert.h>
#include <react/renderer/components/text/ParagraphShadowNode.h> #include <react/renderer/components/text/ParagraphShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h> #include <react/renderer/textlayoutmanager/TextLayoutManager.h>
@ -33,8 +32,6 @@ class ParagraphComponentDescriptor final
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode); ConcreteComponentDescriptor::adopt(shadowNode);
react_native_assert(
std::dynamic_pointer_cast<ParagraphShadowNode>(shadowNode));
auto paragraphShadowNode = auto paragraphShadowNode =
std::static_pointer_cast<ParagraphShadowNode>(shadowNode); std::static_pointer_cast<ParagraphShadowNode>(shadowNode);

Просмотреть файл

@ -15,7 +15,6 @@
#include <yoga/YGEnums.h> #include <yoga/YGEnums.h>
#include <yoga/YGValue.h> #include <yoga/YGValue.h>
#include <react/debug/react_native_assert.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
namespace facebook { namespace facebook {
@ -88,8 +87,6 @@ class AndroidTextInputComponentDescriptor final
protected: protected:
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
react_native_assert(
std::dynamic_pointer_cast<AndroidTextInputShadowNode>(shadowNode));
auto textInputShadowNode = auto textInputShadowNode =
std::static_pointer_cast<AndroidTextInputShadowNode>(shadowNode); std::static_pointer_cast<AndroidTextInputShadowNode>(shadowNode);

Просмотреть файл

@ -7,7 +7,6 @@
#pragma once #pragma once
#include <react/debug/react_native_assert.h>
#include <react/renderer/components/iostextinput/TextInputShadowNode.h> #include <react/renderer/components/iostextinput/TextInputShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h> #include <react/renderer/core/ConcreteComponentDescriptor.h>
@ -30,8 +29,6 @@ class TextInputComponentDescriptor final
void adopt(ShadowNode::Unshared const &shadowNode) const override { void adopt(ShadowNode::Unshared const &shadowNode) const override {
ConcreteComponentDescriptor::adopt(shadowNode); ConcreteComponentDescriptor::adopt(shadowNode);
react_native_assert(
std::dynamic_pointer_cast<TextInputShadowNode>(shadowNode));
auto concreteShadowNode = auto concreteShadowNode =
std::static_pointer_cast<TextInputShadowNode>(shadowNode); std::static_pointer_cast<TextInputShadowNode>(shadowNode);

Просмотреть файл

@ -7,8 +7,6 @@
#include "UnimplementedViewComponentDescriptor.h" #include "UnimplementedViewComponentDescriptor.h"
#include <react/debug/react_native_assert.h>
namespace facebook { namespace facebook {
namespace react { namespace react {
@ -28,8 +26,6 @@ Props::Shared UnimplementedViewComponentDescriptor::cloneProps(
auto clonedProps = auto clonedProps =
ConcreteComponentDescriptor<UnimplementedViewShadowNode>::cloneProps( ConcreteComponentDescriptor<UnimplementedViewShadowNode>::cloneProps(
context, props, rawProps); context, props, rawProps);
react_native_assert(
std::dynamic_pointer_cast<UnimplementedViewProps const>(clonedProps));
// We have to clone `Props` object one more time to make sure that we have // We have to clone `Props` object one more time to make sure that we have
// an unshared (and non-`const`) copy of it which we can mutate. // an unshared (and non-`const`) copy of it which we can mutate.

Просмотреть файл

@ -32,6 +32,8 @@ rn_xplat_cxx_library(
], ],
prefix = "react/renderer/core", prefix = "react/renderer/core",
), ),
compiler_flags_enable_exceptions = True,
compiler_flags_enable_rtti = True, # Needed for DebugStringConvertible - need to find a non-RTTI way to do this / enable RTTI for debug builds only
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
force_static = True, force_static = True,

Просмотреть файл

@ -66,9 +66,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
ShadowNode::Shared createShadowNode( ShadowNode::Shared createShadowNode(
const ShadowNodeFragment &fragment, const ShadowNodeFragment &fragment,
ShadowNodeFamily::Shared const &family) const override { ShadowNodeFamily::Shared const &family) const override {
react_native_assert(
std::dynamic_pointer_cast<const ConcreteProps>(fragment.props));
auto shadowNode = auto shadowNode =
std::make_shared<ShadowNodeT>(fragment, family, getTraits()); std::make_shared<ShadowNodeT>(fragment, family, getTraits());

Просмотреть файл

@ -99,9 +99,6 @@ class ConcreteShadowNode : public BaseShadowNodeT {
ConcreteProps const &getConcreteProps() const { ConcreteProps const &getConcreteProps() const {
react_native_assert( react_native_assert(
BaseShadowNodeT::props_ && "Props must not be `nullptr`."); BaseShadowNodeT::props_ && "Props must not be `nullptr`.");
react_native_assert(
std::dynamic_pointer_cast<ConcreteProps const>(props_) &&
"Props must be an instance of ConcreteProps class.");
return static_cast<ConcreteProps const &>(*props_); return static_cast<ConcreteProps const &>(*props_);
} }
@ -110,10 +107,6 @@ class ConcreteShadowNode : public BaseShadowNodeT {
* Thread-safe after the node is sealed. * Thread-safe after the node is sealed.
*/ */
ConcreteEventEmitter const &getConcreteEventEmitter() const { ConcreteEventEmitter const &getConcreteEventEmitter() const {
react_native_assert(
std::dynamic_pointer_cast<ConcreteEventEmitter const>(
BaseShadowNodeT::getEventEmitter()) &&
"EventEmitter must be an instance of ConcreteEventEmitter class.");
return static_cast<ConcreteEventEmitter const &>( return static_cast<ConcreteEventEmitter const &>(
*BaseShadowNodeT::getEventEmitter()); *BaseShadowNodeT::getEventEmitter());
} }
@ -124,9 +117,6 @@ class ConcreteShadowNode : public BaseShadowNodeT {
*/ */
ConcreteStateData const &getStateData() const { ConcreteStateData const &getStateData() const {
react_native_assert(state_ && "State must not be `nullptr`."); react_native_assert(state_ && "State must not be `nullptr`.");
react_native_assert(
std::dynamic_pointer_cast<ConcreteState const>(state_) &&
"State must be an instance of ConcreteState class.");
return static_cast<ConcreteState const *>(state_.get())->getData(); return static_cast<ConcreteState const *>(state_.get())->getData();
} }