Skip to content

Field utf8span property#1849

Open
kperryua wants to merge 1 commit into
swiftlang:experimental/new-codablefrom
kperryua:field-utf8span-property
Open

Field utf8span property#1849
kperryua wants to merge 1 commit into
swiftlang:experimental/new-codablefrom
kperryua:field-utf8span-property

Conversation

@kperryua

Copy link
Copy Markdown
Contributor

Swap withUTF8Span for utf8Span with a yielding borrow accessor.

Motivation:

The withUTF8Span API on CodingField was an unfortunate accommodation since StaticString's could not guarantee an immortal lifetime for non-pointer-representation strings. This was especially unfortunate given how rare these strings are.

Modifications:

Use yielding borrow accessors to maintain the lifetime of a UTF8Span so we don't need the closure.

Result:

No more unfortunate closures.

Testing:

The utf8Span property implementation is specified by default implementation on StaticStringCodingField, so any test/benchmark types currently using that will automatically get this.

…ielding borrow` that manually keeps a non-pointer-representation StaticString UTF8Span alive
@kperryua kperryua requested a review from a team as a code owner March 24, 2026 20:44
@kperryua kperryua changed the base branch from main to experimental/new-codable March 24, 2026 20:46
@kperryua kperryua added the new-codable Related to new Swift (de)serialization APIs label Mar 24, 2026
@kperryua

Copy link
Copy Markdown
Contributor Author

This construction worked on an older toolchain, but simply fails with a compiler error on newer toolchains. Has it been defined as invalid somehow, or is it a bug?

@kperryua kperryua removed the request for review from a team April 16, 2026 21:16
@kperryua

kperryua commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Update: this still fails on 5/4/26 main toolchain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-codable Related to new Swift (de)serialization APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant