Are generalizations specialized at compile time or are they similar to java generics only for checking compile time?

There are three ways to implement generics:

  • Just a tool for checking compile time, but each instance of the template is compiled into the same byte / assembly code implementation (Java, as indicated in the "type wipe" comments implementation)

  • Each instance of the template is compiled into specialized code (C ++, C #)

  • Combination # 1 and # 2

Which one is implemented in Swift?

+6
source share
1 answer

Swift begins by compiling a single implementation that performs dynamic type checking, but the optimizer can then choose to clone specialized implementations for certain types when it makes sense to compromise between speed sizes and code sizes. Ideally, this gets 90% acceleration of always cloning, without changing the size of the code or compilation time.

+8
source

Source: https://habr.com/ru/post/970263/


All Articles