Skip to content

Commit 825db6c

Browse files
SS-JIAfacebook-github-bot
authored andcommitted
Call destructor explicitly when move constructing Value (#3148)
Summary: Pull Request resolved: #3148 ## Context Inspecting code for ATen and ExecuTorch's `Value` classes (e.g. `IValue` and `EValue` respectively) I noticed that the destructor is called [explicitly when move constructing with non-trivial types](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/core/ivalue.h#L409). In practice I don't think calling the destructor explicitly is necessary because move constructing typically sets the moved from object to an inactive state, but since we use `Value` to encapsulate STL types (i.e. types for which we do not implement the destructor) it's best to call the destructor explicitly to be safe. ghstack-source-id: 223225898 exported-using-ghexport Reviewed By: jorgep31415 Differential Revision: D56357187 fbshipit-source-id: 4797a627efcd2a61ee35d4c6963e524b4161ff3b
1 parent bd07c75 commit 825db6c

File tree

1 file changed

+13
-9
lines changed
  • backends/vulkan/runtime/graph/containers

1 file changed

+13
-9
lines changed

backends/vulkan/runtime/graph/containers/Value.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ struct Value final {
9393
payload.u.member_name = rhs.payload.u.member_name; \
9494
break;
9595

96-
#define CASE_MOVE_MOVEABLE_TYPE(type_tag, type, member_name) \
96+
#define CASE_MOVE_MOVEABLE_TYPE(type_tag, type, member_name, dtor_name) \
9797
case type_tag: \
9898
new (&payload.member_name) type(std::move(rhs.payload.member_name)); \
99+
rhs.payload.member_name.~dtor_name(); \
99100
break;
100101

101102
Value(Value&& rhs) noexcept : tag(rhs.tag) {
@@ -105,20 +106,23 @@ struct Value final {
105106
CASE_MOVE_TRIVIALLY_COPYABLE_TYPE(TypeTag::DOUBLE, as_double);
106107
CASE_MOVE_TRIVIALLY_COPYABLE_TYPE(TypeTag::BOOL, as_bool);
107108
// Tensor and tensor adjacent types
108-
CASE_MOVE_MOVEABLE_TYPE(TypeTag::TENSOR, vTensor, as_tensor);
109-
CASE_MOVE_MOVEABLE_TYPE(TypeTag::STAGING, api::StorageBuffer, as_staging);
110-
CASE_MOVE_MOVEABLE_TYPE(TypeTag::TENSORREF, TensorRef, as_tensorref);
109+
CASE_MOVE_MOVEABLE_TYPE(TypeTag::TENSOR, vTensor, as_tensor, vTensor);
110+
CASE_MOVE_MOVEABLE_TYPE(
111+
TypeTag::STAGING, api::StorageBuffer, as_staging, StorageBuffer);
112+
CASE_MOVE_MOVEABLE_TYPE(
113+
TypeTag::TENSORREF, TensorRef, as_tensorref, TensorRef);
111114
// Scalar lists
112115
CASE_MOVE_MOVEABLE_TYPE(
113-
TypeTag::INTLIST, std::vector<int64_t>, as_int_list);
116+
TypeTag::INTLIST, std::vector<int64_t>, as_int_list, vector);
114117
CASE_MOVE_MOVEABLE_TYPE(
115-
TypeTag::DOUBLELIST, std::vector<double>, as_double_list);
118+
TypeTag::DOUBLELIST, std::vector<double>, as_double_list, vector);
116119
CASE_MOVE_MOVEABLE_TYPE(
117-
TypeTag::BOOLLIST, std::vector<bool>, as_bool_list);
120+
TypeTag::BOOLLIST, std::vector<bool>, as_bool_list, vector);
118121
// Special types
119122
CASE_MOVE_MOVEABLE_TYPE(
120-
TypeTag::VALUELIST, std::vector<ValueRef>, as_value_list);
121-
CASE_MOVE_MOVEABLE_TYPE(TypeTag::STRING, std::string, as_string);
123+
TypeTag::VALUELIST, std::vector<ValueRef>, as_value_list, vector);
124+
CASE_MOVE_MOVEABLE_TYPE(
125+
TypeTag::STRING, std::string, as_string, basic_string);
122126

123127
case TypeTag::NONE:
124128
clearToNone();

0 commit comments

Comments
 (0)