Commit Graph

67 Commits

Author SHA1 Message Date
Slava Pestov
c5dfb5238a AST: Completely hide internal representation of SubstitutionMap
Make the addSubstitution() and addConformance() methods private,
and declare GenericEnvironment and GenericSignature as friends of
SubstitutionMap.

At some point in the future, we can switch to a more efficient
representation of SubstitutionMap, where instead of storing
multiple hashtables, we store arrays; the keys are pre-determined.
2017-02-12 01:42:36 -08:00
Slava Pestov
1954665a95 AST: Remove more uses of SubstitutionMap::add{Substitution,Conformance}()
A new SubstitutionMap::getProtocolSubstitutions() method handles
the case where we construct a trivial SubstitutionMap to replace
the protocol Self type with a concrete type.

When substituting one opened existential archetype for another,
use the form of Type::subst() that takes two callbacks instead of
building a SubstitutionMap. SubstitutionMaps are intended to be
used with keys that either come from a GenericSignature or a
GenericEnvironment, so using them to replace opened archetypes
doesn't fit the conceptual model we're going for.
2017-02-06 20:33:39 -08:00
Slava Pestov
b22f9ea487 AST: Remove SubstitutionMap::getMap()
We don't want to expose the fact that SubstitutionMaps are
backed by a DenseMap, since that's going to change soon.
2017-02-06 19:43:33 -08:00
Slava Pestov
1c21b88260 AST: New SubstitutionMap::combineSubstitutionMaps() method
In several places, we construct a SubstitutionMap by taking
generic parameters from one SubstitutionMap up to a certain
depth, with the rest coming from a second SubstitutionMap.

Factor this out into a new utility method, to help with
hiding the internal representation of SubstitutionMap from
clients.

This was meant to be NFC, but it actually fixes a crash in
the devirtualizer, because the old logic there was slightly
wrong, so I added a test for this.
2017-02-06 16:14:07 -08:00
Doug Gregor
51fbd297bc [AST] Prefer concrete to abstract conformances in SubstitutionMap's lookup. 2017-01-24 19:36:44 -08:00
Doug Gregor
d3c7a71f85 [AST] Factor the search for conformances more cleanly. NFC 2017-01-24 19:36:44 -08:00
Doug Gregor
227919a97e [AST] Add SubstitutionMap::dump() debugging utility 2017-01-24 19:36:44 -08:00
Slava Pestov
24b2531e5f AST: Have SubstitutionMaps manage the memory for the conformance array 2017-01-18 00:15:59 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Doug Gregor
16585992f6 [AST] Strengthen signature of SubstututionMap::addSubstitution().
It requires a CanSubstitutableType internally, so use that in the
signature and fix up all of the callers.
2017-01-05 16:04:19 -08:00
Slava Pestov
ac7a3030e3 Sema: Fix inheritance of designated initializers with default arguments in generic context
We were dropping the substitutions required to call the default
argument generator on the floor, when the correct solution is to
remap them to substitutions in terms of the base class signature.

Fixes <rdar://problem/29721571>.
2016-12-22 14:33:01 -05:00
Joe Groff
b6823b930b SIL: Change SILType::subst to be SubstitutionMap-based.
This simplifies the SILType substitution APIs and brings them in line with Doug and Slava's refactorings to improve AST-level type substitution. NFC intended.
2016-12-14 14:33:32 -08:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Doug Gregor
85ba4fe40f [AST] Narrow TypeSubstitutionMap to SubstitutableType keys.
Type substitution works on a fairly narrow set of types: generic type
parameters (to, e.g., use a generic) and archetypes (to map out of a
generic context). Historically, it was also used with
DependentMemberTypes, but recent refactoring to eliminate witness
markers eliminate that code path.

Therefore, narrow TypeSubstitutionMap's keys to SubstitutableType,
which covers archetypes and generic type parameters. NFC
2016-11-15 11:34:09 -08:00
Doug Gregor
e3ce039705 Remove SubstitutionMap::removeType(). 2016-11-01 20:42:25 -07:00
Doug Gregor
b5511bd3ea [Serialization] (De-)serialize witnesses completely.
The witnesses in a NormalProtocolConformance have never been
completely serialized, because their substitutions involved a weird
mix of archetypes that blew up the deserialization code. So, only the
witness declarations themselves got serialized. Many clients (the type
checker, SourceKit, etc.) didn't need the extra information, but some
clients (e.g., the SIL optimizers) would end up recomputing this
information. Ick.

Now, serialize the complete Witness structure along with the AST,
including information about the synthetic environment, complete
substitutions, etc. This should obsolete some redundant code paths in
the SIL optimization infrastructure.

This (de-)serialization code takes a new-ish approach to serializing
the synthetic environment in that it avoids serializing any
archetypes. Rather, it maps everything back to interface types during
serialization, and deserialization forms a new generic environment
(with new archetypes!) on-the-fly, mapping deserialized types back
into that environment (and to those archetypes). This way, we don't
have to maintain identity of archetypes in the deserialization code,
and might get some better re-use of the archetypes.

More of rdar://problem/24079818.
2016-11-01 17:14:17 -07:00
Slava Pestov
a993e36c06 AST: Add a new SubstitutionMap data structure
This replaces the TypeSubstitutionMap / ConformanceMap pair that
has been appearing more and more lately.
2016-09-08 21:59:11 -07:00