Skip to content

Conversation

@slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Oct 13, 2016

SIL uses canonical types, but we still want to print them as if they were sugared, using the original generic parameter name instead of τ_M_N. Previously we would print the name of the archetype, which was wrong if a generic parameter was mapped to a concrete type, or if multiple generic parameters mapped to the same archetype. Re-work the AST printer and SIL serialization to preserve the sugar on the GenericTypeParamType properly.

This allows @DougGregor's ABI fix to be re-applied.

This is the last remaining issue before we can close rdar://problem/17821143 (that I'm aware of).

slavapestov and others added 3 commits October 12, 2016 18:56
Sugared GenericTypeParamTypes point to GenericTypeParamDecls,
allowing the name of the parameter as written by the user to be
recovered. Canonical GenericTypeParamTypes on the other hand
only store a depth and index, without referencing the original
declaration.

When printing SIL, we wish to output the original generic parameter
names, even though SIL only uses canonical types. Previously,
we used to accomplish this by mapping the generic parameter to an
archetype and printing the name of the archetype. This was not
adequate if multiple generic parameters mapped to the same
archetype, or if a generic parameter was mapped to a concrete type.

The new approach preserves the original sugared types in the
GenericEnvironment, adding a new GenericEnvironment::getSugaredType()
method.

There are also some other assorted simplifications made possible
by this.

Unfortunately this makes GenericEnvironments use a bit more memory,
however I have more improvements coming that will offset the gains,
in addition to making substitution lists smaller also.
Previous refactorings introducing GenericEnvironment left
behind some lint.
Now that we have the ability to write extensions where one of the type
parameters is equivalent to a concrete type, eliminate
_AnyHashableProtocol and provide AnyHashable-specific behavior for
Dictionary (where Key == AnyHashable) and Set (where Element ==
AnyHashable) rather than employing the "Key: _AnyHashableProtocol"
hack.

Fixes standard library ABI FIXME's swiftlang#35, swiftlang#37, swiftlang#39.
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@DougGregor
Copy link
Member

Awesome! -3 ABI FIXMEs. I suggest that you add a ChangeLong entry for this highly-requested feature.

@slavapestov
Copy link
Contributor Author

@DougGregor I added a changelog entry with the original PR, before the follow-up bug fixes.

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.

3 participants