Fixes a compiler crash in case a private global is only reference from another global variable, for example:
```
private var g1 = 27
let g2 = UnsafePointer(&g1)
```
rdar://117189962
The "regular" CMO is done with the option `-cross-module-optimization`. It's good for performance but can increase code size.
Now, which this change CMO is also done if the option is not given, but in a very conservative way. Only very small functions are serialized and not additional type metadata is kept alive.
rdar://70082202
It makes sense to to this in a single pass, because there might be dead cycles for globals and functions, e.g. if a global references a function in its static initializer and the function references that global.
Another improvement: eliminate dead global-initializers. Before we had an explicit SIL representation of statically initialized globals, we had to keep them alive.
rdar://32956923
- Clear the 'serialized' flag on witness tables and vtables
after serialization, not just functions. This fixes SIL
verifier failures if post-serialization SIL is printed
out and parsed back in.
- Clear the 'serialized' flag when deserializing functions,
witness tables and vtables in a module that has already
been serialized. This fixes SIL verifier failures if
we deserialize more declarations after serializing SIL.
We were seeing SIL verifier failures on bots that run the
tests with the stdlib built with non-standard flags.
Unfortunately I don't have a reduced test case that would
fail in PR testing without these fixes.
Fixes <rdar://problem/36682929>.
The witness table had shared linkage, but we weren't serializing them,
which would cause linking errors if we emitted a reference to such a
witness table from a different module than the one where it was first
defined, as a result of deserializing and optimizing SIL.
This issue was introduced when SIL witness table serialization was
made conditional on the -sil-serialize-witness-tables flag, which is
normally only enabled for the standard library.
When the flag was added, existing tests were updated to pass the
flag, which masked the issue. Remove the flag from existing tests,
ensure that imported witness tables are still [serialized], and add
a new test specifically for the behavior enabled by this flag.
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.
This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
Textual SIL was sometimes ambiguous when SILDeclRefs were used, because the textual representation of SILDeclRefs was the same for functions that have the same name, but different signatures.
Textual SIL was sometimes ambiguous when SILDeclRefs were used, because the textual representation of SILDeclRefs was the same for functions that have the same name, but different signatures.
Also, mark witness thunks for [fragile] witnesses as [fragile].
This allows us to serialize the witness table, as well as any thunks
for witnesses declared @_transparent and @inline(__always).