Skip to content

Commit

Permalink
Remove namespace_cpp2 and related machinery
Browse files Browse the repository at this point in the history
Summary:
This diff removes the hacks in C++ (`get_namespace_array_deprecated`).

There is certainly more room for improvement, which will come in future diffs.

Reviewed By: iahs

Differential Revision: D67636660

fbshipit-source-id: 53ce12b130f5aec50d67038265a850ec5baabe9d
  • Loading branch information
praihan authored and facebook-github-bot committed Dec 27, 2024
1 parent 8012ba2 commit c9d660b
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 204 deletions.
36 changes: 6 additions & 30 deletions thrift/compiler/generate/t_mstch_cpp2_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ class t_mstch_cpp2_generator : public t_mstch_generator {
opts.allowed_undefined_variables = {
"program:autogen_path",
"service:autogen_path",
"program:namespace_cpp2",
"service:namespace_cpp2",
"program:qualified_namespace",
"service:qualified_namespace",
"field:fatal_annotations?",
"value:enable_referencing?",
};
Expand All @@ -297,7 +297,6 @@ class t_mstch_cpp2_generator : public t_mstch_generator {
void fill_validator_visitors(ast_validator&) const override;
static std::string get_cpp2_namespace(const t_program* program);
static std::string get_cpp2_unprefixed_namespace(const t_program* program);
static mstch::array get_namespace_array(const t_program* program);
static mstch::array cpp_includes(const t_program* program);
static mstch::node include_prefix(
const t_program* program, std::map<std::string, std::string>& options);
Expand Down Expand Up @@ -347,7 +346,6 @@ class cpp_mstch_program : public mstch_program {
{{"program:cpp_includes", &cpp_mstch_program::cpp_includes},
{"program:qualified_namespace",
&cpp_mstch_program::qualified_namespace},
{"program:namespace_cpp2", &cpp_mstch_program::namespace_cpp2},
{"program:include_prefix", &cpp_mstch_program::include_prefix},
{"program:cpp_declare_hash?", &cpp_mstch_program::cpp_declare_hash},
{"program:thrift_includes", &cpp_mstch_program::thrift_includes},
Expand Down Expand Up @@ -465,9 +463,6 @@ class cpp_mstch_program : public mstch_program {
mstch::node qualified_namespace() {
return t_mstch_cpp2_generator::get_cpp2_unprefixed_namespace(program_);
}
mstch::node namespace_cpp2() {
return t_mstch_cpp2_generator::get_namespace_array(program_);
}
mstch::node cpp_includes() {
mstch::array includes = t_mstch_cpp2_generator::cpp_includes(program_);
auto it = context_.options.find("includes");
Expand Down Expand Up @@ -815,7 +810,6 @@ class cpp_mstch_service : public mstch_service {
{"service:thrift_includes", &cpp_mstch_service::thrift_includes},
{"service:qualified_namespace",
&cpp_mstch_service::qualified_namespace},
{"service:namespace_cpp2", &cpp_mstch_service::namespace_cpp2},
{"service:oneway_functions", &cpp_mstch_service::oneway_functions},
{"service:oneways?", &cpp_mstch_service::has_oneway},
{"service:cpp_includes", &cpp_mstch_service::cpp_includes},
Expand Down Expand Up @@ -871,9 +865,6 @@ class cpp_mstch_service : public mstch_service {
return t_mstch_cpp2_generator::get_cpp2_unprefixed_namespace(
service_->program());
}
mstch::node namespace_cpp2() {
return t_mstch_cpp2_generator::get_namespace_array(service_->program());
}
mstch::node oneway_functions() {
std::vector<const t_function*> oneway_functions;
for (const auto* function : get_functions()) {
Expand Down Expand Up @@ -1099,7 +1090,7 @@ class cpp_mstch_type : public mstch_type {
{"type:cpp_template", &cpp_mstch_type::cpp_template},
{"type:cpp_indirection?", &cpp_mstch_type::cpp_indirection},
{"type:non_empty_struct?", &cpp_mstch_type::is_non_empty_struct},
{"type:namespace_cpp2", &cpp_mstch_type::namespace_cpp2},
{"type:qualified_namespace", &cpp_mstch_type::qualified_namespace},
{"type:cpp_declare_hash", &cpp_mstch_type::cpp_declare_hash},
{"type:cpp_declare_equal_to",
&cpp_mstch_type::cpp_declare_equal_to},
Expand Down Expand Up @@ -1215,8 +1206,9 @@ class cpp_mstch_type : public mstch_type {
auto as_struct = dynamic_cast<const t_struct*>(resolved_type_);
return as_struct && as_struct->has_fields();
}
mstch::node namespace_cpp2() {
return t_mstch_cpp2_generator::get_namespace_array(type_->program());
mstch::node qualified_namespace() {
return t_mstch_cpp2_generator::get_cpp2_unprefixed_namespace(
type_->program());
}
mstch::node type_class() { return cpp2::get_gen_type_class(*resolved_type_); }
mstch::node type_tag() {
Expand Down Expand Up @@ -2727,22 +2719,6 @@ std::string t_mstch_cpp2_generator::get_cpp2_namespace(
return cpp2::get_gen_unprefixed_namespace(*program);
}

mstch::array t_mstch_cpp2_generator::get_namespace_array(
const t_program* program) {
const auto v = cpp2::get_gen_namespace_components(*program);
mstch::array a;
for (auto it = v.begin(); it != v.end(); ++it) {
mstch::map m;
m.emplace("namespace:name", *it);
a.push_back(m);
}
for (auto itr = a.begin(); itr != a.end(); ++itr) {
std::get<mstch::map>(*itr).emplace("first?", itr == a.begin());
std::get<mstch::map>(*itr).emplace("last?", std::next(itr) == a.end());
}
return a;
}

mstch::array t_mstch_cpp2_generator::cpp_includes(const t_program* program) {
mstch::array a;
if (program->language_includes().count("cpp")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Base Constant Values
}}{{#value:string?}}"{{value:string_value}}"{{/value:string?}}{{!
}}{{#value:enum?}}{{!
}}{{#value:enum_value?}}{{> common/type_namespace_cpp2}}{{type:cpp_name}}::{{value:enum_value_cpp_name}}{{/value:enum_value?}}{{!
}}{{^value:enum_value?}}static_cast<{{> common/type_namespace_cpp2}}{{type:cpp_name}}>({{value:integer_value}}){{/value:enum_value?}}{{!
}}{{#value:enum_value?}} ::{{type:qualified_namespace}}::{{type:cpp_name}}::{{value:enum_value_cpp_name}}{{/value:enum_value?}}{{!
}}{{^value:enum_value?}}static_cast< ::{{type:qualified_namespace}}::{{type:cpp_name}}>({{value:integer_value}}){{/value:enum_value?}}{{!
}}{{/value:enum?}}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Reference other constants:
}}{{#value:referenceable?}}{{!
}}{{#value:owning_const}}{{!
}}{{#constant:program}}{{!
}}{{#program:namespace_cpp2}}::{{namespace:name}}{{#last?}}::{{/last?}}{{/program:namespace_cpp2}}{{program:name}}_constants::{{constant:name}}(){{!
}}::{{program:qualified_namespace}}::{{program:name}}_constants::{{constant:name}}(){{!
}}{{/constant:program}}{{!
}}{{/value:owning_const}}{{!
}}{{/value:referenceable?}}{{!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@
See the License for the specific language governing permissions and
limitations under the License.
}}::{{#program:namespace_cpp2}}{{namespace:name}}{{^last?}}::{{/last?}}{{/program:namespace_cpp2}}{{> common/service_namespace_cpp2}}::
}}
{{#pragma single-line}}
::
{{#if program:qualified_namespace}}
{{program:qualified_namespace}}
{{/if program:qualified_namespace}}

{{#if service:qualified_namespace}}
{{service:qualified_namespace}}
{{/if service:qualified_namespace}}
::

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
{{/program:thrift_includes}}

{{#program:services}}
{{> common/service_namespace_cpp2_begin }}
namespace {{service:qualified_namespace}} {
class {{service:cpp_name}};
{{> common/service_namespace_cpp2_end }}
} // namespace {{service:qualified_namespace}}
{{/program:services}}

namespace apache {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ folly::exception_wrapper {{> service_common/client_class_name}}::recv_wrapped_{{
struct ExMapType {
bool operator()(typename result::SinkPResultType& res, folly::exception_wrapper ew) {
{{#function:sink_exceptions}}
if (ew.with_exception([&]({{#field:type}}{{> common/type_namespace_cpp2}}{{type:name}}{{/field:type}}& e) {
if (ew.with_exception([&]({{#field:type}} ::{{type:qualified_namespace}}::{{type:name}}{{/field:type}}& e) {
res.get<{{field:index_plus_one}}>().ref() = e;
res.setIsSet({{field:index_plus_one}}, true);
})) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::optional<apache::thrift::schema::DefinitionsSchema> {{> service_common/serv
{{#program}}
{{#program:has_schema?}}
std::optional<apache::thrift::schema::DefinitionsSchema> ret = schema::DefinitionsSchema{};
ret->schema = ::apache::thrift::SchemaRegistry::mergeSchemas(::{{> common/service_namespace_cpp2}}::{{program:name}}_constants::{{program:schema_name}}_includes());
ret->schema = ::apache::thrift::SchemaRegistry::mergeSchemas(::{{service:qualified_namespace}}::{{program:name}}_constants::{{program:schema_name}}_includes());
ret->definitions = {"{{service:definition_key}}"};
return ret;
{{/program:has_schema?}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ std::pair<apache::thrift::SerializedResponse, apache::thrift::detail::SinkConsum
struct ExMapType {
bool operator()(StreamPResultType& res, folly::exception_wrapper ew) {
{{#function:stream_exceptions}}
if (ew.with_exception([&]({{#field:type}}{{> common/type_namespace_cpp2}}{{type:name}}{{/field:type}}& e) {
if (ew.with_exception([&]({{#field:type}} ::{{type:qualified_namespace}}::{{type:name}}{{/field:type}}& e) {
res.get<{{field:index_plus_one}}>().ref() = e;
res.setIsSet({{field:index_plus_one}}, true);
})) {
Expand Down Expand Up @@ -261,7 +261,7 @@ std::pair<apache::thrift::SerializedResponse, apache::thrift::detail::SinkConsum
struct ExMapType {
bool operator()(FinalResponsePResultType& res, folly::exception_wrapper ew) {
{{#function:sink_final_response_exceptions}}
if (ew.with_exception([&]({{#field:type}}{{> common/type_namespace_cpp2}}{{type:name}}{{/field:type}}& e) {
if (ew.with_exception([&]({{#field:type}} ::{{type:qualified_namespace}}::{{type:name}}{{/field:type}}& e) {
res.get<{{field:index_plus_one}}>().ref() = e;
res.setIsSet({{field:index_plus_one}}, true);
})) {
Expand Down Expand Up @@ -308,12 +308,12 @@ void {{service:parent_service_cpp_name}}AsyncProcessor::throw_wrapped_{{function
{{> common/namespace_cpp2}}{{service:parent_service_cpp_name}}_{{function:prefixed_name}}_presult result;
{{/function:exceptions?}}
{{#function:exceptions}}
if (ew.with_exception([&]({{#field:type}}{{> common/type_namespace_cpp2}}{{type:name}}{{/field:type}}& e) {
if (ew.with_exception([&]({{#field:type}} ::{{type:qualified_namespace}}::{{type:name}}{{/field:type}}& e) {
if (ctx) {
ctx->userExceptionWrapped(true, ew);
}
::apache::thrift::util::appendExceptionToHeader(ew, *reqCtx);
::apache::thrift::util::appendErrorClassificationToHeader<{{#field:type}}{{> common/type_namespace_cpp2}}{{type:name}}{{/field:type}}>(ew, *reqCtx);
::apache::thrift::util::appendErrorClassificationToHeader<{{#field:type}} ::{{type:qualified_namespace}}::{{type:name}}{{/field:type}}>(ew, *reqCtx);
{{#function:cpp_void?}}
result.get<{{field:index}}>().ref() = e;
result.setIsSet({{field:index}}, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@
#include <thrift/lib/cpp2/gen/module_metadata_h.h>
#include "thrift/compiler/test/fixtures/adapter/gen-cpp2/module_types.h"

namespace facebook {
namespace thrift {
namespace test {
namespace facebook::thrift::test {
class Service;
}}} // namespace facebook::thrift::test
namespace facebook {
namespace thrift {
namespace test {
} // namespace facebook::thrift::test
namespace facebook::thrift::test {
class AdapterService;
}}} // namespace facebook::thrift::test
} // namespace facebook::thrift::test

namespace apache {
namespace thrift {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#include "thrift/compiler/test/fixtures/basic-structured-annotations/gen-cpp2/included_metadata.h"
#include "thrift/compiler/test/fixtures/basic-structured-annotations/gen-cpp2/namespaced_metadata.h"

namespace test {
namespace fixtures {
namespace basic-structured-annotations {
namespace test::fixtures::basic-structured-annotations {
class MyService;
}}} // namespace test::fixtures::basic-structured-annotations
} // namespace test::fixtures::basic-structured-annotations

namespace apache {
namespace thrift {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,18 @@
#include <thrift/lib/cpp2/gen/module_metadata_h.h>
#include "thrift/compiler/test/fixtures/basic/gen-cpp2/module_types.h"

namespace test {
namespace fixtures {
namespace basic {
namespace test::fixtures::basic {
class FooService;
}}} // namespace test::fixtures::basic
namespace test {
namespace fixtures {
namespace basic {
} // namespace test::fixtures::basic
namespace test::fixtures::basic {
class FB303Service;
}}} // namespace test::fixtures::basic
namespace test {
namespace fixtures {
namespace basic {
} // namespace test::fixtures::basic
namespace test::fixtures::basic {
class MyService;
}}} // namespace test::fixtures::basic
namespace test {
namespace fixtures {
namespace basic {
} // namespace test::fixtures::basic
namespace test::fixtures::basic {
class DbMixedStackArguments;
}}} // namespace test::fixtures::basic
} // namespace test::fixtures::basic

namespace apache {
namespace thrift {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@
#include "thrift/compiler/test/fixtures/fatal/gen-cpp2/reflection_dep_B_metadata.h"
#include "thrift/compiler/test/fixtures/fatal/gen-cpp2/reflection_dep_C_metadata.h"

namespace test_cpp2 {
namespace cpp_reflection {
namespace test_cpp2::cpp_reflection {
class service1;
}} // namespace test_cpp2::cpp_reflection
namespace test_cpp2 {
namespace cpp_reflection {
} // namespace test_cpp2::cpp_reflection
namespace test_cpp2::cpp_reflection {
class service2;
}} // namespace test_cpp2::cpp_reflection
namespace test_cpp2 {
namespace cpp_reflection {
} // namespace test_cpp2::cpp_reflection
namespace test_cpp2::cpp_reflection {
class service3;
}} // namespace test_cpp2::cpp_reflection
namespace test_cpp2 {
namespace cpp_reflection {
} // namespace test_cpp2::cpp_reflection
namespace test_cpp2::cpp_reflection {
class service_with_special_names;
}} // namespace test_cpp2::cpp_reflection
} // namespace test_cpp2::cpp_reflection

namespace apache {
namespace thrift {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
#include <thrift/lib/cpp2/gen/module_metadata_h.h>
#include "thrift/compiler/test/fixtures/interactions/gen-cpp2/shared_types.h"

namespace thrift {
namespace shared_interactions {
namespace thrift::shared_interactions {
class InteractLocally;
}} // namespace thrift::shared_interactions
} // namespace thrift::shared_interactions

namespace apache {
namespace thrift {
Expand Down
Loading

0 comments on commit c9d660b

Please sign in to comment.