Skip to content

Commit 41cc512

Browse files
thedavekwonfacebook-github-bot
authored andcommitted
Use same annotationsMap in TypeSystemBuilder
Summary: This is strictly better and it makes sense to share same annotations type with TypeSystem Reviewed By: pranavtbhat Differential Revision: D79855446 fbshipit-source-id: 0a54e0fc1ddac3f0c12c5d03da0d1ba866b6b8e2
1 parent ab67908 commit 41cc512

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

third-party/thrift/src/thrift/lib/cpp2/dynamic/TypeSystemBuilder.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,7 @@ namespace {
463463

464464
using RawAnnotations = folly::F14FastMap<Uri, SerializableRecordUnion>;
465465

466-
static RawAnnotations toRawAnnotations(
467-
const TypeSystemBuilder::DefinitionHelper::Annotations& annotations) {
466+
static RawAnnotations toRawAnnotations(const AnnotationsMap& annotations) {
468467
RawAnnotations raw;
469468
for (const auto& [uri, record] : annotations) {
470469
raw.emplace(uri, SerializableRecord::toThrift(record));
@@ -485,7 +484,7 @@ TypeSystemBuilder::DefinitionHelper::Field(
485484
PresenceQualifier presence,
486485
TypeId type,
487486
std::optional<SerializableRecord> customDefault,
488-
const Annotations& annotations) {
487+
const AnnotationsMap& annotations) {
489488
SerializableFieldDefinition def;
490489
def.identity() = std::move(identity);
491490
def.presence() = presence;
@@ -501,7 +500,7 @@ TypeSystemBuilder::DefinitionHelper::Field(
501500
TypeSystemBuilder::DefinitionHelper::Struct(
502501
std::vector<SerializableFieldDefinition> fields,
503502
bool isSealed,
504-
const Annotations& annotations) {
503+
const AnnotationsMap& annotations) {
505504
SerializableStructDefinition def;
506505
def.fields() = fields;
507506
def.isSealed() = isSealed;
@@ -513,7 +512,7 @@ TypeSystemBuilder::DefinitionHelper::Struct(
513512
TypeSystemBuilder::DefinitionHelper::Union(
514513
std::vector<SerializableFieldDefinition> fields,
515514
bool isSealed,
516-
const Annotations& annotations) {
515+
const AnnotationsMap& annotations) {
517516
SerializableUnionDefinition def;
518517
def.fields() = fields;
519518
def.isSealed() = isSealed;
@@ -523,7 +522,7 @@ TypeSystemBuilder::DefinitionHelper::Union(
523522

524523
/* static */ SerializableEnumDefinition
525524
TypeSystemBuilder::DefinitionHelper::Enum(
526-
const std::vector<EnumValue>& values, const Annotations& annotations) {
525+
const std::vector<EnumValue>& values, const AnnotationsMap& annotations) {
527526
SerializableEnumDefinition enumDef;
528527
for (auto& [name, value, enumValueAnnotations] : values) {
529528
SerializableEnumValueDefinition v;
@@ -538,7 +537,7 @@ TypeSystemBuilder::DefinitionHelper::Enum(
538537

539538
/* static */ SerializableOpaqueAliasDefinition
540539
TypeSystemBuilder::DefinitionHelper::OpaqueAlias(
541-
TypeId targetType, const Annotations& annotations) {
540+
TypeId targetType, const AnnotationsMap& annotations) {
542541
SerializableOpaqueAliasDefinition def;
543542
def.targetType() = targetType;
544543
def.annotations() = toRawAnnotations(annotations);

third-party/thrift/src/thrift/lib/cpp2/dynamic/TypeSystemBuilder.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ class TypeSystemBuilder {
127127
static constexpr inline PresenceQualifier AlwaysPresent =
128128
PresenceQualifier::UNQUALIFIED;
129129

130-
using Annotations = folly::F14FastMap<Uri, SerializableRecord>;
131-
132130
/**
133131
* Creates the identity a field for use in a struct or union definition.
134132
*
@@ -144,15 +142,15 @@ class TypeSystemBuilder {
144142
PresenceQualifier presence,
145143
TypeId type,
146144
std::optional<SerializableRecord> customDefault = std::nullopt,
147-
const Annotations& annotations = {});
145+
const AnnotationsMap& annotations = {});
148146

149147
/**
150148
* Defines a Thrift struct, which is a collection of fields.
151149
*/
152150
static SerializableStructDefinition Struct(
153151
std::vector<SerializableFieldDefinition> fields,
154152
bool isSealed = false,
155-
const Annotations& annotations = {});
153+
const AnnotationsMap& annotations = {});
156154

157155
/**
158156
* Defines a Thrift union, which is a collection of fields. At most one
@@ -161,15 +159,15 @@ class TypeSystemBuilder {
161159
static SerializableUnionDefinition Union(
162160
std::vector<SerializableFieldDefinition> fields,
163161
bool isSealed = false,
164-
const Annotations& annotations = {});
162+
const AnnotationsMap& annotations = {});
165163

166164
struct EnumValue {
167165
std::string name;
168166
std::int32_t value;
169-
Annotations annotations;
167+
AnnotationsMap annotations;
170168

171169
EnumValue(std::string n, std::int32_t v) : name{std::move(n)}, value{v} {}
172-
EnumValue(std::string n, std::int32_t v, Annotations m)
170+
EnumValue(std::string n, std::int32_t v, AnnotationsMap m)
173171
: name{std::move(n)}, value{v}, annotations(std::move(m)) {}
174172
};
175173

@@ -179,7 +177,7 @@ class TypeSystemBuilder {
179177
*/
180178
static SerializableEnumDefinition Enum(
181179
const std::vector<EnumValue>& values,
182-
const Annotations& annotations = {});
180+
const AnnotationsMap& annotations = {});
183181

184182
/**
185183
* Defines a Thrift opaque alias, which is a distinct user-defined type
@@ -188,7 +186,7 @@ class TypeSystemBuilder {
188186
* The target type must not be a user-defined type.
189187
*/
190188
static SerializableOpaqueAliasDefinition OpaqueAlias(
191-
TypeId targetType, const Annotations& annotations = {});
189+
TypeId targetType, const AnnotationsMap& annotations = {});
192190

193191
/**
194192
* Optional information about the source IDL files from which a definition

third-party/thrift/src/thrift/lib/cpp2/dynamic/test/TypeSystemTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ TEST(TypeSystemTest, Annotations) {
319319
def::Struct({def::Field(
320320
def::Identity(1, "field1"), def::Optional, TypeIds::I32)}));
321321

322-
folly::F14FastMap<Uri, SerializableRecord> annots = {
322+
AnnotationsMap annots = {
323323
{"meta.com/thrift/test/MyAnnot",
324324
{SerializableRecord::FieldSet(
325325
{{FieldId(1), SerializableRecord::Int32(42)}})}}};
@@ -412,7 +412,7 @@ TEST(TypeSystemTest, Annotations) {
412412
TEST(TypeSystemTest, WrongAnnotationTypeUri) {
413413
TypeSystemBuilder builder;
414414

415-
folly::F14FastMap<Uri, SerializableRecord> annots = {
415+
AnnotationsMap annots = {
416416
{"meta.com/thrift/test/MyAnnot",
417417
{SerializableRecord::FieldSet(
418418
{{FieldId(1), SerializableRecord::Int32(42)}})}}};
@@ -444,7 +444,7 @@ TEST(TypeSystemTest, WrongAnnotationTypeValue) {
444444
TypeSystemBuilder builder;
445445

446446
// Value is not a FieldSetDatum.
447-
folly::F14FastMap<Uri, SerializableRecord> annots = {
447+
AnnotationsMap annots = {
448448
{"meta.com/thrift/test/MyAnnot", {SerializableRecord::Int32(42)}}};
449449

450450
// @MyAnnot{field1=42}
@@ -473,7 +473,7 @@ TEST(TypeSystemTest, WrongAnnotationTypeValue) {
473473
TEST(TypeSystemTest, MissingAnnotationType) {
474474
TypeSystemBuilder builder;
475475

476-
folly::F14FastMap<Uri, SerializableRecord> annots = {
476+
AnnotationsMap annots = {
477477
{"meta.com/thrift/test/MyAnnot",
478478
{SerializableRecord::FieldSet(
479479
{{FieldId(1), SerializableRecord::Int32(42)}})}}};

0 commit comments

Comments
 (0)