Obfuscated Tiny C Compiler (2002)
bellard.org
bellard.org
Of course the C code was a lot simpler, but still...
Of course, there are (still) pathological cases where a single line of code will abort because it runs out of time.
> cat too-complex.swift
let a:[Int] = [1] + [2] + [3] + [4] + [5] + [6] + [7]
For me, this aborts after about a minute and a half: > time swiftc too-complex.swift
too-complex.swift:1:49: error: expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions
let a:[Int] = [1] + [2] + [3] + [4] + [5] + [6] + [7]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
real 1m35.094s
user 1m16.698s
sys 0m5.141s
That appears to be some sort of exponential in type inference. Other similar ones have been fixed.The ternary expressions mentioned elsewhere also appear to be problematic, and in general, there's little time bombs all over just waiting to go off.
The rate I mentioned earlier was taken from a CocoaHeads talk by someone who built a caching mechanism for Carthage, because their Swift framework(s) of around 20KLOC were taking ages to compile.
So it's a real-world example, not something made up.
If I recall, it's in the implicit conversions, not strictly the type inference.
To compare a historical compiler with your Swift numbers: In 1989, Turbo C compiled 16K lines per minute on a ho-hum machine. The computers today, 30 years later, are more than 60x faster, so one would expect compilation speeds exceeding 16k per second of swift code. Turbo Pascal compiled about twice as fast as Turbo C at the time.
There are 60 seconds in a minute.
Wow, how common is this in practice? That sounds broken.
This is the active code repository of TCC: http://repo.or.cz/w/tinycc.git
- Mach-O binaries?
- ARM?
- Objective-C?
- ?
Is it just for fun, or could it be 'useful'? iOS categorically prohibits JIT, right?
It should be pretty easy to add Objective-C and C++ support, right? ( ͡° ͜ʖ ͡°)
That said, it is indeed tiny. Very nice project, as usual from FB.
My current interest in studying this code is more the journey than the result, but I am quite sure I will have to try to approach someone more familiar with the code at some point.
I guess this is also why Kona is generally regarded dismally - I wonder if that view isn't carefully cultured/spread for similar reasons. In any case the implementation is heavily tied to the success (which is interesting in and of itself), which also ties the implementation to the niche, and I guess I lament the impact the language's resulting general accessibility and reach because things won't be changing anytime soon. Eh, I guess the selfish(?)/survivalist(?) view is to clear the calendar and say hi while Whitney's still teaching :P (I've been meaning to do exactly this, but my, er, calendar (life, really) doesn't permit me the confidence to say I'd definitely be able to keep up.)
In the video it's mentioned there's not much optimization in kos. That's mildly encouraging, from a general systems perspective and also from an architectural standpoint (eg, functional programming can be interesting/novel/weirdly-aesthetic and "efficient enough" (or even more than) with eg UI latency).
I am still working in b.c itself. I have started from the entry point and try to make sense of it following different simple examples, with help from an opcodes table and other references. It is a very interesting exercise, and I think I have already found some bug, but it is not an easy task. I am not sure I will ever totally decipher it.
I would like to make public what I have so far and ask for help, but since this code does not have a public license, I would not feel comfortable doing that. My plan is to try to get as far as possible (I have only been working on it for a couple of weeks so far), and ask for permission to make it public from Whitney, though I am not sure what to expect.
https://news.ycombinator.com/item?id=8558822
https://news.ycombinator.com/item?id=8746054
They're quite a bit larger, but not "obfuscated" (although still terse), so could be more suitable to learn from.