-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add (cpp.experimental.lazy) annotation
Summary: This added `(cpp.experimental.lazy)` annotation to thrift C++ compiler. Currently there only affect is that 1. lazy field's data member will always be private 2. lazy field won't have setter/getter (this can be implemented in the future) Reviewed By: vitaut Differential Revision: D26715914 fbshipit-source-id: e1298bf372e2104c3faf7be03760072e14dc3e3d
- Loading branch information
1 parent
27547e2
commit 240b7fe
Showing
19 changed files
with
941 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mstch_cpp2 src/simple.thrift |
6 changes: 6 additions & 0 deletions
6
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_constants.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ |
19 changes: 19 additions & 0 deletions
19
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_constants.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
#pragma once | ||
|
||
#include <thrift/lib/cpp2/gen/module_constants_h.h> | ||
|
||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_types.h" | ||
|
||
namespace apache { namespace thrift { namespace test { | ||
|
||
struct simple_constants { | ||
|
||
}; | ||
|
||
}}} // apache::thrift::test |
35 changes: 35 additions & 0 deletions
35
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_data.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
|
||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_data.h" | ||
|
||
#include <thrift/lib/cpp2/gen/module_data_cpp.h> | ||
|
||
namespace apache { | ||
namespace thrift { | ||
|
||
const std::array<folly::StringPiece, 4> TStructDataStorage<::apache::thrift::test::Foo>::fields_names = {{ | ||
"field1", | ||
"field2", | ||
"field3", | ||
"field4", | ||
}}; | ||
const std::array<int16_t, 4> TStructDataStorage<::apache::thrift::test::Foo>::fields_ids = {{ | ||
1, | ||
2, | ||
3, | ||
4, | ||
}}; | ||
const std::array<protocol::TType, 4> TStructDataStorage<::apache::thrift::test::Foo>::fields_types = {{ | ||
TType::T_STRING, | ||
TType::T_STRING, | ||
TType::T_LIST, | ||
TType::T_LIST, | ||
}}; | ||
|
||
} // namespace thrift | ||
} // namespace apache |
22 changes: 22 additions & 0 deletions
22
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_data.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
#pragma once | ||
|
||
#include <thrift/lib/cpp2/gen/module_data_h.h> | ||
|
||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_types.h" | ||
|
||
namespace apache { namespace thrift { | ||
|
||
template <> struct TStructDataStorage<::apache::thrift::test::Foo> { | ||
static constexpr const std::size_t fields_size = 4; | ||
static const std::array<folly::StringPiece, fields_size> fields_names; | ||
static const std::array<int16_t, fields_size> fields_ids; | ||
static const std::array<protocol::TType, fields_size> fields_types; | ||
}; | ||
|
||
}} // apache::thrift |
28 changes: 28 additions & 0 deletions
28
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_for_each_field.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
#pragma once | ||
|
||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_metadata.h" | ||
#include <thrift/lib/cpp2/visitation/for_each.h> | ||
|
||
namespace apache { | ||
namespace thrift { | ||
namespace detail { | ||
|
||
template <> | ||
struct ForEachField<::apache::thrift::test::Foo> { | ||
template <typename F, typename... T> | ||
void operator()(FOLLY_MAYBE_UNUSED F&& f, FOLLY_MAYBE_UNUSED T&&... t) const { | ||
f(0, static_cast<T&&>(t).field1_ref()...); | ||
f(1, static_cast<T&&>(t).field2_ref()...); | ||
f(2, static_cast<T&&>(t).field3_ref()...); | ||
f(3, static_cast<T&&>(t).field4_ref()...); | ||
} | ||
}; | ||
} // namespace detail | ||
} // namespace thrift | ||
} // namespace apache |
53 changes: 53 additions & 0 deletions
53
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_metadata.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
#include <thrift/lib/cpp2/gen/module_metadata_cpp.h> | ||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_metadata.h" | ||
|
||
namespace apache { | ||
namespace thrift { | ||
namespace detail { | ||
namespace md { | ||
using ThriftMetadata = ::apache::thrift::metadata::ThriftMetadata; | ||
using ThriftPrimitiveType = ::apache::thrift::metadata::ThriftPrimitiveType; | ||
using ThriftType = ::apache::thrift::metadata::ThriftType; | ||
using ThriftService = ::apache::thrift::metadata::ThriftService; | ||
using ThriftServiceContext = ::apache::thrift::metadata::ThriftServiceContext; | ||
using ThriftFunctionGenerator = void (*)(ThriftMetadata&, ThriftService&); | ||
|
||
|
||
const ::apache::thrift::metadata::ThriftStruct& | ||
StructMetadata<::apache::thrift::test::Foo>::gen(ThriftMetadata& metadata) { | ||
auto res = metadata.structs_ref()->emplace("simple.Foo", ::apache::thrift::metadata::ThriftStruct{}); | ||
if (!res.second) { | ||
return res.first->second; | ||
} | ||
::apache::thrift::metadata::ThriftStruct& simple_Foo = res.first->second; | ||
simple_Foo.name_ref() = "simple.Foo"; | ||
simple_Foo.is_union_ref() = false; | ||
static const EncodedThriftField | ||
simple_Foo_fields[] = { | ||
std::make_tuple(1, "field1", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{}), | ||
std::make_tuple(2, "field2", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{}), | ||
std::make_tuple(3, "field3", false, std::make_unique<List>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::vector<ThriftConstStruct>{}), | ||
std::make_tuple(4, "field4", false, std::make_unique<List>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::vector<ThriftConstStruct>{}), | ||
}; | ||
for (const auto& f : simple_Foo_fields) { | ||
::apache::thrift::metadata::ThriftField field; | ||
field.id_ref() = std::get<0>(f); | ||
field.name_ref() = std::get<1>(f); | ||
field.is_optional_ref() = std::get<2>(f); | ||
std::get<3>(f)->writeAndGenType(*field.type_ref(), metadata); | ||
field.structured_annotations_ref() = std::get<4>(f); | ||
simple_Foo.fields_ref()->push_back(std::move(field)); | ||
} | ||
return res.first->second; | ||
} | ||
|
||
} // namespace md | ||
} // namespace detail | ||
} // namespace thrift | ||
} // namespace apache |
26 changes: 26 additions & 0 deletions
26
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_metadata.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
#pragma once | ||
|
||
#include <thrift/lib/cpp2/gen/module_metadata_h.h> | ||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_types.h" | ||
|
||
|
||
namespace apache { | ||
namespace thrift { | ||
namespace detail { | ||
namespace md { | ||
|
||
template <> | ||
class StructMetadata<::apache::thrift::test::Foo> { | ||
public: | ||
static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); | ||
}; | ||
} // namespace md | ||
} // namespace detail | ||
} // namespace thrift | ||
} // namespace apache |
130 changes: 130 additions & 0 deletions
130
thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_types.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/** | ||
* Autogenerated by Thrift for src/simple.thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_types.h" | ||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_types.tcc" | ||
|
||
#include <thrift/lib/cpp2/gen/module_types_cpp.h> | ||
|
||
#include "thrift/compiler/test/fixtures/lazy_deserialization/gen-cpp2/simple_data.h" | ||
|
||
|
||
namespace apache { | ||
namespace thrift { | ||
namespace detail { | ||
|
||
void TccStructTraits<::apache::thrift::test::Foo>::translateFieldName( | ||
folly::StringPiece _fname, | ||
int16_t& fid, | ||
apache::thrift::protocol::TType& _ftype) noexcept { | ||
using data = apache::thrift::TStructDataStorage<::apache::thrift::test::Foo>; | ||
static const st::translate_field_name_table table{ | ||
data::fields_size, | ||
data::fields_names.data(), | ||
data::fields_ids.data(), | ||
data::fields_types.data()}; | ||
st::translate_field_name(_fname, fid, _ftype, table); | ||
} | ||
|
||
} // namespace detail | ||
} // namespace thrift | ||
} // namespace apache | ||
|
||
namespace apache { namespace thrift { namespace test { | ||
|
||
THRIFT_IGNORE_ISSET_USE_WARNING_BEGIN | ||
Foo::Foo(apache::thrift::FragileConstructor, ::std::string field1__arg, ::std::string field2__arg, ::std::vector<int32_t> field3__arg, ::std::vector<int32_t> field4__arg) : | ||
field1(std::move(field1__arg)), | ||
field2(std::move(field2__arg)), | ||
field3(std::move(field3__arg)), | ||
field4(std::move(field4__arg)) { | ||
__isset.field1 = true; | ||
__isset.field2 = true; | ||
__isset.field3 = true; | ||
__isset.field4 = true; | ||
} | ||
THRIFT_IGNORE_ISSET_USE_WARNING_END | ||
void Foo::__clear() { | ||
// clear all fields | ||
field1 = apache::thrift::StringTraits< std::string>::fromStringLiteral(""); | ||
field2 = apache::thrift::StringTraits< std::string>::fromStringLiteral(""); | ||
field3.clear(); | ||
field4.clear(); | ||
THRIFT_IGNORE_ISSET_USE_WARNING_BEGIN | ||
__isset = {}; | ||
THRIFT_IGNORE_ISSET_USE_WARNING_END | ||
} | ||
|
||
bool Foo::operator==(const Foo& rhs) const { | ||
(void)rhs; | ||
auto& lhs = *this; | ||
(void)lhs; | ||
if (!(lhs.field1 == rhs.field1)) { | ||
return false; | ||
} | ||
if (!(lhs.field2 == rhs.field2)) { | ||
return false; | ||
} | ||
if (!(lhs.field3 == rhs.field3)) { | ||
return false; | ||
} | ||
if (!(lhs.field4 == rhs.field4)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool Foo::operator<(const Foo& rhs) const { | ||
(void)rhs; | ||
auto& lhs = *this; | ||
(void)lhs; | ||
if (!(lhs.field1 == rhs.field1)) { | ||
return lhs.field1 < rhs.field1; | ||
} | ||
if (!(lhs.field2 == rhs.field2)) { | ||
return lhs.field2 < rhs.field2; | ||
} | ||
if (!(lhs.field3 == rhs.field3)) { | ||
return lhs.field3 < rhs.field3; | ||
} | ||
if (!(lhs.field4 == rhs.field4)) { | ||
return lhs.field4 < rhs.field4; | ||
} | ||
return false; | ||
} | ||
|
||
const ::std::vector<int32_t>& Foo::get_field4() const& { | ||
return field4; | ||
} | ||
|
||
::std::vector<int32_t> Foo::get_field4() && { | ||
return std::move(field4); | ||
} | ||
|
||
|
||
void swap(Foo& a, Foo& b) { | ||
using ::std::swap; | ||
swap(a.field1_ref().value(), b.field1_ref().value()); | ||
swap(a.field2_ref().value(), b.field2_ref().value()); | ||
swap(a.field3_ref().value(), b.field3_ref().value()); | ||
swap(a.field4_ref().value(), b.field4_ref().value()); | ||
THRIFT_IGNORE_ISSET_USE_WARNING_BEGIN | ||
swap(a.__isset, b.__isset); | ||
THRIFT_IGNORE_ISSET_USE_WARNING_END | ||
} | ||
|
||
template void Foo::readNoXfer<>(apache::thrift::BinaryProtocolReader*); | ||
template uint32_t Foo::write<>(apache::thrift::BinaryProtocolWriter*) const; | ||
template uint32_t Foo::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; | ||
template uint32_t Foo::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; | ||
template void Foo::readNoXfer<>(apache::thrift::CompactProtocolReader*); | ||
template uint32_t Foo::write<>(apache::thrift::CompactProtocolWriter*) const; | ||
template uint32_t Foo::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; | ||
template uint32_t Foo::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; | ||
|
||
|
||
|
||
}}} // apache::thrift::test |
Oops, something went wrong.