Commit Graph

86 Commits

Author SHA1 Message Date
Doug Gregor
cdff7427f8 [AST] Unique and ASTContext-allocate SubstitutionMaps.
Prepare for SubstitutionMaps to be stored in other AST nodes by making
them ASTContext-allocated and uniqued (via a FoldingSet). They are now
cheap to copy and have trivial destructors.
2018-04-30 10:42:03 -07:00
Doug Gregor
cebbe45c23 [AST] Flatten internal representation of SubstitutionMap.
Collapse the out-of-line array of replacement types and the DenseMap used
for conformances into a single field that references out-of-line,
tail-allocated storage for all of the contents of a SubstitutionMap.
The conformances are now represented as a flat array whose indices
line up with the indices of the conformance requirements in the
underlying generic signtature.

Reference this storage via a single shared_ptr, so that copies of
SubstitutionMaps are cheap but we aren't (yet) uniqueing them or
storing them within the ASTContext.
2018-04-30 00:41:28 -07:00
Doug Gregor
7f2c88fad5 [AST] Internalize details of constructing a SubstitutionMap. 2018-04-29 23:03:12 -07:00
Doug Gregor
80eae200b6 [AST] Preserve type sugar for generic typealiases
Introduce a new Type node, BoundNameAliasType, which describes a
reference to a typealias that requires substitutions to produce the
underlying type. This new type node is used both for references to
generic typealiases and for references to (non-generic) typealiases
that occur within generic contexts, e.g., Array<Int>.Element.

At present, the new type node is mainly useful in preserving type
sugar for diagnostics purposes, as well as being reflected in other
tools (indexing, code completion, etc.). The intent is to completely
replace NameAliasType in the future.
2018-03-21 23:49:17 -07:00
Joe Groff
d4e03f2ba3 SIL: Add an 'external' KeyPathPatternComponent kind.
This will allow key paths to resiliently reference public properties from other binaries by referencing a descriptor vended by the originating binary. NFC yet, this just provides printing/parsing/verification of the new component.
2018-02-14 10:48:24 -08:00
Jordan Rose
10daf26bf7 [AST] Use CanType in SubstitutionMap
No functionality change---the code was already using canonical types
in practice.
2018-01-30 15:24:06 -08:00
Doug Gregor
6ef76a92f4 [AST] Use flat array storage for SubstitutionMap's replacement types.
The replacement types in a SubstitutionMap correspond with the generic
parameters of its generic signature, so replace the DenseMap storage
with a flat array of Types, one element for each generic parameter.
2017-04-28 16:22:07 -07:00
Slava Pestov
0290c2d5d8 AST: Make GenericSignature and GenericEnvironment SubstitutionMaps interchangable
SubstitutionMap::lookupConformance() would map archetypes out
of context to compute a conformance path. Do the same thing
in SubstitutionMap::lookupSubstitution().

The DenseMap of replacement types in a SubstitutionMap now
always has GenericTypeParamTypes as keys.

This simplifies some code and brings us one step closer to
a more efficient representation of SubstitutionMaps.
2017-04-24 14:12:36 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Doug Gregor
6878538ba1 [AST] Remove GenericEnvironment from SubstitutionMap; it's unnecessary. 2017-04-05 11:21:39 -07:00
Doug Gregor
d0499a3613 [SubstitutionMap] Eliminate the parent map and handle archetype conformances.
When looking for a conformance for an archetype, map it out of context
to compute the conformance access path, then do the actual lookups
based on mapping the starting type back into the context. Eliminate
the parent map and "walk the conformances" functionality.
2017-04-04 10:58:01 -07:00
Doug Gregor
81c21b85f2 [AST] Track the generic signature/environment for a substitution map.
Substitution maps are effectively tied to a particular generic
signature or environment; keep track of that signature/environment so
that we can (eventually) use it to find conformances.
2017-04-04 10:58:01 -07:00
Roman Levenstein
6f54798df8 Verify the construction of SubstitutionMaps
After substitution maps are constructed, check their invariants. It helps to catch very subtle bugs related to substitutions.
2017-03-20 15:30:12 -07:00
Slava Pestov
5381921131 AST: Generalize SubstitutionMap::combineSubstitutionMaps() 2017-03-08 13:54:28 -08:00
Slava Pestov
de2f5f78ac AST: Remove Substitution::subst()
I want to get rid of Substitution entirely, and now we have
the right abstractions to do everything with SubstitutionMap.
2017-03-07 16:04:54 -08:00
Slava Pestov
13cc1ad07c AST: Remove SubstitutionMap::getConformances() 2017-03-07 16:04:53 -08:00
Slava Pestov
b41888acdf AST: Add SubstitutionMap::subst()
This will replace Substitution::subst().
2017-03-07 16:04:46 -08:00
Slava Pestov
8fe97c46eb AST: Make SubstitutionMap::lookupSubstitution() private 2017-03-02 13:31:15 -08:00
practicalswift
65b0219f7b [gardening] Fix typos 2017-02-14 20:04:08 +01:00
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