Skip to content

Commit

Permalink
Remove common/namespace_cpp2
Browse files Browse the repository at this point in the history
Summary:
This diff removes the reliance on the undefined variables, `program:namespaces` and `service:namespaces` in templates.

This lets us delete `common/namespace_cpp2.mustache`.

Reviewed By: ahilger, iahs

Differential Revision: D67637425

fbshipit-source-id: 937557738f0815f0a556baf7c6d4936e350a5c65
  • Loading branch information
praihan authored and facebook-github-bot committed Dec 27, 2024
1 parent c9d660b commit adbfa28
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 44 deletions.
2 changes: 0 additions & 2 deletions thrift/compiler/generate/t_mstch_cpp2_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ class t_mstch_cpp2_generator : public t_mstch_generator {
opts.allowed_undefined_variables = {
"program:autogen_path",
"service:autogen_path",
"program:qualified_namespace",
"service:qualified_namespace",
"field:fatal_annotations?",
"value:enable_referencing?",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
namespace apache { namespace thrift {
{{#program:enums}}

template <> struct TEnumDataStorage<{{> common/namespace_cpp2}}{{enum:cpp_name}}> {
using type = {{> common/namespace_cpp2}}{{enum:cpp_name}};
template <> struct TEnumDataStorage<::{{program:qualified_namespace}}::{{enum:cpp_name}}> {
using type = ::{{program:qualified_namespace}}::{{enum:cpp_name}};
static constexpr const std::size_t size = {{enum:size}};
static constexpr std::array<type, size> values = { {
{{#enum:values}}{{!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ struct {{program:name}}_module_traits {
>;
using enums = ::fatal::list<
{{#program:fatal_enums}}{{#fatal_strings:items}}
::fatal::pair<{{> common/namespace_cpp2}}{{fatal_string:name}}, strings::{{fatal_string:name}}>{{^last?}},{{/last?}}
::fatal::pair<::{{program:qualified_namespace}}::{{fatal_string:name}}, strings::{{fatal_string:name}}>{{^last?}},{{/last?}}
{{/fatal_strings:items}}{{/program:fatal_enums}}
>;
using unions = ::fatal::list<
{{#program:fatal_unions}}{{#fatal_strings:items}}
::fatal::pair<{{> common/namespace_cpp2}}{{fatal_string:name}}, strings::{{fatal_string:name}}>{{^last?}},{{/last?}}
::fatal::pair<::{{program:qualified_namespace}}::{{fatal_string:name}}, strings::{{fatal_string:name}}>{{^last?}},{{/last?}}
{{/fatal_strings:items}}{{/program:fatal_unions}}
>;
using structs = ::fatal::list<
{{#program:fatal_structs}}{{#fatal_strings:items}}
::fatal::pair<{{> common/namespace_cpp2}}{{fatal_string:name}}, strings::{{fatal_string:name}}>{{^last?}},{{/last?}}
::fatal::pair<::{{program:qualified_namespace}}::{{fatal_string:name}}, strings::{{fatal_string:name}}>{{^last?}},{{/last?}}
{{/fatal_strings:items}}{{/program:fatal_structs}}
>;
using constants = ::fatal::list<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ using ThriftServiceContext = ::apache::thrift::metadata::ThriftServiceContext;
using ThriftFunctionGenerator = void (*)(ThriftMetadata&, ThriftService&);
{{#program:enums}}
void EnumMetadata<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::gen(ThriftMetadata& metadata) {
void EnumMetadata<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::gen(ThriftMetadata& metadata) {
auto res = metadata.enums()->emplace("{{program:name}}.{{enum:name}}", ::apache::thrift::metadata::ThriftEnum{});
if (!res.second) {
return;
}
::apache::thrift::metadata::ThriftEnum& enum_metadata = res.first->second;
enum_metadata.name() = "{{program:name}}.{{enum:name}}";
using EnumTraits = TEnumTraits<{{> common/namespace_cpp2}}{{enum:cpp_name}}>;
using EnumTraits = TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}>;
for (std::size_t i = 0; i != EnumTraits::size; ++i) {
enum_metadata.elements()->emplace(static_cast<int32_t>(EnumTraits::values[i]), EnumTraits::names[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ namespace md {
{{#program:enums}}
{{^program:no_metadata?}}
template <>
class EnumMetadata<{{> common/namespace_cpp2}}{{enum:cpp_name}}> {
class EnumMetadata<::{{program:qualified_namespace}}::{{enum:cpp_name}}> {
public:
static void gen(ThriftMetadata& metadata);
};
{{/program:no_metadata?}}
{{#program:no_metadata?}}
template <>
class EnumMetadata<{{> common/namespace_cpp2}}{{enum:cpp_name}}>
class EnumMetadata<::{{program:qualified_namespace}}::{{enum:cpp_name}}>
: private EmptyMetadata {
public:
using EmptyMetadata::gen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ namespace detail {
{{#program:split_enums}}
const ::apache::thrift::detail::TypeInfo TypeToInfo<
apache::thrift::type_class::enumeration,
{{> common/namespace_cpp2}}{{enum:cpp_name}}>::typeInfo = {
::{{program:qualified_namespace}}::{{enum:cpp_name}}>::typeInfo = {
/* .type */ apache::thrift::protocol::TType::T_I32,
/* .get */ get<std::int32_t, {{> common/namespace_cpp2}}{{enum:cpp_name}}>,
/* .set */ reinterpret_cast<VoidFuncPtr>(set<{{> common/namespace_cpp2}}{{enum:cpp_name}}, std::int32_t>),
/* .get */ get<std::int32_t, ::{{program:qualified_namespace}}::{{enum:cpp_name}}>,
/* .set */ reinterpret_cast<VoidFuncPtr>(set<::{{program:qualified_namespace}}::{{enum:cpp_name}}, std::int32_t>),
/* .typeExt */ nullptr,
};
{{/program:split_enums}}
Expand All @@ -294,7 +294,7 @@ const ::apache::thrift::detail::TypeInfo TypeToInfo<
/* .type */ ::apache::thrift::protocol::TType::T_STRUCT,
/* .get */ nullptr,
/* .set */ nullptr,
/* .typeExt */ &{{> common/namespace_cpp2 }}__fbthrift_struct_info_{{struct:cpp_underlying_name}},
/* .typeExt */ &::{{program:qualified_namespace}}::__fbthrift_struct_info_{{struct:cpp_underlying_name}},
};
{{/program:split_structs}}
}}} // namespace apache::thrift::detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct TypeToInfo<
template <>
struct TypeToInfo<
::apache::thrift::type_class::enumeration,
{{> common/namespace_cpp2}}{{enum:cpp_name}}> {
::{{program:qualified_namespace}}::{{enum:cpp_name}}> {
static const ::apache::thrift::detail::TypeInfo typeInfo;
};
{{/program:enums}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@

namespace apache { namespace thrift {
const std::string_view TEnumTraits<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::__fbthrift_module_name_internal_do_not_use = kModuleName;
folly::Range<{{> common/namespace_cpp2}}{{enum:cpp_name}} const*> const TEnumTraits<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::values = {{!
const std::string_view TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::__fbthrift_module_name_internal_do_not_use = kModuleName;
folly::Range<::{{program:qualified_namespace}}::{{enum:cpp_name}} const*> const TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::values = {{!
}}{{#enum:empty?}}{{!
}}{};{{!
}}{{/enum:empty?}}{{!
}}{{^enum:empty?}}{{!
}}folly::range(TEnumDataStorage<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::values);{{!
}}folly::range(TEnumDataStorage<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::values);{{!
}}{{/enum:empty?}}
folly::Range<std::string_view const*> const TEnumTraits<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::names = {{!
folly::Range<std::string_view const*> const TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::names = {{!
}}{{#enum:empty?}}{{!
}}{};{{!
}}{{/enum:empty?}}{{!
}}{{^enum:empty?}}{{!
}}folly::range(TEnumDataStorage<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::names);{{!
}}folly::range(TEnumDataStorage<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::names);{{!
}}{{/enum:empty?}}

bool TEnumTraits<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::findName(type value, std::string_view* out) noexcept {
bool TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::findName(type value, std::string_view* out) noexcept {
return ::apache::thrift::detail::st::enum_find_name(value, out);
}

bool TEnumTraits<{{> common/namespace_cpp2}}{{enum:cpp_name}}>::findValue(std::string_view name, type* out) noexcept {
bool TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}>::findValue(std::string_view name, type* out) noexcept {
return ::apache::thrift::detail::st::enum_find_value(name, out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ enum {{^enum:cpp_is_unscoped}}class {{/enum:cpp_is_unscoped}}{{enum:cpp_name}}{{

namespace std {
{{#program:enums}}
template<> struct hash<{{> common/namespace_cpp2}}{{enum:cpp_name}}> :
::apache::thrift::detail::enum_hash<{{> common/namespace_cpp2}}{{enum:cpp_name}}> {};
template<> struct hash<::{{program:qualified_namespace}}::{{enum:cpp_name}}> :
::apache::thrift::detail::enum_hash<::{{program:qualified_namespace}}::{{enum:cpp_name}}> {};
{{/program:enums}}
} // std

namespace apache { namespace thrift {
{{#program:enums}}

template <> struct TEnumDataStorage<{{> common/namespace_cpp2}}{{enum:cpp_name}}>;
template <> struct TEnumDataStorage<::{{program:qualified_namespace}}::{{enum:cpp_name}}>;

template <> struct TEnumTraits<{{> common/namespace_cpp2}}{{enum:cpp_name}}> {
using type = {{> common/namespace_cpp2}}{{enum:cpp_name}};
template <> struct TEnumTraits<::{{program:qualified_namespace}}::{{enum:cpp_name}}> {
using type = ::{{program:qualified_namespace}}::{{enum:cpp_name}};

static constexpr std::size_t const size = {{enum:size}};
static folly::Range<type const*> const values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void {{struct:cpp_underlying_name}}::readNoXfer(Protocol_* iprot) {
::apache::thrift::detail::read(
iprot,
::apache::thrift::detail::toStructInfo(
{{> common/namespace_cpp2}}__fbthrift_struct_info_{{struct:cpp_underlying_name}}
::{{program:qualified_namespace}}::__fbthrift_struct_info_{{struct:cpp_underlying_name}}
),
this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void {{struct:cpp_underlying_name}}::readNoXfer(Protocol_* iprot) {
::apache::thrift::detail::read(
iprot,
::apache::thrift::detail::toStructInfo(
{{> common/namespace_cpp2}}__fbthrift_struct_info_{{struct:cpp_underlying_name}}
::{{program:qualified_namespace}}::__fbthrift_struct_info_{{struct:cpp_underlying_name}}
),
this);
}{{!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ uint32_t {{struct:cpp_underlying_name}}::write(Protocol_* iprot) const {
return ::apache::thrift::detail::write(
iprot,
::apache::thrift::detail::toStructInfo(
{{> common/namespace_cpp2}}__fbthrift_struct_info_{{struct:cpp_underlying_name}}
::{{program:qualified_namespace}}::__fbthrift_struct_info_{{struct:cpp_underlying_name}}
),
this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ uint32_t {{struct:cpp_underlying_name}}::write(Protocol_* iprot) const {
return ::apache::thrift::detail::write(
iprot,
::apache::thrift::detail::toStructInfo(
{{> common/namespace_cpp2}}__fbthrift_struct_info_{{struct:cpp_underlying_name}}
::{{program:qualified_namespace}}::__fbthrift_struct_info_{{struct:cpp_underlying_name}}
),
this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void {{> service_common/client_class_name}}::{{function:cpp_name}}(apache::thrif
apache::thrift::SerializedRequest {{> service_common/client_class_name}}::fbthrift_serialize_{{function:cpp_name}}(const RpcOptions& rpcOptions, apache::thrift::transport::THeader& header, apache::thrift::ContextStack* contextStack{{function:comma}}{{> service_common/function_param_list_client}}) {
return apache::thrift::detail::ac::withProtocolWriter(apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId(), [&](auto&& prot) {
using ProtocolWriter = std::decay_t<decltype(prot)>;
{{> common/namespace_cpp2}}{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_pargs args;
::{{service:qualified_namespace}}::{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_pargs args;
{{#function:args}}{{#field:type}}
{{^type:resolves_to_complex_return?}}
args.get<{{field:index}}>().value = &p_{{field:cpp_name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ folly::exception_wrapper {{> service_common/client_class_name}}::recv_wrapped_{{
return folly::make_exception_wrapper<apache::thrift::TApplicationException>("recv_ called without result");
}

using result = {{> common/namespace_cpp2}}{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_presult;
using result = ::{{service:qualified_namespace}}::{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_presult;
{{#function:sink?}}
{{^function:sink_exceptions?}}
using ExMapType = apache::thrift::detail::ap::EmptyExMapType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ apache::thrift::ServiceRequestInfoMap {{service:cpp_name}}ServiceInfoHolder::sta
{{/function:return_type}}{{/service:functions}}{{/service:interactions}}
};
{{#service:extends}}
apache::thrift::ServiceRequestInfoMap parentMap = {{> common/namespace_cpp2}}{{service:cpp_name}}ServiceInfoHolder::staticRequestInfoMap();
apache::thrift::ServiceRequestInfoMap parentMap = ::{{service:qualified_namespace}}::{{service:cpp_name}}ServiceInfoHolder::staticRequestInfoMap();
requestInfoMap.insert(std::begin(parentMap), std::end(parentMap));
{{/service:extends}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class {{service:cpp_name}};
namespace apache::thrift {
template <>
class Client<{{service:qualified_name}}> : public {{#service:extends}}{{> common/namespace_cpp2}}{{service:cpp_name}}AsyncClient{{/service:extends}}{{^service:extends}}apache::thrift::GeneratedAsyncClient{{/service:extends}} {
class Client<{{service:qualified_name}}> : public {{#service:extends}}::{{service:qualified_namespace}}::{{service:cpp_name}}AsyncClient{{/service:extends}}{{^service:extends}}apache::thrift::GeneratedAsyncClient{{/service:extends}} {
public:
using {{#service:extends}}{{> common/namespace_cpp2}}{{service:cpp_name}}AsyncClient::{{service:cpp_name}}AsyncClient{{/service:extends}}{{^service:extends}}apache::thrift::GeneratedAsyncClient::GeneratedAsyncClient{{/service:extends}};
using {{#service:extends}}::{{service:qualified_namespace}}::{{service:cpp_name}}AsyncClient::{{service:cpp_name}}AsyncClient{{/service:extends}}{{^service:extends}}apache::thrift::GeneratedAsyncClient::GeneratedAsyncClient{{/service:extends}};

char const* getServiceName() const noexcept override {
return "{{service:parent_service_name}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
See the License for the specific language governing permissions and
limitations under the License.
}}class {{service:cpp_name}}AsyncProcessor : public {{#service:extends}}{{> common/namespace_cpp2}}{{service:cpp_name}}AsyncProcessor{{/service:extends}}{{^service:extends}}::apache::thrift::GeneratedAsyncProcessorBase{{/service:extends}} {
}}class {{service:cpp_name}}AsyncProcessor : public {{#service:extends}}::{{service:qualified_namespace}}::{{service:cpp_name}}AsyncProcessor{{/service:extends}}{{^service:extends}}::apache::thrift::GeneratedAsyncProcessorBase{{/service:extends}} {
public:
const char* getServiceName() override;
void getServiceMetadata(apache::thrift::metadata::ThriftServiceMetadataResponse& response) override;
{{#service:extends}}
using BaseAsyncProcessor = {{> common/namespace_cpp2}}{{service:cpp_name}}AsyncProcessor;
using BaseAsyncProcessor = ::{{service:qualified_namespace}}::{{service:cpp_name}}AsyncProcessor;
{{/service:extends}}
{{^service:extends}}
using BaseAsyncProcessor = void;
Expand Down Expand Up @@ -56,7 +56,7 @@
public:
{{service:cpp_name}}AsyncProcessor(::apache::thrift::ServiceHandler<{{service:qualified_name}}>* iface) :
{{#service:extends}}
{{> common/namespace_cpp2}}{{service:cpp_name}}AsyncProcessor(iface),
::{{service:qualified_namespace}}::{{service:cpp_name}}AsyncProcessor(iface),
{{/service:extends}}
iface_(iface) {}
~{{service:cpp_name}}AsyncProcessor() override {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class {{service:cpp_name}}AsyncProcessor;

namespace apache::thrift {
template <>
class ServiceHandler<{{service:qualified_name}}> : {{#service:extends}}virtual public {{> common/namespace_cpp2}}{{service:cpp_name}}SvIf{{/service:extends}}{{^service:extends}}public apache::thrift::ServerInterface{{/service:extends}} {
class ServiceHandler<{{service:qualified_name}}> : {{#service:extends}}virtual public ::{{service:qualified_namespace}}::{{service:cpp_name}}SvIf{{/service:extends}}{{^service:extends}}public apache::thrift::ServerInterface{{/service:extends}} {
public:
std::string_view getGeneratedName() const override { return "{{service:name}}"; }
{{#service:thrift_uri}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
}}class {{service:cpp_name}}SvNull : public ::apache::thrift::ServiceHandler<{{service:cpp_name}}>{{#service:extends}}, virtual public ::apache::thrift::ServiceHandler<{{> common/namespace_cpp2}}{{service:cpp_name}}>{{/service:extends}} {
}}class {{service:cpp_name}}SvNull : public ::apache::thrift::ServiceHandler<{{service:cpp_name}}>{{#service:extends}}, virtual public ::apache::thrift::ServiceHandler<::{{service:qualified_namespace}}::{{service:cpp_name}}>{{/service:extends}} {
public:
{{#service:functions}}{{#function:return_type}}{{^function:starts_interaction?}}{{^function:creates_interaction?}}{{^function:eb}}{{^function:stream?}}
{{> service_common/sync_function_return_type_server}} {{function:cpp_name}}({{> service_common/sync_function_return_param_server}}{{> service_common/function_param_list_server_commented_out}}) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ std::pair<apache::thrift::SerializedResponse, apache::thrift::detail::SinkConsum
return {serializeResponse("{{> common/function_name}}", &prot, ctx, result), std::move(sinkConsumerImpl)};
{{/function:sink?}}
{{^function:stream?}}{{^function:sink?}}
{{> common/namespace_cpp2}}{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_presult result;
::{{service:qualified_namespace}}::{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_presult result;
{{^type:void?}}
result.get<0>().value = const_cast<{{function:cpp_return_type}}*>(&_return);
result.setIsSet(0, true);
Expand All @@ -305,7 +305,7 @@ void {{service:parent_service_cpp_name}}AsyncProcessor::throw_wrapped_{{function
return;
}
{{#function:exceptions?}}
{{> common/namespace_cpp2}}{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_presult result;
::{{service:qualified_namespace}}::{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_presult result;
{{/function:exceptions?}}
{{#function:exceptions}}
if (ew.with_exception([&]({{#field:type}} ::{{type:qualified_namespace}}::{{type:name}}{{/field:type}}& e) {
Expand Down

0 comments on commit adbfa28

Please sign in to comment.