Skip to content

Commit

Permalink
Removed merged features from the edition defaults IR.
Browse files Browse the repository at this point in the history
All of this information is still available by merging fixed_features and overridable_features.  This new split will make validation easier for runtimes that need to do dynamic builds.

PiperOrigin-RevId: 624377797
  • Loading branch information
mkruskal-google authored and copybara-github committed Apr 17, 2024
1 parent 1d44d84 commit 5dcdf7a
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 526 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class FeatureSetDescriptorTest
{
// Canonical serialized form of the edition defaults, generated by embed_edition_defaults.
// TODO: Update this automatically.
private const string DefaultsBase64 = "CrEBEqsBCAEQAhgCIAMoATAC6vAEMQj+//////////8BEAEYASABKAEwATgBQAFIAVABWABlzcyMP2oAcAB4AYIBBDIwMjPy8AQxCP7//////////wEQARgBIAEoATABOAFAAUgBUAFYAGXNzIw/agBwAHgBggEEMjAyM/rwBDEI/v//////////ARABGAEgASgBMAE4AUABSAFQAVgAZc3MjD9qAHAAeAGCAQQyMDIzGOYHCrEBEqsBCAIQARgBIAIoATAB6vAEMQj9//////////8BEAEYASABKAEwATgBQAFIAVABWABlzcyMP2oAcAB4AYIBBDIwMjPy8AQxCP3//////////wEQARgBIAEoATABOAFAAUgBUAFYAGXNzIw/agBwAHgBggEEMjAyM/rwBDEI/f//////////ARABGAEgASgBMAE4AUABSAFQAVgAZc3MjD9qAHAAeAGCAQQyMDIzGOcHCsMBEr0BCAEQARgBIAIoATAB6vAENwgBEAEYASABKAEwATgBQAFIAVABWABlzcyMP2oPCAEQAR0AAMA/IgQyMDIzcAF4AYIBBDIwMjPy8AQ3CAEQARgBIAEoATABOAFAAUgBUAFYAGXNzIw/ag8IARABHQAAwD8iBDIwMjNwAXgBggEEMjAyM/rwBDcIARABGAEgASgBMAE4AUABSAFQAVgAZc3MjD9qDwgBEAEdAADAPyIEMjAyM3ABeAGCAQQyMDIzGOgHIOgHKOgH";
private const string DefaultsBase64 =
"ChMY5gciDAgBEAIYAiADKAEwAioAChMY5wciDAgCEAEYASACKAEwASoAChMY6AciDAgBEAEYASACKAEwASoAIOYHKOgH";

[Test]
[TestCase(Edition.Proto2)]
Expand All @@ -29,7 +30,11 @@ public void DefaultsMatchCanonicalSerializedForm(Edition edition)
var canonicalDefaults = FeatureSetDefaults.Parser
.WithDiscardUnknownFields(true) // Discard language-specific extensions.
.ParseFrom(Convert.FromBase64String(DefaultsBase64));
var canonicalEditionDefaults = canonicalDefaults.Defaults.Single(def => def.Edition == edition).Features;
var canonicalEditionDefaults = new FeatureSet();
canonicalEditionDefaults.MergeFrom(
canonicalDefaults.Defaults.Single(def => def.Edition == edition).FixedFeatures);
canonicalEditionDefaults.MergeFrom(
canonicalDefaults.Defaults.Single(def => def.Edition == edition).OverridableFeatures);
var candidateEditionDefaults = FeatureSetDescriptor.GetEditionDefaults(edition).Proto;

Assert.AreEqual(canonicalEditionDefaults, candidateEditionDefaults);
Expand Down
24 changes: 0 additions & 24 deletions src/google/protobuf/compiler/code_generator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,6 @@ TEST_F(CodeGeneratorTest, BuildFeatureSetDefaults) {
EXPECT_THAT(generator.BuildFeatureSetDefaults(),
IsOkAndHolds(EqualsProto(R"pb(
defaults {
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
edition: EDITION_PROTO2
overridable_features {}
fixed_features {
Expand All @@ -291,14 +283,6 @@ TEST_F(CodeGeneratorTest, BuildFeatureSetDefaults) {
}
}
defaults {
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_PROTO3
overridable_features {}
fixed_features {
Expand All @@ -311,14 +295,6 @@ TEST_F(CodeGeneratorTest, BuildFeatureSetDefaults) {
}
}
defaults {
features {
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_2023
overridable_features {
field_presence: EXPLICIT
Expand Down
72 changes: 0 additions & 72 deletions src/google/protobuf/compiler/command_line_interface_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1865,14 +1865,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaults) {
FeatureSetDefaults defaults = ReadEditionDefaults("defaults");
EXPECT_THAT(defaults, EqualsProto(R"pb(
defaults {
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
edition: EDITION_PROTO2
overridable_features {}
fixed_features {
Expand All @@ -1885,14 +1877,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaults) {
}
}
defaults {
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_PROTO3
overridable_features {}
fixed_features {
Expand All @@ -1905,14 +1889,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaults) {
}
}
defaults {
features {
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_2023
overridable_features {
field_presence: EXPLICIT
Expand Down Expand Up @@ -1941,14 +1917,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMaximum) {
FeatureSetDefaults defaults = ReadEditionDefaults("defaults");
EXPECT_THAT(defaults, EqualsProto(R"pb(
defaults {
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
edition: EDITION_PROTO2
overridable_features {}
fixed_features {
Expand All @@ -1961,14 +1929,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMaximum) {
}
}
defaults {
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_PROTO3
overridable_features {}
fixed_features {
Expand All @@ -1981,14 +1941,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMaximum) {
}
}
defaults {
features {
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_2023
overridable_features {
field_presence: EXPLICIT
Expand Down Expand Up @@ -2018,14 +1970,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMinimum) {
FeatureSetDefaults defaults = ReadEditionDefaults("defaults");
EXPECT_THAT(defaults, EqualsProto(R"pb(
defaults {
features {
field_presence: EXPLICIT
enum_type: CLOSED
repeated_field_encoding: EXPANDED
utf8_validation: NONE
message_encoding: LENGTH_PREFIXED
json_format: LEGACY_BEST_EFFORT
}
edition: EDITION_PROTO2
overridable_features {}
fixed_features {
Expand All @@ -2038,14 +1982,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMinimum) {
}
}
defaults {
features {
field_presence: IMPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_PROTO3
overridable_features {}
fixed_features {
Expand All @@ -2058,14 +1994,6 @@ TEST_F(CommandLineInterfaceTest, EditionDefaultsWithMinimum) {
}
}
defaults {
features {
field_presence: EXPLICIT
enum_type: OPEN
repeated_field_encoding: PACKED
utf8_validation: VERIFY
message_encoding: LENGTH_PREFIXED
json_format: ALLOW
}
edition: EDITION_2023
overridable_features {
field_presence: EXPLICIT
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/cpp_edition_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the C++ runtime. This is used for feature resolution under Editions.
// NOLINTBEGIN
// clang-format off
#define PROTOBUF_INTERNAL_CPP_EDITION_DEFAULTS "\n2\022\023\010\001\020\002\030\002 \003(\0010\002\302>\004\010\001\020\003\030\346\007\"\003\302>\000*\023\010\001\020\002\030\002 \003(\0010\002\302>\004\010\001\020\003\n2\022\023\010\002\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003\030\347\007\"\003\302>\000*\023\010\002\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003\n2\022\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003\030\350\007\"\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003*\003\302>\000\n2\022\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\001\030\351\007\"\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\001*\003\302>\000 \346\007(\351\007"
#define PROTOBUF_INTERNAL_CPP_EDITION_DEFAULTS "\n\035\030\346\007\"\003\302>\000*\023\010\001\020\002\030\002 \003(\0010\002\302>\004\010\001\020\003\n\035\030\347\007\"\003\302>\000*\023\010\002\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003\n\035\030\350\007\"\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\003*\003\302>\000\n\035\030\351\007\"\023\010\001\020\001\030\001 \002(\0010\001\302>\004\010\000\020\001*\003\302>\000 \346\007(\351\007"
// clang-format on
// NOLINTEND

Expand Down
5 changes: 3 additions & 2 deletions src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9523,10 +9523,11 @@ void FieldDescriptor::InternalTypeOnceInit() const {
Symbol result = file()->pool()->CrossLinkOnDemandHelper(
lazy_type_name, type_ == FieldDescriptor::TYPE_ENUM);
if (result.type() == Symbol::MESSAGE) {
type_ = FieldDescriptor::TYPE_MESSAGE;
ABSL_CHECK(type_ == FieldDescriptor::TYPE_MESSAGE ||
type_ == FieldDescriptor::TYPE_GROUP);
type_descriptor_.message_type = result.descriptor();
} else if (result.type() == Symbol::ENUM) {
type_ = FieldDescriptor::TYPE_ENUM;
ABSL_CHECK(type_ == FieldDescriptor::TYPE_ENUM);
enum_type = type_descriptor_.enum_type = result.enum_descriptor();
}

Expand Down
Loading

0 comments on commit 5dcdf7a

Please sign in to comment.