Skip to content

Commit

Permalink
Breaking change: Remove C++ legacy syntax descriptor APIs
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 589879506
  • Loading branch information
mkruskal-google authored and copybara-github committed Dec 11, 2023
1 parent 1dd6a7d commit cf2d696
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 181 deletions.
1 change: 0 additions & 1 deletion python/build_targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def build_targets(name):
deps = [
":proto_api",
"//:protobuf",
"//src/google/protobuf:descriptor_legacy",
] + select({
"//conditions:default": [],
":use_fast_cpp_protos": ["//external:python_headers"],
Expand Down
16 changes: 0 additions & 16 deletions src/google/protobuf/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -580,20 +580,6 @@ cc_library(
strip_include_prefix = "/src",
)

cc_library(
name = "descriptor_legacy",
hdrs = ["descriptor_legacy.h"],
copts = COPTS,
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
visibility = ["//:__subpackages__"],
deps = [
":port_def",
":protobuf_nowkt",
"@com_google_absl//absl/strings",
],
)

cc_library(
name = "descriptor_visitor",
hdrs = ["descriptor_visitor.h"],
Expand Down Expand Up @@ -1043,7 +1029,6 @@ cc_test(
}),
deps = [
":cc_test_protos",
":descriptor_legacy",
":protobuf",
":test_textproto",
"//src/google/protobuf/compiler:importer",
Expand Down Expand Up @@ -1339,7 +1324,6 @@ cc_test(
}),
deps = [
":cc_test_protos",
":descriptor_legacy",
":protobuf",
":test_util",
"//src/google/protobuf/stubs",
Expand Down
25 changes: 5 additions & 20 deletions src/google/protobuf/descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -810,21 +810,6 @@ const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = {
"repeated", // LABEL_REPEATED
};

const char* FileDescriptor::SyntaxName(FileDescriptor::Syntax syntax) {
switch (syntax) {
case SYNTAX_PROTO2:
return "proto2";
case SYNTAX_PROTO3:
return "proto3";
case SYNTAX_EDITIONS:
return "editions";
case SYNTAX_UNKNOWN:
return "unknown";
}
ABSL_LOG(FATAL) << "can't reach here.";
return nullptr;
}

static const char* const kNonLinkedWeakMessageReplacementName = "google.protobuf.Empty";

#if !defined(_MSC_VER) || (_MSC_VER >= 1900 && _MSC_VER < 1912)
Expand Down Expand Up @@ -3802,6 +3787,11 @@ bool FieldDescriptor::legacy_enum_field_treated_as_closed() const {
enum_type()->is_closed());
}

bool FieldDescriptor::has_optional_keyword() const {
return proto3_optional_ || (file()->edition() == Edition::EDITION_PROTO2 &&
is_optional() && !containing_oneof());
}

// Location methods ===============================================

bool FileDescriptor::GetSourceLocation(const std::vector<int>& path,
Expand Down Expand Up @@ -5070,7 +5060,6 @@ FileDescriptor* DescriptorPool::NewPlaceholderFileWithMutexHeld(
placeholder->tables_ = &FileDescriptorTables::GetEmptyInstance();
placeholder->source_code_info_ = &SourceCodeInfo::default_instance();
placeholder->is_placeholder_ = true;
placeholder->syntax_ = FileDescriptor::SYNTAX_UNKNOWN;
placeholder->finished_building_ = true;
// All other fields are zero or nullptr.

Expand Down Expand Up @@ -5682,16 +5671,12 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
// TODO: Report error when the syntax is empty after all the protos
// have added the syntax statement.
if (proto.syntax().empty() || proto.syntax() == "proto2") {
file_->syntax_ = FileDescriptor::SYNTAX_PROTO2;
file_->edition_ = Edition::EDITION_PROTO2;
} else if (proto.syntax() == "proto3") {
file_->syntax_ = FileDescriptor::SYNTAX_PROTO3;
file_->edition_ = Edition::EDITION_PROTO3;
} else if (proto.syntax() == "editions") {
file_->syntax_ = FileDescriptor::SYNTAX_EDITIONS;
file_->edition_ = proto.edition();
} else {
file_->syntax_ = FileDescriptor::SYNTAX_UNKNOWN;
file_->edition_ = Edition::EDITION_UNKNOWN;
AddError(proto.name(), proto, DescriptorPool::ErrorCollector::OTHER, [&] {
return absl::StrCat("Unrecognized syntax: ", proto.syntax());
Expand Down
50 changes: 3 additions & 47 deletions src/google/protobuf/descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1856,35 +1856,9 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
// descriptor.proto, and any available extensions of that message.
const FileOptions& options() const;

private:
// With the upcoming release of editions, syntax should not be used for
// business logic. Instead, the various feature helpers defined in this file
// should be used to query more targeted behaviors. For example:
// has_presence, is_closed, requires_utf8_validation.
enum Syntax
#ifndef SWIG
: int
#endif // !SWIG
{
SYNTAX_UNKNOWN = 0,
SYNTAX_PROTO2 = 2,
SYNTAX_PROTO3 = 3,
SYNTAX_EDITIONS = 99,
};
PROTOBUF_IGNORE_DEPRECATION_START
Syntax syntax() const;
PROTOBUF_IGNORE_DEPRECATION_STOP

// Define a visibility-restricted wrapper for internal use until the migration
// is complete.
friend class FileDescriptorLegacy;

PROTOBUF_IGNORE_DEPRECATION_START
static const char* SyntaxName(Syntax syntax);
PROTOBUF_IGNORE_DEPRECATION_STOP

public:
// Returns EDITION_UNKNOWN if syntax() is not SYNTAX_EDITIONS.
// Returns edition of this file. For legacy proto2/proto3 files, special
// EDITION_PROTO2 and EDITION_PROTO3 values are used.
Edition edition() const;

// Find a top-level message type by name (not full_name). Returns nullptr if
Expand Down Expand Up @@ -1920,7 +1894,7 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
// Fill the json_name field of FieldDescriptorProto for all fields. Can only
// be called after CopyTo().
void CopyJsonNameTo(FileDescriptorProto* proto) const;
// Fills in the file-level settings of this file (e.g. syntax, package,
// Fills in the file-level settings of this file (e.g. edition, package,
// file options) to `proto`.
void CopyHeadingTo(FileDescriptorProto* proto) const;

Expand Down Expand Up @@ -1962,8 +1936,6 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
// that type accessor functions that can possibly build a dependent file
// aren't called during the process of building the file.
bool finished_building_;
// Actually a `Syntax` but stored as uint8_t to save space.
uint8_t syntax_;
// This one is here to fill the padding.
int extension_count_;

Expand Down Expand Up @@ -2725,19 +2697,9 @@ inline bool FieldDescriptor::is_map() const {
return type() == TYPE_MESSAGE && is_map_message_type();
}

inline bool FieldDescriptor::has_optional_keyword() const {
PROTOBUF_IGNORE_DEPRECATION_START
return proto3_optional_ ||
(file()->syntax() == FileDescriptor::SYNTAX_PROTO2 && is_optional() &&
!containing_oneof());
PROTOBUF_IGNORE_DEPRECATION_STOP
}

inline const OneofDescriptor* FieldDescriptor::real_containing_oneof() const {
PROTOBUF_IGNORE_DEPRECATION_START
auto* oneof = containing_oneof();
return oneof && !oneof->is_synthetic() ? oneof : nullptr;
PROTOBUF_IGNORE_DEPRECATION_STOP
}

// To save space, index() is computed by looking at the descriptor's position
Expand Down Expand Up @@ -2844,12 +2806,6 @@ inline const FileDescriptor* FileDescriptor::weak_dependency(int index) const {
return dependency(weak_dependencies_[index]);
}

PROTOBUF_IGNORE_DEPRECATION_START
inline FileDescriptor::Syntax FileDescriptor::syntax() const {
return static_cast<Syntax>(syntax_);
}
PROTOBUF_IGNORE_DEPRECATION_STOP

namespace internal {

// FieldRange(desc) provides an iterable range for the fields of a
Expand Down
97 changes: 0 additions & 97 deletions src/google/protobuf/descriptor_legacy.h

This file was deleted.

0 comments on commit cf2d696

Please sign in to comment.