Regular bump as I get increasingly annoyed at trying to work with Foundation Essentials. Is there any movement on this @Tony_Parker ?
Should we "just" move Data from Foundation to stdlib, let the networking folks handle replacing all the bits that start with URL, hope SwiftSystem covers the filesystem & code loading, and declare bankruptcy on the rest?
Most (but definitely not all) of the remainder is either
- legacy ObjC-esque mess that people writing new Swift code don't actually want; or
- Apple-specific
That would be massively breaking. There's so much that would be missing, everything from UUID to Date to JSONEncoder/Decoder to String extensions etc etc
Moving DataProtocol, however, should be doable, I think.
It would; but:
- UUID should be in the stdlib
- Date should be deprecated (nobody wants the
Doublerepresentation) and in the stdlib (there should be a wallClock) - JSONEncoder/JSONDecoder should be in the stdlib, or if "new Codable" is winning, then that should be in the stdlib or in a separate first-party package
- String extensions aren't one-size-fits-all, but roughly:
- path-manipulation bits should be on
FilePath, either in the stdlib, swift-system, or a separate first-party package - find-and-replace bits including
CharacterSetshould be in the stdlib (likely on Regex)
- path-manipulation bits should be on
Some others:
Decimalshould be replaced with IEEE-754Decimal128, and belongs in the stdlib or a separate first-party packageLocale&FormatStylebelong in the stdlib.Formatter& subclasses should be deprecated
Calendarbelongs in the stdlib or in a separate first-party packageUserDefaultshas no place outside Apple platforms, and should stay in Foundation.Bundlehas no place outside Apple platforms, and should stay in Foundation,- The existing "resource bundle accessor" stuff should be reworked to behave sensibly for non-Apple platforms
- Localization stuff is Apple-specific; non-Apple platforms would rather have eg. a gettext-compatible package
RunLoopis Apple-specific and should stay in FoundationOperationQueue&Threadare anachronistic and should be deprecated- All the ObjC-compatibility types are anachronistic and effectively Apple-specific and should stay in
FoundationJSONSerializationby extension
This is my thesis: that nothing that is both "good" and "cross-platform" in Foundation should actually live in Foundation. (In theory; obviously "in practice" arriving at that destination is an enormous amount of hard work).
While those ideas are reasonable in a vacuum and I agree that I wish Swift stdlib had a few more fundamentals and Foundation was less necessary, I don't know how productive it is to spend time discussing changes that would be so ABI-breaking on Apple platforms that they would require heroics to implement—if they're possible at all.
This is definitely a valid viewpoint. However, I think that the opposite viewpoint is just as valid.
The standard library should contain nearly nothing. String, Int & family, Character, and some of the basic operators.
Putting everything into the standard library makes the standard library much larger. With static linking, clustering will cause code bloat in the generated binaries as well. This also then forces a split across environments (embedded vs desktop).
Pushing more out of the standard library is a better solution: it allows for a smaller, more compact runtime that hosts the rest of the environment, you can pick and choose what you include for your particular domain.
However, as much as that would be nice, it is also likely a similar problem: it would require a significant investment to ensure that existing packages and already built applications do not break due to the re-organisation of the interfaces.
the world is moving away from JSON, and JSON shouldn’t be in the standard library.
It represents point in time, not just a calendar day, like 2026-08-13, and so should be represented by a floating point type. Is there something that I'm missing? A newer type with higher precision maybe? I think only scientists need point in time precision better than Double.
What about DispatchQueue?
Much of what's suggested in this thread cannot happen for one reason or another, but this specific point probably merits discussion:
Double is basically adequate for most use, but has some drawbacks. In particular, it is desirable to either have uniform precision across the representable date range (i.e. a 96b or 128b binary or decimal fixed-point type), or to have it be so precise that the gradual loss of precision as you move away from the epoch does not matter for normal computations (either Binary128 or a head-tail representation with two Doubles).
I actually tried to move Date to a 2 x double representation last year; the sticking point that we encountered is that, while Date is not frozen, it unfortunately used an unkeyed representation for conforming to Codable, which means that almost any change to Date's representation results in it no longer round-tripping through encoding and decoding. I have a few ideas for ways that we might be able to mitigate this and move forward without having to introduce an all-new type, but it's a fairly subtle problem.
Shouldn't dead code stripping solve this issue?
Swift 6 already broke Date and the Double precision started causing problems in tests. I don't think there's an issue but it was discussed at Swift Foundation Date Representation - #4 by 0xTim
Wow, what is the world moving towards to replace JSON?
It depends, may require some work for it to do much.
As far as I'm concerned, the inability to do better DCE in Swift today is a bug to be fixed, not a constraint to be designed around. The embedded Swift work is great for this because I'm hoping it's possible to take some of those ideas and adapt them to Desktop Swift as well.
There's some experimental work in the compiler that we've been using for a while (like the -internalize-at-link flag, which stops aggressively tagging anything public as @llvm.used) and seen good results. Productionizing things like that and improving DCE for global records like protocol conformances is the way forward, not saying just "things should be as small as possible because of static linking". That's true today because of the reality of the compiler but we shouldn't settle for that indefinitely.
I agree, there is probably no good reason to add such types into the core standard library or to contemplate radical changes to Foundation.
Data types for working with dates and URLs are notoriously difficult to get right, and Foundation has served Objective-C and Swift well over the years.
If someone wants to try a different approach to these types, it would be best to launch a new community-driven project that provides such types as a Swift package.
If the new design gains traction, it’s not beyond the realm of possibility that Foundation’s types could be deprecated, over a long enough time horizon.
But yeah, attempting major ABI surgery to move these types out of Foundation, or to change their internal representation significantly, is probably not the best path forward at this stage.
@0xTim - attempting to keep this thread on topic:
I have actually been thinking about this, and @icharleshu has been working on exploring some options as well.
If we are willing to discuss something here which does not yet work, but possibly could with changes to swift and its tooling, then:
- I think it would be interesting to consider
import FoundationEssentialsas a kind of availability annotation in addition to naming a module (this does not exist today, I do not know if it is plausible) - We need to expand the functionality of the "availability domains" pitch ([Pitch] [Embedded] "Unicode" availability domain for APIs requiring the Unicode tables). This would allow us to provide custom availability for various features in Foundation. At a really coarse level, that is Essentials, i18n, etc. It is TBD what level of granularity it means.
FoundationEssentialscould also be a predefined collection of custom availability domains. - We need to accept that
import FoundationEssentialsdoes not mean the exact same thing on every platform. This is actually already true today forimport Foundation. The source of truth will always be the module that Swift is actually using in the toolchain for the specified platform. - We need accept that there is no mechanism here to prevent "accidental" linking of the larger library in a package graph
With these, then we basically collapse Foundation back into a single module, but with availability domains to expose specific APIs.
We also need to sort out if this means that static builds can dead code strip parts of any library which are unused in the entire binary. Or if the packaging/installation of dynamically linked apps can replace the dylib with customized smaller versions.
You can always just add a target named Foundation that only does @_exported import FoundationEssentials.
Can even add stuff like a DateFormatter class with private init() {} and some functions that fatalError. In case it's in public API of some dependencies but never actually used.
The thing that's always kind of bugged me about Date is that it's misnamed. It's not a date; it's a timestamp. A real date type shouldn't encode the time of day in it. Not that I think there's much probability of Date being deprecated, but if we did want to do so in order to replace the Double with a better representation, at least it wouldn't be hard to find a better name for the replacement type.
Thanks for following up!
I think the important point is 3 - if everyone can agree that macOS will be stuck with the old implementation and every other platform gets the new implementation and there are going to be differences then that resolves a lot of the issues. I don't think there are too many points to discuss on this since that's the current situation anyway.
For 1 and 2, that would help solve things if just exposing a FoundationEssentials module with a Foundation module that exports essentials on macOS is a no go. I'm open to anything that moves towards solving the horrible DX.
For 4 - we already have a number of CI jobs that can enforce this so it's not a major blocker. I've actually been looking into this to add a compiler flag to error at link time if a module is linked in. It's definitely possible to add, most of the scaffolding is already there so I'm happy to expand this in a new thread if it's of interest