If the ABI supports inline key functions we must emit them eagerly. The generic reason is that CodeGen might assume they are emitted and generate a reference to the vtable. In deserialization this rule becomes a little less clear because if a reference is generated, CodeGen will make a request and we will emit the vtable on demand.
This patch improves the performance of loading modules by slimming down the EAGERLY_DESERIALIZED_DECLS sections. It is equivalent to 'pinning' the vtable, with two benefits: (a) it does not require expertise in modules to find out that outlining the key function brings performance; (b) it also helps with third-party codebases.
We ran this change through our codebase and we saw no observable changes in behavior.
Patch by Yuka Takahashi and me!
If the function must be emitted for some reason other than being a key function (for instance, due to __attribute__((used)) or simply not being declared inline), this may result in it not getting emitted; that doesn't seem correct. (For a module it might typically work because most such cases would be redefinition errors, but it's wrong for cases like a precompiled preamble or PCH, which can be intended to be used only once and thus can contain strong external symbol definitions.)