mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Rather than storing associated type metadata access functions in witness tables, initially store a pointer to a mangled type name. On first access, demangle that type name and replace the witness table entry with the resulting type metadata. This reduces the code size of protocol conformances, because we no longer need to create associated type metadata access functions for every associated type, and the mangled names are much smaller (and sharable). The same code size improvements apply to defaulted associated types for resilient protocols, although those are more rare. Witness tables themselves are slightly smaller, because we don’t need separate private entries in them to act as caches. On the caller side, associated type metadata is always produced via a call to swift_getAssociatedTypeWitness(), which handles the demangling and caching behavior. In all, this reduces the size of the standard library by ~70k. There are additional code-size wins that are possible with follow-on work: * We can stop emitting type metadata access functions for non-resilient types that have constant metadata (like `Int`), because they’re only currently used as associated type metadata access functions. * We can stop emitting separate associated type reflection metadata, because the reflection infrastructure can use these mangled names directly.
25 KiB
25 KiB