2017 LLVM Developers’ Meeting: “Implementing Swift Generics ”
Channel:LLVM · Length:44:37 · Published:2017-10-31 · Views:20879
Summary
Swift compiler engineers explain how Swift implements generics using dictionary-passing with reified type metadata. They compare it with Java-style uniform representation and C++ or Rust monomorphization.
Why HN recommends it
Recommended as the clearest explanation of how Swift generics compile and how that differs from other languages.
there's a very nice talk on how Swift's generics compile. — HN, 2017
Programming language design · Compilers, interpreters & program analysis
Subtitles (excerpt)
okay I'm Slava pest ah've and today we're going to talk about generics and Swift so with other languages that have generics there are two popular implementation strategies so one you see a lot is just two mono morphing you take your generic function and for every instantiation of that function with concrete types the compiler generates a new specialization another common strategy is to use the types to type-check the function but then use some kind of boxed representation or runtime erasing the generic types so what a swift do well Swift does something different and it will take most of this talk to describe that but first let's start by giving an overview of the language so in Swift generic parameters are bounded this means that the type signature of a generic function places constraints on those parameters which describes what you can do with values of that type in this respect it's similar to most other languages that have generics but different than C++ templates for example and bounded generics is what enables us to do separate compilation so if we can type check and generate the code for a generic function separately from any specific instantiation or that function with concrete types and we can call it from another
On Hacker News
Swift's generics have some unique properties at module boundaries to allow for a stable ABI while enabling library evolution. To get additional background, you might be interested in this[0] conference talk (the paper's author is one of the co-presenters). Also, this post[1] by a Rust and Swift compiler engineer talks about what Swift does differently than other languages, and the tradeoffs that … — favorited, 2022-10
If you're interested, there's a very nice talk on how Swift's generics compile. It's different to Rust in some key ways. [VIDEO] — Veedrac, 2017-12
> It doesn't make sense to me that an embedded VM/interpreter could ever outperform direct code. You're adding a layer of abstraction and indirection, so how is it possible that a more indirect solution can have better performance? It is funny, but (like I’ve already mentioned[1] a few months ago) for serialization(-adjacent) formats in particular the preferential position of bytecode interpreter… — mananaysiempre, 2026-04
The Swift story around ABI stability and library evolution is pretty unique. Relatedly, its approach to generics doesn't fall into either of the 2 traditional paths (either box everything like Java and C#, or template instantiation like C++ or Rust). [LINK] [VIDEO] — favorited, 2022-11
Related videos
- CppCon 2015: Andrei Alexandrescu “std::allocator...” · CppCon · 1:12:27
- "What UNIX Cost Us" - Benno Rice (LCA 2020) · linux.conf.au · 34:14
- The Problem With Facebook · 2veritasium · 6:59
- Facebook Fraud · Veritasium · 8:59
- Intro to AI Safety, Remastered · Robert Miles AI Safety · 18:04
- Why Would AI Want to do Bad Things? Instrumental Convergence · Robert Miles AI Safety · 10:35
- Nick Bostrom - The Simulation Argument (Full) · Science, Technology & the Future · 23:28
- Why Not Just: Think of AGI Like a Corporation? · Robert Miles AI Safety · 15:27
- How Python was Shaped by leaky Internals, Armin Ronacher, Flask framework · Видео с мероприятий {speach! · 49:55
- Rich Harris - Rethinking reactivity · You Gotta Love Frontend · 36:45
- Lexical Scanning in Go - Rob Pike · GoogleFOSSSydney · 51:17
- William Byrd on "The Most Beautiful Program Ever Written" [PWL NYC] · PapersWeLove · 1:31:05
- Why Isn't Functional Programming the Norm? – Richard Feldman · Metosin · 46:09
- Maybe Not - Rich Hickey · ClojureTV · 1:03:28
- Conway's Game Of Life in APL · Dyalog · 7:47
- Lecture 1A | MIT 6.001 Structure and Interpretation, 1986 · MIT OpenCourseWare · 1:12:55