Skip to content

Commit

Permalink
Reduce build-time by moving the definition of setter/getter to module…
Browse files Browse the repository at this point in the history
…_types.cpp (redo again)

Reviewed By: vitaut

Differential Revision: D67667232

fbshipit-source-id: 7f273ea462dcc056af8c6c199776815824ac8757
  • Loading branch information
TJ Yin authored and facebook-github-bot committed Dec 29, 2024
1 parent d62a3a1 commit 1b90607
Show file tree
Hide file tree
Showing 131 changed files with 5,879 additions and 4,271 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,39 @@
limitations under the License.
}}{{#struct:fields?}}{{#struct:fields}}{{#field:type}}{{#field:has_deprecated_accessors?}}
{{#type:resolves_to_container_or_struct?}}
{{#field:optional?}}
{{#if field:optional?}}

const {{type:cpp_type}}* {{struct:cpp_underlying_name}}::get_{{field:cpp_name}}() const& {
return {{field:cpp_name}}_ref().has_value() ? std::addressof({{field:cpp_storage_name}}) : nullptr;
}

{{type:cpp_type}}* {{struct:cpp_underlying_name}}::get_{{field:cpp_name}}() & {
return {{field:cpp_name}}_ref().has_value() ? std::addressof({{field:cpp_storage_name}}) : nullptr;
}
{{#else}}
{{#if type:resolves_to_fixed_size?}}

{{type:cpp_type}} {{struct:cpp_underlying_name}}::get_{{field:cpp_name}}() const {
return {{field:cpp_storage_name}};
}
{{#else}}
{{#if type:resolves_to_container_or_struct?}}

{{/field:optional?}}
{{^field:optional?}}
const {{type:cpp_type}}& {{struct:cpp_underlying_name}}::get_{{field:cpp_name}}() const& {
return {{field:cpp_storage_name}};
}

{{type:cpp_type}} {{struct:cpp_underlying_name}}::get_{{field:cpp_name}}() && {
return std::move({{field:cpp_storage_name}});
return static_cast<{{type:cpp_type}}&&>({{field:cpp_storage_name}});
}
{{/if type:resolves_to_container_or_struct?}}
{{/if type:resolves_to_fixed_size?}}
{{/if field:optional?}}
{{#if type:resolves_to_fixed_size?}}

{{/field:optional?}}
{{/type:resolves_to_container_or_struct?}}
{{type:cpp_type}}& {{struct:cpp_underlying_name}}::set_{{field:cpp_name}}({{type:cpp_type}} {{field:cpp_name}}_) {
{{field:cpp_name}}_ref() = {{field:cpp_name}}_;
return {{field:cpp_storage_name}};
}
{{/if type:resolves_to_fixed_size?}}
{{/field:has_deprecated_accessors?}}{{/field:type}}{{/struct:fields}}{{/struct:fields?}}
Original file line number Diff line number Diff line change
Expand Up @@ -15,81 +15,54 @@
limitations under the License.
}}{{#struct:fields}}{{#field:type}}{{#field:has_deprecated_accessors?}}
{{^type:resolves_to_container_or_struct?}}
{{#if field:optional?}}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
const {{type:cpp_type}}* get_{{field:cpp_name}}() const& {
return {{field:cpp_name}}_ref().has_value() ? std::addressof({{field:cpp_storage_name}}) : nullptr;
}
const {{type:cpp_type}}* get_{{field:cpp_name}}() const&;

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
{{type:cpp_type}}* get_{{field:cpp_name}}() & {
return {{field:cpp_name}}_ref().has_value() ? std::addressof({{field:cpp_storage_name}}) : nullptr;
}
{{type:cpp_type}}* get_{{field:cpp_name}}() &;

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
{{type:cpp_type}}* get_{{field:cpp_name}}() && = delete;
{{#else}}
{{#if type:resolves_to_fixed_size?}}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
{{type:cpp_type}} get_{{field:cpp_name}}() const {
return {{field:cpp_storage_name}};
}
{{type:cpp_type}} get_{{field:cpp_name}}() const;
{{#else}}
{{#if type:resolves_to_container_or_struct?}}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
const {{type:cpp_type}}& get_{{field:cpp_name}}() const& {
return {{field:cpp_storage_name}};
}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
{{type:cpp_type}} get_{{field:cpp_name}}() && {
return std::move({{field:cpp_storage_name}});
}
{{/if type:resolves_to_fixed_size?}}
{{/if field:optional?}}
{{/type:resolves_to_container_or_struct?}}
{{#type:resolves_to_container_or_struct?}}
{{#if field:optional?}}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
const {{type:cpp_type}}* get_{{field:cpp_name}}() const&;

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
{{type:cpp_type}}* get_{{field:cpp_name}}() &;
const {{type:cpp_type}}& get_{{field:cpp_name}}() const&;

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
{{type:cpp_type}}* get_{{field:cpp_name}}() && = delete;
{{type:cpp_type}} get_{{field:cpp_name}}() &&;
{{#else}}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
const {{type:cpp_type}}& get_{{field:cpp_name}}() const&;
const {{type:cpp_type}}& get_{{field:cpp_name}}() const& {
return {{field:cpp_storage_name}};
}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}().value();` instead of `FOO.get_{{field:cpp_name}}();`")]]
{{type:cpp_type}} get_{{field:cpp_name}}() &&;
{{/if field:optional?}}
{{/type:resolves_to_container_or_struct?}}
{{type:cpp_type}} get_{{field:cpp_name}}() && {
return static_cast<{{type:cpp_type}}&&>({{field:cpp_storage_name}});
}
{{/if type:resolves_to_container_or_struct?}}
{{/if type:resolves_to_fixed_size?}}
{{/if field:optional?}}
{{#if type:resolves_to_fixed_size?}}

{{> common/field_docblock}}
[[deprecated("Use `FOO.{{field:cpp_name}}() = BAR;` instead of `FOO.set_{{field:cpp_name}}(BAR);`")]]
{{type:cpp_type}}& set_{{field:cpp_name}}({{type:cpp_type}} {{field:cpp_name}}_) {
{{field:cpp_name}}_ref() = {{field:cpp_name}}_;
return {{field:cpp_storage_name}};
}
{{type:cpp_type}}& set_{{field:cpp_name}}({{type:cpp_type}} {{field:cpp_name}}_);
{{#else}}

{{> common/field_docblock}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ bool MyAnnotation::operator<([[maybe_unused]] const MyAnnotation& rhs) const {
}


::facebook::thrift::test::Color MyAnnotation::get_color() const {
return __fbthrift_field_color;
}

::facebook::thrift::test::Color& MyAnnotation::set_color(::facebook::thrift::test::Color color_) {
color_ref() = color_;
return __fbthrift_field_color;
}

void swap([[maybe_unused]] MyAnnotation& a, [[maybe_unused]] MyAnnotation& b) {
using ::std::swap;
swap(a.__fbthrift_field_signature, b.__fbthrift_field_signature);
Expand Down Expand Up @@ -381,39 +390,39 @@ bool Foo::operator<([[maybe_unused]] const Foo& rhs) const {
return ::apache::thrift::op::detail::StructLessThan{}(*this, rhs);
}


const ::std::vector<::std::int32_t>& Foo::get_adapted_list() const& {
return __fbthrift_field_adapted_list;
}

::std::vector<::std::int32_t> Foo::get_adapted_list() && {
return std::move(__fbthrift_field_adapted_list);
return static_cast<::std::vector<::std::int32_t>&&>(__fbthrift_field_adapted_list);
}

const ::std::set<::std::int32_t>& Foo::get_adapted_set() const& {
return __fbthrift_field_adapted_set;
}

::std::set<::std::int32_t> Foo::get_adapted_set() && {
return std::move(__fbthrift_field_adapted_set);
return static_cast<::std::set<::std::int32_t>&&>(__fbthrift_field_adapted_set);
}

const ::std::map<::std::string, ::std::int32_t>& Foo::get_adapted_map() const& {
return __fbthrift_field_adapted_map;
}

::std::map<::std::string, ::std::int32_t> Foo::get_adapted_map() && {
return std::move(__fbthrift_field_adapted_map);
return static_cast<::std::map<::std::string, ::std::int32_t>&&>(__fbthrift_field_adapted_map);
}

const ::std::vector<::std::vector<::std::map<::std::int32_t, ::std::int32_t>>>& Foo::get_adapted_list_nested() const& {
return __fbthrift_field_adapted_list_nested;
}

::std::vector<::std::vector<::std::map<::std::int32_t, ::std::int32_t>>> Foo::get_adapted_list_nested() && {
return std::move(__fbthrift_field_adapted_list_nested);
return static_cast<::std::vector<::std::vector<::std::map<::std::int32_t, ::std::int32_t>>>&&>(__fbthrift_field_adapted_list_nested);
}


void swap([[maybe_unused]] Foo& a, [[maybe_unused]] Foo& b) {
using ::std::swap;
swap(a.__fbthrift_field_intField, b.__fbthrift_field_intField);
Expand Down Expand Up @@ -759,12 +768,13 @@ bool Bar::operator<([[maybe_unused]] const Bar& rhs) const {
return ::apache::thrift::op::detail::StructLessThan{}(*this, rhs);
}


const ::std::vector<::facebook::thrift::test::FooWithAdapter_9317>& Bar::get_structListField() const& {
return __fbthrift_field_structListField;
}

::std::vector<::facebook::thrift::test::FooWithAdapter_9317> Bar::get_structListField() && {
return std::move(__fbthrift_field_structListField);
return static_cast<::std::vector<::facebook::thrift::test::FooWithAdapter_9317>&&>(__fbthrift_field_structListField);
}

const ::std::vector<::facebook::thrift::test::FooWithAdapter_9317>* Bar::get_optionalStructListField() const& {
Expand All @@ -775,7 +785,6 @@ ::std::vector<::facebook::thrift::test::FooWithAdapter_9317>* Bar::get_optionalS
return optionalStructListField_ref().has_value() ? std::addressof(__fbthrift_field_optionalStructListField) : nullptr;
}


void swap([[maybe_unused]] Bar& a, [[maybe_unused]] Bar& b) {
using ::std::swap;
swap(a.__fbthrift_field_structField, b.__fbthrift_field_structField);
Expand Down Expand Up @@ -895,6 +904,15 @@ bool DirectlyAdapted::operator<([[maybe_unused]] const DirectlyAdapted& rhs) con
}


::std::int32_t DirectlyAdapted::get_field() const {
return __fbthrift_field_field;
}

::std::int32_t& DirectlyAdapted::set_field(::std::int32_t field_) {
field_ref() = field_;
return __fbthrift_field_field;
}

void swap([[maybe_unused]] DirectlyAdapted& a, [[maybe_unused]] DirectlyAdapted& b) {
using ::std::swap;
swap(a.__fbthrift_field_field, b.__fbthrift_field_field);
Expand Down Expand Up @@ -979,6 +997,15 @@ bool IndependentDirectlyAdapted::operator<([[maybe_unused]] const IndependentDir
}


::std::int32_t IndependentDirectlyAdapted::get_field() const {
return __fbthrift_field_field;
}

::std::int32_t& IndependentDirectlyAdapted::set_field(::std::int32_t field_) {
field_ref() = field_;
return __fbthrift_field_field;
}

void swap([[maybe_unused]] IndependentDirectlyAdapted& a, [[maybe_unused]] IndependentDirectlyAdapted& b) {
using ::std::swap;
swap(a.__fbthrift_field_field, b.__fbthrift_field_field);
Expand Down Expand Up @@ -1671,6 +1698,15 @@ bool MyStruct::operator<([[maybe_unused]] const MyStruct& rhs) const {
}


::std::int32_t MyStruct::get_field() const {
return __fbthrift_field_field;
}

::std::int32_t& MyStruct::set_field(::std::int32_t field_) {
field_ref() = field_;
return __fbthrift_field_field;
}

void swap([[maybe_unused]] MyStruct& a, [[maybe_unused]] MyStruct& b) {
using ::std::swap;
swap(a.__fbthrift_field_field, b.__fbthrift_field_field);
Expand Down Expand Up @@ -2345,15 +2381,15 @@ bool AdaptTemplatedNestedTestStruct::operator<([[maybe_unused]] const AdaptTempl
return ::apache::thrift::op::detail::StructLessThan{}(*this, rhs);
}


const ::facebook::thrift::test::AdaptTemplatedTestStruct& AdaptTemplatedNestedTestStruct::get_adaptedStruct() const& {
return __fbthrift_field_adaptedStruct;
}

::facebook::thrift::test::AdaptTemplatedTestStruct AdaptTemplatedNestedTestStruct::get_adaptedStruct() && {
return std::move(__fbthrift_field_adaptedStruct);
return static_cast<::facebook::thrift::test::AdaptTemplatedTestStruct&&>(__fbthrift_field_adaptedStruct);
}


void swap([[maybe_unused]] AdaptTemplatedNestedTestStruct& a, [[maybe_unused]] AdaptTemplatedNestedTestStruct& b) {
using ::std::swap;
swap(a.__fbthrift_field_adaptedStruct, b.__fbthrift_field_adaptedStruct);
Expand Down Expand Up @@ -2580,6 +2616,15 @@ bool ThriftAdaptedStruct::operator<([[maybe_unused]] const ThriftAdaptedStruct&
}


::std::int64_t ThriftAdaptedStruct::get_data() const {
return __fbthrift_field_data;
}

::std::int64_t& ThriftAdaptedStruct::set_data(::std::int64_t data_) {
data_ref() = data_;
return __fbthrift_field_data;
}

void swap([[maybe_unused]] ThriftAdaptedStruct& a, [[maybe_unused]] ThriftAdaptedStruct& b) {
using ::std::swap;
swap(a.__fbthrift_field_data, b.__fbthrift_field_data);
Expand Down Expand Up @@ -2663,6 +2708,15 @@ bool DirectlyAdaptedStruct::operator<([[maybe_unused]] const DirectlyAdaptedStru
}


::std::int64_t DirectlyAdaptedStruct::get_data() const {
return __fbthrift_field_data;
}

::std::int64_t& DirectlyAdaptedStruct::set_data(::std::int64_t data_) {
data_ref() = data_;
return __fbthrift_field_data;
}

void swap([[maybe_unused]] DirectlyAdaptedStruct& a, [[maybe_unused]] DirectlyAdaptedStruct& b) {
using ::std::swap;
swap(a.__fbthrift_field_data, b.__fbthrift_field_data);
Expand Down Expand Up @@ -2920,15 +2974,15 @@ bool CircularAdaptee::operator<([[maybe_unused]] const CircularAdaptee& rhs) con
return ::apache::thrift::op::detail::StructLessThan{}(*this, rhs);
}


const ::facebook::thrift::test::CircularStruct& CircularAdaptee::get_field() const& {
return __fbthrift_field_field;
}

::facebook::thrift::test::CircularStruct CircularAdaptee::get_field() && {
return std::move(__fbthrift_field_field);
return static_cast<::facebook::thrift::test::CircularStruct&&>(__fbthrift_field_field);
}


void swap([[maybe_unused]] CircularAdaptee& a, [[maybe_unused]] CircularAdaptee& b) {
using ::std::swap;
swap(a.__fbthrift_field_field, b.__fbthrift_field_field);
Expand Down Expand Up @@ -3325,6 +3379,15 @@ bool UnderlyingRenamedStruct::operator<([[maybe_unused]] const UnderlyingRenamed
}


::std::int64_t UnderlyingRenamedStruct::get_data() const {
return __fbthrift_field_data;
}

::std::int64_t& UnderlyingRenamedStruct::set_data(::std::int64_t data_) {
data_ref() = data_;
return __fbthrift_field_data;
}

void swap([[maybe_unused]] UnderlyingRenamedStruct& a, [[maybe_unused]] UnderlyingRenamedStruct& b) {
using ::std::swap;
swap(a.__fbthrift_field_data, b.__fbthrift_field_data);
Expand Down Expand Up @@ -3407,6 +3470,15 @@ bool UnderlyingSameNamespaceStruct::operator<([[maybe_unused]] const UnderlyingS
}


::std::int64_t UnderlyingSameNamespaceStruct::get_data() const {
return __fbthrift_field_data;
}

::std::int64_t& UnderlyingSameNamespaceStruct::set_data(::std::int64_t data_) {
data_ref() = data_;
return __fbthrift_field_data;
}

void swap([[maybe_unused]] UnderlyingSameNamespaceStruct& a, [[maybe_unused]] UnderlyingSameNamespaceStruct& b) {
using ::std::swap;
swap(a.__fbthrift_field_data, b.__fbthrift_field_data);
Expand Down
Loading

0 comments on commit 1b90607

Please sign in to comment.