Skip to content

Commit fe12348

Browse files
iahsmeta-codesync[bot]
authored andcommitted
Add FunctionNode pointer to MethodMetadata
Summary: Add a `const syntax_graph::FunctionNode* functionNode` field to `MethodMetadata` to provide direct access to schema information for each method. This eliminates the need for a separate FunctionNodeMap cache and lookups at runtime. The field is populated at compile time by the Thrift compiler during code generation. Helper functions `getFunctionNode<ServiceTag>()` and `getInteractionFunctionNode<ServiceTag>()` look up the FunctionNode from the SchemaRegistry and embed the pointer directly in the ServiceRequestInfo initializer. Implementation: - Added `functionNode` field to `ServiceRequestInfo` struct - Added `functionNode` parameter to `MethodMetadata` constructor - Updated `GeneratedMethodMetadata` to pass `functionNode` through - Modified `populateMethodMetadataMap` to propagate `functionNode` - Created helper functions in `service_cpp.h` for FunctionNode lookup - Updated Thrift compiler template `processmap.mustache` to populate the field - Added comprehensive test verifying both regular and interaction methods Reviewed By: praihan Differential Revision: D91171976 fbshipit-source-id: 2c3a7e64b6d65b266f9ee7a37d1180d62fe35753
1 parent 3edd921 commit fe12348

71 files changed

Lines changed: 978 additions & 427 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

third-party/thrift/src/thrift/compiler/generate/templates/cpp2/service_cpp/processmap.mustache

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ apache::thrift::ServiceRequestInfoMap {{service:cpp_name}}ServiceInfoHolder::sta
5454
"{{service:parent_service_name}}.{{> common/function_name}}",
5555
std::nullopt,
5656
apache::thrift::concurrency::{{function:priority}},
57-
{{#if function:creates_interaction?}}"{{function:created_interaction.cpp_name}}"{{#else}}std::nullopt{{/if}}}},
57+
{{#if function:creates_interaction?}}"{{function:created_interaction.cpp_name}}"{{#else}}std::nullopt{{/if}},
58+
::apache::thrift::detail::getFunctionNode<{{service:qualified_name}}>("{{function:name}}")}},
5859
{{/function:starts_interaction?}}{{/function:return_type}}{{/service:functions}}
5960
{{#service:interactions}}{{#service:functions}}{{#function:return_type}}
6061
{"{{service:name}}.{{function:name}}",
@@ -63,7 +64,8 @@ apache::thrift::ServiceRequestInfoMap {{service:cpp_name}}ServiceInfoHolder::sta
6364
"{{service:parent_service_name}}.{{> common/function_name}}",
6465
"{{service:name}}",
6566
apache::thrift::concurrency::{{function:priority}},
66-
std::nullopt}},
67+
std::nullopt,
68+
::apache::thrift::detail::getInteractionFunctionNode<{{service:parent_service_qualified_name}}>("{{service:name}}", "{{function:name}}")}},
6769
{{/function:return_type}}{{/service:functions}}{{/service:interactions}}
6870
};
6971
{{#service:extends}}

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/cpp2/gen-cpp2/AdapterService.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,16 @@ apache::thrift::ServiceRequestInfoMap AdapterServiceServiceInfoHolder::staticReq
387387
"AdapterService.count",
388388
std::nullopt,
389389
apache::thrift::concurrency::NORMAL,
390-
std::nullopt}},
390+
std::nullopt,
391+
::apache::thrift::detail::getFunctionNode<::facebook::thrift::test::fixtures::adapter::AdapterService>("count")}},
391392
{"adaptedTypes",
392393
{ false,
393394
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
394395
"AdapterService.adaptedTypes",
395396
std::nullopt,
396397
apache::thrift::concurrency::NORMAL,
397-
std::nullopt}},
398+
std::nullopt,
399+
::apache::thrift::detail::getFunctionNode<::facebook::thrift::test::fixtures::adapter::AdapterService>("adaptedTypes")}},
398400
};
399401

400402
return requestInfoMap;

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/cpp2/gen-cpp2/Service.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ apache::thrift::ServiceRequestInfoMap ServiceServiceInfoHolder::staticRequestInf
228228
"Service.func",
229229
std::nullopt,
230230
apache::thrift::concurrency::NORMAL,
231-
std::nullopt}},
231+
std::nullopt,
232+
::apache::thrift::detail::getFunctionNode<::facebook::thrift::test::fixtures::adapter::Service>("func")}},
232233
};
233234

234235
return requestInfoMap;

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/cpp2/gen-cpp2/BadService.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,16 @@ apache::thrift::ServiceRequestInfoMap GoodServiceServiceInfoHolder::staticReques
378378
"BadService.bar",
379379
std::nullopt,
380380
apache::thrift::concurrency::NORMAL,
381-
std::nullopt}},
381+
std::nullopt,
382+
::apache::thrift::detail::getFunctionNode<::cpp2::GoodService>("bar")}},
382383
{"BadInteraction.foo",
383384
{ false,
384385
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
385386
"BadService.BadInteraction.foo",
386387
"BadInteraction",
387388
apache::thrift::concurrency::NORMAL,
388-
std::nullopt}},
389+
std::nullopt,
390+
::apache::thrift::detail::getInteractionFunctionNode<::cpp2::GoodService>("BadInteraction", "foo")}},
389391
};
390392

391393
return requestInfoMap;

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/cpp2/gen-cpp2/FooBarBazService.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,21 +541,24 @@ apache::thrift::ServiceRequestInfoMap FooBarBazServiceServiceInfoHolder::staticR
541541
"FooBarBazService.foo",
542542
std::nullopt,
543543
apache::thrift::concurrency::NORMAL,
544-
std::nullopt}},
544+
std::nullopt,
545+
::apache::thrift::detail::getFunctionNode<::cpp2::FooBarBazService>("foo")}},
545546
{"bar",
546547
{ false,
547548
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
548549
"FooBarBazService.bar",
549550
std::nullopt,
550551
apache::thrift::concurrency::NORMAL,
551-
std::nullopt}},
552+
std::nullopt,
553+
::apache::thrift::detail::getFunctionNode<::cpp2::FooBarBazService>("bar")}},
552554
{"baz",
553555
{ false,
554556
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
555557
"FooBarBazService.baz",
556558
std::nullopt,
557559
apache::thrift::concurrency::NORMAL,
558-
std::nullopt}},
560+
std::nullopt,
561+
::apache::thrift::detail::getFunctionNode<::cpp2::FooBarBazService>("baz")}},
559562
};
560563

561564
return requestInfoMap;

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/cpp2/gen-cpp2/MyService.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,49 +1165,56 @@ apache::thrift::ServiceRequestInfoMap MyServiceServiceInfoHolder::staticRequestI
11651165
"MyService.ping",
11661166
std::nullopt,
11671167
apache::thrift::concurrency::NORMAL,
1168-
std::nullopt}},
1168+
std::nullopt,
1169+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("ping")}},
11691170
{"getRandomData",
11701171
{ false,
11711172
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
11721173
"MyService.getRandomData",
11731174
std::nullopt,
11741175
apache::thrift::concurrency::NORMAL,
1175-
std::nullopt}},
1176+
std::nullopt,
1177+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("getRandomData")}},
11761178
{"hasDataById",
11771179
{ false,
11781180
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
11791181
"MyService.hasDataById",
11801182
std::nullopt,
11811183
apache::thrift::concurrency::NORMAL,
1182-
std::nullopt}},
1184+
std::nullopt,
1185+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("hasDataById")}},
11831186
{"getDataById",
11841187
{ false,
11851188
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
11861189
"MyService.getDataById",
11871190
std::nullopt,
11881191
apache::thrift::concurrency::NORMAL,
1189-
std::nullopt}},
1192+
std::nullopt,
1193+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("getDataById")}},
11901194
{"putDataById",
11911195
{ false,
11921196
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
11931197
"MyService.putDataById",
11941198
std::nullopt,
11951199
apache::thrift::concurrency::NORMAL,
1196-
std::nullopt}},
1200+
std::nullopt,
1201+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("putDataById")}},
11971202
{"lobDataById",
11981203
{ false,
11991204
apache::thrift::RpcKind::SINGLE_REQUEST_NO_RESPONSE,
12001205
"MyService.lobDataById",
12011206
std::nullopt,
12021207
apache::thrift::concurrency::NORMAL,
1203-
std::nullopt}},
1208+
std::nullopt,
1209+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("lobDataById")}},
12041210
{"doNothing",
12051211
{ false,
12061212
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
12071213
"MyService.doNothing",
12081214
std::nullopt,
12091215
apache::thrift::concurrency::NORMAL,
1210-
std::nullopt}},
1216+
std::nullopt,
1217+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("doNothing")}},
12111218
};
12121219

12131220
return requestInfoMap;

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/cpp2/gen-cpp2/MyServicePrioChild.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ apache::thrift::ServiceRequestInfoMap MyServicePrioChildServiceInfoHolder::stati
229229
"MyServicePrioChild.pang",
230230
std::nullopt,
231231
apache::thrift::concurrency::BEST_EFFORT,
232-
std::nullopt}},
232+
std::nullopt,
233+
::apache::thrift::detail::getFunctionNode<::cpp2::MyServicePrioChild>("pang")}},
233234
};
234235
apache::thrift::ServiceRequestInfoMap parentMap = ::cpp2::MyServicePrioParentServiceInfoHolder::staticRequestInfoMap();
235236
requestInfoMap.insert(std::begin(parentMap), std::end(parentMap));

third-party/thrift/src/thrift/compiler/test/fixtures/basic-annotations/out/cpp2/gen-cpp2/MyServicePrioParent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,16 @@ apache::thrift::ServiceRequestInfoMap MyServicePrioParentServiceInfoHolder::stat
385385
"MyServicePrioParent.ping",
386386
std::nullopt,
387387
apache::thrift::concurrency::IMPORTANT,
388-
std::nullopt}},
388+
std::nullopt,
389+
::apache::thrift::detail::getFunctionNode<::cpp2::MyServicePrioParent>("ping")}},
389390
{"pong",
390391
{ false,
391392
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
392393
"MyServicePrioParent.pong",
393394
std::nullopt,
394395
apache::thrift::concurrency::HIGH_IMPORTANT,
395-
std::nullopt}},
396+
std::nullopt,
397+
::apache::thrift::detail::getFunctionNode<::cpp2::MyServicePrioParent>("pong")}},
396398
};
397399

398400
return requestInfoMap;

third-party/thrift/src/thrift/compiler/test/fixtures/basic-stack-arguments/out/cpp2/gen-cpp2/DbMixedStackArguments.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,16 @@ apache::thrift::ServiceRequestInfoMap DbMixedStackArgumentsServiceInfoHolder::st
387387
"DbMixedStackArguments.getDataByKey0",
388388
std::nullopt,
389389
apache::thrift::concurrency::NORMAL,
390-
std::nullopt}},
390+
std::nullopt,
391+
::apache::thrift::detail::getFunctionNode<::cpp2::DbMixedStackArguments>("getDataByKey0")}},
391392
{"getDataByKey1",
392393
{ false,
393394
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
394395
"DbMixedStackArguments.getDataByKey1",
395396
std::nullopt,
396397
apache::thrift::concurrency::NORMAL,
397-
std::nullopt}},
398+
std::nullopt,
399+
::apache::thrift::detail::getFunctionNode<::cpp2::DbMixedStackArguments>("getDataByKey1")}},
398400
};
399401

400402
return requestInfoMap;

third-party/thrift/src/thrift/compiler/test/fixtures/basic-stack-arguments/out/cpp2/gen-cpp2/MyService.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -696,28 +696,32 @@ apache::thrift::ServiceRequestInfoMap MyServiceServiceInfoHolder::staticRequestI
696696
"MyService.hasDataById",
697697
std::nullopt,
698698
apache::thrift::concurrency::NORMAL,
699-
std::nullopt}},
699+
std::nullopt,
700+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("hasDataById")}},
700701
{"getDataById",
701702
{ false,
702703
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
703704
"MyService.getDataById",
704705
std::nullopt,
705706
apache::thrift::concurrency::NORMAL,
706-
std::nullopt}},
707+
std::nullopt,
708+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("getDataById")}},
707709
{"putDataById",
708710
{ false,
709711
apache::thrift::RpcKind::SINGLE_REQUEST_SINGLE_RESPONSE,
710712
"MyService.putDataById",
711713
std::nullopt,
712714
apache::thrift::concurrency::NORMAL,
713-
std::nullopt}},
715+
std::nullopt,
716+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("putDataById")}},
714717
{"lobDataById",
715718
{ false,
716719
apache::thrift::RpcKind::SINGLE_REQUEST_NO_RESPONSE,
717720
"MyService.lobDataById",
718721
std::nullopt,
719722
apache::thrift::concurrency::NORMAL,
720-
std::nullopt}},
723+
std::nullopt,
724+
::apache::thrift::detail::getFunctionNode<::cpp2::MyService>("lobDataById")}},
721725
};
722726

723727
return requestInfoMap;

0 commit comments

Comments
 (0)