Skip to content

Commit c42a0a8

Browse files
JasonLunncopybara-github
authored andcommitted
Internal Change
PiperOrigin-RevId: 948947555
1 parent 013009b commit c42a0a8

1 file changed

Lines changed: 176 additions & 2 deletions

File tree

content/editions/features.md

Lines changed: 176 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ and `export` keywords to set per-field behavior. Read more about this at
101101
* `LOCAL_ALL`: All symbols default to local.
102102
* `STRICT`: All symbols local by default. Nested types cannot be exported,
103103
except for a special-case caveat for `message { enum {} reserved 1 to max;
104-
}`. This will become the default in a future edition.
104+
}`.
105105

106106
**Applicable to the following scope:** file
107107

@@ -111,6 +111,7 @@ and `export` keywords to set per-field behavior. Read more about this at
111111

112112
Syntax/edition | Default
113113
-------------- | ------------------
114+
2026 | `STRICT`
114115
2024 | `EXPORT_TOP_LEVEL`
115116
2023 | `EXPORT_ALL`
116117
proto3 | `EXPORT_ALL`
@@ -167,6 +168,8 @@ legacy naming style.
167168

168169
**Values available:**
169170

171+
* `STYLE2026`: Enforces strict adherence to the 2026 style guide for naming to
172+
discourage common field-naming collisions.
170173
* `STYLE2024`: Enforces strict adherence to the style guide for naming.
171174
* `STYLE_LEGACY`: Applies the pre-Edition 2024 level of style guide
172175
enforcement.
@@ -180,6 +183,7 @@ oneof, enum, enum value, service, method
180183

181184
Syntax/edition | Default
182185
-------------- | --------------
186+
2026 | `STYLE2026`
183187
2024 | `STYLE2024`
184188
2023 | `STYLE_LEGACY`
185189
proto3 | `STYLE_LEGACY`
@@ -215,6 +219,107 @@ message Foo {
215219
}
216220
```
217221

222+
The following code sample shows an Edition 2024 file:
223+
224+
Edition 2024 defaults to `STYLE2024`, so collision avoidance is not enforced:
225+
226+
```proto
227+
edition = "2024";
228+
229+
// Field name collision avoidance is not enforced
230+
message Bar {
231+
int64 x = 1;
232+
int64 has_x = 2;
233+
}
234+
```
235+
236+
Edition 2026 defaults to `STYLE2026`, so an override is needed to keep the
237+
colliding field names:
238+
239+
```proto
240+
edition = "2024";
241+
242+
option features.enforce_naming_style = STYLE2024;
243+
244+
// To keep the colliding field names, override the STYLE2026 setting
245+
message Bar {
246+
int64 x = 1;
247+
int64 has_x = 2;
248+
}
249+
```
250+
251+
### `features.enforce_proto_limits` {#enforce_proto_limits}
252+
253+
Introduced in Edition 2026, this feature enables structure size limit
254+
enforcement in the Protobuf compiler when parsing `.proto` files to prevent
255+
oversize message and enum definitions.
256+
257+
**Values available:**
258+
259+
* `PROTO_LIMITS2026`: Enforces maximum limit checks:
260+
* Up to 1500 fields per message
261+
* Up to 1000 oneofs per message
262+
* Up to 1200 fields per oneof
263+
* Up to 1700 values per enum
264+
* `LEGACY_NO_EXPLICIT_LIMITS`: Opts out of limit checking.
265+
266+
**Applicable to the following scope:** message, oneof, enum
267+
268+
**Added in:** Edition 2026
269+
270+
**Default behavior per syntax/edition:**
271+
272+
Syntax/edition | Default
273+
-------------- | ---------------------------
274+
2026 | `PROTO_LIMITS2026`
275+
2024 | `LEGACY_NO_EXPLICIT_LIMITS`
276+
2023 | `LEGACY_NO_EXPLICIT_LIMITS`
277+
proto3 | `LEGACY_NO_EXPLICIT_LIMITS`
278+
proto2 | `LEGACY_NO_EXPLICIT_LIMITS`
279+
280+
**Note:** Feature settings on different schema elements
281+
[have different scopes](#cascading).
282+
283+
The following code sample shows an Edition 2024 file:
284+
285+
Edition 2024 defaults to `LEGACY_NO_EXPLICIT_LIMITS`, so a message with 1501
286+
fields is fine:
287+
288+
```proto
289+
edition = "2024";
290+
291+
message Foo {
292+
// A message with more than 1500 fields
293+
int64 one = 1;
294+
int64 two = 2;
295+
int64 three = 3;
296+
# ...
297+
int64 one_thousand_five_hundred = 1500;
298+
int64 one_thousand_five_hundred_and_one = 1501;
299+
}
300+
```
301+
302+
Edition 2026 defaults to `PROTO_LIMITS2026`, so an override is needed to keep
303+
oversized messages:
304+
305+
```proto
306+
edition = "2026";
307+
308+
// To keep the colliding field names, override the STYLE2026 setting
309+
message Foo {
310+
// Must be set at the level of the oversized message, enum, or oneof as this
311+
// feature is not allowed at the file level.
312+
option features.enforce_proto_limits = PROTO_LIMITS2026;
313+
314+
int64 one = 1;
315+
int64 two = 2;
316+
int64 three = 3;
317+
# ...
318+
int64 one_thousand_five_hundred = 1500;
319+
int64 one_thousand_five_hundred_and_one = 1501;
320+
}
321+
```
322+
218323
### `features.enum_type` {#enum_type}
219324

220325
This feature sets the behavior for how enum values that aren't contained within
@@ -239,6 +344,7 @@ and after of a proto3 file.
239344

240345
Syntax/edition | Default
241346
-------------- | --------
347+
2026 | `OPEN`
242348
2024 | `OPEN`
243349
2023 | `OPEN`
244350
proto3 | `OPEN`
@@ -300,6 +406,7 @@ whether a protobuf field has a value.
300406

301407
Syntax/edition | Default
302408
-------------- | -----------
409+
2026 | `EXPLICIT`
303410
2024 | `EXPLICIT`
304411
2023 | `EXPLICIT`
305412
proto3 | `IMPLICIT`*
@@ -393,6 +500,7 @@ and after of a proto3 file. Editions behavior matches the behavior in proto3.
393500

394501
Syntax/edition | Default
395502
-------------- | --------------------
503+
2026 | `ALLOW`
396504
2024 | `ALLOW`
397505
2023 | `ALLOW`
398506
proto3 | `ALLOW`
@@ -456,6 +564,7 @@ the following conditions are met:
456564

457565
Syntax/edition | Default
458566
-------------- | -----------------
567+
2026 | `LENGTH_PREFIXED`
459568
2024 | `LENGTH_PREFIXED`
460569
2023 | `LENGTH_PREFIXED`
461570
proto3 | `LENGTH_PREFIXED`
@@ -512,6 +621,7 @@ for `repeated` fields has been migrated to in Editions.
512621

513622
Syntax/edition | Default
514623
-------------- | ----------
624+
2026 | `PACKED`
515625
2024 | `PACKED`
516626
2023 | `PACKED`
517627
proto3 | `PACKED`
@@ -599,6 +709,7 @@ and after of a proto3 file.
599709

600710
Syntax/edition | Default
601711
-------------- | --------
712+
2026 | `VERIFY`
602713
2024 | `VERIFY`
603714
2023 | `VERIFY`
604715
proto3 | `VERIFY`
@@ -665,8 +776,9 @@ blog post for an introduction.
665776

666777
Syntax/edition | Default
667778
-------------- | ------------
668-
2023 | `API_OPEN`
779+
2026 | `API_OPAQUE`
669780
2024 | `API_OPAQUE`
781+
2023 | `API_OPEN`
670782

671783
**Note:** Feature settings on different schema elements
672784
[have different scopes](#cascading).
@@ -717,6 +829,7 @@ in the migration guide for more on this topic.
717829
718830
Syntax/edition | Default
719831
-------------- | -------
832+
2026 | `true`
720833
2024 | `true`
721834
2023 | `false`
722835
proto3 | `false`
@@ -725,6 +838,40 @@ proto2 | `false`
725838
**Note:** Feature settings on different schema elements
726839
[have different scopes](#cascading).
727840
841+
### `features.(pb.cpp).repeated_type` {#cpp-repeated_type}
842+
843+
**Languages:** C++
844+
845+
When set to `PROXY`, repeated field accessors return proxy types
846+
(`RepeatedFieldProxy`) instead of pointers or references to `RepeatedField` or
847+
`RepeatedPtrField`. Proxies allow for a more efficient in-memory representation
848+
of repeated fields in messages.
849+
850+
Importing this feature requires `import option "google/protobuf/cpp_features.proto";`
851+
852+
**Values available:**
853+
854+
* `PROXY`: Accessors return proxy types.
855+
* `LEGACY`: Accessors return legacy `RepeatedField` or `RepeatedPtrField`
856+
pointers/references.
857+
858+
**Applicable to the following scopes:** file, field
859+
860+
**Added in:** Edition 2026
861+
862+
**Default behavior per syntax/edition:**
863+
864+
Syntax/edition | Default
865+
-------------- | --------
866+
2026 | `LEGACY`
867+
2024 | `LEGACY`
868+
2023 | `LEGACY`
869+
proto3 | `LEGACY`
870+
proto2 | `LEGACY`
871+
872+
**Note:** Feature settings on different schema elements
873+
[have different scopes](#cascading).
874+
728875
### `features.(pb.java).large_enum` {#java-large_enum}
729876
730877
**Languages:** Java
@@ -747,6 +894,7 @@ example, switch statements are not supported.
747894
748895
Syntax/edition | Default
749896
-------------- | -------
897+
2026 | `false`
750898
2024 | `false`
751899
2023 | `false`
752900
proto3 | `false`
@@ -780,6 +928,7 @@ before and after of a proto3 file.
780928
781929
Syntax/edition | Default
782930
-------------- | -------
931+
2026 | `false`
783932
2024 | `false`
784933
2023 | `false`
785934
proto3 | `false`
@@ -847,6 +996,7 @@ becomes `BarBazProto`). You can still override this using the
847996

848997
Syntax/edition | Default
849998
-------------- | -------
999+
2026 | `NO`
8501000
2024 | `NO`
8511001
2023 | Legacy
8521002
proto3 | Legacy
@@ -880,6 +1030,7 @@ removed.
8801030

8811031
Syntax/edition | Default
8821032
-------------- | --------
1033+
2026 | `VIEW`
8831034
2024 | `VIEW`
8841035
2023 | `STRING`
8851036
proto3 | `STRING`
@@ -961,6 +1112,7 @@ before and after of a proto3 file.
9611112

9621113
Syntax/edition | Default
9631114
-------------- | ---------
1115+
2026 | `DEFAULT`
9641116
2024 | `DEFAULT`
9651117
2023 | `DEFAULT`
9661118
proto3 | `DEFAULT`
@@ -1042,6 +1194,7 @@ generator strips the repetitive prefix or not.
10421194

10431195
Syntax/edition | Default
10441196
-------------- | ------------------------
1197+
2026 | `STRIP_ENUM_PREFIX_KEEP`
10451198
2024 | `STRIP_ENUM_PREFIX_KEEP`
10461199

10471200
**Note:** Feature settings on different schema elements
@@ -1157,6 +1310,18 @@ message MyMessage {
11571310
}
11581311
```
11591312

1313+
### Edition 2024 to 2026 {#2024-2026}
1314+
1315+
The following shows the settings to replicate Edition 2024 behavior with
1316+
Edition 2026.
1317+
1318+
```proto
1319+
edition = "2026";
1320+
1321+
option features.enforce_naming_style = STYLE2024;
1322+
option features.default_symbol_visibility = EXPORT_TOP_LEVEL;
1323+
```
1324+
11601325
### Caveats and Exceptions {#caveats}
11611326

11621327
This section shows the changes that you'll need to make manually if you choose
@@ -1197,3 +1362,12 @@ behaviors in most cases, but there are a few exceptions.
11971362
instead.
11981363
* (Java) `java_multiple_files`: Remove `java_multiple_files` and use
11991364
[`features.(pb.java).nest_in_file_class`](#java-nest_in_file) instead.
1365+
1366+
**Edition 2026 and later**
1367+
1368+
* (C++) Remove Language-specific options (`cc_api_version`,
1369+
`cc_utf8_verification`, `cc_enable_arenas`).
1370+
* Set `features.enforce_proto_limits` to `LEGACY_NO_EXPLICIT_LIMITS` within
1371+
1. Messages that have either more than 1500 fields or more than 1000 oneofs
1372+
1. Oneofs that have more than 1200 fields
1373+
1. Enums that have more than 1700 values

0 commit comments

Comments
 (0)