Top
Best
New

Posted by DASD 13 hours ago

Swift at Apple: Migrating the TrueType hinting interpreter(www.swift.org)
200 points | 86 comments
jacquesgt 8 hours ago|
If you want to help improve the security of OS software through the magic of memory safe languages, the team that did this work is hiring: https://jobs.apple.com/en-us/search?search=Spear&sort=releva...

Knowledge of Swift not required. If you know your way around OS software, can reason about the security of the code you write, and are excited about writing exhaustively tested software, we’d love to talk to you.

We’re hiring for roles in kernel/systems and userspace. Like the Platforms SOTU mentioned, we’re using Swift at all layers of the software stack now. https://www.youtube.com/live/yl2jsIoMfDU

I had the pleasure of leading the effort to ship Swift in the Secure Enclave back in 2022. Now I have multiple teams working on accelerating the transition to memory safe languages. We’re showing that with good planning and a relentless focus on testing, we can improve security, performance, and functionality. And we get to have a ton of fun working with some amazing colleagues. It’s the most enjoyable and impactful work I’ve ever done in my career.

byproxy 4 hours ago|
Any resources you'd recommend for learning about reasoning about the security of code?
rinon 3 hours ago||
For low-level system security, I'm a fan of https://llsoftsec.github.io/llsoftsecbook/LLSoftSecBook.pdf as an overview for any systems developer, not just compiler devs. It might not be the most approachable, but it's got great info on everything memory corruption.
KolmogorovComp 1 hour ago||
> Operations like filter and map allocate memory, but that allocation is only necessary if the value escapes. The Swift standard library provides .lazy.map and .lazy.filter, but they don’t work in every case. For logic that only iterates over the filter or map, it’s much more efficient to loop with continue (or use for … in … where) and transform elements into local variables as necessary.

It does feel like a compiler/optimiser failure to have to rewrite those cases.

comex 7 hours ago||
Beware: As of a few months ago, when I tried to use the lifetime features shown off in this post, I ran into constant compiler crashes with very simple programs, until I gave up and wrote off the features as unusable. This happened on both stable and nightly compilers. I guess they work well enough for this TrueType interpreter, but I suspect they’re using a narrow subset of what the features are supposed to support. Or maybe things have been fixed very recently.

That said, I’m looking forward to using Swift lifetimes once they actually work!

stephencanon 7 hours ago|
The work discussed in this post shipped in the OS last year (fall 2025), so nothing here is dependent on very recent changes.
pjmlp 13 hours ago||
During the State of Platform keynote, on the subject of Swift adoption across macOS, several examples were given, not only TrueType engine.

RIS is happening across all OS levels, if the keynote is to be believed.

MBCook 10 hours ago||
They’ve been doing it for years. I don’t remember how we first knew, but I know they’ve been using Swift in kernels for at least some of the other chips like the Secure Enclave or whatever.

I’m not sure exactly which. I assume it’s some of the code and not all. But it’s not new in the abstract.

That said I don’t think I’ve heard of it in the kernel of MacOS on the main processor. That may be new.

Either way this is certainly the most concrete announcement I remember them ever giving on this stuff.

commandersaki 8 hours ago|||
I know internally they use an IPsec implementation written by Rust (I think in the iCloud infra). Heard this from an ex-Apple engineer Ben (forgot his last name) that did a wonderful presentation of Rust from first principles. He said that it was hard to get people in on Rust when most would argue for Swift.

Edit: This is the guy: https://rustcurious.com/course/

pjmlp 2 hours ago|||
Some stuff was discussed at Meet with Apple security event a few months ago, and the talks on FoundationDB rewrite, or why Swift Embedded subset came to be.

However I miss them actually having had one of those 15 - 30m WWDC sessions, where they could have gone a bit deeper into the keynote examples

DASD 12 hours ago|||
Curious the direction of Webkit as there was a nebulous mention of select portions being rewritten from C++ to Swift. And yet, the new ECMAScript module (ESM) loader for Safari 27 is implemented in C++ (https://webkit.org/blog/17967/news-from-wwdc26-webkit-in-saf...).
pjmlp 12 hours ago||
No idea, maybe the private parts of the code, Safari isn't open source, or is coming later.

In any case I would have liked to have more info during the deep dive sessions.

As it is, Meet with Apple on security (a 5h long event) had much more information.

hirvi74 11 hours ago||
What does RIS stand for?
gyomu 11 hours ago||
Rewrite in Swift
willXare 11 hours ago||
So RIS is Apple’s version of RiiR, but with better fonts.
cwillu 8 hours ago||
s/better/blurrier/
steve1977 5 hours ago|||
Life without retina displays is possible, but pointless.
thewebguyd 8 hours ago|||
Careful, you’ll bring out all the “but it’s true to print media” people.
mrpippy 12 hours ago||
The author discussed this a bit on Mastodon as well:

https://xoxo.zone/@numist/116716469017975106

numist 12 hours ago|
I'm also here :)
atdt 9 hours ago||
Excellent write-up!
numist 7 hours ago||
Thanks!
saagarjha 12 hours ago||
Interesting that this is published under the MIT, rather than Apple’s more favorite Apache 2, license
JumpCrisscross 12 hours ago|
Why is it interesting?
drob518 12 hours ago||
Presumably because MIT is even more permissive and it’s a change in Apple’s behavior.
favorited 11 hours ago|||
Some corporations prefer Apache 2.0 for projects where they'll be accepting contributions, because it includes patent protection and retaliation clauses. In case like this, where source code is just being published for reference and contributions aren't accepted, those risks don't exist.
zdw 11 hours ago|||
Given the age of TrueType, wouldn't nearly all patents be expired already?

Apache2's license I've heard described as mutually-assured-patent-destruction - if you use the code and make a patent claim, your rights to use the code go away.

So Apache2 offers little benefit here, and MIT may get it into more hands?

weinzierl 12 hours ago||
Back in 2023 there was talks about Microsoft rewriting the font stuff in Rust for similar reasons Apple is now doing the Swift move.

I'm not sure what became of it and if it ever shipped. If anyone knows I'd be curious.

DASD 12 hours ago|
Russinovitch (Azure's CTO/CISO) gave a speech at RustConf 2025 and mentions it(DirectWriteCore) took 2 engineers 6 months resulting in 154K LOC and 5-15 percent performance increase for font shaping. https://www.youtube.com/watch?v=uDtMuS7BExE&list=PL2b0df3jKK...
ks2048 7 hours ago||
So, hinting only takes place at low resolutions, I believe. How often is it used, eg viewing “typical” PDFs on “typical” screens?
airstrike 12 hours ago||
As much as I enjoyed Swift, one can only wonder what the world would look like if they had gone with Rust as their default language instead.
AceJohnny2 11 hours ago||
Rust doesn't have an ABI [1]. Swift needed one to be a useable application language:

https://faultlore.com/blah/swift-abi/ (written by a core Rust developer)

[1] apart from the basic/universal C one, which prevents exposing any useful Rust semantics over the interface

afavour 10 hours ago|||
One of the genius things about Swift is its interop with Objective C. Made the switch over considerably easier for developers. I’m not sure what that looks like in a Rust world.

Rust is also just a more complex language. I’m not convinced the benefits would have been worth it.

inkyoto 4 hours ago||
Not just interoperability with Objective C but with C (full) and C++ (increasingly better but not full) as well.

Swift is also interoperable with different versions of itself courtesy of the Swift stable ABI (Application Binary Interface)[0], which they invested a significant amount of time into at the expense of adding other new features to the language, which have come along later.

Rust offers a different approach: recompile everything and static linking.

[0] https://faultlore.com/blah/swift-abi/

pjmlp 2 hours ago||
C compatibility comes via Objective-C, because contrary to C++, Objective-C extends C, instead of being based on a C subset.

You missed Java as well.

pjmlp 2 hours ago|||
Swift takes the right approach in language ergonomics, many of its use cases would be much harder with explicit .clone() all over the place, lack of back references, no standard ABI for binary libraries, interop with Objective-C and C++, no standard concurrency runtime, or error handling types.

Rust 2026 roadmap has language ergonomics on it for a reason.

That said, outside Apple ecosystem you probably better with Rust, or if one has no GC issues, OCaml, Haskell, F#, Scala, C#.

jadengeller 12 hours ago||
Modern Swift borrows a lot from Rust! And it also has its own benefits, both ergonomic and also supporting eg generic in dynamic libraries
ecshafer 11 hours ago|||
Swift and Rust were developed at similar times. I think of them more as having similar influences than borrowing from each other.
pohl 8 hours ago|||
There’s no reason to invent your own head canon, the influence was openly acknowledged when Swift was new and it continues now that the language is developed out in the open (see Swift Ownership Manifesto)
zarzavat 6 hours ago||
Obviously Rust was first but over time both languages have been taking inspiration from each other. For example let-else was motivated directly because of its success in Swift: https://rust-lang.github.io/rfcs/3137-let-else.html#prior-ar...
pjmlp 2 hours ago||||
Additionally both have influences from CLU, C++, Object Pascal, Modula-2, Mesa/Cedar, Standard ML, Cyclone.

Many features that get discussed as being Swift/Rust, trace back to one of those languages.

est31 11 hours ago|||
Similar times and the Rust originator went on to work on Swift after it.
DenisChetwynd 11 hours ago||
Graydon Hoare's impact on the language is marginal than that of Chris Lattner, the originator (also, Hoare joined the team much later)
airstrike 12 hours ago||||
These days I mainly write Rust but I did write a semi complex iOS app and enjoyed Swift. I just didn't love how slow the type checker was and how it got lost. I recall having to break things into smaller bits to help the compiler, and there were some oddities about the language.

The gap between the two languages is quite small, it just makes me wish Apple was also all-in on Rust

MBCook 10 hours ago|||
In the last year they’ve added improvements to the type checker to speed it up, those would have been released now.

They have further and much more significant changes that I think might have recently landed in the development version. That should make an even bigger difference. But it’s not in a released version yet.

And yes, none of us like that one part of Swift. Especially the DRASTIC difference compared to objective-C which really only checked syntax and little else.

It’s still probably my favorite language right now though I don’t get to write in it much.

DenisChetwynd 11 hours ago||||
maybe so on the surface, but it remains quite massive underneath; these languages are fundamentally different and target entirely different use cases
airstrike 9 hours ago||
I'm not sure Rust has one specific use case as its main goal, despite being immediately suitable for systems programming.

I use it for making user-facing desktop applications, to name one example.

inkyoto 4 hours ago|||
I see Swift as a more approachable version of Rust.

If somebody is mulling over Rust but finds it too difficult to grasp, they could start off with Swift first and then move over to Rust.

One of the main advantages of Rust is a more developed and thriving ecosystem.

vardump 11 hours ago|||
Does it borrow borrow checker?
tialaramex 10 hours ago|||
I believe Swift tends to use reference counting and copy-on-write strategies. This, like GC, is less for the programmer to think about and doesn't require the semantic checks, but sometimes the performance cost is unacceptable compared to what you'd write in Rust.
airspeedswift 10 hours ago|||
You can choose to use either refcounting or unique ownership for your types. For most use cases, refcounted (+ copy-on-write) is the best choice and is the default, but the truetype interpreter made extensive use of non-refcounted types to achieve this performance.
pjmlp 2 hours ago||||
You can pick and chose, and memory ownership is getting better in latest versions.

Being more ergonomic is relevant enough for increasing language adoption, that possible improvements are now on Rust roadmap.

MBCook 10 hours ago|||
They have either recently added or talked about a borrow style system in the language as a way to avoid more copies and speed things up/lower memory usage/help with asynchronous programming.
anextio 10 hours ago|||
Yes, it has a borrow checker.
raphlinus 11 hours ago|
Welcome to the club of doing high performance text in a memory safe language!
masiulis 3 hours ago||
There are dozens of us! Dozens!

Vello has been a big inspiration and source of knowledge for my own webgpu text renderer, thank you for that!

WalterGR 3 hours ago||
> high performance text

Just strings or rendering strings?

If the latter, who are the other members of the club?

More comments...