Skip to content

Commit cf2d696

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Breaking change: Remove C++ legacy syntax descriptor APIs
PiperOrigin-RevId: 589879506
1 parent 1dd6a7d commit cf2d696

File tree

5 files changed

+8
-181
lines changed

5 files changed

+8
-181
lines changed

python/build_targets.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ def build_targets(name):
121121
deps = [
122122
":proto_api",
123123
"//:protobuf",
124-
"//src/google/protobuf:descriptor_legacy",
125124
] + select({
126125
"//conditions:default": [],
127126
":use_fast_cpp_protos": ["//external:python_headers"],

src/google/protobuf/BUILD.bazel

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,6 @@ cc_library(
580580
strip_include_prefix = "/src",
581581
)
582582

583-
cc_library(
584-
name = "descriptor_legacy",
585-
hdrs = ["descriptor_legacy.h"],
586-
copts = COPTS,
587-
linkopts = LINK_OPTS,
588-
strip_include_prefix = "/src",
589-
visibility = ["//:__subpackages__"],
590-
deps = [
591-
":port_def",
592-
":protobuf_nowkt",
593-
"@com_google_absl//absl/strings",
594-
],
595-
)
596-
597583
cc_library(
598584
name = "descriptor_visitor",
599585
hdrs = ["descriptor_visitor.h"],
@@ -1043,7 +1029,6 @@ cc_test(
10431029
}),
10441030
deps = [
10451031
":cc_test_protos",
1046-
":descriptor_legacy",
10471032
":protobuf",
10481033
":test_textproto",
10491034
"//src/google/protobuf/compiler:importer",
@@ -1339,7 +1324,6 @@ cc_test(
13391324
}),
13401325
deps = [
13411326
":cc_test_protos",
1342-
":descriptor_legacy",
13431327
":protobuf",
13441328
":test_util",
13451329
"//src/google/protobuf/stubs",

src/google/protobuf/descriptor.cc

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -810,21 +810,6 @@ const char* const FieldDescriptor::kLabelToName[MAX_LABEL + 1] = {
810810
"repeated", // LABEL_REPEATED
811811
};
812812

813-
const char* FileDescriptor::SyntaxName(FileDescriptor::Syntax syntax) {
814-
switch (syntax) {
815-
case SYNTAX_PROTO2:
816-
return "proto2";
817-
case SYNTAX_PROTO3:
818-
return "proto3";
819-
case SYNTAX_EDITIONS:
820-
return "editions";
821-
case SYNTAX_UNKNOWN:
822-
return "unknown";
823-
}
824-
ABSL_LOG(FATAL) << "can't reach here.";
825-
return nullptr;
826-
}
827-
828813
static const char* const kNonLinkedWeakMessageReplacementName = "google.protobuf.Empty";
829814

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

3790+
bool FieldDescriptor::has_optional_keyword() const {
3791+
return proto3_optional_ || (file()->edition() == Edition::EDITION_PROTO2 &&
3792+
is_optional() && !containing_oneof());
3793+
}
3794+
38053795
// Location methods ===============================================
38063796

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

@@ -5682,16 +5671,12 @@ FileDescriptor* DescriptorBuilder::BuildFileImpl(
56825671
// TODO: Report error when the syntax is empty after all the protos
56835672
// have added the syntax statement.
56845673
if (proto.syntax().empty() || proto.syntax() == "proto2") {
5685-
file_->syntax_ = FileDescriptor::SYNTAX_PROTO2;
56865674
file_->edition_ = Edition::EDITION_PROTO2;
56875675
} else if (proto.syntax() == "proto3") {
5688-
file_->syntax_ = FileDescriptor::SYNTAX_PROTO3;
56895676
file_->edition_ = Edition::EDITION_PROTO3;
56905677
} else if (proto.syntax() == "editions") {
5691-
file_->syntax_ = FileDescriptor::SYNTAX_EDITIONS;
56925678
file_->edition_ = proto.edition();
56935679
} else {
5694-
file_->syntax_ = FileDescriptor::SYNTAX_UNKNOWN;
56955680
file_->edition_ = Edition::EDITION_UNKNOWN;
56965681
AddError(proto.name(), proto, DescriptorPool::ErrorCollector::OTHER, [&] {
56975682
return absl::StrCat("Unrecognized syntax: ", proto.syntax());

src/google/protobuf/descriptor.h

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,35 +1856,9 @@ class PROTOBUF_EXPORT FileDescriptor : private internal::SymbolBase {
18561856
// descriptor.proto, and any available extensions of that message.
18571857
const FileOptions& options() const;
18581858

1859-
private:
1860-
// With the upcoming release of editions, syntax should not be used for
1861-
// business logic. Instead, the various feature helpers defined in this file
1862-
// should be used to query more targeted behaviors. For example:
1863-
// has_presence, is_closed, requires_utf8_validation.
1864-
enum Syntax
1865-
#ifndef SWIG
1866-
: int
1867-
#endif // !SWIG
1868-
{
1869-
SYNTAX_UNKNOWN = 0,
1870-
SYNTAX_PROTO2 = 2,
1871-
SYNTAX_PROTO3 = 3,
1872-
SYNTAX_EDITIONS = 99,
1873-
};
1874-
PROTOBUF_IGNORE_DEPRECATION_START
1875-
Syntax syntax() const;
1876-
PROTOBUF_IGNORE_DEPRECATION_STOP
1877-
1878-
// Define a visibility-restricted wrapper for internal use until the migration
1879-
// is complete.
1880-
friend class FileDescriptorLegacy;
1881-
1882-
PROTOBUF_IGNORE_DEPRECATION_START
1883-
static const char* SyntaxName(Syntax syntax);
1884-
PROTOBUF_IGNORE_DEPRECATION_STOP
1885-
18861859
public:
1887-
// Returns EDITION_UNKNOWN if syntax() is not SYNTAX_EDITIONS.
1860+
// Returns edition of this file. For legacy proto2/proto3 files, special
1861+
// EDITION_PROTO2 and EDITION_PROTO3 values are used.
18881862
Edition edition() const;
18891863

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

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

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

2728-
inline bool FieldDescriptor::has_optional_keyword() const {
2729-
PROTOBUF_IGNORE_DEPRECATION_START
2730-
return proto3_optional_ ||
2731-
(file()->syntax() == FileDescriptor::SYNTAX_PROTO2 && is_optional() &&
2732-
!containing_oneof());
2733-
PROTOBUF_IGNORE_DEPRECATION_STOP
2734-
}
2735-
27362700
inline const OneofDescriptor* FieldDescriptor::real_containing_oneof() const {
2737-
PROTOBUF_IGNORE_DEPRECATION_START
27382701
auto* oneof = containing_oneof();
27392702
return oneof && !oneof->is_synthetic() ? oneof : nullptr;
2740-
PROTOBUF_IGNORE_DEPRECATION_STOP
27412703
}
27422704

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

2847-
PROTOBUF_IGNORE_DEPRECATION_START
2848-
inline FileDescriptor::Syntax FileDescriptor::syntax() const {
2849-
return static_cast<Syntax>(syntax_);
2850-
}
2851-
PROTOBUF_IGNORE_DEPRECATION_STOP
2852-
28532809
namespace internal {
28542810

28552811
// FieldRange(desc) provides an iterable range for the fields of a

src/google/protobuf/descriptor_legacy.h

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)