FREN

#FF00AA


26 oct. 2014

The Third Coming of Objective-C?

I’ve already written about how much I dislike Swift, and how much more I resent it for signaling the death of Objective-C: just like everyone could read the writing on the wall regarding Carbon and knew they had to port their apps to Cocoa as soon as possible, the Swift announcement seemed to make it obvious that Objective-C is now an evolutionary dead end that I will have to abandon sooner than later, despite my strong preference for nil messaging.

But John Siracusa’s digression on Swift in his Yosemite review suddenly gave me what could either be new hope or utter delusion:

The Swift compiler introduces another step and another intermediate form into the compilation process: Swift Intermediate Language (SIL). Here’s the process for compiling Swift code for an x86-64 CPU using swiftc. […]

It’s worth considering why SIL exists at all. […] Despite the obvious benefits of SIL in its current role, a syntax-independent, high-level intermediate form with its own optimizer definitely seems like a technology with some potential. It’s possible that the larger purpose of SIL has not yet been revealed.

How far-fetched is it to imagine that, a few years down the line, Objective-C code could be compiled into SIL? I’m sure Apple will want to get rid of the Obj-C runtime in a few years (or at least stop loading it in memory by default — which would make Obj-C apps second-class citizens that start up and run slower on future devices), but what if that legacy code was able to run on top of the Swift runtime?

Of course, there are integral, structural differences between Objective-C and Swift, which would make such a translation extremely complicated and costly in resources, but… wait, are there?

Despite its rich feature set, the Swift language itself is actually quite minimal. All the basic data types are not part of the language proper. They’re part of the Swift standard library that is loaded automatically by the compiler—and the Swift standard library is written in Swift [and named Swift].

Could Objective-C code be translated into SIL and linked to an “ObjectiveC” library? Could existing Objective-C binaries be translated into SIL, even, so that legacy apps from the Store would still be able to run on top of Swift?

I don’t know nearly enough about languages and compilers to have an idea of how complicated what I’m suggesting might be. But I understand that the engineers in charge of Apple’s compilers and development tools are a pretty smart bunch, so who better to do something like this?

Want to know when I post new content to my blog? It's a simple as registering for free to an RSS aggregator (Feedly, NewsBlur, Inoreader, …) and adding www.ff00aa.com to your feeds (or www.garoo.net if you want to subscribe to all my topics). We don't need newsletters, and we don't need Twitter; RSS still exists.

Legal information: This blog is hosted par OVH, 2 rue Kellermann, 59100 Roubaix, France, www.ovhcloud.com.

Personal data about this blog's readers are not used nor transmitted to third-parties. Comment authors can request their deletion by e-mail.

All contents © the author or quoted under fair use.