Skip to content

Commit 356b1b1

Browse files
avalonalexfacebook-github-bot
authored andcommitted
fbcode/thrift/compiler/
Reviewed By: iahs Differential Revision: D59628500 fbshipit-source-id: f262de4ef615965eff0c8949095094d4cc792683
1 parent d3cf241 commit 356b1b1

File tree

17 files changed

+192
-44
lines changed

17 files changed

+192
-44
lines changed

thrift/compiler/test/fixtures/coroutines/out/cpp2/gen-cpp2/module_metadata.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::MyService>>::gen_g
7171
module_MyService_getDataById_id_1_type->writeAndGenType(*module_MyService_getDataById_id_1.type(), metadata);
7272
func.arguments()->push_back(std::move(module_MyService_getDataById_id_1));
7373
func.is_oneway() = false;
74+
func.structured_annotations()->push_back(*cvStruct("cpp.ProcessInEbThreadUnsafe", { }).cv_struct_ref());
7475
service.functions()->push_back(std::move(func));
7576
}
7677
void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::MyService>>::gen_putDataById([[maybe_unused]] ThriftMetadata& metadata, ThriftService& service) {

thrift/compiler/test/fixtures/coroutines/src/module.thrift

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17+
include "thrift/annotation/cpp.thrift"
18+
1719
service MyService {
18-
void ping() (cpp.coroutine);
20+
void ping();
1921
string getRandomData();
20-
bool hasDataById(1: i64 id) (cpp.coroutine);
21-
string getDataById(1: i64 id) (cpp.coroutine, thread = 'eb');
22+
bool hasDataById(1: i64 id);
23+
@cpp.ProcessInEbThreadUnsafe
24+
string getDataById(1: i64 id);
2225
void putDataById(1: i64 id, 2: string data);
2326
}

thrift/compiler/test/fixtures/enums/out/cpp2/gen-cpp2/module_metadata.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ void EnumMetadata<::test::fixtures::enums::MyBitmaskEnum1>::gen(ThriftMetadata&
9696
for (std::size_t i = 0; i != EnumTraits::size; ++i) {
9797
enum_metadata.elements()->emplace(static_cast<int32_t>(EnumTraits::values[i]), EnumTraits::names[i]);
9898
}
99+
enum_metadata.structured_annotations()->push_back(*cvStruct("thrift.BitmaskEnum", { }).cv_struct_ref());
99100
}
100101
void EnumMetadata<::test::fixtures::enums::MyBitmaskEnum2>::gen(ThriftMetadata& metadata) {
101102
auto res = metadata.enums()->emplace("module.MyBitmaskEnum2", ::apache::thrift::metadata::ThriftEnum{});

thrift/compiler/test/fixtures/enums/out/cpp2/gen-cpp2/module_types.h

+31
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,38 @@ enum class MyBitmaskEnum1 {
116116
FOUR = 4,
117117
};
118118

119+
inline constexpr MyBitmaskEnum1 operator&(MyBitmaskEnum1 a, MyBitmaskEnum1 b) {
120+
using E = MyBitmaskEnum1;
121+
using U = std::underlying_type_t<E>;
122+
return static_cast<E>(static_cast<U>(a) & static_cast<U>(b));
123+
}
124+
inline constexpr MyBitmaskEnum1& operator&=(MyBitmaskEnum1& a, MyBitmaskEnum1 b) {
125+
return a = a & b;
126+
}
127+
128+
inline constexpr MyBitmaskEnum1 operator|(MyBitmaskEnum1 a, MyBitmaskEnum1 b) {
129+
using E = MyBitmaskEnum1;
130+
using U = std::underlying_type_t<E>;
131+
return static_cast<E>(static_cast<U>(a) | static_cast<U>(b));
132+
}
133+
inline constexpr MyBitmaskEnum1& operator|=(MyBitmaskEnum1& a, MyBitmaskEnum1 b) {
134+
return a = a | b;
135+
}
136+
137+
inline constexpr MyBitmaskEnum1 operator^(MyBitmaskEnum1 a, MyBitmaskEnum1 b) {
138+
using E = MyBitmaskEnum1;
139+
using U = std::underlying_type_t<E>;
140+
return static_cast<E>(static_cast<U>(a) ^ static_cast<U>(b));
141+
}
142+
inline constexpr MyBitmaskEnum1& operator^=(MyBitmaskEnum1& a, MyBitmaskEnum1 b) {
143+
return a = a ^ b;
144+
}
119145

146+
inline constexpr MyBitmaskEnum1 operator~(MyBitmaskEnum1 a) {
147+
using E = MyBitmaskEnum1;
148+
using U = std::underlying_type_t<E>;
149+
return static_cast<E>(~static_cast<U>(a));
150+
}
120151

121152
enum class MyBitmaskEnum2 {
122153
ONE = 1,

thrift/compiler/test/fixtures/enums/out/hack/gen-hack/module_types.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ public static function getEnumMetadata()[]: \tmeta_ThriftEnum {
220220

221221
public static function getAllStructuredAnnotations()[write_props]: \TEnumAnnotations {
222222
return shape(
223-
'enum' => dict[],
223+
'enum' => dict[
224+
'\facebook\thrift\annotation\BitmaskEnum' => \facebook\thrift\annotation\BitmaskEnum::fromShape(
225+
shape(
226+
)
227+
),
228+
],
224229
'constants' => dict[
225230
],
226231
);

thrift/compiler/test/fixtures/enums/out/json/gen-json/module.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,25 @@
118118
"column" : 1
119119
},
120120
"end" : {
121-
"line" : 81,
122-
"column" : 16
121+
"line" : 82,
122+
"column" : 2
123123
}
124124
}
125125
},
126126
"MyBitmaskEnum2" : {
127-
"lineno" : 83,
127+
"lineno" : 84,
128128
"constants" : {
129129
"ONE" : 1,
130130
"TWO" : 2,
131131
"FOUR" : 4
132132
},
133133
"source_range" : {
134134
"begin" : {
135-
"line" : 83,
135+
"line" : 84,
136136
"column" : 1
137137
},
138138
"end" : {
139-
"line" : 88,
139+
"line" : 89,
140140
"column" : 2
141141
}
142142
}

thrift/compiler/test/fixtures/enums/out/json_experimental/gen-json_experimental/module.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,17 @@
168168
"constants" : {
169169
"ONE" : {
170170
"name" : "ONE",
171-
"lineno" : 78,
171+
"lineno" : 79,
172172
"value" : 1
173173
},
174174
"TWO" : {
175175
"name" : "TWO",
176-
"lineno" : 79,
176+
"lineno" : 80,
177177
"value" : 2
178178
},
179179
"FOUR" : {
180180
"name" : "FOUR",
181-
"lineno" : 80,
181+
"lineno" : 81,
182182
"value" : 4
183183
}
184184
},
@@ -189,21 +189,21 @@
189189
"constants" : {
190190
"ONE" : {
191191
"name" : "ONE",
192-
"lineno" : 85,
192+
"lineno" : 86,
193193
"value" : 1
194194
},
195195
"TWO" : {
196196
"name" : "TWO",
197-
"lineno" : 86,
197+
"lineno" : 87,
198198
"value" : 2
199199
},
200200
"FOUR" : {
201201
"name" : "FOUR",
202-
"lineno" : 87,
202+
"lineno" : 88,
203203
"value" : 4
204204
}
205205
},
206-
"lineno" : 83
206+
"lineno" : 84
207207
}
208208
},
209209
"structs" :

thrift/compiler/test/fixtures/enums/src/module.thrift

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ struct MyStruct {
7474
6: MyEnum1 me1_t2 = MyEnum1.ME1_1;
7575
}
7676

77+
@thrift.BitmaskEnum
7778
enum MyBitmaskEnum1 {
7879
ONE = 1,
7980
TWO = 2,
8081
FOUR = 4,
81-
} (bitmask = 1)
82+
}
8283

8384
@thrift.BitmaskEnum
8485
enum MyBitmaskEnum2 {

thrift/compiler/test/fixtures/exceptions/out/cpp2/gen-cpp2/module_metadata.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ StructMetadata<::cpp2::Fiery>::gen(ThriftMetadata& metadata) {
3737
module_Fiery.is_union() = false;
3838
static const auto* const
3939
module_Fiery_fields = new std::array<EncodedThriftField, 1>{ {
40-
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
40+
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
4141
for (const auto& f : *module_Fiery_fields) {
4242
::apache::thrift::metadata::ThriftField field;
4343
field.id() = f.id;
@@ -60,7 +60,7 @@ StructMetadata<::cpp2::Serious>::gen(ThriftMetadata& metadata) {
6060
module_Serious.is_union() = false;
6161
static const auto* const
6262
module_Serious_fields = new std::array<EncodedThriftField, 1>{ {
63-
{ 1, "sonnet", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
63+
{ 1, "sonnet", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
6464
for (const auto& f : *module_Serious_fields) {
6565
::apache::thrift::metadata::ThriftField field;
6666
field.id() = f.id;
@@ -83,7 +83,7 @@ StructMetadata<::cpp2::ComplexFieldNames>::gen(ThriftMetadata& metadata) {
8383
module_ComplexFieldNames.is_union() = false;
8484
static const auto* const
8585
module_ComplexFieldNames_fields = new std::array<EncodedThriftField, 2>{ {
86-
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
86+
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
8787
for (const auto& f : *module_ComplexFieldNames_fields) {
8888
::apache::thrift::metadata::ThriftField field;
8989
field.id() = f.id;
@@ -106,7 +106,7 @@ StructMetadata<::cpp2::CustomFieldNames>::gen(ThriftMetadata& metadata) {
106106
module_CustomFieldNames.is_union() = false;
107107
static const auto* const
108108
module_CustomFieldNames_fields = new std::array<EncodedThriftField, 2>{ {
109-
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
109+
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
110110
for (const auto& f : *module_CustomFieldNames_fields) {
111111
::apache::thrift::metadata::ThriftField field;
112112
field.id() = f.id;
@@ -129,7 +129,7 @@ StructMetadata<::cpp2::ExceptionWithPrimitiveField>::gen(ThriftMetadata& metadat
129129
module_ExceptionWithPrimitiveField.is_union() = false;
130130
static const auto* const
131131
module_ExceptionWithPrimitiveField_fields = new std::array<EncodedThriftField, 2>{ {
132-
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "error_code", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector<ThriftConstStruct>{ }}, }};
132+
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, { 2, "error_code", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector<ThriftConstStruct>{ }}, }};
133133
for (const auto& f : *module_ExceptionWithPrimitiveField_fields) {
134134
::apache::thrift::metadata::ThriftField field;
135135
field.id() = f.id;
@@ -185,7 +185,7 @@ void ExceptionMetadata<::cpp2::Fiery>::gen(ThriftMetadata& metadata) {
185185
module_Fiery.name() = "module.Fiery";
186186
static const auto* const
187187
module_Fiery_fields = new std::array<EncodedThriftField, 1>{ {
188-
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
188+
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
189189
for (const auto& f : *module_Fiery_fields) {
190190
::apache::thrift::metadata::ThriftField field;
191191
field.id() = f.id;
@@ -204,7 +204,7 @@ void ExceptionMetadata<::cpp2::Serious>::gen(ThriftMetadata& metadata) {
204204
module_Serious.name() = "module.Serious";
205205
static const auto* const
206206
module_Serious_fields = new std::array<EncodedThriftField, 1>{ {
207-
{ 1, "sonnet", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
207+
{ 1, "sonnet", true, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
208208
for (const auto& f : *module_Serious_fields) {
209209
::apache::thrift::metadata::ThriftField field;
210210
field.id() = f.id;
@@ -223,7 +223,7 @@ void ExceptionMetadata<::cpp2::ComplexFieldNames>::gen(ThriftMetadata& metadata)
223223
module_ComplexFieldNames.name() = "module.ComplexFieldNames";
224224
static const auto* const
225225
module_ComplexFieldNames_fields = new std::array<EncodedThriftField, 2>{ {
226-
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
226+
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
227227
for (const auto& f : *module_ComplexFieldNames_fields) {
228228
::apache::thrift::metadata::ThriftField field;
229229
field.id() = f.id;
@@ -242,7 +242,7 @@ void ExceptionMetadata<::cpp2::CustomFieldNames>::gen(ThriftMetadata& metadata)
242242
module_CustomFieldNames.name() = "module.CustomFieldNames";
243243
static const auto* const
244244
module_CustomFieldNames_fields = new std::array<EncodedThriftField, 2>{ {
245-
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, }};
245+
{ 1, "error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "internal_error_message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, }};
246246
for (const auto& f : *module_CustomFieldNames_fields) {
247247
::apache::thrift::metadata::ThriftField field;
248248
field.id() = f.id;
@@ -261,7 +261,7 @@ void ExceptionMetadata<::cpp2::ExceptionWithPrimitiveField>::gen(ThriftMetadata&
261261
module_ExceptionWithPrimitiveField.name() = "module.ExceptionWithPrimitiveField";
262262
static const auto* const
263263
module_ExceptionWithPrimitiveField_fields = new std::array<EncodedThriftField, 2>{ {
264-
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }}, { 2, "error_code", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector<ThriftConstStruct>{ }}, }};
264+
{ 1, "message", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ *cvStruct("thrift.ExceptionMessage", { }).cv_struct_ref(), }}, { 2, "error_code", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector<ThriftConstStruct>{ }}, }};
265265
for (const auto& f : *module_ExceptionWithPrimitiveField_fields) {
266266
::apache::thrift::metadata::ThriftField field;
267267
field.id() = f.id;

thrift/compiler/test/fixtures/exceptions/out/hack/gen-hack/module_types.php

+45
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot
7878
return shape(
7979
'struct' => dict[],
8080
'fields' => dict[
81+
'message' => shape(
82+
'field' => dict[
83+
'\facebook\thrift\annotation\ExceptionMessage' => \facebook\thrift\annotation\ExceptionMessage::fromShape(
84+
shape(
85+
)
86+
),
87+
],
88+
'type' => dict[],
89+
),
8190
],
8291
);
8392
}
@@ -166,6 +175,15 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot
166175
return shape(
167176
'struct' => dict[],
168177
'fields' => dict[
178+
'sonnet' => shape(
179+
'field' => dict[
180+
'\facebook\thrift\annotation\ExceptionMessage' => \facebook\thrift\annotation\ExceptionMessage::fromShape(
181+
shape(
182+
)
183+
),
184+
],
185+
'type' => dict[],
186+
),
169187
],
170188
);
171189
}
@@ -277,6 +295,15 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot
277295
return shape(
278296
'struct' => dict[],
279297
'fields' => dict[
298+
'internal_error_message' => shape(
299+
'field' => dict[
300+
'\facebook\thrift\annotation\ExceptionMessage' => \facebook\thrift\annotation\ExceptionMessage::fromShape(
301+
shape(
302+
)
303+
),
304+
],
305+
'type' => dict[],
306+
),
280307
],
281308
);
282309
}
@@ -388,6 +415,15 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot
388415
return shape(
389416
'struct' => dict[],
390417
'fields' => dict[
418+
'internal_error_message' => shape(
419+
'field' => dict[
420+
'\facebook\thrift\annotation\ExceptionMessage' => \facebook\thrift\annotation\ExceptionMessage::fromShape(
421+
shape(
422+
)
423+
),
424+
],
425+
'type' => dict[],
426+
),
391427
],
392428
);
393429
}
@@ -494,6 +530,15 @@ public static function getAllStructuredAnnotations()[write_props]: \TStructAnnot
494530
return shape(
495531
'struct' => dict[],
496532
'fields' => dict[
533+
'message' => shape(
534+
'field' => dict[
535+
'\facebook\thrift\annotation\ExceptionMessage' => \facebook\thrift\annotation\ExceptionMessage::fromShape(
536+
shape(
537+
)
538+
),
539+
],
540+
'type' => dict[],
541+
),
497542
],
498543
);
499544
}

thrift/compiler/test/fixtures/exceptions/out/py/gen-py/module/ttypes.py

-5
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,6 @@ def _to_py_deprecated(self):
800800
)))
801801

802802
Fiery.thrift_struct_annotations = {
803-
"message": "message",
804803
}
805804
Fiery.thrift_field_annotations = {
806805
}
@@ -823,7 +822,6 @@ def Fiery__setstate__(self, state):
823822
)))
824823

825824
Serious.thrift_struct_annotations = {
826-
"message": "sonnet",
827825
}
828826
Serious.thrift_field_annotations = {
829827
}
@@ -847,7 +845,6 @@ def Serious__setstate__(self, state):
847845
)))
848846

849847
ComplexFieldNames.thrift_struct_annotations = {
850-
"message": "internal_error_message",
851848
}
852849
ComplexFieldNames.thrift_field_annotations = {
853850
}
@@ -873,7 +870,6 @@ def ComplexFieldNames__setstate__(self, state):
873870
)))
874871

875872
CustomFieldNames.thrift_struct_annotations = {
876-
"message": "internal_error_message",
877873
}
878874
CustomFieldNames.thrift_field_annotations = {
879875
2: {
@@ -902,7 +898,6 @@ def CustomFieldNames__setstate__(self, state):
902898
)))
903899

904900
ExceptionWithPrimitiveField.thrift_struct_annotations = {
905-
"message": "message",
906901
}
907902
ExceptionWithPrimitiveField.thrift_field_annotations = {
908903
}

0 commit comments

Comments
 (0)