Are generics specialized during compilation or they are just like java generics only for compile time checks?

后端 未结 1 504
再見小時候
再見小時候 2020-12-18 01:33

There are three ways to implement generics:

  1. Just a tool for compile time checks, but every template instance is compiled to the same byte/assembly code impl

相关标签:
1条回答
  • 2020-12-18 02:10

    Swift starts by compiling a single implementation that does dynamic type checking, but the optimizer can then choose to clone off specialized implementations for particular types when the speed vs code size tradeoffs make sense. Ideally, this gets 90% of the speedup of always cloning, without the code size and compilation time exploding.

    0 讨论(0)
提交回复
热议问题