Skip to content

[WIP] [Mangling] Mangle more standard substitutions #17290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jun 18, 2018

Introduce more standard substitutions to the mangling scheme, to better compress manglings that involve common standard library types.

Implements rdar://problem/40468532.

Note: This shaves ~472k off the size of the unstripped standard library binary.

@DougGregor DougGregor requested a review from eeckstein June 18, 2018 06:21
@jckarter
Copy link
Contributor

@eeckstein With the new substitution mangling scheme, is S0 still a valid normal substitution? If not, we could squeeze eleven more standard substitutions using S[0-9_].

@jrose-apple
Copy link
Contributor

It seems useful to me to reserve some expansion capacity—for example, S_XY could mean "standard substitution of length 2, value XY". Even without that there's still a few letters left.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is silly of me but I'd prefer if the letters lined up with the protocols as much as possible too, like they do for many of the structs.

STANDARD_TYPE(Protocol, B, BinaryFloatingPoint)
STANDARD_TYPE(Protocol, C, Character) // not actually a protocol??
STANDARD_TYPE(Protocol, E, Encodable)
STANDARD_TYPE(Protocol, e, Decodable) // to go with Encodable; Set becomes 'h', to go with Hashable
STANDARD_TYPE(Protocol, F, FloatingPoint)
STANDARD_TYPE(Protocol, G, RandomNumberGenerator)
// 'g' is open
STANDARD_TYPE(Protocol, H, Hashable)
// 'h' for Set, to go with Hashable
// 'J' is open
STANDARD_TYPE(Protocol, j, Numeric) // a stretch, comes from i-j-k as indexes
STANDARD_TYPE(Protocol, K, BidirectionalCollection) // "kollection", plus pairing with RAC
STANDARD_TYPE(Protocol, k, RandomAccessCollection) // "kollection", plus pairing with BC
STANDARD_TYPE(Protocol, L, Comparable) // "less than"
STANDARD_TYPE(Protocol, l, Collection) // co'l'lection, plus right before MC
STANDARD_TYPE(Protocol, M, MutableCollection)
STANDARD_TYPE(Protocol, m, RangeReplaceableCollection) // pairing with MC
// 'o' is open
STANDARD_TYPE(Protocol, Q, Equatable) // e'q'uatable
STANDARD_TYPE(Protocol, T, Sequence) // pairing with IteratorProtocol
STANDARD_TYPE(Protocol, t, IteratorProtocol) // i't'erator
STANDARD_TYPE(Protocol, U, UnsignedInteger)
STANDARD_TYPE(Protocol, X, RangeExpression) // e'x'pression
STANDARD_TYPE(Protocol, x, Strideable) // pairing with RangeExpression
STANDARD_TYPE(Protocol, Y, RawRepresentable) // arbitrary
STANDARD_TYPE(Protocol, y, StringProtocol) // arbitrary
STANDARD_TYPE(Protocol, Z, BinaryInteger) // Z, from math
STANDARD_TYPE(Protocol, z, SignedInteger) // Z, from math

STANDARD_TYPE(Protocol, j, Equatable)
STANDARD_TYPE(Protocol, K, Comparable)
STANDARD_TYPE(Protocol, k, Hashable)
STANDARD_TYPE(Protocol, L, Character)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a struct, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes! It is a struct, thank you.

@jckarter
Copy link
Contributor

Did you look at what impact this has on binary sizes on a corpus like the compatibility suite? The effect on standard library binary size may not be representative due to the fact that these types are all defined there, but the standard library's size is somewhat less important in the future for Apple platforms when it's in the shared cache.

@DougGregor
Copy link
Member Author

I did not look at binary sizes across the compatibility suite. I'm going to call "perfect is the enemy of the good" on this optimization problem and focus on getting it merged. Y'all didn't comment on the (de-/re-/)mangler code changes ;)

@DougGregor
Copy link
Member Author

Sigh, I'm taking @jrose-apple 's attempt at lining up letters with names, though. Updates coming.

@DougGregor
Copy link
Member Author

Note that o and C are for Objective-C and C imports.

@jckarter
Copy link
Contributor

@DougGregor Sorry, I didn't mean to raise the issue saying you should redo your work or try to adapt the set of substitutions based on some statistical model or anything like that, only that I think the size savings there would be a more interesting and compelling message than the size impact on the stdlib alone.

@jrose-apple
Copy link
Contributor

Okay, okay, I'll admit I'm not sure why some of those manglings are disallowing the standard substitutions, and comments as to why would be nice.

@jrose-apple
Copy link
Contributor

In that case I suggest 'g' for "grapheme cluster" for Character.

@DougGregor
Copy link
Member Author

g is already used as a shortcut for optional types:

type ::= type 'Sg' // optional type, shortcut for: type 'ySqG'

@DougGregor DougGregor force-pushed the mangle-more-standard-substitutions branch from 99b1a28 to 6b8c802 Compare June 19, 2018 06:36
@jrose-apple
Copy link
Contributor

…I guess that makes it 'J', and the alphabet is filled after all!

…ypes.

Since the mangling scheme and set of standard library types is effectively
fixed now, introduce known mangling substitutions for a number of new
standard library types, filling out the S[A-Za-z] space.

Reduces standard library binary size by ~195k.
Protocol name mangling didn’t always go through a path that allowed the use
of standard substitutions. Enable standard substitutions for protocol name
manglings where they make sense.

Removes ~277k from the standard library binary size.
@DougGregor DougGregor force-pushed the mangle-more-standard-substitutions branch from 6b8c802 to a66df57 Compare June 20, 2018 06:24
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor DougGregor merged commit 36acac7 into swiftlang:master Jun 20, 2018
@DougGregor DougGregor deleted the mangle-more-standard-substitutions branch June 20, 2018 13:29
@eeckstein
Copy link
Contributor

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants