Skip to content

Commit

Permalink
Remove PROTOBUF_FUTURE_EDITIONS guards.
Browse files Browse the repository at this point in the history
This is just cruft used for selectively rolling out the editions changes.  Since it's not tested, it would be dangerous to keep it in place.

PiperOrigin-RevId: 547979600
  • Loading branch information
mkruskal-google authored and copybara-github committed Jul 14, 2023
1 parent f254501 commit 6098c02
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 338 deletions.
3 changes: 0 additions & 3 deletions src/google/protobuf/compiler/code_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class PROTOC_EXPORT CodeGenerator {
// method can be removed.
virtual bool HasGenerateAll() const { return true; }

#ifdef PROTOBUF_FUTURE_EDITIONS

protected:
// Retrieves the resolved source features for a given descriptor. These
// should be used to make any feature-based decisions during code generation.
Expand All @@ -157,7 +155,6 @@ class PROTOC_EXPORT CodeGenerator {
StripSourceRetentionOptions(*file.pool(), proto);
return proto;
}
#endif // PROTOBUF_FUTURE_EDITIONS
};

// CodeGenerators generate one or more files in a given directory. This
Expand Down
8 changes: 0 additions & 8 deletions src/google/protobuf/compiler/command_line_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,6 @@ bool CommandLineInterface::ParseInputFiles(
}
parsed_files->push_back(parsed_file);

#ifdef PROTOBUF_FUTURE_EDITIONS
if (!experimental_editions_ && !IsEarlyEditionsFile(parsed_file->name())) {
if (FileDescriptorLegacy(parsed_file).syntax() ==
FileDescriptorLegacy::Syntax::SYNTAX_EDITIONS) {
Expand All @@ -1568,7 +1567,6 @@ bool CommandLineInterface::ParseInputFiles(
break;
}
}
#endif // PROTOBUF_FUTURE_EDITIONS

// Enforce --disallow_services.
if (disallow_services_ && parsed_file->service_count() > 0) {
Expand Down Expand Up @@ -1619,9 +1617,7 @@ void CommandLineInterface::Clear() {
descriptor_set_out_name_.clear();
dependency_out_name_.clear();

#ifdef PROTOBUF_FUTURE_EDITIONS
experimental_editions_ = false;
#endif // PROTOBUF_FUTURE_EDITIONS

mode_ = MODE_COMPILE;
print_mode_ = PRINT_NONE;
Expand Down Expand Up @@ -1940,9 +1936,7 @@ bool CommandLineInterface::ParseArgument(const char* arg, std::string* name,
*name == "--include_imports" || *name == "--include_source_info" ||
*name == "--retain_options" || *name == "--version" ||
*name == "--decode_raw" ||
#ifdef PROTOBUF_FUTURE_EDITIONS
*name == "--experimental_editions" ||
#endif // PROTOBUF_FUTURE_EDITIONS
*name == "--print_free_field_numbers" ||
*name == "--experimental_allow_proto3_optional" ||
*name == "--deterministic_output" || *name == "--fatal_warnings") {
Expand Down Expand Up @@ -2269,14 +2263,12 @@ CommandLineInterface::InterpretArgument(const std::string& name,
#else
::setenv(io::Printer::kProtocCodegenTrace.data(), "yes", 0);
#endif
#ifdef PROTOBUF_FUTURE_EDITIONS
} else if (name == "--experimental_editions") {
// If you're reading this, you're probably wondering what
// --experimental_editions is for and thinking of turning it on. This is an
// experimental, undocumented, unsupported flag. Enable it at your own risk
// (or, just don't!).
experimental_editions_ = true;
#endif // PROTOBUF_FUTURE_EDITIONS
} else {
// Some other flag. Look it up in the generators list.
const GeneratorInfo* generator_info = FindGeneratorByFlag(name);
Expand Down
2 changes: 0 additions & 2 deletions src/google/protobuf/compiler/command_line_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,7 @@ class PROTOC_EXPORT CommandLineInterface {
// dependency file will be written. Otherwise, empty.
std::string dependency_out_name_;

#ifdef PROTOBUF_FUTURE_EDITIONS
bool experimental_editions_ = false;
#endif // PROTOBUF_FUTURE_EDITIONS

// True if --include_imports was given, meaning that we should
// write all transitive dependencies to the DescriptorSet. Otherwise, only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,6 @@ TEST_F(CommandLineInterfaceTest, AllowServicesHasService) {
ExpectGenerated("test_generator", "", "foo.proto", "Foo");
}

#ifdef PROTOBUF_FUTURE_EDITIONS

TEST_F(CommandLineInterfaceTest, EditionsAreNotAllowed) {
CreateTempFile("foo.proto",
"edition = \"very-cool\";\n"
Expand Down Expand Up @@ -1678,8 +1676,6 @@ TEST_F(CommandLineInterfaceTest, PluginNoEditionsSupport) {
"code generator prefix-gen-plug hasn't been updated to support editions");
}

#endif // PROTOBUF_FUTURE_EDITIONS


TEST_F(CommandLineInterfaceTest, DirectDependencies_Missing_EmptyList) {
CreateTempFile("foo.proto",
Expand Down
6 changes: 1 addition & 5 deletions src/google/protobuf/compiler/cpp/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@
#include "absl/strings/string_view.h"
#include "google/protobuf/compiler/cpp/file.h"
#include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/cpp_features.pb.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/descriptor_visitor.h"

#ifdef PROTOBUF_FUTURE_EDITIONS
#include "google/protobuf/cpp_features.pb.h"
#endif // PROTOBUF_FUTURE_EDITIONS

namespace google {
namespace protobuf {
Expand Down Expand Up @@ -367,7 +365,6 @@ bool CppGenerator::Generate(const FileDescriptor* file,

absl::Status CppGenerator::ValidateFeatures(const FileDescriptor* file) const {
absl::Status status = absl::OkStatus();
#ifdef PROTOBUF_FUTURE_EDITIONS
google::protobuf::internal::VisitDescriptors(*file, [&](const FieldDescriptor& field) {
const FeatureSet& source_features = GetSourceFeatures(field);
const FeatureSet& raw_features = GetSourceRawFeatures(field);
Expand All @@ -385,7 +382,6 @@ absl::Status CppGenerator::ValidateFeatures(const FileDescriptor* file) const {
" has a closed enum type with implicit presence."));
}
});
#endif // PROTOBUF_FUTURE_EDITIONS
return status;
}

Expand Down
6 changes: 0 additions & 6 deletions src/google/protobuf/compiler/cpp/generator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
#include "google/protobuf/descriptor.pb.h"
#include <gtest/gtest.h>
#include "google/protobuf/compiler/command_line_interface_tester.h"
#ifdef PROTOBUF_FUTURE_EDITIONS
#include "google/protobuf/cpp_features.pb.h"
#endif // PROTOBUF_FUTURE_EDITIONS

namespace google {
namespace protobuf {
Expand All @@ -55,10 +53,8 @@ class CppGeneratorTest : public CommandLineInterfaceTester {
CreateTempFile(
"google/protobuf/descriptor.proto",
google::protobuf::DescriptorProto::descriptor()->file()->DebugString());
#ifdef PROTOBUF_FUTURE_EDITIONS
CreateTempFile("google/protobuf/cpp_features.proto",
pb::CppFeatures::descriptor()->file()->DebugString());
#endif // PROTOBUF_FUTURE_EDITIONS
}
};

Expand Down Expand Up @@ -91,7 +87,6 @@ TEST_F(CppGeneratorTest, BasicError) {
"foo.proto:4:7: Expected \"required\", \"optional\", or \"repeated\"");
}

#ifdef PROTOBUF_FUTURE_EDITIONS

TEST_F(CppGeneratorTest, LegacyClosedEnumOnNonEnumField) {
CreateTempFile("foo.proto",
Expand Down Expand Up @@ -176,7 +171,6 @@ TEST_F(CppGeneratorTest, LegacyClosedEnumImplicit) {
ExpectErrorSubstring(
"Field Foo.bar has a closed enum type with implicit presence.");
}
#endif // PROTOBUF_FUTURE_EDITIONS

} // namespace
} // namespace cpp
Expand Down
2 changes: 0 additions & 2 deletions src/google/protobuf/compiler/cpp/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1418,10 +1418,8 @@ bool GetBootstrapBasename(const Options& options, absl::string_view basename,
new absl::flat_hash_map<absl::string_view, std::string>{
{"net/proto2/proto/descriptor",
"third_party/protobuf/descriptor"},
#ifdef PROTOBUF_FUTURE_EDITIONS
{"third_party/protobuf/cpp_features",
"third_party/protobuf/cpp_features"},
#endif // PROTOBUF_FUTURE_EDITIONS
{"third_party/protobuf/compiler/plugin",
"third_party/protobuf/compiler/plugin"},
{"net/proto2/compiler/proto/profile",
Expand Down
2 changes: 0 additions & 2 deletions src/google/protobuf/compiler/objectivec/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,9 @@ void FileGenerator::EmitFileDescription(io::Printer* p) const {
case FileDescriptorLegacy::Syntax::SYNTAX_PROTO3:
syntax = "GPBFileSyntaxProto3";
break;
#ifdef PROTOBUF_FUTURE_EDITIONS
case FileDescriptorLegacy::Syntax::SYNTAX_EDITIONS:
syntax = "GPBFileSyntaxProtoEditions";
break;
#endif // PROTOBUF_FUTURE_EDITIONS
}

p->Emit({{"file_description_name", file_description_name_},
Expand Down
14 changes: 0 additions & 14 deletions src/google/protobuf/compiler/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,7 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) {
DescriptorPool::ErrorCollector::OTHER);

if (require_syntax_identifier_ || LookingAt("syntax")
#ifdef PROTOBUF_FUTURE_EDITIONS
|| LookingAt("edition")
#endif // PROTOBUF_FUTURE_EDITIONS
) {
if (!ParseSyntaxIdentifier(file, root_location)) {
// Don't attempt to parse the file if we didn't recognize the syntax
Expand All @@ -674,11 +672,9 @@ bool Parser::Parse(io::Tokenizer* input, FileDescriptorProto* file) {
// Store the syntax into the file.
if (file != nullptr) {
file->set_syntax(syntax_identifier_);
#ifdef PROTOBUF_FUTURE_EDITIONS
if (syntax_identifier_ == "editions") {
file->set_edition(edition_);
}
#endif // PROTOBUF_FUTURE_EDITIONS
}
} else if (!stop_after_syntax_identifier_) {
ABSL_LOG(WARNING) << "No syntax specified for the proto file: "
Expand Down Expand Up @@ -718,28 +714,23 @@ bool Parser::ParseSyntaxIdentifier(const FileDescriptorProto* file,
const LocationRecorder& parent) {
LocationRecorder syntax_location(parent,
FileDescriptorProto::kSyntaxFieldNumber);
#ifdef PROTOBUF_FUTURE_EDITIONS
syntax_location.RecordLegacyLocation(
file, DescriptorPool::ErrorCollector::EDITIONS);
bool has_edition = false;
if (TryConsume("edition")) {
has_edition = true;
} else {
#endif // PROTOBUF_FUTURE_EDITIONS
DO(Consume("syntax",
"File must begin with a syntax statement, e.g. 'syntax = "
"\"proto2\";'."));
#ifdef PROTOBUF_FUTURE_EDITIONS
}
#endif // PROTOBUF_FUTURE_EDITIONS

DO(Consume("="));
io::Tokenizer::Token syntax_token = input_->current();
std::string syntax;
DO(ConsumeString(&syntax, "Expected syntax identifier."));
DO(ConsumeEndOfDeclaration(";", &syntax_location));

#ifdef PROTOBUF_FUTURE_EDITIONS
(has_edition ? edition_ : syntax_identifier_) = syntax;
if (has_edition) {
if (syntax.empty()) {
Expand All @@ -751,7 +742,6 @@ bool Parser::ParseSyntaxIdentifier(const FileDescriptorProto* file,
syntax_identifier_ = "editions";
return true;
}
#endif // PROTOBUF_FUTURE_EDITIONS
syntax_identifier_ = syntax;
if (syntax != "proto2" && syntax != "proto3" &&
!stop_after_syntax_identifier_) {
Expand Down Expand Up @@ -2343,7 +2333,6 @@ bool Parser::ParseLabel(FieldDescriptorProto::Label* label,
!LookingAt("required")) {
return false;
}
#ifdef PROTOBUF_FUTURE_EDITIONS
if (LookingAt("optional") && syntax_identifier_ == "editions") {
RecordError(
"Label \"optional\" is not supported in editions. By default, all "
Expand All @@ -2354,7 +2343,6 @@ bool Parser::ParseLabel(FieldDescriptorProto::Label* label,
"Label \"required\" is not supported in editions, use "
"features.field_presence = LEGACY_REQUIRED.");
}
#endif // PROTOBUF_FUTURE_EDITIONS

LocationRecorder location(field_location,
FieldDescriptorProto::kLabelFieldNumber);
Expand All @@ -2374,15 +2362,13 @@ bool Parser::ParseType(FieldDescriptorProto::Type* type,
const auto& type_names_table = GetTypeNameTable();
auto iter = type_names_table.find(input_->current().text);
if (iter != type_names_table.end()) {
#ifdef PROTOBUF_FUTURE_EDITIONS
if (syntax_identifier_ == "editions" &&
iter->second == FieldDescriptorProto::TYPE_GROUP) {
RecordError(
"Group syntax is no longer supported in editions. To get group "
"behavior you can specify features.message_encoding = DELIMITED on a "
"message field.");
}
#endif // PROTOBUF_FUTURE_EDITIONS
*type = iter->second;
input_->Next();
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/google/protobuf/compiler/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,7 @@ class PROTOBUF_EXPORT Parser {

// Whether fields without label default to optional fields.
bool DefaultToOptionalFields() const {
#ifdef PROTOBUF_FUTURE_EDITIONS
if (syntax_identifier_ == "editions") return true;
#endif // PROTOBUF_FUTURE_EDITIONS
return syntax_identifier_ == "proto3";
}

Expand All @@ -548,9 +546,7 @@ class PROTOBUF_EXPORT Parser {
bool require_syntax_identifier_;
bool stop_after_syntax_identifier_;
std::string syntax_identifier_;
#ifdef PROTOBUF_FUTURE_EDITIONS
std::string edition_;
#endif // PROTOBUF_FUTURE_EDITIONS

// Leading doc comments for the next declaration. These are not complete
// yet; use ConsumeEndOfDeclaration() to get the complete comments.
Expand Down
2 changes: 0 additions & 2 deletions src/google/protobuf/compiler/parser_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3914,7 +3914,6 @@ TEST_F(SourceInfoTest, DocCommentsOneof) {

// ===================================================================

#ifdef PROTOBUF_FUTURE_EDITIONS
typedef ParserTest ParseEditionsTest;

TEST_F(ParseEditionsTest, Editions) {
Expand Down Expand Up @@ -4143,7 +4142,6 @@ TEST_F(ParseEditionsTest, FeaturesWithoutEditions) {
"4:17: Features are only valid under editions.\n");
}

#endif // PROTOBUF_FUTURE_EDITIONS


} // anonymous namespace
Expand Down
Loading

0 comments on commit 6098c02

Please sign in to comment.