From a6768bfd70187634e587d7b2e92d2b6735a4037e Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 24 Aug 2021 09:49:12 -0700 Subject: [PATCH] Remove usages of `dynamic_casts` that are used inside assertions Summary: This diff is part of a bigger effort to remove the RTTI flags. To do so we need to remove occurrences of `dynamic_cast` and other functions that rely on runtime type informations. Changelog: [Internal][Changed] - Removed extra asserts relying on dynamic_cast Reviewed By: JoshuaGross Differential Revision: D30483554 fbshipit-source-id: 92b31281841a92c7b43e918938248431265dd654 --- .../renderer/components/text/RawTextShadowNode.h | 6 ------ .../react/renderer/components/text/TextShadowNode.h | 6 ------ .../components/view/ViewPropsInterpolation.h | 7 ------- .../components/view/YogaLayoutableShadowNode.h | 6 ------ .../renderer/core/ConcreteComponentDescriptor.h | 13 ------------- .../react/renderer/core/LayoutableShadowNode.h | 6 ------ 6 files changed, 44 deletions(-) diff --git a/ReactCommon/react/renderer/components/text/RawTextShadowNode.h b/ReactCommon/react/renderer/components/text/RawTextShadowNode.h index 0a2b76e70b1..8dbde86c996 100644 --- a/ReactCommon/react/renderer/components/text/RawTextShadowNode.h +++ b/ReactCommon/react/renderer/components/text/RawTextShadowNode.h @@ -39,9 +39,6 @@ inline RawTextShadowNode const &traitCast( ShadowNode const &shadowNode) { bool castable = shadowNode.getTraits().check(ShadowNodeTraits::Trait::RawText); - react_native_assert( - castable == - (dynamic_cast(&shadowNode) != nullptr)); react_native_assert(castable); (void)castable; return static_cast(shadowNode); @@ -55,9 +52,6 @@ inline RawTextShadowNode const *traitCast( } bool castable = shadowNode->getTraits().check(ShadowNodeTraits::Trait::RawText); - react_native_assert( - castable == - (dynamic_cast(shadowNode) != nullptr)); if (!castable) { return nullptr; } diff --git a/ReactCommon/react/renderer/components/text/TextShadowNode.h b/ReactCommon/react/renderer/components/text/TextShadowNode.h index 9e9a9f6b079..57e3f25076b 100644 --- a/ReactCommon/react/renderer/components/text/TextShadowNode.h +++ b/ReactCommon/react/renderer/components/text/TextShadowNode.h @@ -62,9 +62,6 @@ template <> inline TextShadowNode const &traitCast( ShadowNode const &shadowNode) { bool castable = shadowNode.getTraits().check(ShadowNodeTraits::Trait::Text); - react_native_assert( - castable == - (dynamic_cast(&shadowNode) != nullptr)); react_native_assert(castable); (void)castable; return static_cast(shadowNode); @@ -77,9 +74,6 @@ inline TextShadowNode const *traitCast( return nullptr; } bool castable = shadowNode->getTraits().check(ShadowNodeTraits::Trait::Text); - react_native_assert( - castable == - (dynamic_cast(shadowNode) != nullptr)); if (!castable) { return nullptr; } diff --git a/ReactCommon/react/renderer/components/view/ViewPropsInterpolation.h b/ReactCommon/react/renderer/components/view/ViewPropsInterpolation.h index ddbf1d5367d..c2352460b2f 100644 --- a/ReactCommon/react/renderer/components/view/ViewPropsInterpolation.h +++ b/ReactCommon/react/renderer/components/view/ViewPropsInterpolation.h @@ -24,13 +24,6 @@ static inline void interpolateViewProps( const SharedProps &oldPropsShared, const SharedProps &newPropsShared, SharedProps &interpolatedPropsShared) { - // Verify the static_casts below are safe - react_native_assert( - dynamic_cast(oldPropsShared.get()) != nullptr && - dynamic_cast(newPropsShared.get()) != nullptr && - dynamic_cast(interpolatedPropsShared.get()) != - nullptr); - ViewProps const *oldViewProps = static_cast(oldPropsShared.get()); ViewProps const *newViewProps = diff --git a/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h b/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h index 7fd6edf4f80..77ba8131145 100644 --- a/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h +++ b/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.h @@ -186,9 +186,6 @@ inline YogaLayoutableShadowNode const & traitCast(ShadowNode const &shadowNode) { bool castable = shadowNode.getTraits().check(ShadowNodeTraits::Trait::YogaLayoutableKind); - react_native_assert( - castable == - (dynamic_cast(&shadowNode) != nullptr)); react_native_assert(castable); (void)castable; return static_cast(shadowNode); @@ -202,9 +199,6 @@ traitCast(ShadowNode const *shadowNode) { } bool castable = shadowNode->getTraits().check( ShadowNodeTraits::Trait::YogaLayoutableKind); - react_native_assert( - castable == - (dynamic_cast(shadowNode) != nullptr)); if (!castable) { return nullptr; } diff --git a/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index 45625c8f5eb..a66f8e2573b 100644 --- a/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -79,10 +79,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { ShadowNode::Unshared cloneShadowNode( const ShadowNode &sourceShadowNode, const ShadowNodeFragment &fragment) const override { - react_native_assert( - dynamic_cast(&sourceShadowNode) && - "Provided `sourceShadowNode` has an incompatible type."); - auto shadowNode = std::make_shared(sourceShadowNode, fragment); adopt(shadowNode); @@ -92,10 +88,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { void appendChild( const ShadowNode::Shared &parentShadowNode, const ShadowNode::Shared &childShadowNode) const override { - react_native_assert( - dynamic_cast(parentShadowNode.get()) && - "Provided `parentShadowNode` has an incompatible type."); - auto concreteParentShadowNode = std::static_pointer_cast(parentShadowNode); auto concreteNonConstParentShadowNode = @@ -107,11 +99,6 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { const PropsParserContext &context, const SharedProps &props, const RawProps &rawProps) const override { - react_native_assert( - !props || - dynamic_cast(props.get()) && - "Provided `props` has an incompatible type."); - // Optimization: // Quite often nodes are constructed with default/empty props: the base // `props` object is `null` (there no base because it's not cloning) and the diff --git a/ReactCommon/react/renderer/core/LayoutableShadowNode.h b/ReactCommon/react/renderer/core/LayoutableShadowNode.h index 3ffb162198e..b816b54a2cf 100644 --- a/ReactCommon/react/renderer/core/LayoutableShadowNode.h +++ b/ReactCommon/react/renderer/core/LayoutableShadowNode.h @@ -170,9 +170,6 @@ inline LayoutableShadowNode const &traitCast( ShadowNode const &shadowNode) { bool castable = shadowNode.getTraits().check(ShadowNodeTraits::Trait::LayoutableKind); - react_native_assert( - castable == - (dynamic_cast(&shadowNode) != nullptr)); react_native_assert(castable); (void)castable; return static_cast(shadowNode); @@ -186,9 +183,6 @@ inline LayoutableShadowNode const *traitCast( } bool castable = shadowNode->getTraits().check(ShadowNodeTraits::Trait::LayoutableKind); - react_native_assert( - castable == - (dynamic_cast(shadowNode) != nullptr)); if (!castable) { return nullptr; }