Skip to content

Commit d3cf241

Browse files
iahsfacebook-github-bot
authored andcommitted
Suppress docs and source ranges in bundled schema
Summary: We don't expect to use this information and it contributes ~20% of the size of the schema in the fixture Reviewed By: praihan Differential Revision: D59598493 fbshipit-source-id: a9aafee599cd8a8103a3c6213c015d4b7cbb058c
1 parent 2845c48 commit d3cf241

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

thrift/compiler/generate/t_ast_generator.cc

+7-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ type::Schema t_ast_generator::gen_schema(
253253
program_pos_index[program_id] = pos;
254254
hydrate_const(programs.emplace_back(), *schema_source.gen_schema(program));
255255
programs.back().id() = program_id;
256-
if (program.has_doc()) {
256+
if (program.has_doc() &&
257+
schema_opts.include.test(schematizer::included_data::Docs) &&
258+
schema_opts.include.test(schematizer::included_data::SourceRanges)) {
257259
programs.back().attrs()->docs()->sourceRange() =
258260
src_range(program.doc_range(), program);
259261
}
@@ -310,8 +312,10 @@ type::Schema t_ast_generator::gen_schema(
310312
positionToId<apache::thrift::type::DefinitionId>(pos);
311313
auto& def = kind_ref_fn(definitions.emplace_back()).ensure();
312314
hydrate_const(def, *schema_source.gen_schema(node));
313-
set_source_range(node, *def.attrs());
314-
set_child_source_ranges(node, def);
315+
if (schema_opts.include.test(schematizer::included_data::SourceRanges)) {
316+
set_source_range(node, *def.attrs());
317+
set_child_source_ranges(node, def);
318+
}
315319
if (ast.definitionsMap()->count(key)) {
316320
throw std::runtime_error(fmt::format(
317321
"Duplicate definition key: {}",

thrift/compiler/lib/schematizer.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class schematizer {
4040
DoubleWrites = 1, // Legacy copies of data for backcompat
4141
Annotations = 2,
4242
Docs = 4,
43+
SourceRanges = 8,
4344
};
4445

4546
struct included_data_set {

thrift/compiler/sema/standard_mutator.cc

+2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ void inject_schema_const(
407407
opts.only_root_program_ = true;
408408
opts.use_hash = true;
409409
opts.include.reset(schematizer::included_data::DoubleWrites);
410+
opts.include.reset(schematizer::included_data::Docs);
411+
opts.include.reset(schematizer::included_data::SourceRanges);
410412
std::string serialized;
411413
try {
412414
serialized = detail::pluggable_functions().call<GetSchemaTag>(

0 commit comments

Comments
 (0)