Tag: Swift

High-Level SIL Optimization in the Swift Compiler

Matt Rajca discovered last year that Swift’s Array.append(element) is 6x faster than Array operator+=(collection). This is a shame, because the latter is semantically equivalent, easier to type, and more pleasing to the eye. Swift is a new language, so there is no shortage of opportunities for optimization. I’ve enjoyed the recent uptick in “how to build a super simple compiler” blog posts, but there isn’t […]

Continue Reading

Algebraic Data Types in Swift

An algebraic data type is a type that’s the union of other data types. That is, it’s a type that may be one of several other types. Here’s how we would implement a linked list as an algebraic data type in Swift: enum LinkedList<Element> { case empty indirect case node(data: Element, next: LinkedList) } This defines an enum called LinkedList that might either be .empty […]

Continue Reading