Skip to content

Commit

Permalink
Revert D64867178
Browse files Browse the repository at this point in the history
Summary:
This diff reverts D64867178
Broke a bunch of use cases where people were relying on cpp.adapters in py3 (somehow)

Reviewed By: Filip-F

Differential Revision: D64952860

fbshipit-source-id: 2b80395339c06e5e2a1d95146a07c88794026385
  • Loading branch information
generatedunixname89002005232357 authored and facebook-github-bot committed Oct 25, 2024
1 parent 9a52ef1 commit 1ac8570
Show file tree
Hide file tree
Showing 19 changed files with 381 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ std::string get_cpp_template(const t_type& type) {

bool is_hidden(const t_named& node) {
return node.has_annotation("py3.hidden") ||
node.find_structured_annotation_or_null(kCppAdapterUri) ||
node.find_structured_annotation_or_null(kPythonPy3HiddenUri);
}

Expand Down Expand Up @@ -807,7 +806,9 @@ class py3_mstch_struct : public mstch_struct {
py3_fields_.begin(),
py3_fields_.end(),
[this](const t_field* field) {
bool hidden = is_hidden(*field);
bool hidden = field->has_annotation("py3.hidden") ||
field->find_structured_annotation_or_null(
kPythonPy3HiddenUri);
this->hidden_fields |= hidden;
return hidden;
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,36 @@ inline void reset_field<::facebook::thrift::test::Foo>(
::facebook::thrift::test::Foo& obj, uint16_t index) {
switch (index) {
case 0:
obj.setField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().setField_ref());
obj.intField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().intField_ref());
return;
case 1:
obj.optionalSetField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalSetField_ref());
obj.optionalIntField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalIntField_ref());
return;
case 2:
obj.longField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().longField_ref());
obj.intFieldWithDefault_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().intFieldWithDefault_ref());
return;
case 3:
obj.setField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().setField_ref());
return;
case 4:
obj.optionalSetField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalSetField_ref());
return;
case 5:
obj.mapField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().mapField_ref());
return;
case 6:
obj.optionalMapField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().optionalMapField_ref());
return;
case 7:
obj.binaryField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().binaryField_ref());
return;
case 8:
obj.longField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().longField_ref());
return;
case 9:
obj.adaptedLongField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().adaptedLongField_ref());
return;
case 10:
obj.doubleAdaptedField_ref().copy_from(default_inst<::facebook::thrift::test::Foo>().doubleAdaptedField_ref());
return;
}
Expand All @@ -55,12 +76,24 @@ inline void reset_field<::facebook::thrift::test::Bar>(
::facebook::thrift::test::Bar& obj, uint16_t index) {
switch (index) {
case 0:
obj.structListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().structListField_ref());
obj.structField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().structField_ref());
return;
case 1:
obj.optionalStructListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalStructListField_ref());
obj.optionalStructField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalStructField_ref());
return;
case 2:
obj.structListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().structListField_ref());
return;
case 3:
obj.optionalStructListField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalStructListField_ref());
return;
case 4:
obj.unionField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().unionField_ref());
return;
case 5:
obj.optionalUnionField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().optionalUnionField_ref());
return;
case 6:
obj.adaptedStructField_ref().copy_from(default_inst<::facebook::thrift::test::Bar>().adaptedStructField_ref());
return;
}
Expand All @@ -70,13 +103,34 @@ template<>
inline void reset_field<::facebook::thrift::test::StructWithFieldAdapter>(
::facebook::thrift::test::StructWithFieldAdapter& obj, uint16_t index) {
switch (index) {
case 0:
obj.field_ref().copy_from(default_inst<::facebook::thrift::test::StructWithFieldAdapter>().field_ref());
return;
case 1:
obj.shared_field_ref().reset();
return;
case 2:
obj.opt_shared_field_ref().reset();
return;
case 3:
obj.opt_boxed_field_ref().copy_from(default_inst<::facebook::thrift::test::StructWithFieldAdapter>().opt_boxed_field_ref());
return;
}
}

template<>
inline void reset_field<::facebook::thrift::test::TerseAdaptedFields>(
::facebook::thrift::test::TerseAdaptedFields& obj, uint16_t index) {
switch (index) {
case 0:
obj.int_field_ref().copy_from(default_inst<::facebook::thrift::test::TerseAdaptedFields>().int_field_ref());
return;
case 1:
obj.string_field_ref().copy_from(default_inst<::facebook::thrift::test::TerseAdaptedFields>().string_field_ref());
return;
case 2:
obj.set_field_ref().copy_from(default_inst<::facebook::thrift::test::TerseAdaptedFields>().set_field_ref());
return;
}
}

Expand Down Expand Up @@ -131,11 +185,29 @@ inline void reset_field<::facebook::thrift::test::AdaptTestStruct>(
obj.custom_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().custom_ref());
return;
case 2:
obj.meta_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().meta_ref());
obj.timeout_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().timeout_ref());
return;
case 3:
obj.data_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().data_ref());
return;
case 4:
obj.meta_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().meta_ref());
return;
case 5:
obj.indirectionString_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().indirectionString_ref());
return;
case 6:
obj.string_data_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().string_data_ref());
return;
case 7:
obj.double_wrapped_bool_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().double_wrapped_bool_ref());
return;
case 8:
obj.double_wrapped_integer_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().double_wrapped_integer_ref());
return;
case 9:
obj.binary_data_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTestStruct>().binary_data_ref());
return;
}
}

Expand Down Expand Up @@ -165,30 +237,48 @@ inline void reset_field<::facebook::thrift::test::AdaptTemplatedTestStruct>(
obj.adaptedString_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedString_ref());
return;
case 7:
obj.adaptedBoolDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedBoolDefault_ref());
obj.adaptedList_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedList_ref());
return;
case 8:
obj.adaptedByteDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedByteDefault_ref());
obj.adaptedSet_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedSet_ref());
return;
case 9:
obj.adaptedShortDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedShortDefault_ref());
obj.adaptedMap_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedMap_ref());
return;
case 10:
obj.adaptedIntegerDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedIntegerDefault_ref());
obj.adaptedBoolDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedBoolDefault_ref());
return;
case 11:
obj.adaptedLongDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedLongDefault_ref());
obj.adaptedByteDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedByteDefault_ref());
return;
case 12:
obj.adaptedDoubleDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedDoubleDefault_ref());
obj.adaptedShortDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedShortDefault_ref());
return;
case 13:
obj.adaptedStringDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedStringDefault_ref());
obj.adaptedIntegerDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedIntegerDefault_ref());
return;
case 14:
obj.adaptedEnum_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedEnum_ref());
obj.adaptedLongDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedLongDefault_ref());
return;
case 15:
obj.adaptedDoubleDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedDoubleDefault_ref());
return;
case 16:
obj.adaptedStringDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedStringDefault_ref());
return;
case 17:
obj.adaptedEnum_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedEnum_ref());
return;
case 18:
obj.adaptedListDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedListDefault_ref());
return;
case 19:
obj.adaptedSetDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedSetDefault_ref());
return;
case 20:
obj.adaptedMapDefault_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().adaptedMapDefault_ref());
return;
case 21:
obj.doubleTypedefBool_ref().copy_from(default_inst<::facebook::thrift::test::AdaptTemplatedTestStruct>().doubleTypedefBool_ref());
return;
}
Expand Down Expand Up @@ -219,12 +309,15 @@ inline void reset_field<::facebook::thrift::test::StructFieldAdaptedStruct>(
::facebook::thrift::test::StructFieldAdaptedStruct& obj, uint16_t index) {
switch (index) {
case 0:
obj.adaptedTypedef_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().adaptedTypedef_ref());
obj.adaptedStruct_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().adaptedStruct_ref());
return;
case 1:
obj.directlyAdapted_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().directlyAdapted_ref());
obj.adaptedTypedef_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().adaptedTypedef_ref());
return;
case 2:
obj.directlyAdapted_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().directlyAdapted_ref());
return;
case 3:
obj.typedefOfAdapted_ref().copy_from(default_inst<::facebook::thrift::test::StructFieldAdaptedStruct>().typedefOfAdapted_ref());
return;
}
Expand Down Expand Up @@ -274,6 +367,9 @@ template<>
inline void reset_field<::facebook::thrift::test::AlsoMoveOnly>(
::facebook::thrift::test::AlsoMoveOnly& obj, uint16_t index) {
switch (index) {
case 0:
obj.ptr_ref().copy_from(default_inst<::facebook::thrift::test::AlsoMoveOnly>().ptr_ref());
return;
}
}

Expand All @@ -289,8 +385,14 @@ inline void reset_field<::facebook::thrift::test::CountingStruct>(
::facebook::thrift::test::CountingStruct& obj, uint16_t index) {
switch (index) {
case 0:
obj.regularInt_ref().copy_from(default_inst<::facebook::thrift::test::CountingStruct>().regularInt_ref());
return;
case 1:
obj.countingInt_ref().copy_from(default_inst<::facebook::thrift::test::CountingStruct>().countingInt_ref());
return;
case 2:
obj.regularString_ref().copy_from(default_inst<::facebook::thrift::test::CountingStruct>().regularString_ref());
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,24 @@ class AdaptedStructWithInternBox_Builder(thrift.py3.builder.StructBuilder):
_struct_type = _fbthrift_struct_type__AdaptedStructWithInternBox

def __init__(self):
pass
self.field1: _typing.Any = None
self.field2: _typing.Any = None

def __iter__(self):
pass
yield "field1", self.field1
yield "field2", self.field2

_fbthrift_struct_type__AdaptedStructWithTerseInternBox = _module_types.AdaptedStructWithTerseInternBox
class AdaptedStructWithTerseInternBox_Builder(thrift.py3.builder.StructBuilder):
_struct_type = _fbthrift_struct_type__AdaptedStructWithTerseInternBox

def __init__(self):
pass
self.field1: _typing.Any = None
self.field2: _typing.Any = None

def __iter__(self):
pass
yield "field1", self.field1
yield "field2", self.field2

_fbthrift_struct_type__StructWithRefTypeUnique = _module_types.StructWithRefTypeUnique
class StructWithRefTypeUnique_Builder(thrift.py3.builder.StructBuilder):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,25 @@ template<>
inline void reset_field<::cpp2::AdaptedStructWithInternBox>(
::cpp2::AdaptedStructWithInternBox& obj, uint16_t index) {
switch (index) {
case 0:
obj.field1_ref().copy_from(default_inst<::cpp2::AdaptedStructWithInternBox>().field1_ref());
return;
case 1:
obj.field2_ref().copy_from(default_inst<::cpp2::AdaptedStructWithInternBox>().field2_ref());
return;
}
}

template<>
inline void reset_field<::cpp2::AdaptedStructWithTerseInternBox>(
::cpp2::AdaptedStructWithTerseInternBox& obj, uint16_t index) {
switch (index) {
case 0:
obj.field1_ref().copy_from(default_inst<::cpp2::AdaptedStructWithTerseInternBox>().field1_ref());
return;
case 1:
obj.field2_ref().copy_from(default_inst<::cpp2::AdaptedStructWithTerseInternBox>().field2_ref());
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ cdef extern from "thrift/compiler/test/fixtures/refs/gen-cpp2/module_types_custo
bint operator>(cAdaptedStructWithInternBox&)
bint operator<=(cAdaptedStructWithInternBox&)
bint operator>=(cAdaptedStructWithInternBox&)
__field_ref[cEmpty] field1_ref "field1_ref" ()
__field_ref[cMyField] field2_ref "field2_ref" ()


cdef cppclass cAdaptedStructWithTerseInternBox "::cpp2::AdaptedStructWithTerseInternBox":
Expand All @@ -282,6 +284,8 @@ cdef extern from "thrift/compiler/test/fixtures/refs/gen-cpp2/module_types_custo
bint operator>(cAdaptedStructWithTerseInternBox&)
bint operator<=(cAdaptedStructWithTerseInternBox&)
bint operator>=(cAdaptedStructWithTerseInternBox&)
__terse_field_ref[cEmpty] field1_ref "field1_ref" ()
__terse_field_ref[cMyField] field2_ref "field2_ref" ()


cdef cppclass cStructWithRefTypeUnique "::cpp2::StructWithRefTypeUnique":
Expand Down Expand Up @@ -555,6 +559,10 @@ cdef class StructWithTerseInternBox(thrift.py3.types.Struct):
cdef class AdaptedStructWithInternBox(thrift.py3.types.Struct):
cdef shared_ptr[cAdaptedStructWithInternBox] _cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE
cdef _fbthrift_types_fields.__AdaptedStructWithInternBox_FieldsSetter _fields_setter
cdef inline object field1_impl(self)
cdef inline object field2_impl(self)
cdef Empty __fbthrift_cached_field1
cdef MyField __fbthrift_cached_field2

@staticmethod
cdef _create_FBTHRIFT_ONLY_DO_NOT_USE(shared_ptr[cAdaptedStructWithInternBox])
Expand All @@ -564,6 +572,10 @@ cdef class AdaptedStructWithInternBox(thrift.py3.types.Struct):
cdef class AdaptedStructWithTerseInternBox(thrift.py3.types.Struct):
cdef shared_ptr[cAdaptedStructWithTerseInternBox] _cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE
cdef _fbthrift_types_fields.__AdaptedStructWithTerseInternBox_FieldsSetter _fields_setter
cdef inline object field1_impl(self)
cdef inline object field2_impl(self)
cdef Empty __fbthrift_cached_field1
cdef MyField __fbthrift_cached_field2

@staticmethod
cdef _create_FBTHRIFT_ONLY_DO_NOT_USE(shared_ptr[cAdaptedStructWithTerseInternBox])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,23 @@ class StructWithTerseInternBox(thrift.py3.types.Struct, _typing.Hashable):

class AdaptedStructWithInternBox(thrift.py3.types.Struct, _typing.Hashable):
class __fbthrift_IsSet:
field1: bool
field2: bool
pass

field1: _typing.Final[Empty] = ...
field2: _typing.Final[MyField] = ...

def __init__(
self,
self, *,
field1: _typing.Optional[Empty]=None,
field2: _typing.Optional[MyField]=None
) -> None: ...

def __call__(
self,
self, *,
field1: _typing.Union[Empty, None]=None,
field2: _typing.Union[MyField, None]=None
) -> AdaptedStructWithInternBox: ...

def __reduce__(self) -> _typing.Tuple[_typing.Callable, _typing.Tuple[_typing.Type['AdaptedStructWithInternBox'], bytes]]: ...
Expand All @@ -537,13 +545,19 @@ class AdaptedStructWithTerseInternBox(thrift.py3.types.Struct, _typing.Hashable)
class __fbthrift_IsSet:
pass

field1: _typing.Final[Empty] = ...
field2: _typing.Final[MyField] = ...

def __init__(
self,
self, *,
field1: _typing.Optional[Empty]=None,
field2: _typing.Optional[MyField]=None
) -> None: ...

def __call__(
self,
self, *,
field1: _typing.Union[Empty, None]=None,
field2: _typing.Union[MyField, None]=None
) -> AdaptedStructWithTerseInternBox: ...

def __reduce__(self) -> _typing.Tuple[_typing.Callable, _typing.Tuple[_typing.Type['AdaptedStructWithTerseInternBox'], bytes]]: ...
Expand Down
Loading

0 comments on commit 1ac8570

Please sign in to comment.