Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[embedded] Port Swift.String to embedded Swift #70446

Merged
merged 4 commits into from
May 26, 2024

Conversation

kubamracek
Copy link
Contributor

@kubamracek kubamracek commented Dec 13, 2023

This is a port of String, as it is, to Embedded Swift. While a lot of embedded developers might not want Unicode-compliant, dynamically allocated strings in their programs, some might and so let's enable that, and explore "other" strings separately.

Notably, this enables:

  • string interpolations
  • printing with string interpolations
  • using the usual dynamic strings operations, like concatenation, splitting, iteration, etc.

Notably, this does not enable:

  • printing of arbitrary types via reflection
  • string intepolating arbitrary types via reflection
  • String(describing: ...) and String(reflecting: ...) of arbitrary types
  • converting arrays, dictionaries into strings with their elements described

This PR roughly contains this:

  • Enable building the parts of the stdlib that implement String in the embedded stdlib.
  • Add missing refcounting facilities that are needed for String into the embedded runtime, notably bridgeObject refcounting and immortal pointer bit handling.
  • Remove a lot of stubs and annotations that were previously disabling strings and string related code.
  • Implement integer to string conversions in Swift
  • Tweak and ifdef out the usage of AnyObject in StringObject.swift and related code.
  • Adopt typed throws in validateUTF8.
  • Add a bunch of runtime tests.

@kubamracek kubamracek changed the title [WIP] Embedded string [embedded] Port Swift.String to embedded Swift May 8, 2024
@kubamracek kubamracek marked this pull request as ready for review May 8, 2024 18:22
@kubamracek kubamracek requested a review from a team as a code owner May 8, 2024 18:22
@kubamracek
Copy link
Contributor Author

@mikeash @al45tair I wonder if I could ask for a review of the EmbeddedRuntime.swift changes specifically (and any other part of the PR too if you're interested, of course)

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@phausler phausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to follow up on this to introduce a flag for the data tables inclusion as well as a flag to turn off strings entirely (due to code-size impact).

These improvements can be done post-facto imho.

Copy link
Contributor

@al45tair al45tair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EmbeddedRuntime changes look good to me.

@MihaelIsaev
Copy link

It looks amazing! 🥳
I can't wait to see it next nightly build and test it with Embedded Swift with Webssembly, since we really need String in web development.
How soon it could be available in development snapshot?

@kubamracek
Copy link
Contributor Author

@swift-ci please build macOS toolchain

@kubamracek
Copy link
Contributor Author

@swift-ci Please Build Toolchain macOS Platform

@MaxDesiatov
Copy link
Contributor

MaxDesiatov commented May 10, 2024

It looks amazing! 🥳 I can't wait to see it next nightly build and test it with Embedded Swift with Webssembly, since we really need String in web development.

If you're using Embedded Swift to reduce final binary size, using String in your project will negate those gains by bringing Unicode tables back, and generics specialization can even make binaries even bigger in large projects when compared to non-embedded Swift. What you'd need on the web for efficiency is a special string type, ideally that uses UTF-16 under the hood to also avoid UTF-8 <-> UTF-16 re-encoding overhead, since JavaScript strings are UTF-16.

How soon it could be available in development snapshot?

After a PR is merged, development snapshots are tagged nightly on a condition that all tests are passing on all platforms, which may not always be the case. Last time this happened on 1st of May, for a new snapshot to be created again all of the failing toolchain snapshots have to be fixed on all officially supported platforms.

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci Please Build Toolchain macOS Platform

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek kubamracek merged commit 545c243 into swiftlang:main May 26, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedded Embedded Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants