Comment by munificent
5 hours ago
Good article. Some related bits that other languages do:
Swift is able to avoid monomorphizing even when the type arguments have different GC shapes and allocation strategies. To do that, the dictionary (what Swift calls a "witness table") has entries for the functions the memory manager needs to allocate and trace a value of type argument's type.
Go's notion of dictionary and Swift's witness tables share a lot of DNA with how Haskell compiles generic code using type classes.
C#/.NET does an interesting hybrid approach. When source code is compiled to .NET bytecode, the generic code is only compiled once. Then at load time, the JIT will take that bytecode and monomorphize it to native code for each instantiation using a value type (primitive or struct). But instantiations of reference types all share a single JITTed implementation.
I'd be curious about the runtime cost of the extra lookup in case of Swift compared to Go.