Skip to content

Commit df34009

Browse files
hchokshifacebook-github-bot
authored andcommitted
De-templatize non-ref field accessors in C++ code generation
Summary: Field accessor methods were previously emitted during code generation as templates to reduce the amount of code being compiled and improve build performance, by only compiling overloads which were used by user code. Benchmarking shows that the build-time performance benefit of this is now negligible, so we can now emit these accessors as non-templated methods. #buildall #buildsonlynotests Reviewed By: vitaut Differential Revision: D77674004 fbshipit-source-id: 5a03d300018a273cb39a63cc67502b1436a7e3fc
1 parent ad5d0f4 commit df34009

File tree

17 files changed

+1080
-1800
lines changed

17 files changed

+1080
-1800
lines changed

third-party/thrift/src/thrift/compiler/generate/templates/cpp2/module_types_h/field_ref.mustache

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,63 +72,55 @@
7272
private:
7373
{{/struct:legacy_api?}}
7474
{{> common/field_docblock}}
75-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
76-
{{field:cpp_accessor_attribute}} fbthrift_T& {{field:cpp_name}}_ref() & {
75+
{{field:cpp_accessor_attribute}} {{field:cpp_storage_type}}& {{field:cpp_name}}_ref() & {
7776
{{> module_types_h/field_interceptor}}
7877
return {{> common/field_value}};
7978
}
8079

8180
{{> common/field_docblock}}
82-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
83-
{{field:cpp_accessor_attribute}} const fbthrift_T& {{field:cpp_name}}_ref() const& {
81+
{{field:cpp_accessor_attribute}} const {{field:cpp_storage_type}}& {{field:cpp_name}}_ref() const& {
8482
{{> module_types_h/field_interceptor}}
8583
return {{> common/field_value}};
8684
}
8785

8886
{{> common/field_docblock}}
89-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
90-
{{field:cpp_accessor_attribute}} fbthrift_T&& {{field:cpp_name}}_ref() && {
87+
{{field:cpp_accessor_attribute}} {{field:cpp_storage_type}}&& {{field:cpp_name}}_ref() && {
9188
{{> module_types_h/field_interceptor}}
92-
return static_cast<fbthrift_T&&>({{> common/field_value}});
89+
return static_cast<{{field:cpp_storage_type}}&&>({{> common/field_value}});
9390
}
9491

9592
{{> common/field_docblock}}
96-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
97-
{{field:cpp_accessor_attribute}} const fbthrift_T&& {{field:cpp_name}}_ref() const&& {
93+
{{field:cpp_accessor_attribute}} const {{field:cpp_storage_type}}&& {{field:cpp_name}}_ref() const&& {
9894
{{> module_types_h/field_interceptor}}
99-
return static_cast<const fbthrift_T&&>({{> common/field_value}});
95+
return static_cast<const {{field:cpp_storage_type}}&&>({{> common/field_value}});
10096
}
10197
{{^struct:legacy_api?}}
10298
public:
10399
{{/struct:legacy_api?}}
104100
{{#field:eligible_for_storage_name_mangling?}}
105101

106102
{{> common/field_docblock}}
107-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
108-
FOLLY_ERASE fbthrift_T& {{field:cpp_name}}() & {
103+
FOLLY_ERASE {{field:cpp_storage_type}}& {{field:cpp_name}}() & {
109104
{{> module_types_h/field_interceptor}}
110105
return {{> common/field_value}};
111106
}
112107

113108
{{> common/field_docblock}}
114-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
115-
FOLLY_ERASE const fbthrift_T& {{field:cpp_name}}() const& {
109+
FOLLY_ERASE const {{field:cpp_storage_type}}& {{field:cpp_name}}() const& {
116110
{{> module_types_h/field_interceptor}}
117111
return {{> common/field_value}};
118112
}
119113

120114
{{> common/field_docblock}}
121-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
122-
FOLLY_ERASE fbthrift_T&& {{field:cpp_name}}() && {
115+
FOLLY_ERASE {{field:cpp_storage_type}}&& {{field:cpp_name}}() && {
123116
{{> module_types_h/field_interceptor}}
124-
return static_cast<fbthrift_T&&>({{> common/field_value}});
117+
return static_cast<{{field:cpp_storage_type}}&&>({{> common/field_value}});
125118
}
126119

127120
{{> common/field_docblock}}
128-
template <typename..., typename fbthrift_T = {{field:cpp_storage_type}}>
129-
FOLLY_ERASE const fbthrift_T&& {{field:cpp_name}}() const&& {
121+
FOLLY_ERASE const {{field:cpp_storage_type}}&& {{field:cpp_name}}() const&& {
130122
{{> module_types_h/field_interceptor}}
131-
return static_cast<const fbthrift_T&&>({{> common/field_value}});
123+
return static_cast<const {{field:cpp_storage_type}}&&>({{> common/field_value}});
132124
}
133125
{{/field:eligible_for_storage_name_mangling?}}
134126
{{/field:use_field_ref?}}

third-party/thrift/src/thrift/compiler/test/fixtures/adapter/out/cpp2/gen-cpp2/module_types.h

Lines changed: 48 additions & 80 deletions
Large diffs are not rendered by default.

third-party/thrift/src/thrift/compiler/test/fixtures/basic-structured-annotations/out/cpp2/gen-cpp2/module_types.h

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -859,51 +859,43 @@ class structured_annotation_recursive final {
859859
return {static_cast<fbthrift_T&&>(this->__fbthrift_field_name), __isset.at(0), __isset.bit(0)};
860860
}
861861
/** Glean { "field": "recurse" } */
862-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
863-
FOLLY_ERASE fbthrift_T& recurse_ref() & {
862+
FOLLY_ERASE ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>& recurse_ref() & {
864863
return __fbthrift_field_recurse;
865864
}
866865

867866
/** Glean { "field": "recurse" } */
868-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
869-
FOLLY_ERASE const fbthrift_T& recurse_ref() const& {
867+
FOLLY_ERASE const ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>& recurse_ref() const& {
870868
return __fbthrift_field_recurse;
871869
}
872870

873871
/** Glean { "field": "recurse" } */
874-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
875-
FOLLY_ERASE fbthrift_T&& recurse_ref() && {
876-
return static_cast<fbthrift_T&&>(__fbthrift_field_recurse);
872+
FOLLY_ERASE ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&& recurse_ref() && {
873+
return static_cast<::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&&>(__fbthrift_field_recurse);
877874
}
878875

879876
/** Glean { "field": "recurse" } */
880-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
881-
FOLLY_ERASE const fbthrift_T&& recurse_ref() const&& {
882-
return static_cast<const fbthrift_T&&>(__fbthrift_field_recurse);
877+
FOLLY_ERASE const ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&& recurse_ref() const&& {
878+
return static_cast<const ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&&>(__fbthrift_field_recurse);
883879
}
884880

885881
/** Glean { "field": "recurse" } */
886-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
887-
FOLLY_ERASE fbthrift_T& recurse() & {
882+
FOLLY_ERASE ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>& recurse() & {
888883
return __fbthrift_field_recurse;
889884
}
890885

891886
/** Glean { "field": "recurse" } */
892-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
893-
FOLLY_ERASE const fbthrift_T& recurse() const& {
887+
FOLLY_ERASE const ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>& recurse() const& {
894888
return __fbthrift_field_recurse;
895889
}
896890

897891
/** Glean { "field": "recurse" } */
898-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
899-
FOLLY_ERASE fbthrift_T&& recurse() && {
900-
return static_cast<fbthrift_T&&>(__fbthrift_field_recurse);
892+
FOLLY_ERASE ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&& recurse() && {
893+
return static_cast<::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&&>(__fbthrift_field_recurse);
901894
}
902895

903896
/** Glean { "field": "recurse" } */
904-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>>
905-
FOLLY_ERASE const fbthrift_T&& recurse() const&& {
906-
return static_cast<const fbthrift_T&&>(__fbthrift_field_recurse);
897+
FOLLY_ERASE const ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&& recurse() const&& {
898+
return static_cast<const ::std::unique_ptr<::test::fixtures::basic-structured-annotations::structured_annotation_recursive>&&>(__fbthrift_field_recurse);
907899
}
908900

909901
/** Glean { "field": "forward" } */

third-party/thrift/src/thrift/compiler/test/fixtures/deprecated-public-fields-for-cpp-ref/out/cpp2/gen-cpp2/module_types.h

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -119,98 +119,82 @@ class Foo final {
119119
bool operator==(const Foo&) const;
120120
bool operator<(const Foo&) const;
121121
/** Glean { "field": "foo" } */
122-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
123-
FOLLY_ERASE fbthrift_T& foo_ref() & {
122+
FOLLY_ERASE ::std::unique_ptr<::cpp2::Foo>& foo_ref() & {
124123
return __fbthrift_field_foo;
125124
}
126125

127126
/** Glean { "field": "foo" } */
128-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
129-
FOLLY_ERASE const fbthrift_T& foo_ref() const& {
127+
FOLLY_ERASE const ::std::unique_ptr<::cpp2::Foo>& foo_ref() const& {
130128
return __fbthrift_field_foo;
131129
}
132130

133131
/** Glean { "field": "foo" } */
134-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
135-
FOLLY_ERASE fbthrift_T&& foo_ref() && {
136-
return static_cast<fbthrift_T&&>(__fbthrift_field_foo);
132+
FOLLY_ERASE ::std::unique_ptr<::cpp2::Foo>&& foo_ref() && {
133+
return static_cast<::std::unique_ptr<::cpp2::Foo>&&>(__fbthrift_field_foo);
137134
}
138135

139136
/** Glean { "field": "foo" } */
140-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
141-
FOLLY_ERASE const fbthrift_T&& foo_ref() const&& {
142-
return static_cast<const fbthrift_T&&>(__fbthrift_field_foo);
137+
FOLLY_ERASE const ::std::unique_ptr<::cpp2::Foo>&& foo_ref() const&& {
138+
return static_cast<const ::std::unique_ptr<::cpp2::Foo>&&>(__fbthrift_field_foo);
143139
}
144140

145141
/** Glean { "field": "foo" } */
146-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
147-
FOLLY_ERASE fbthrift_T& foo() & {
142+
FOLLY_ERASE ::std::unique_ptr<::cpp2::Foo>& foo() & {
148143
return __fbthrift_field_foo;
149144
}
150145

151146
/** Glean { "field": "foo" } */
152-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
153-
FOLLY_ERASE const fbthrift_T& foo() const& {
147+
FOLLY_ERASE const ::std::unique_ptr<::cpp2::Foo>& foo() const& {
154148
return __fbthrift_field_foo;
155149
}
156150

157151
/** Glean { "field": "foo" } */
158-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
159-
FOLLY_ERASE fbthrift_T&& foo() && {
160-
return static_cast<fbthrift_T&&>(__fbthrift_field_foo);
152+
FOLLY_ERASE ::std::unique_ptr<::cpp2::Foo>&& foo() && {
153+
return static_cast<::std::unique_ptr<::cpp2::Foo>&&>(__fbthrift_field_foo);
161154
}
162155

163156
/** Glean { "field": "foo" } */
164-
template <typename..., typename fbthrift_T = ::std::unique_ptr<::cpp2::Foo>>
165-
FOLLY_ERASE const fbthrift_T&& foo() const&& {
166-
return static_cast<const fbthrift_T&&>(__fbthrift_field_foo);
157+
FOLLY_ERASE const ::std::unique_ptr<::cpp2::Foo>&& foo() const&& {
158+
return static_cast<const ::std::unique_ptr<::cpp2::Foo>&&>(__fbthrift_field_foo);
167159
}
168160
/** Glean { "field": "bar" } */
169-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
170-
FOLLY_ERASE fbthrift_T& bar_ref() & {
161+
FOLLY_ERASE ::std::shared_ptr<::cpp2::Foo>& bar_ref() & {
171162
return __fbthrift_field_bar;
172163
}
173164

174165
/** Glean { "field": "bar" } */
175-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
176-
FOLLY_ERASE const fbthrift_T& bar_ref() const& {
166+
FOLLY_ERASE const ::std::shared_ptr<::cpp2::Foo>& bar_ref() const& {
177167
return __fbthrift_field_bar;
178168
}
179169

180170
/** Glean { "field": "bar" } */
181-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
182-
FOLLY_ERASE fbthrift_T&& bar_ref() && {
183-
return static_cast<fbthrift_T&&>(__fbthrift_field_bar);
171+
FOLLY_ERASE ::std::shared_ptr<::cpp2::Foo>&& bar_ref() && {
172+
return static_cast<::std::shared_ptr<::cpp2::Foo>&&>(__fbthrift_field_bar);
184173
}
185174

186175
/** Glean { "field": "bar" } */
187-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
188-
FOLLY_ERASE const fbthrift_T&& bar_ref() const&& {
189-
return static_cast<const fbthrift_T&&>(__fbthrift_field_bar);
176+
FOLLY_ERASE const ::std::shared_ptr<::cpp2::Foo>&& bar_ref() const&& {
177+
return static_cast<const ::std::shared_ptr<::cpp2::Foo>&&>(__fbthrift_field_bar);
190178
}
191179

192180
/** Glean { "field": "bar" } */
193-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
194-
FOLLY_ERASE fbthrift_T& bar() & {
181+
FOLLY_ERASE ::std::shared_ptr<::cpp2::Foo>& bar() & {
195182
return __fbthrift_field_bar;
196183
}
197184

198185
/** Glean { "field": "bar" } */
199-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
200-
FOLLY_ERASE const fbthrift_T& bar() const& {
186+
FOLLY_ERASE const ::std::shared_ptr<::cpp2::Foo>& bar() const& {
201187
return __fbthrift_field_bar;
202188
}
203189

204190
/** Glean { "field": "bar" } */
205-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
206-
FOLLY_ERASE fbthrift_T&& bar() && {
207-
return static_cast<fbthrift_T&&>(__fbthrift_field_bar);
191+
FOLLY_ERASE ::std::shared_ptr<::cpp2::Foo>&& bar() && {
192+
return static_cast<::std::shared_ptr<::cpp2::Foo>&&>(__fbthrift_field_bar);
208193
}
209194

210195
/** Glean { "field": "bar" } */
211-
template <typename..., typename fbthrift_T = ::std::shared_ptr<::cpp2::Foo>>
212-
FOLLY_ERASE const fbthrift_T&& bar() const&& {
213-
return static_cast<const fbthrift_T&&>(__fbthrift_field_bar);
196+
FOLLY_ERASE const ::std::shared_ptr<::cpp2::Foo>&& bar() const&& {
197+
return static_cast<const ::std::shared_ptr<::cpp2::Foo>&&>(__fbthrift_field_bar);
214198
}
215199

216200
template <class Protocol_>

third-party/thrift/src/thrift/compiler/test/fixtures/encode/out/cpp2/gen-cpp2/module_types.h

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -942,51 +942,43 @@ class OpEncodeStruct final {
942942
return {static_cast<fbthrift_T&&>(this->__fbthrift_field_list_field), __isset.at(4), __isset.bit(4)};
943943
}
944944
/** Glean { "field": "list_shared_ptr_field" } */
945-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
946-
FOLLY_ERASE fbthrift_T& list_shared_ptr_field_ref() & {
945+
FOLLY_ERASE ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>& list_shared_ptr_field_ref() & {
947946
return __fbthrift_field_list_shared_ptr_field;
948947
}
949948

950949
/** Glean { "field": "list_shared_ptr_field" } */
951-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
952-
FOLLY_ERASE const fbthrift_T& list_shared_ptr_field_ref() const& {
950+
FOLLY_ERASE const ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>& list_shared_ptr_field_ref() const& {
953951
return __fbthrift_field_list_shared_ptr_field;
954952
}
955953

956954
/** Glean { "field": "list_shared_ptr_field" } */
957-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
958-
FOLLY_ERASE fbthrift_T&& list_shared_ptr_field_ref() && {
959-
return static_cast<fbthrift_T&&>(__fbthrift_field_list_shared_ptr_field);
955+
FOLLY_ERASE ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&& list_shared_ptr_field_ref() && {
956+
return static_cast<::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&&>(__fbthrift_field_list_shared_ptr_field);
960957
}
961958

962959
/** Glean { "field": "list_shared_ptr_field" } */
963-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
964-
FOLLY_ERASE const fbthrift_T&& list_shared_ptr_field_ref() const&& {
965-
return static_cast<const fbthrift_T&&>(__fbthrift_field_list_shared_ptr_field);
960+
FOLLY_ERASE const ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&& list_shared_ptr_field_ref() const&& {
961+
return static_cast<const ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&&>(__fbthrift_field_list_shared_ptr_field);
966962
}
967963

968964
/** Glean { "field": "list_shared_ptr_field" } */
969-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
970-
FOLLY_ERASE fbthrift_T& list_shared_ptr_field() & {
965+
FOLLY_ERASE ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>& list_shared_ptr_field() & {
971966
return __fbthrift_field_list_shared_ptr_field;
972967
}
973968

974969
/** Glean { "field": "list_shared_ptr_field" } */
975-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
976-
FOLLY_ERASE const fbthrift_T& list_shared_ptr_field() const& {
970+
FOLLY_ERASE const ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>& list_shared_ptr_field() const& {
977971
return __fbthrift_field_list_shared_ptr_field;
978972
}
979973

980974
/** Glean { "field": "list_shared_ptr_field" } */
981-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
982-
FOLLY_ERASE fbthrift_T&& list_shared_ptr_field() && {
983-
return static_cast<fbthrift_T&&>(__fbthrift_field_list_shared_ptr_field);
975+
FOLLY_ERASE ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&& list_shared_ptr_field() && {
976+
return static_cast<::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&&>(__fbthrift_field_list_shared_ptr_field);
984977
}
985978

986979
/** Glean { "field": "list_shared_ptr_field" } */
987-
template <typename..., typename fbthrift_T = ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>>
988-
FOLLY_ERASE const fbthrift_T&& list_shared_ptr_field() const&& {
989-
return static_cast<const fbthrift_T&&>(__fbthrift_field_list_shared_ptr_field);
980+
FOLLY_ERASE const ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&& list_shared_ptr_field() const&& {
981+
return static_cast<const ::std::shared_ptr<const ::std::vector<::facebook::thrift::test::AdaptedFoo>>&&>(__fbthrift_field_list_shared_ptr_field);
990982
}
991983

992984
/** Glean { "field": "list_cpp_type_field" } */

0 commit comments

Comments
 (0)