From 7e267bdb14fded764170ba88c459a1efaddef152 Mon Sep 17 00:00:00 2001 From: Dave Kwon Date: Mon, 13 Jan 2025 00:41:49 -0800 Subject: [PATCH] Carbon codegen to use @cpp.EnumType Summary: `cpp.enum_type` is deprecated, and always include `cpp.thrift`. Reviewed By: yoney Differential Revision: D68079869 fbshipit-source-id: 8bca8d0686ba16ab96eed19870504cdfed15a433 --- .../carbon/example/gen/HelloGoodbye.thrift | 4 +++- .../src/mcrouter/lib/carbon/test/gen/A.thrift | 1 + .../src/mcrouter/lib/carbon/test/gen/B.thrift | 1 + .../lib/carbon/test/gen/CarbonTest.thrift | 19 +++++++++++++------ .../carbon/test/gen/CarbonThriftTest.thrift | 3 ++- .../mcrouter/lib/network/gen/Common.thrift | 2 +- .../mcrouter/lib/network/gen/Memcache.thrift | 1 + .../lib/network/test/gen/CarbonTest.thrift | 2 +- 8 files changed, 23 insertions(+), 10 deletions(-) diff --git a/third-party/mcrouter/src/mcrouter/lib/carbon/example/gen/HelloGoodbye.thrift b/third-party/mcrouter/src/mcrouter/lib/carbon/example/gen/HelloGoodbye.thrift index 6fc16bb39a994e..df8924b82f5ed5 100644 --- a/third-party/mcrouter/src/mcrouter/lib/carbon/example/gen/HelloGoodbye.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/carbon/example/gen/HelloGoodbye.thrift @@ -14,6 +14,7 @@ */ include "mcrouter/lib/carbon/carbon.thrift" include "mcrouter/lib/carbon/carbon_result.thrift" +include "thrift/annotation/cpp.thrift" include "mcrouter/lib/network/gen/Common.thrift" cpp_include "" @@ -21,11 +22,12 @@ cpp_include "" namespace cpp2 hellogoodbye.thrift namespace py3 hellogoodbye.thrift +@cpp.EnumType{type = cpp.EnumUnderlyingType.U32} enum EnumUInt32 { HIGH = 0, URGENT = 1, YESTERDAY = 2 -} (cpp.enum_type="uint32_t") +} struct HelloRequest { 1: carbon.IOBufKey key diff --git a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/A.thrift b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/A.thrift index b25120f593e71e..264ed0b7a076f2 100644 --- a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/A.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/A.thrift @@ -14,6 +14,7 @@ */ include "mcrouter/lib/carbon/carbon.thrift" include "mcrouter/lib/carbon/carbon_result.thrift" +include "thrift/annotation/cpp.thrift" include "mcrouter/lib/network/gen/Common.thrift" include "mcrouter/lib/carbon/test/gen/B.thrift" include "graphene/ticket/if/ticket_rep.thrift" diff --git a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/B.thrift b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/B.thrift index b24bc6b4f3c099..9ae05f1b4a2612 100644 --- a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/B.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/B.thrift @@ -14,6 +14,7 @@ */ include "mcrouter/lib/carbon/carbon.thrift" include "mcrouter/lib/carbon/carbon_result.thrift" +include "thrift/annotation/cpp.thrift" include "mcrouter/lib/network/gen/Common.thrift" include "graphene/ticket/if/ticket_rep.thrift" diff --git a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonTest.thrift b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonTest.thrift index 87ff52058edfb9..2ff303252a579d 100644 --- a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonTest.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonTest.thrift @@ -14,6 +14,7 @@ */ include "mcrouter/lib/carbon/carbon.thrift" include "mcrouter/lib/carbon/carbon_result.thrift" +include "thrift/annotation/cpp.thrift" include "mcrouter/lib/network/gen/Common.thrift" cpp_include "" @@ -208,41 +209,47 @@ struct TestStdContainers { void deserialize(carbon::CarbonProtocolReader& reader); ") +@cpp.EnumType{type = cpp.EnumUnderlyingType.U32} enum EnumUInt32 { AAA = 0, BBB = 1, CCC = 2 -} (cpp.enum_type="uint32_t") +} +@cpp.EnumType{type = cpp.EnumUnderlyingType.U16} enum EnumUInt16 { AAA = 0, BBB = 1, CCC = 2 -} (cpp.enum_type="uint16_t") +} +@cpp.EnumType{type = cpp.EnumUnderlyingType.U8} enum EnumUInt8 { AAA = 0, BBB = 1, CCC = 2 -} (cpp.enum_type="uint8_t") +} + enum EnumInt32 { AAA = 0, BBB = 1, CCC = 2 -} (cpp.enum_type="int32_t") +} +@cpp.EnumType{type = cpp.EnumUnderlyingType.I16} enum EnumInt16 { AAA = 0, BBB = 1, CCC = 2 -} (cpp.enum_type="int16_t") +} +@cpp.EnumType{type = cpp.EnumUnderlyingType.I8} enum EnumInt8 { AAA = 0, BBB = 1, CCC = 2 -} (cpp.enum_type="int8_t") +} struct StructWithEnumUInt32 { 1: EnumUInt32 testEnum diff --git a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonThriftTest.thrift b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonThriftTest.thrift index 650d80ae7c0a15..78319143fab17a 100644 --- a/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonThriftTest.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/carbon/test/gen/CarbonThriftTest.thrift @@ -28,11 +28,12 @@ typedef i64 CustomAdapterTypeI64 @cpp.Adapter{name = "::carbon::test::DummyPairAdapter<::carbon::test::Timestamp,uint32_t>"} typedef binary (cpp.type = "::folly::IOBuf") CustomAdapterTypeBinary + enum MyEnum { A = 0, B = 1, C = 2 -} (cpp.enum_type="int32_t") +} union TestUnionThrift { 1: i64_3264 a diff --git a/third-party/mcrouter/src/mcrouter/lib/network/gen/Common.thrift b/third-party/mcrouter/src/mcrouter/lib/network/gen/Common.thrift index ae19dbbe31af49..e82500c16ee017 100644 --- a/third-party/mcrouter/src/mcrouter/lib/network/gen/Common.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/network/gen/Common.thrift @@ -14,7 +14,7 @@ */ include "mcrouter/lib/carbon/carbon.thrift" include "mcrouter/lib/carbon/carbon_result.thrift" - +include "thrift/annotation/cpp.thrift" cpp_include "" diff --git a/third-party/mcrouter/src/mcrouter/lib/network/gen/Memcache.thrift b/third-party/mcrouter/src/mcrouter/lib/network/gen/Memcache.thrift index 05c7c19c86359e..83b6dbe9fa7bb3 100644 --- a/third-party/mcrouter/src/mcrouter/lib/network/gen/Memcache.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/network/gen/Memcache.thrift @@ -14,6 +14,7 @@ */ include "mcrouter/lib/carbon/carbon.thrift" include "mcrouter/lib/carbon/carbon_result.thrift" +include "thrift/annotation/cpp.thrift" include "mcrouter/lib/network/gen/Common.thrift" cpp_include "" diff --git a/third-party/mcrouter/src/mcrouter/lib/network/test/gen/CarbonTest.thrift b/third-party/mcrouter/src/mcrouter/lib/network/test/gen/CarbonTest.thrift index f384f79519c184..d015605cd0ec10 100644 --- a/third-party/mcrouter/src/mcrouter/lib/network/test/gen/CarbonTest.thrift +++ b/third-party/mcrouter/src/mcrouter/lib/network/test/gen/CarbonTest.thrift @@ -14,7 +14,7 @@ */ include "mcrouter/lib/carbon/carbon.thrift" include "mcrouter/lib/carbon/carbon_result.thrift" - +include "thrift/annotation/cpp.thrift" cpp_include ""