From c9a3b660c52bb0c856aaad2ee8f1753167b3398d Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Thu, 18 Jun 2026 17:26:21 -0700 Subject: [PATCH] When generating YAML from config, skip overload_id if identical to signature PiperOrigin-RevId: 934628038 --- env/env_yaml.cc | 21 +++++++++++++------ env/env_yaml_test.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/env/env_yaml.cc b/env/env_yaml.cc index e7b8a7885..d5e3ad059 100644 --- a/env/env_yaml.cc +++ b/env/env_yaml.cc @@ -725,6 +725,9 @@ absl::StatusOr ParseFunctionOverloadConfig( function_name, "\"")); } overload_config.is_member_function = parsed_signature.is_member; + if (overload_config.overload_id.empty()) { + overload_config.overload_id = signature; + } if (!parsed_signature.signature_type.has_function()) { return absl::InternalError(absl::StrCat( "Function overload signature has no function type: ", signature)); @@ -1101,11 +1104,8 @@ void EmitFunctionOverloadConfig( const Config::FunctionOverloadConfig& overload_config, YAML::Emitter& out, const EnvConfigToYamlOptions& options) { out << YAML::BeginMap; - if (!overload_config.overload_id.empty()) { - out << YAML::Key << "id"; - out << YAML::Value << YAML::DoubleQuoted << overload_config.overload_id; - } bool signature_generated = false; + std::string signature_str; if (options.use_type_signatures) { bool param_type_spec_generated = true; std::vector params; @@ -1123,12 +1123,21 @@ void EmitFunctionOverloadConfig( common_internal::MakeOverloadSignature( function_name, params, overload_config.is_member_function); if (signature.ok()) { - out << YAML::Key << "signature"; - out << YAML::Value << YAML::DoubleQuoted << *signature; + signature_str = std::move(*signature); signature_generated = true; } } } + if (!overload_config.overload_id.empty()) { + if (!signature_generated || overload_config.overload_id != signature_str) { + out << YAML::Key << "id"; + out << YAML::Value << YAML::DoubleQuoted << overload_config.overload_id; + } + } + if (signature_generated) { + out << YAML::Key << "signature"; + out << YAML::Value << YAML::DoubleQuoted << signature_str; + } if (!signature_generated) { if (overload_config.is_member_function) { out << YAML::Key << "target" << YAML::Value; diff --git a/env/env_yaml_test.cc b/env/env_yaml_test.cc index 38f08e371..c5bd1b787 100644 --- a/env/env_yaml_test.cc +++ b/env/env_yaml_test.cc @@ -545,12 +545,15 @@ std::vector GetParseFunctionTestCases() { .overload_configs = { Config::FunctionOverloadConfig{ + .overload_id = + "google.protobuf.StringValue.isEmpty()", .examples = {"''.isEmpty() // true"}, .is_member_function = true, .parameters = {{.name = "string_wrapper"}}, .return_type = {.name = "bool"}, }, Config::FunctionOverloadConfig{ + .overload_id = "list<~T>.isEmpty()", .examples = {"[].isEmpty() // true", "[1].isEmpty() // false"}, .is_member_function = true, @@ -635,6 +638,7 @@ std::vector GetParseFunctionTestCases() { .overload_configs = { Config::FunctionOverloadConfig{ + .overload_id = "contains(list<~T>, ~T)", .examples = {"contains([1, 2, 3], 2) // true"}, .is_member_function = false, .parameters = @@ -1740,6 +1744,45 @@ std::vector GetExportTestCases() { - type_name: "int" )yaml", }, + ExportTestCase{ + .config = []() -> absl::StatusOr { + Config config; + CEL_RETURN_IF_ERROR(config.AddFunctionConfig( + {.name = "foo", + .overload_configs = { + {.overload_id = "timestamp.foo(A<~B>)", + .is_member_function = true, + .parameters = {{.name = "timestamp"}, + {.name = "A", + .params = {{.name = "B", + .is_type_param = true}}}}, + .return_type = {.name = "int"}}, + }})); + return config; + }(), + .expected_yaml = R"yaml( + functions: + - name: "foo" + overloads: + - signature: "timestamp.foo(A<~B>)" + return: "int" + )yaml", + .expected_alt_yaml = R"yaml( + functions: + - name: "foo" + overloads: + - id: "timestamp.foo(A<~B>)" + target: + type_name: "timestamp" + args: + - type_name: "A" + params: + - type_name: "B" + is_type_param: true + return: + type_name: "int" + )yaml", + }, }; }; @@ -1888,6 +1931,13 @@ std::vector GetSignatureRoundTripTestCases() { signature: "foo(timestamp,A<~B>)" return: "list" )yaml", + R"yaml( + functions: + - name: "foo" + overloads: + - signature: "timestamp.foo(A<~B>)" + return: "int" + )yaml", }; }