Top
Best
New

Posted by DASD 2 days ago

Swift at Apple: Migrating the TrueType hinting interpreter(www.swift.org)
238 points | 131 commentspage 2
troupo 2 days ago|
I think these are the types of things Apple should've focused on instead of half-heartedly barging ahead with SwiftUI and breaking the language in the process
saagarjha 2 days ago|
I mean they’re doing both
airstrike 2 days 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 2 days 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 2 days 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 2 days 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 days 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.

jadengeller 2 days 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
airstrike 2 days 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 2 days 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.

geodel 1 day ago||||
Apple is not going bet all on language whose roadmap they do not control 100%.
inkyoto 2 days 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.

stasomatic 1 day ago||
It has an unfortunate name though, maybe a short shelf life. Rust++ doesn’t seem inviting either.
steveklabnik 1 day ago||
Rust does not have a ++ operator, so that name would make no sense.
stasomatic 1 day ago||
Not yet.
kibwen 1 day ago||
I can assure you that Rust will never have a ++ operator. Not only is it semantically bizarre, it's entirely unnecessary in a language where iteration is overwhelmingly performed via iterators rather than via manually incrementing array indices.
stasomatic 9 hours ago||
Is that a bullet point in the Rust manifesto? :) In any case, ++ has taken another meaning outside of operator loading and such some.

The “Rust” branding, to this rando, implies corrosion, oxidation, decay, regardless of the true origin of the name. Swift is “quick”, Java is “caffeine”, Rust is something I need kerosene for.

steveklabnik 7 hours ago|||
Yes, it is pretty universally agreed upon that a ++ operator in Rust doesn’t make any sense. += 1 is barely longer, not special cased, and does not make users memorize odd precedence rules.
airstrike 7 hours ago|||
Rust isn't named after what you think it is, but after fungi.
DenisChetwynd 2 days ago|||
maybe so on the surface, but it remains quite massive underneath; these languages are fundamentally different and target entirely different use cases
airstrike 2 days 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.

ecshafer 2 days ago||||
Swift and Rust were developed at similar times. I think of them more as having similar influences than borrowing from each other.
pohl 2 days 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 2 days 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 days 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 2 days ago|||
Similar times and the Rust originator went on to work on Swift after it.
DenisChetwynd 2 days ago||
Graydon Hoare's impact on the language is marginal than that of Chris Lattner, the originator (also, Hoare joined the team much later)
vardump 2 days ago|||
Does it borrow borrow checker?
tialaramex 2 days 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 2 days 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 days 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 2 days 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 2 days ago|||
Yes, it has a borrow checker.
pjmlp 2 days 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#.

jounker 1 day ago||
Apple has a runtime system that looks a lot like smalltalk. Everything at that layer is dynamic. They needed a language that could seamlessly interact with that system.
LoganDark 2 days ago||
I'm surprised the code has visible LLM smells. Though, I shouldn't be surprised. I hope the important bits are still human-controlled (and the same for Apple's many operating systems that absolutely deserve to remain stable and understood).
airspeedswift 2 days ago||
I assure you, every inch of the interpreter code has been stared at by humans, a lot. TBH even the assembly generated by it has.
ahartmetz 1 day ago||
All 150 kloc in six months by two people? Actually, it sounds like way too much code for the task unless 70+% of it is tests.
dcrazy 1 day ago||
> By the end of the project, we wrote nearly four times as many lines of test code as we wrote for the Swift interpreter itself.
dgellow 2 days ago||
From what I got Apple is using claude code A LOT internally
wahnfrieden 2 days ago|||
Yes they are using Claude Code - not the Xcode agents.

It worries me. I hope Codex adoption picks up there.

andrekandre 2 days ago||
thats a shame if true, they really should be dog-fooding that horrible agent ui in xcode to bring it up to a usable state
dcrazy 1 day ago|||
The UI got a massive overhaul in the new Xcode beta. It’s no longer confined to the sidebar.
wahnfrieden 1 day ago||
Devs continue to be tricked by incremental updates to it. It's still deficient
wahnfrieden 2 days ago|||
A lot of devs are tricked into using it because it’s official
LoganDark 1 day ago||
I love how it doesn't even support reasoning output or edit tool diffs. (Yes it can show diffs sometimes when using the 100% official flow but not when using ACP)
wahnfrieden 1 day ago||
It also doesn't support Computer Use or Browser Use among other deficiencies
LoganDark 1 day ago||
Sure but the basics should be down before tackling those, and they're not.
wahnfrieden 1 day ago||
You call it solid foundations, I call it deficiency and being over a year behind state of art available elsewhere (from the same service you're already paying for)
Cassell 2 days ago|||
It would be interesting to see their internal guidance on LLM use. It’s a massive amount of new power that has to be wielded carefully. That kind of guidance might mean the survival or downfall of some big corps in the next few years.
raphlinus 2 days ago||
Welcome to the club of doing high performance text in a memory safe language!
masiulis 2 days 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 2 days ago||
> high performance text

Just strings or rendering strings?

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

raphlinus 1 day ago||
Yeah, probably should have made a more substantive comment. I'm mostly thinking of the trio of Skrifa, Harfrust, and Parley, but there is other open source Rust work that qualifies as well.

There's also, very relevantly, the DWriteCore work from Microsoft. My understanding is that there's been some talk of open sourcing that, but it's still proprietary.

There are other things that count as high performance text in memory safe languages, for example implementations in Go, but in general those are not a good candidate to replace C and C++ in environments like operating systems and browsers.

AndriyKunitsyn 2 days ago||
What's funny is from 2023 (I think), macOS just draws the UI unhinted. You have a 1080p display and you don't want to see the letters in the UI blurred to death? Tough luck, 1080p is incompatible with macOS, everybody needs "retina", and nobody cares that Windows and all Linux DEs look on 1080p just fine.

It looks like this hinter will be used only in rendering PDFs, because that's where they test the performance.

jacquesgt 2 days ago||
While hinting is disabled for most fonts, there are some fonts that require hinting to render correctly. We have to support hinting for those fonts, and it was easier to make it secure by rewriting hinting in Swift than it would have been to comprehensively identify every font created by those foundries.
nomel 2 days ago|||
My last 1080p monitor was around 20 years ago. I have trouble comprehending people still use them regularly.
afavour 2 days ago|||
A very quick search yielded Dell selling 1080p laptops today:

https://www.dell.com/en-us/shop/dell-laptops/dell-15-laptop/...

It is very, very common. Just not in the Mac world.

kbolino 2 days ago|||
It's also the corporate standard for generic cubicle workstation monitors, though it's unusual to find a Mac in such a place anyway.
import 2 days ago|||
It’s very common for the people who got their last monitor 8 years ago.
bigyabai 2 days ago||
It's still the most common resolution for people using desktop monitors today, according to: https://gs.statcounter.com/screen-resolution-stats/desktop/w...
SSLy 1 day ago||
Also for gaming too: https://store.steampowered.com/hwsurvey/

1920 x 1080 51.89%

2560 x 1440 21.20%

3840 x 2160 5.00%

carlosjobim 1 day ago||
OS font rendering doesn't matter for gaming.
AndriyKunitsyn 2 days ago||||
People also use usable mice instead of touchpads, and they put the "ctrl" key where Apple thinks a useless "fn" should be. All kinds of things happen outside Apple world.

To me, it's more about what I'm used to. I have a perfectly fine several years-old monitor, so why should I throw it away?

nomel 1 day ago||
I'm a PC user with a work MacBook. I was talking about my PC.
yjftsjthsd-h 2 days ago||||
Then let me blow your mind:) One of my daily drivers is an ex-Chromebook at 1366x768. Granted, it's also physically smallish so the DPI isn't quite as low as a macbook would be with those pixels, but still. And that's a touch cramped but it's fine.
incanus77 2 days ago||
I'm reading on that resolution right now! MacBook Air 11" running Linux that I use as a quick hacking/reading machine in bed.
mschuster91 2 days ago|||
The problem is, as soon as you are not on a Mac but Linux or Windows, you are in for an awful, truly awful lot of pain. HiDPI support is a mess because even in the rare case applications are made with HiDPI in mind they are not tested on HiDPI machines.

Other way around, most Mac software is not tested how it behaves on inferior external monitors.

AndriyKunitsyn 2 days ago|||
What kind of windows programs are these? HiDPI is more than a decade old. A desktop application, no matter what OS it is, should always be tested with different scaling factors.
mschuster91 2 days ago|||
Ham radio software, both open-source and commercial, is a big thing, and so is many an in-house development in many businesses.
AndriyKunitsyn 6 hours ago||
Any particular program? GNU Radio seems perfectly fine.
dcrazy 1 day ago|||
Oh my sweet summer child. Even software being written TODAY isn’t being tested in HiDPI. Win32 still makes it difficult.
AndriyKunitsyn 1 day ago||
I’m not your child, and that’s false, it’s literally one key to change in the settings. That allows you to select the exact scaling factor, not macos’s “more text”/“less text”.
dcrazy 1 day ago||
Have you ever tried to write HiDPI-aware Win32 code? I suggest enabling HiDPI in Control Panel sometimes and marveling at how many Win32 apps just don’t notice and draw as postage stamps.

Mac OS X 10.4 tried the same thing (Quartz2D scaling) and it was so damn difficult that they threw it out and went for simple 1x/2x/3x auto-scaling. Even 3x was a challenge because of pixel alignment.

AndriyKunitsyn 6 hours ago||
Well, you were talking about testing, development of DPI-aware apps is another thing. It requires the developers to be, well, DPI-aware, but I don't think there are particular obstacles to that in winapi itself.

>Have you ever tried to write HiDPI-aware Win32 code?

I haven't. I don't think there's any reason to, I'm more of a wxwidgets fan. I don't think even Microsoft makes applications in raw WinAPI.

>I suggest enabling HiDPI in Control Panel sometimes and marveling at how many Win32 apps just don’t notice and draw as postage stamps.

The default behaviour of a DPI-unaware app in Windows is to scale everything by the scale factor. Which - yes, looks completely awful and blurry, but that's not what you describe.

wmedrano 1 day ago|||
I've been fine with Linux/KDE. Even the fractional scaling support is decent.

Edit: Guess it depends on the app

TazeTSchnitzel 2 days ago|||
macOS has been drawing unhinted text for an eternity, and for those who can tolerate it on low-DPI screens, it's a great thing: the letter shapes look the same at all sizes, and the spacing between letters is consistent at all sizes.
bschwindHN 2 days ago||
I'm a high DPI snob so I haven't used a low res monitor for work in forever, but isn't the entire point of font hinting to make the text more legible at smaller pixel grid sizes? Yes, of course the shapes are more consistent since the hinter isn't touching them, but isn't the end result just less legible text?
kccqzy 2 days ago||
Hinting purposefully destroys letter shapes in exchange for crispness. People who like macOS style font rendering prioritize letter shapes faithful to the font designer more than crispness.

Whether good letter shapes is more legible or crisper text is more legible is basically subjective. In the 2000s before HiDPI became popular different people really thought one was more legible than the other and vice versa. HiDPI made this basically moot.

kbolino 2 days ago|||
I had this problem on the first Apple Silicon Mac Mini in 2020 so it's at least a little older than 2023.
carlosjobim 1 day ago||
Retina displays were introduced more than a decade ago. Why should Apple still support outdated technology after such a long time?

If you work with text and fine UI elements, do yourself a favour and get proper tools for the job. Get an ergonomic mouse and a good keyboard while you're at it. In every other field professionals use high quality tools to do their jobs, IT shouldn't be any different.

A plumber has equipment worth tens of thousands of dollars, while IT professionals think it's outrageous to pay a few hundred for equipment which is undeniably an improvement.

wg0 2 days ago|
No mention of AI? Hand written code?
numist 2 days ago|
There's mention at the end. The models (and Swift itself!) have evolved a lot since this project started, so the early code is largely hand-rolled and the later changes were mostly authored by centaurs (to steal a term from chess).

But I personally reviewed every line that shipped and was absolutely insufferable about testing.