From 8750350f46783e501a40dfad552a04f92287b583 Mon Sep 17 00:00:00 2001 From: Haozheng Fan Date: Sat, 29 Feb 2020 02:20:05 +0800 Subject: [PATCH] Fix compiler warnings in new FFI (#17718) Introduced in https://github.com/apache/incubator-mxnet/pull/17510 --- include/mxnet/ir/expr.h | 4 +- include/mxnet/node/container.h | 2 +- include/mxnet/runtime/container.h | 4 +- include/mxnet/runtime/ffi_helper.h | 10 ++--- include/mxnet/runtime/object.h | 66 +++++++++++++++--------------- 5 files changed, 42 insertions(+), 44 deletions(-) diff --git a/include/mxnet/ir/expr.h b/include/mxnet/ir/expr.h index b9483c74320a..a9f4ff2bbf70 100644 --- a/include/mxnet/ir/expr.h +++ b/include/mxnet/ir/expr.h @@ -141,7 +141,7 @@ class IntImmNode : public PrimExprNode { int64_t value; static constexpr const char* _type_key = "IntImm"; - MXNET_DECLARE_FINAL_OBJECT_INFO(IntImmNode, PrimExprNode); + MXNET_DECLARE_FINAL_OBJECT_INFO(IntImmNode, PrimExprNode) }; /*! @@ -186,7 +186,7 @@ class FloatImmNode : public PrimExprNode { double value; static constexpr const char* _type_key = "FloatImm"; - MXNET_DECLARE_FINAL_OBJECT_INFO(FloatImmNode, PrimExprNode); + MXNET_DECLARE_FINAL_OBJECT_INFO(FloatImmNode, PrimExprNode) }; /*! diff --git a/include/mxnet/node/container.h b/include/mxnet/node/container.h index 27b9853a74b7..e164f64a9184 100644 --- a/include/mxnet/node/container.h +++ b/include/mxnet/node/container.h @@ -42,7 +42,7 @@ class ArrayNode : public Object { std::vector data; static constexpr const char* _type_key = "Array"; - MXNET_DECLARE_FINAL_OBJECT_INFO(ArrayNode, Object); + MXNET_DECLARE_FINAL_OBJECT_INFO(ArrayNode, Object) }; /*! diff --git a/include/mxnet/runtime/container.h b/include/mxnet/runtime/container.h index 3dd7e0fc9c79..cd719aaa51a6 100644 --- a/include/mxnet/runtime/container.h +++ b/include/mxnet/runtime/container.h @@ -173,7 +173,7 @@ class ADTObj : public Object, public InplaceArrayBase { static constexpr const uint32_t _type_index = TypeIndex::kMXNetADT; static constexpr const char* _type_key = "MXNet.ADT"; - MXNET_DECLARE_FINAL_OBJECT_INFO(ADTObj, Object); + MXNET_DECLARE_FINAL_OBJECT_INFO(ADTObj, Object) private: /*! @@ -273,7 +273,7 @@ class ADT : public ObjectRef { return ADT(0, std::forward(args)...); } - MXNET_DEFINE_OBJECT_REF_METHODS(ADT, ObjectRef, ADTObj); + MXNET_DEFINE_OBJECT_REF_METHODS(ADT, ObjectRef, ADTObj) }; } // namespace runtime diff --git a/include/mxnet/runtime/ffi_helper.h b/include/mxnet/runtime/ffi_helper.h index b539524dfd05..49134ca122a7 100644 --- a/include/mxnet/runtime/ffi_helper.h +++ b/include/mxnet/runtime/ffi_helper.h @@ -38,7 +38,7 @@ class EllipsisObj : public Object { public: static constexpr const uint32_t _type_index = TypeIndex::kEllipsis; static constexpr const char* _type_key = "MXNet.Ellipsis"; - MXNET_DECLARE_FINAL_OBJECT_INFO(EllipsisObj, Object); + MXNET_DECLARE_FINAL_OBJECT_INFO(EllipsisObj, Object) }; inline ObjectRef CreateEllipsis() { @@ -54,7 +54,7 @@ class SliceObj : public Object { static constexpr const uint32_t _type_index = TypeIndex::kSlice; static constexpr const char* _type_key = "MXNet.Slice"; - MXNET_DECLARE_FINAL_OBJECT_INFO(SliceObj, Object); + MXNET_DECLARE_FINAL_OBJECT_INFO(SliceObj, Object) }; class Slice : public ObjectRef { @@ -74,7 +74,7 @@ class Slice : public ObjectRef { // constant to represent None. static constexpr int64_t kNoneValue = std::numeric_limits::min(); - MXNET_DEFINE_OBJECT_REF_METHODS(Slice, ObjectRef, SliceObj); + MXNET_DEFINE_OBJECT_REF_METHODS(Slice, ObjectRef, SliceObj) }; int64_t inline SliceNoneValue() { @@ -86,7 +86,7 @@ class IntegerObj: public Object { int64_t value; static constexpr const uint32_t _type_index = TypeIndex::kInteger; static constexpr const char* _type_key = "MXNet.Integer"; - MXNET_DECLARE_FINAL_OBJECT_INFO(IntegerObj, Object); + MXNET_DECLARE_FINAL_OBJECT_INFO(IntegerObj, Object) }; class Integer: public ObjectRef { @@ -96,7 +96,7 @@ class Integer: public ObjectRef { data->value = value; data_ = std::move(data); } - MXNET_DEFINE_OBJECT_REF_METHODS(Integer, ObjectRef, IntegerObj); + MXNET_DEFINE_OBJECT_REF_METHODS(Integer, ObjectRef, IntegerObj) }; // Helper functions for fast FFI implementations diff --git a/include/mxnet/runtime/object.h b/include/mxnet/runtime/object.h index e2fb067f1067..a031a56d88ed 100644 --- a/include/mxnet/runtime/object.h +++ b/include/mxnet/runtime/object.h @@ -644,22 +644,20 @@ struct ObjectEqual { * \param TypeName The name of the current type. * \param ParentType The name of the ParentType */ -#define MXNET_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType) \ - static const uint32_t RuntimeTypeIndex() { \ - if (TypeName::_type_index != ::mxnet::runtime::TypeIndex::kDynamic) { \ - return TypeName::_type_index; \ - } \ - return _GetOrAllocRuntimeTypeIndex(); \ - } \ - static const uint32_t _GetOrAllocRuntimeTypeIndex() { \ - static uint32_t tidx = GetOrAllocRuntimeTypeIndex( \ - TypeName::_type_key, \ - TypeName::_type_index, \ - ParentType::_GetOrAllocRuntimeTypeIndex(), \ - TypeName::_type_child_slots, \ - TypeName::_type_child_slots_can_overflow); \ - return tidx; \ - } \ +#define MXNET_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType) \ + static uint32_t RuntimeTypeIndex() { \ + return TypeName::_type_index != ::mxnet::runtime::TypeIndex::kDynamic ? \ + TypeName::_type_index : _GetOrAllocRuntimeTypeIndex(); \ + } \ + static uint32_t _GetOrAllocRuntimeTypeIndex() { \ + static uint32_t tidx = GetOrAllocRuntimeTypeIndex( \ + TypeName::_type_key, \ + TypeName::_type_index, \ + ParentType::_GetOrAllocRuntimeTypeIndex(), \ + TypeName::_type_child_slots, \ + TypeName::_type_child_slots_can_overflow); \ + return tidx; \ + } /*! * \brief helper macro to declare type information in a final class. @@ -667,8 +665,8 @@ struct ObjectEqual { * \param ParentType The name of the ParentType */ #define MXNET_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType) \ - static const constexpr bool _type_final = true; \ - static const constexpr int _type_child_slots = 0; \ + static const constexpr bool _type_final = true; \ + static const constexpr int _type_child_slots = 0; \ MXNET_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType) \ @@ -684,25 +682,25 @@ struct ObjectEqual { #define MXNET_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName) \ - TypeName() {} \ - explicit TypeName( \ - ::mxnet::runtime::ObjectPtr<::mxnet::runtime::Object> n) \ - : ParentType(n) {} \ - const ObjectName* operator->() const { \ - return static_cast(data_.get()); \ - } \ - operator bool() const { return data_ != nullptr; } \ + TypeName() {} \ + explicit TypeName( \ + ::mxnet::runtime::ObjectPtr<::mxnet::runtime::Object> n) \ + : ParentType(n) {} \ + const ObjectName* operator->() const { \ + return static_cast(data_.get()); \ + } \ + operator bool() const { return data_ != nullptr; } \ using ContainerType = ObjectName; #define MXNET_DEFINE_OBJECT_REF_METHODS_MUT(TypeName, ParentType, ObjectName) \ - TypeName() {} \ - explicit TypeName( \ - ::mxnet::runtime::ObjectPtr<::mxnet::runtime::Object> n) \ - : ParentType(n) {} \ - ObjectName* operator->() { \ - return static_cast(data_.get()); \ - } \ - operator bool() const { return data_ != nullptr; } \ + TypeName() {} \ + explicit TypeName( \ + ::mxnet::runtime::ObjectPtr<::mxnet::runtime::Object> n) \ + : ParentType(n) {} \ + ObjectName* operator->() { \ + return static_cast(data_.get()); \ + } \ + operator bool() const { return data_ != nullptr; } \ using ContainerType = ObjectName; // Implementations details below