Skip to content

Add Foundation trait - #399

Open
ph1ps wants to merge 2 commits into
pointfreeco:mainfrom
ph1ps:foundation-trait
Open

ph1ps wants to merge 2 commits into
pointfreeco:mainfrom
ph1ps:foundation-trait

Conversation

@ph1ps

@ph1ps ph1ps commented Sep 30, 2026

Copy link
Copy Markdown

Hello,

I recently had the need for Foundation-less parsing and printing, to have minimal binary size impact for WASM & Android. This follows a similar pattern to what you guys have gone with in swift-dependencies.

The majority of changes should be straight forward except localizedDescription. It introduces runtime differences when either enabling or disabling the trait rather than hiding/showing API which is a bit odd, but not sure if there is a way around that, but definitely open to feedback here.

Thanks.

Gate all Foundation usage behind a new, default-enabled `Foundation`
trait, mirroring swift-dependencies. With default traits disabled,
Parsing no longer links Foundation (or ICU) on non-Darwin platforms.

* `Data`, `JSON`, `UUID` and `CharacterSet` conversions/parsers, and
  `Data: PrependableCollection`, require the trait.
* `ParsingError` only formats `LocalizedError` via
  `localizedDescription` with the trait, and otherwise falls back to
  `"\(error)"`.
* Format style parsers require the trait in addition to Apple
  platforms.
* `Many` imports the platform C library for `memcmp` instead of
  Foundation.
* Drop unused Foundation imports from `BinaryFloatingPoint` and
  `Identity`.
@mbrandonw

Copy link
Copy Markdown
Member

Hi @ph1ps, thanks, this does seem like a good change to make! Will take a look soon.

I'm also realizing that we should at least build the library with traits off to make sure things are good. That wasn't such a big deal for the CasePaths trait since it's mostly self contained, but it may be more important for a Foundation trait.

Run the macOS and Linux jobs over a matrix of no traits, each trait on
its own, and all traits (the default), like swift-sharing.

Also only import CasePaths in the JSON benchmark when the `CasePaths`
trait is enabled, which previously broke builds with default traits
disabled.
@ph1ps

ph1ps commented Oct 1, 2026

Copy link
Copy Markdown
Author

@mbrandonw Added the trait tests + small correction in the benchmarks, the configuration is most similar to the one you have in swift-sharing.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants