Skip to content

Commit

Permalink
Fix metadata bug
Browse files Browse the repository at this point in the history
Summary:
We were missing some types from metadata.

This bug went unnoticed because it has no effect on Thrift Fiddle performance/correctness.

However, it has an effect on the metadata work I am doing downstream, so let's fix it.

Reviewed By: leoleovich

Differential Revision: D63495649

fbshipit-source-id: 916048ac625d3058bf862082694e72e80d2a02aa
  • Loading branch information
echistyakov authored and facebook-github-bot committed Sep 27, 2024
1 parent ca9f3b4 commit 2e953f2
Show file tree
Hide file tree
Showing 78 changed files with 2,974 additions and 168 deletions.
19 changes: 16 additions & 3 deletions thrift/compiler/lib/go/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ void codegen_data::compute_service_to_req_resp_structs() {

void codegen_data::add_to_thrift_metadata_types(
const t_type* type, std::set<std::string>& visited_type_names) {
// skip over typedefs that are not "defined"
// Check if we have already visited this type.
auto type_name = type->get_full_name();
if (visited_type_names.count(type_name) > 0) {
return; // Already visited
return;
}

// skip over a chain of non-defined typedefs
// Skip over a chain of "non-defined" typedefs.
if (type->is_typedef()) {
auto typedef_ = dynamic_cast<const t_typedef*>(type);
if (typedef_->typedef_kind() != t_typedef::kind::defined) {
Expand Down Expand Up @@ -201,21 +201,34 @@ void codegen_data::compute_thrift_metadata_types() {

std::set<std::string> visited_type_names;

for (auto const& enum_ : current_program_->enums()) {
// Visit each enum
add_to_thrift_metadata_types(enum_, visited_type_names);
}
for (auto const& struct_ : current_program_->structs_and_unions()) {
// Visit struct fields
for (auto const& field : struct_->fields()) {
auto type = field.type().get_type();
add_to_thrift_metadata_types(type, visited_type_names);
}
// Visit struct itself
add_to_thrift_metadata_types(struct_, visited_type_names);
}
for (auto const& exception : current_program_->exceptions()) {
// Visit exception members
for (auto const& field : exception->get_members()) {
auto type = field->get_type();
add_to_thrift_metadata_types(type, visited_type_names);
}
// Visit exception itself
add_to_thrift_metadata_types(exception, visited_type_names);
}
for (auto const& typedef_ : current_program_->typedefs()) {
auto type = typedef_->get_type();
// Visit the underlying type
add_to_thrift_metadata_types(type, visited_type_names);
// Visit the typedef itself
add_to_thrift_metadata_types(typedef_, visited_type_names);
}

for (auto const& service : current_program_->services()) {
Expand Down
136 changes: 115 additions & 21 deletions thrift/compiler/test/fixtures/adapter/out/go/gen-go/module/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@ var _ = metadata.GoUnusedProtection__

// Premade Thrift types
var (
premadeThriftType_string = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_STRING_TYPE.Ptr(),
)
premadeThriftType_module_Color = metadata.NewThriftType().SetTEnum(
metadata.NewThriftEnumType().
SetName("module.Color"),
)
premadeThriftType_module_ThriftAdaptedEnum = metadata.NewThriftType().SetTEnum(
metadata.NewThriftEnumType().
SetName("module.ThriftAdaptedEnum"),
)
premadeThriftType_string = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_STRING_TYPE.Ptr(),
)
premadeThriftType_module_MyAnnotation = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.MyAnnotation"),
)
premadeThriftType_i32 = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_I32_TYPE.Ptr(),
)
Expand Down Expand Up @@ -102,6 +110,10 @@ var (
metadata.NewThriftStructType().
SetName("module.Foo"),
)
premadeThriftType_module_Baz = metadata.NewThriftType().SetTUnion(
metadata.NewThriftUnionType().
SetName("module.Baz"),
)
premadeThriftType_module_Foo_6868 = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.Foo_6868").
Expand All @@ -126,10 +138,6 @@ var (
metadata.NewThriftListType().
SetValueType(premadeThriftType_module_FooWithAdapter_9317),
)
premadeThriftType_module_Baz = metadata.NewThriftType().SetTUnion(
metadata.NewThriftUnionType().
SetName("module.Baz"),
)
premadeThriftType_module_Baz_7352 = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.Baz_7352").
Expand All @@ -139,10 +147,26 @@ var (
metadata.NewThriftStructType().
SetName("module.DirectlyAdapted"),
)
premadeThriftType_module_Bar = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.Bar"),
)
premadeThriftType_module_IndependentDirectlyAdapted = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.IndependentDirectlyAdapted"),
)
premadeThriftType_module_StructWithFieldAdapter = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.StructWithFieldAdapter"),
)
premadeThriftType_set_i32 = metadata.NewThriftType().SetTSet(
metadata.NewThriftSetType().
SetValueType(premadeThriftType_i32),
)
premadeThriftType_module_TerseAdaptedFields = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.TerseAdaptedFields"),
)
premadeThriftType_module_A = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.A"),
Expand All @@ -152,6 +176,18 @@ var (
SetName("module.AdaptedA").
SetUnderlyingType(premadeThriftType_module_A),
)
premadeThriftType_module_B = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.B"),
)
premadeThriftType_module_Config = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.Config"),
)
premadeThriftType_module_MyStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.MyStruct"),
)
premadeThriftType_module_DurationMs = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.DurationMs").
Expand Down Expand Up @@ -185,6 +221,10 @@ var (
SetName("module.AdaptedInteger").
SetUnderlyingType(premadeThriftType_i32),
)
premadeThriftType_module_AdaptTestStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.AdaptTestStruct"),
)
premadeThriftType_byte = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_BYTE_TYPE.Ptr(),
)
Expand Down Expand Up @@ -232,10 +272,6 @@ var (
SetKeyType(premadeThriftType_i64).
SetValueType(premadeThriftType_i64),
)
premadeThriftType_module_ThriftAdaptedEnum = metadata.NewThriftType().SetTEnum(
metadata.NewThriftEnumType().
SetName("module.ThriftAdaptedEnum"),
)
premadeThriftType_module_AdaptedEnum = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.AdaptedEnum").
Expand All @@ -250,24 +286,36 @@ var (
metadata.NewThriftStructType().
SetName("module.AdaptTemplatedTestStruct"),
)
premadeThriftType_module_AdaptTemplatedNestedTestStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.AdaptTemplatedNestedTestStruct"),
)
premadeThriftType_module_AdaptTestUnion = metadata.NewThriftType().SetTUnion(
metadata.NewThriftUnionType().
SetName("module.AdaptTestUnion"),
)
premadeThriftType_module_AdaptedStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.AdaptedStruct"),
)
premadeThriftType_module_DirectlyAdaptedStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.DirectlyAdaptedStruct"),
)
premadeThriftType_module_AdaptedTypedef = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.AdaptedTypedef").
SetUnderlyingType(premadeThriftType_module_AdaptedStruct),
)
premadeThriftType_module_DirectlyAdaptedStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.DirectlyAdaptedStruct"),
)
premadeThriftType_module_TypedefOfDirect = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.TypedefOfDirect").
SetUnderlyingType(premadeThriftType_module_DirectlyAdaptedStruct),
)
premadeThriftType_module_StructFieldAdaptedStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.StructFieldAdaptedStruct"),
)
premadeThriftType_module_CircularStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.CircularStruct"),
Expand All @@ -285,24 +333,74 @@ var (
metadata.NewThriftStructType().
SetName("module.DeclaredAfterStruct"),
)
premadeThriftType_module_ReorderedStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.ReorderedStruct"),
)
premadeThriftType_module_RenamedStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.RenamedStruct"),
)
premadeThriftType_module_SameNamespaceStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.SameNamespaceStruct"),
)
premadeThriftType_module_HeapAllocated = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.HeapAllocated"),
)
premadeThriftType_module_MoveOnly = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.MoveOnly"),
)
premadeThriftType_module_AlsoMoveOnly = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.AlsoMoveOnly"),
)
premadeThriftType_module_ApplyAdapter = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.ApplyAdapter"),
)
premadeThriftType_module_TransitiveAdapted = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.TransitiveAdapted"),
)
premadeThriftType_module_CountingInt = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.CountingInt").
SetUnderlyingType(premadeThriftType_i64),
)
premadeThriftType_module_Bar = metadata.NewThriftType().SetTStruct(
premadeThriftType_module_CountingStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.Bar"),
SetName("module.CountingStruct"),
)
premadeThriftType_module_Person = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.Person"),
)
premadeThriftType_module_Person2 = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.Person2"),
)
premadeThriftType_module_RenamedStructWithStructAdapterAndFieldAdapter = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.RenamedStructWithStructAdapterAndFieldAdapter"),
)
premadeThriftType_module_MyI32 = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.MyI32").
SetUnderlyingType(premadeThriftType_i32),
)
premadeThriftType_module_StructWithAdapter = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.StructWithAdapter").
SetUnderlyingType(premadeThriftType_module_Bar),
)
premadeThriftType_module_UnionWithAdapter = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.UnionWithAdapter").
SetUnderlyingType(premadeThriftType_module_Baz),
)
premadeThriftType_module_MyI32_4873 = metadata.NewThriftType().SetTTypedef(
metadata.NewThriftTypedefType().
SetName("module.MyI32_4873").
Expand All @@ -313,10 +411,6 @@ var (
SetName("module.StringWithAdapter_7208").
SetUnderlyingType(premadeThriftType_module_StringWithAdapter),
)
premadeThriftType_module_CountingStruct = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("module.CountingStruct"),
)
)

var structMetadatas = []*metadata.ThriftStruct{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,92 @@ var _ = metadata.GoUnusedProtection__

// Premade Thrift types
var (
premadeThriftType_string = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_STRING_TYPE.Ptr(),
)
premadeThriftType_cpp_RefType = metadata.NewThriftType().SetTEnum(
metadata.NewThriftEnumType().
SetName("cpp.RefType"),
)
premadeThriftType_bool = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_BOOL_TYPE.Ptr(),
)
premadeThriftType_cpp_EnumUnderlyingType = metadata.NewThriftType().SetTEnum(
metadata.NewThriftEnumType().
SetName("cpp.EnumUnderlyingType"),
)
premadeThriftType_string = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_STRING_TYPE.Ptr(),
)
premadeThriftType_cpp_Type = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.Type"),
)
premadeThriftType_cpp_Ref = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.Ref"),
)
premadeThriftType_cpp_Name = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.Name"),
)
premadeThriftType_bool = metadata.NewThriftType().SetTPrimitive(
metadata.ThriftPrimitiveType_THRIFT_BOOL_TYPE.Ptr(),
)
premadeThriftType_cpp_Lazy = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.Lazy"),
)
premadeThriftType_cpp_DisableLazyChecksum = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.DisableLazyChecksum"),
)
premadeThriftType_cpp_Adapter = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.Adapter"),
)
premadeThriftType_cpp_PackIsset = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.PackIsset"),
)
premadeThriftType_cpp_MinimizePadding = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.MinimizePadding"),
)
premadeThriftType_cpp_ScopedEnumAsUnionType = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.ScopedEnumAsUnionType"),
)
premadeThriftType_cpp_FieldInterceptor = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.FieldInterceptor"),
)
premadeThriftType_cpp_UseOpEncode = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.UseOpEncode"),
)
premadeThriftType_cpp_EnumType = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.EnumType"),
)
premadeThriftType_cpp_Frozen2Exclude = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.Frozen2Exclude"),
)
premadeThriftType_cpp_Frozen2RequiresCompleteContainerParams = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.Frozen2RequiresCompleteContainerParams"),
)
premadeThriftType_cpp_ProcessInEbThreadUnsafe = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.ProcessInEbThreadUnsafe"),
)
premadeThriftType_cpp_RuntimeAnnotation = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.RuntimeAnnotation"),
)
premadeThriftType_cpp_UseCursorSerialization = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.UseCursorSerialization"),
)
premadeThriftType_cpp_GenerateDeprecatedHeaderClientMethods = metadata.NewThriftType().SetTStruct(
metadata.NewThriftStructType().
SetName("cpp.GenerateDeprecatedHeaderClientMethods"),
)
)

var structMetadatas = []*metadata.ThriftStruct{
Expand Down
Loading

0 comments on commit 2e953f2

Please sign in to comment.