# What’s next for Foundation

**URL:** <https://forums.swift.org/t/what-s-next-for-foundation/61939>\
**Category:** Core Libraries\
**Created:** [December 9, 2022, 4:38pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939 "2022-12-09T16:38:55Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![austintatious](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@austintatious](https://forums.swift.org/u/austintatious)\
**Post date:** [December 12, 2022, 5:44am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/41 "2022-12-12T05:44:09Z")

</div>

> [@Tony\_Parker](#):
>
> ### `Stream`, `Port`, `Timer`
> 
> `Stream`, `Port`, and `Timer` are inherently tied to `RunLoop`, which is itself inherently thread-based. Given the move away from concrete threads with the introduction of tasks in structured concurrency, it doesn't seem like these API are the right model to encourage going forward. I'm still open to discussion on that point.
> 
> It may be the case that we could use a new API for structured concurrency that adjusts the fire date like `Timer` and `RunLoop` do. I'm not sure.

Structured concurrency is still in its infancy and suffers a lot in terms of performance. Regardless of that removing well established classes for the purpose of forcing the still-in-infancy “new” way feels more ideologically motivated.

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [December 12, 2022, 6:01am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/42 "2022-12-12T06:01:52Z")

</div>

> [@tera](#):
>
> One of the features of timer is that it it is drift free: say if I fire a timer with 1 second interval it would fire at, say:
> 
> ```swift
> 0.02s, 1.01s, 1.999s, 3.0s, 4.001s, 4.98s, ...
> 
> ```
> 
> Replicating this behaviour with "sleep" is doable but not quite convenient.

Forgot to mention the "leeway" functionality that optimises system power consumption by coalescing timers' firing.

> [@](#):
>
> Besides, using timer doesn't has a viral effect on the caller (the way async await does).

This is quite serious. Not all code can be (or afford being) async/await-able. If RunLoop concept in its whole is a no-no in the new foundation consider some simplified version of it, e.g. an explicit "make this call every now and then when you can" model that would be useful for clients outside of structured concurrency.

> [@](#):
>
> I'd also miss "Lock".

Locks (various flavours) and the mentioned above atomics are very important for lower level code. "Is it useful for foundation itself?" could be a good litmus test on what to include. IMHO Swift should be generic enough to implement Swift compiler itself, a new implementation of Foundation, a device driver, a realtime function, etc.

---

<div class="post-metadata">

**Author:** ![esummers](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@esummers](https://forums.swift.org/u/esummers)\
**Post date:** [December 12, 2022, 6:55am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/43 "2022-12-12T06:55:39Z")

</div>

The proposal is to use a flat module structure. Submodules are not needed. I assume the Foundation module would just re-export the modules like is done in other places:

```swift
@_exported import FoundationEssentials
@_exported import FoundationInternationalization
@_exported import FoundationNetworking
...etc...

```

---

<div class="post-metadata">

**Author:** ![esummers](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@esummers](https://forums.swift.org/u/esummers)\
**Post date:** [December 12, 2022, 7:09am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/44 "2022-12-12T07:09:46Z")

</div>

Hopefully there will be some modernization of FileManager. I'm a fan of moving FileManager APIs to use a `FilePath` struct similar to swift-system. It would be great to see FileManger drop the delegate pattern. Callbacks might be fine for the features that currently require a delegate.

---

<div class="post-metadata">

**Author:** ![mickeyl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mickeyl/32/12258_2.png) [@mickeyl](https://forums.swift.org/u/mickeyl)\
**Post date:** [December 12, 2022, 9:20am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/46 "2022-12-12T09:20:49Z")

</div>

Disclaimer: Don't let me spoil your excitement, I find this exciting as well, but I keep thinking about the miserable status quo and what that means for people who are already writing cross-platform programs.

I think we can all agree that [swift-corelibs-foundation](https://github.com/apple/swift-corelibs-foundation) is kind of stuck. Despite dozens of valuable bug reports (among those [ones](https://github.com/apple/swift-corelibs-foundation/issues/4619) opened by the Swift Server Team themselves) and even more valuable pull requests (like [this one here](https://github.com/apple/swift-corelibs-foundation/pull/3106)), it doesn't look like anyone is scheduled to move forward with this repository.

This may or may not be a reason why there is this sudden movement about the future of foundation.

Although swift-corelibs-foundation does not fulfill its mission (source compatibility), many people are actively using it, because _they must_ ­– there are just no feasible alternatives available for many of the critical parts, such as RunLoops, Streams, and more (and for the fun of it, exactly those critical parts are now scheduled to be removed…)

Let me tell you why Streams and RunLoops are critical to me: I write software that talks to OBD2 adapters for automotive diagnostics. Those adapters come in various forms with various interfaces,  
e.g. WiFi, BLE, MFI, Bluetooth Classic, TTY, and what not. At the end of the day there is always a byte stream abstraction, hence `Stream` is the best common abstraction layer (in fact, it's a _must_, since on iOS, it's inevitable when you want to use L2CAP channels or an ExternalAccessory protocol).

Most of the automotive business logic is cross-platform, hence being able to run the lower part of this stack on Linux is a must for me. Hence I put a lot of work into a cross-platform [streams library](https://github.com/Cornucopia-Swift/CornucopiaStreams) that makes communicating with such (and other) devices a breeze.

Now if you say `Stream`, you also need to say `RunLoop`, I don't know any other way to make use of streams. Swift Concurrency is not an option here and will not be for quite a long time ­– at least not until e.g., Apple changes their `L2CAP` and `ExternalAccessory` frameworks.

And rather than shrinking the functionality and semantics gap of swift-corelibs-foundation, it looks like you now want to "officially" abandon this. And even more, you don't even want to consider critical parts of the infrastructure in your rewrite.

If this is true, could you at least help us in providing the means to fork swift-corelibs-foundation, so that we can unblock it for !APPLE platforms?

In any case, this is going to be tough for me and it really dampens my enthusiasm over all the new development in Foundation.

---

<div class="post-metadata">

**Author:** ![davdroman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/davdroman/32/46501_2.png) [@davdroman](https://forums.swift.org/u/davdroman)\
**Post date:** [December 12, 2022, 9:32am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/47 "2022-12-12T09:32:58Z")

</div>

> [@Tony\_Parker](#):
>
> `Date` itself is just a `Double`, really, so it can be used independently of any dependency on ICU

A bit of a side note, but I personally think this might be the perfect (and only) opportunity to rename `Date` to something more accurate to what it actually is — e.g. `Instant`.

---

<div class="post-metadata">

**Author:** ![dhoepfl](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@dhoepfl](https://forums.swift.org/u/dhoepfl)\
**Post date:** [December 12, 2022, 11:51am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/48 "2022-12-12T11:51:33Z")

</div>

Great to hear … but … scary.

Is there a time frame for when to expect the new implementation? I’m asking because I _fear_ that this makes it official that there will be no bug fixes in the existing foundation from now on.

I agree 100% with @mickeyl that “it doesn't look like anyone is scheduled to move forward with this repository.“ Actually this caused a lot of frustration in me:

I am tracking a [more than 6 years old bug report](https://github.com/apple/swift-corelibs-foundation/issues/4342) where I provided a [fix more than two years ago](https://github.com/apple/swift-corelibs-foundation/pull/2920) that is not merged. _Communication just stopped._

When I [noticed this bug](https://github.com/apple/swift-corelibs-foundation/issues/4642), that was [first report one year earlier](https://github.com/apple/swift/issues/56730), I provided a simple, 3 lines fix. Even this [simple pull request](https://github.com/apple/swift-corelibs-foundation/pull/4653) has not been merged for nearly a month now. Someone got assigned, CI was triggered, that’s it. No comment, nothing. Just ignored.

_For a bug that is crashing the app._

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [December 12, 2022, 12:32pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/49 "2022-12-12T12:32:44Z")

</div>

Hold on, are Threads also out? I hope not. Threads are essential for low level apps.

---

<div class="post-metadata">

**Author:** ![tclementdev](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tclementdev/32/13398_2.png) [@tclementdev](https://forums.swift.org/u/tclementdev)\
**Post date:** [December 12, 2022, 1:18pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/50 "2022-12-12T13:18:49Z")

</div>

As to [where things should go](https://forums.swift.org/t/what-s-next-for-foundation/61939/38), I think threads should go in the standard library, not Foundation. Same goes for locks and atomics. These are the building blocks to write everything else. The fact that they are lacking from the standard library is a problem (in my opinion) and maybe is also one of the reasons why almost all of swift concurrency is actually written in C++, not Swift.

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [December 12, 2022, 1:29pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/51 "2022-12-12T13:29:38Z")

</div>

> [@tclementdev](#):
>
> As to [where things should go](https://forums.swift.org/t/what-s-next-for-foundation/61939/38), I think threads should go in the standard library, not Foundation. Same goes for locks and atomics. These are the building blocks to write everything else.

OTOH putting threads / locks / atomics into a separate framework makes total sense IRT platforms that don't need those things (embedded systems or other handicapped / minimal environments). For the same reason unicode handling should also be separable, IMHO.

---

<div class="post-metadata">

**Author:** ![tclementdev](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tclementdev/32/13398_2.png) [@tclementdev](https://forums.swift.org/u/tclementdev)\
**Post date:** [December 12, 2022, 1:58pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/52 "2022-12-12T13:58:42Z")

</div>

My reasoning was that this all needs to be available to swift concurrency which is itself already in the standard library. C++ also seems to have it all as part of its standard library. But maybe there's some clever module dependencies that can be made available right down to the stdlib, I don't know enough to give a good answer.

---

<div class="post-metadata">

**Author:** ![tclementdev](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tclementdev/32/13398_2.png) [@tclementdev](https://forums.swift.org/u/tclementdev)\
**Post date:** [December 12, 2022, 3:44pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/53 "2022-12-12T15:44:40Z")

</div>

oh also it seems that parts of swift concurrency are already being modified to be compatible with more constrained environments (see [1](https://github.com/apple/swift/commit/ab16a647d8bf304198f9e41a0dbcea0f9f20c0a8), [2](https://github.com/apple/swift/commit/fa82280337374e8bf34b65528c5ccf559f3f497f), [3](https://github.com/apple/swift/commit/b2f51dd3de097efddfb82ae44d76eb36a737baf6)). The same could apply to locks, atomics and threads.

---

<div class="post-metadata">

**Author:** ![Tony\_Parker](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tony_parker/32/273_2.png) [@Tony\_Parker](https://forums.swift.org/u/Tony_Parker)\
**Post date:** [December 12, 2022, 6:43pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/54 "2022-12-12T18:43:54Z")

</div>

I understand how frustrating this is. In fact, that is a big reason we've decided to take this new direction. swift-corelibs-foundation, as it exists today, is fundamentally a fork. We can't use the Objective-C code for `NSXMLParser` (as in your example) for Linux, and we couldn't use the Swift code on Darwin. The need to do everything twice is just not supportable.

It will take us some time to get up to unifying the XML implementations, but once we get there then this kind of bug fix should be much easier to deal with. I don't have an exact time frame yet. I think we will know more about the velocity of the project once we get through some of the bring-up tasks to get _Essentials_ and _Internationalization_ ready.

---

<div class="post-metadata">

**Author:** ![zaneenders](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/zaneenders/32/27225_2.png) [@zaneenders](https://forums.swift.org/u/zaneenders)\
**Post date:** [December 12, 2022, 8:22pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/55 "2022-12-12T20:22:46Z")

</div>

Hi,

I was wondering how I could help with Date, FileManager, FileHandle, Process, Pipe, and ProcessInfo if possible. I am new to open source and a CS student and was hoping I could maybe learn more about how Files, and Processes actually work well learning/ practicing more Swift. I am taking Computer Systems and a Compilers class in Spring23 (C and C++).

This week I started playing around/ using [SwiftNIO](https://github.com/apple/swift-nio) as well as [SwiftSystem](https://github.com/apple/swift-system) a bit. I am wondering how these repos may or may not be involved in the new Foundation. NIO's `NIOPipeBootstrap` and `NonBlockingFileIO` look to be a smart abstractions, but I don't have enough experience to understand what downsides these might have.

Let me know how I can help/ get involved, maybe even with just the Swift NIO project? I know I have a lot to learn about Computer Science but Concurrency and Distributed Systems interest me a lot and is one reason why I'm Interested in learning more about Swift.

Thanks,  
Zane

---

<div class="post-metadata">

**Author:** ![amebahead](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/amebahead/32/27953_2.png) [@amebahead](https://forums.swift.org/u/amebahead)\
**Post date:** [December 13, 2022, 5:14pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/57 "2022-12-13T17:14:33Z")

</div>

I Love it :)

---

<div class="post-metadata">

**Author:** ![rtharston](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rtharston/32/22150_2.png) [@rtharston](https://forums.swift.org/u/rtharston)\
**Post date:** [December 13, 2022, 9:02pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/58 "2022-12-13T21:02:38Z")

</div>

Hey mickeyl, did you see Tony's reply regarding [Foundation on Darwin platforms](https://forums.swift.org/t/what-s-next-for-foundation/61939/31)?

> [@Tony\_Parker](#):
>
> Darwin Foundation (what we will call 'Foundation framework' to distinguish it) will be a superset of the package, because it will include all of the implementations we cannot remove or refactor as part of this work (stuff written in Objective-C or which we decide to omit from the package for some reason). Clearly we can't just yank the rug out from all existing apps on iOS or macOS. Therefore, the main task here is to refactor the code that we choose to have a common implementation into Swift and make _that_ the core instead of C or ObjC.

I don't fully understand your use case, but I think what Tony says here means you'll be fine. Darwin platforms will have all the same old Foundation API available to them, but the bits that are common with other platforms will have a new core. The discussion about what to include in the new Foundation packages is about what goes in that cross platform core.

Also, thanks for sharing your streams library. I haven't had to deal with communicating directly with devices in Swift yet, but I have had to on other platforms before.

---

<div class="post-metadata">

**Author:** ![bastie](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bastie/32/22636_2.png) [@bastie](https://forums.swift.org/u/bastie)\
**Post date:** [December 17, 2022, 9:04am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/59 "2022-12-17T09:04:04Z")

</div>

Love to hear the first step of Swifts digital sovereignty (SDS) and hope this SDS go ahead to the full SDS ecosystem. For example we have not all (public) methods to work with SPM in result that git use a compression method which not directly in Swift compression framework supported.

**Do not stop at Foundation!**

If you are right and Swift implementation is fast as C/ObjC go ahead. And also build not an only FoundationObjC-Bridge. Let FoundationFFI come to us and ObjC, C++, Python, Java and important COBOL Bridges are the following step.

**Question:**  
When Swift is so fast, is some reimplementation of Darwin OS the next step? _Hope dies last._

---

<div class="post-metadata">

**Author:** ![austintatious](https://avatars.discourse-cdn.com/v4/letter/a/ce73a5/32.png) [@austintatious](https://forums.swift.org/u/austintatious)\
**Post date:** [December 17, 2022, 5:09pm UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/60 "2022-12-17T17:09:16Z")

</div>

It really is sad that Apple’s ObjC was not fully ported to other systems or that working current implementation of ObjC on Linux wasn’t done.

---

<div class="post-metadata">

**Author:** ![YOCKOW](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/yockow/32/20636_2.png) [@YOCKOW](https://forums.swift.org/u/YOCKOW)\
**Post date:** [December 18, 2022, 3:40am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/61 "2022-12-18T03:40:46Z")

</div>

By the way, to what extent does "written in Swift" mean? 🤔

For example, as to XML stuff;

- Current FoundationXML:
  - `XML*` wraps `CFXML*` that depends on libxml2.

- Future FoundationXML:
  - `XML*` will directly depend on libxml2 (or other C library).
  - Or XML stuff will be all written in Swift from scratch.

I know it's a kind of "future direction", but I'm curious about how we decide goals.

---

<div class="post-metadata">

**Author:** ![esummers](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@esummers](https://forums.swift.org/u/esummers)\
**Post date:** [December 18, 2022, 4:30am UTC](https://forums.swift.org/t/what-s-next-for-foundation/61939/62 "2022-12-18T04:30:25Z")

</div>

Yeah, I hope language bridges in general move to use the in the works C++ interop stuff. Objective-C is a pretty ancient language, so I think bridges should start to move away from that as soon as they can.

[Previous page](https://forums.swift.org/t/what-s-next-for-foundation/61939.md?page=2)

[Next page](https://forums.swift.org/t/what-s-next-for-foundation/61939.md?page=4)
