[swift-dev] Changing how nominal type descriptors store type names

Joe Groff jgroff at apple.com
Fri Jan 22 20:21:57 CST 2016

Nominal type descriptors currently store the mangled name of the type they represent, but I don't think this is necessary or optimal. I don't believe the string is directly used for uniquing, and it's mostly used for reflective purposes. Since we've decided we want to use a human-parsable syntax for runtime type lookup, a more structured representation would likely be easier to match. Furthermore, since every mangled name includes the containing module name, there's a lot of redundancy in the mangled strings for every type. If we instead store only the unqualified type name, and a reference to the module name as a separate string, that's likely to be more space-efficient, since all types can share the same module name string, and most module names are shorter than the four bytes necessary for a relative reference. So instead of:

@"nominal type descriptor for Foo.Bar" = {
  .name = relative reference to "C3Foo3Bar",

we'd have:

@"nominal type descriptor for Foo.Bar" = {
  .name = relative reference to "Bar",
  .moduleName = relative reference to "Foo"

The one exception is the standard library, which gets a special one-character mangling; we could maybe pack an "is in standard library" bit somewhere so we avoid storing an extra reference in that case. Any objections or concerns?


More information about the swift-dev mailing list