I saw that SILGen has mechanisms for lazily emitting conformances. I wonder why this is done: is it an optimization (performance, code-size), or is it necessary for correctness?
If we emit conformances eagerly, we generate a massive volume of witness tables and thunks that aren't really needed by the program, so it saves a lot of memory and time in the SIL optimizer to avoid emitting these unnecessary objects in the first place.
Thank you!
I wonder if this rationale is documented anywhere? If not, adding some code documentation sounds good. I care about documentation like this so I'm happy to write a short draft sometime.
Also adding more detail here to Joe's reply, just like the other thread: imported types often conform to a variety of protocols, such as RawRepresentable
, OptionSet
, Equatable
, and more. If you reference a type but don't use the conformance -- which is the common case -- we can avoid doing a lot of work. Together with lazy body synthesis, this cuts down on unnecessary type checking and SILGen work for imported decls.