35 Commits
Author SHA1 Message Date
George Barnett 2f58de3712 Generate nonisolated code (#2055)
Motivation:

When setting the default actor isolation to 'MainActor', generated
protobuf code will fail to compile.

Modifications:

- Add 'nonisolated' to generated declaration
- Add a compile test

Result:

- Resolves https://github.com/apple/swift-protobuf/issues/1797
2026-05-13 16:53:23 +01:00
b16843c4f8 Move runtime to FoundationEssentials (#1993)
As per the recent [forums
post](https://forums.swift.org/t/the-adoption-of-import-foundationessentials-throughout-the-package-ecosystem/84112/16)
on the `import FoundationEssentials`, this PR implements the strategy
described.

The generator now generates the conditional essentials import.

The only remaining part after this is to do something about the
`BinaryDelimited` APIs which use `InputStream` and `OutputStream`

Fixes #1756

---------

Co-authored-by: Franz Busch <f.busch@apple.com>
Co-authored-by: Thomas Van Lenten <thomasvl@google.com>
2026-03-01 11:05:47 -05:00
George Barnett 4bd401a822 Use implicit returns in generated code (#1894)
Motivation:

The generated code has explicit returns for computed properties in a
number of places.

Modifications:

- Removed explicit 'return' where possible

Result:

Generated code is ever-so-slightly smaller
2025-11-04 15:04:02 +00:00
Tony Allevato 27d8bb9f90 Inline the bytecode string into the _NameMap.init(bytecode:) call. (#1804)
This has no impact on the optimized+stripped release builds I was
testing, but in a debug build of our internal huge-proto example, this
shaves an additional ~750KB off a 32MB binary (2.3%!). Presumably this
comes from debug info, accessors that are no longer being generated,
etc.
2025-06-30 10:53:38 -04:00
Tony Allevato 0f043ac24a Create a bytecode interpreter to compactly represent text/JSON name maps. (#1789)
The problem with the `ExpressibleByDictionaryLiteral` approach we're
using today is that its codegen is unpredictable. For what is really
just static data, the Swift compiler always generates sequences of
instructions in debug mode, and in release mode it may or may not be
outlined into global data depending on various things outside of the
author's control.

`StaticString`s, on the other hand, are super predictable since they
always become static read-only data (ignoring the oddball edge case
involving a single code point). So, why not do what some other languages
do and create blobs of binary data that we can process at runtime
instead?

The catch is that since `StaticString`s must be valid UTF-8, we have to
invent our own little bytecode format a bit, to avoid encodings that
might be invalid. The format is a stream of bytes as follows:

* Integers are represented as varints with 6-bit shifts and an always
cleared MSB. This is similar to protobuf's own 7-bit varints except we
lose a bit to ensure that continuation bytes are in the range 0x40–0x7F
instead of 0x80–0xFF.
* Strings are represented as null-terminated UTF-8.
* String arrays are represented by a count integer followed by that many
null-terminated UTF-8 strings.
* The stream always starts with an integer "version" number, which
future-proofs us if we want to change the encoding. Right now, it's
always zero.

Layered on top of the bytecode stream is an interpreter, which abstracts
"instructions" that are `RawRepresentable` as `UInt64`, and the
interpreter loop just reads the next instruction and invokes a callback
that is supposed to read and process the operands.

The bytecode is an "ABI" that we can add to, but never remove from (for
a particular major version of the runtime). For example, we could add
new instructions in the future to represent things differently, as long
as the runtime can still correctly interpret the bytecode from older
generated code.
2025-06-27 15:42:21 -04:00
Thomas Van Lenten a2f2b46c27 As of Swift 5.9 Data was Sendable, so remove @unchecked use. (#1787)
The Swift minimum is now high enough that the use of `@unchecked` is no
longer needed.
2025-06-09 12:10:04 -04:00
Rick Newton-Rogers e41d3f0c93 Drop Swift 5.9 (#1775)
### Motivation:

Swift 5.9 is no longer supported, we should bump the tools version

### Modifications:

* Bump the Swift tools version to Swift 5.10
* Remove unsupported versions from CI in build.yml

### Result:

Code reflects the expected support window.
2025-05-14 15:30:41 +01:00
Nick Randall 4f6e091eab Cleaned up generated code for closed Enums (#1751)
For closed enums there no special `UNRECOGNIZED` case, so a plain Swift
`Int` enum with explicit values can be used directly.

This results in the generated `init?(rawValue:)` and `var rawValue`
functions not being needed, since the compiler will create them
automatically.
2025-02-05 09:49:27 -05:00
Tim Kientzle 967b423485 Rebuild reference files 2024-08-13 12:23:17 -07:00
Thomas Van Lenten eeb8e13f21 Regenerate 2024-07-25 14:55:57 -04:00
Gus Cairo 2cca8e8a4a Regenerate protos 2024-06-06 13:13:41 +01:00
Thomas Van Lenten 22a7b40ad2 Regenerate to pick up the new name table entries. 2024-04-16 08:41:18 -04:00
Gus Cairo 72e6933d06 Regenerate protos
squash
2024-04-10 12:12:24 -04:00
Takumi Muraishi b88d9378ee fix generated extended 2024-03-24 15:18:07 +09:00
Takumi Muraishi 6821ffa4c2 revert .pb.swift files diff 2024-03-20 10:16:46 +09:00
Takumi Muraishi d3f24b6b8d Fix Typo in FuzzTesting 2024-03-20 03:51:11 +09:00
Thomas Van Lenten 280be4260e Regenerate. 2024-03-05 09:15:58 -05:00
Thomas Van Lenten bc5a1bab2c Regenerate for Message Sendable change 2023-09-26 10:30:09 -04:00
Thomas Van Lenten 1ebd1f9d7d Regenerate for Oneof Sendable change 2023-09-26 10:30:09 -04:00
Thomas Van Lenten 37a0e0b967 Standardize proto namespaces.
Make the proto namespace used more consistent and ensure they are scoped to this
project more clearly.

Delete files that don't seem to be use/validating anything.
2023-07-24 14:49:30 -04:00
Thomas Van Lenten 3632da754a Update generated_swift_names* and Reference files. 2023-04-26 12:39:34 -04:00
Gus Cairo 5002f4cee6 Split SwiftProtobuf into SwiftProtobufCore & SwiftProtobufFoundationCompat 2022-11-01 10:40:14 +00:00
Thomas Van Lenten aba9915acb Regenerate to remove the old code.
Progress on #1210
2022-04-07 13:21:27 -04:00
Thomas Van Lenten c9b8d3348c Regenerate to pick up the changes 2022-04-07 13:20:50 -04:00
Thomas Van Lenten c89385a57d Regenerate to drop the guards 2022-04-07 13:20:50 -04:00
Thomas Van Lenten ffc7d0baed Regenerate. 2022-04-05 13:34:41 -04:00
Thomas Van Lenten f96ebaa2e1 Regenerate 2022-03-17 10:53:16 -04:00
Thomas Van Lenten 63e341f579 Bump the source compat version checks.
- Update generated_swift_names_*.
- Regenerate all files.
2022-03-07 13:44:20 -05:00
Zachary Waldowski afee26df00 Regenerate 2022-02-22 09:40:11 -05:00
Zachary Waldowski aaead67360 Regenerate 2022-02-09 13:00:32 -05:00
Thomas Van Lenten fda439518d Regenerate 2021-09-20 10:47:15 -04:00
Thomas Van Lenten 1302e6bb15 Regenerate files 2021-09-16 13:32:04 -04:00
Thomas Van Lenten ddbc8f3dc6 Add a message using message_set_wire_format.
Looking at
  https://storage.googleapis.com/oss-fuzz-coverage/swift-protobuf/reports/20210903/linux/report.html,
shows the message set related codepaths not getting traversed, so add that to
the test message.
2021-09-07 11:17:46 -04:00
Thomas Van Lenten 7c36b52ca9 Update the generated files. 2021-04-19 09:56:43 -04:00
Thomas Van Lenten 582c903886 Make a FuzzTesting directory with package file.
On macOS this requires using a swift.org toolchain since the swift support in
Xcode doesn't include fuzz support.

Add a second stage to the 'build' CI workflow to ensure these targets stay
building also.
2021-04-13 13:48:58 -04:00