Commit Graph

134 Commits

Author SHA1 Message Date
Jordan Rose
f8fd85b51b Cache ConformanceAccessPaths in GSB::EquivalenceClass for big wins
This dramatically speeds up SubstitutionMap::lookupConformance,
shaving off 1/3 of the time spent compiling the standard library.
2018-08-09 11:58:19 -07:00
Slava Pestov
d8fc9decf9 AST: Remove GenericSignature::getSubstitutionMap() 2018-05-28 19:45:28 -07:00
Slava Pestov
bd6281c558 AST: Change SubstitutionMap conformance lookup callbacks to take ProtocolDecl and not ProtocolType 2018-05-19 01:09:17 -07:00
Doug Gregor
a03a7b85de Eliminate GenericSignature::enumeratePairedRequirements() 2018-05-11 23:35:41 -07:00
Doug Gregor
8010939238 [AST] Eliminate several uses of enumeratePairedRequirements(). 2018-05-11 22:33:03 -07:00
Doug Gregor
ef020c74aa Eliminate all vestiges of Substitution and SubstitutionList.
Introduced during the bring-up of the generics system in July, 2012,
Substitution (and SubstitutionList) has been completely superseded by
SubstitutionMap. R.I.P.
2018-05-11 21:43:40 -07:00
Doug Gregor
4136a1897a [AST] Split SubstitutionMap::Storage into its own header.
Now that SubstitutionMap is used in so many places, reduce it's header
dependencies by moving SubstitutionMap::Storage into its own separate
implementation header. Use forward declarations of other entities
(GenericSignature, Substitution) instead.

Good for build times and general sanity.
2018-05-03 09:49:09 -07:00
Doug Gregor
7f2c88fad5 [AST] Internalize details of constructing a SubstitutionMap. 2018-04-29 23:03:12 -07:00
Joe Groff
bd974f0cc4 AST: Exclude noncanonical params from GenericSignature::enumeratePairedRequirements.
Fixes a bug where having two generic params same-typed together would lead to crashes in IRGen, and maybe other places, that only expect to deal with canonical params.
2018-04-17 10:45:57 -07:00
Slava Pestov
75db43b978 AST: Replace ProtocolType::compareProtocols() with TypeDecl::compare() 2018-04-06 15:41:07 -07:00
Huon Wilson
0e337acae0 Revert "[AST] Ensure requirements are correctly identified as conditional." 2018-03-14 08:12:37 +11:00
Huon Wilson
88b9f2c94d [AST] Ensure requirements are correctly identified as conditional.
Previously, the following code would result in different sets of
conditional requirements:

  struct RedundancyOrderDependenceGood<T: P1, U> {}
  extension RedundancyOrderDependenceGood: P2 where U: P1, T == U {}

  struct RedundancyOrderDependenceBad<T, U: P1> {}
  extension RedundancyOrderDependenceBad: P2 where T: P1, T == U {}

The T: P1 requirement is redundant: it is implied from U: P1 and T == U,
but just checking it in the signature of the struct isn't sufficient,
the T == U requirement needs to be considered too. This uses a quadratic
algorithm to identify those cases. We don't think the quadratic-ness is
too bad: most cases have relatively few requirements.

Fixes rdar://problem/34944318.
2018-03-09 14:00:09 +11:00
Doug Gregor
bd266b0520 [GSB] Introduce type-rewriting rules only when we merge equivalence classes.
Instead of representing every same-type constraint we see as a rewrite rule,
only record rewrite rules when we merge equivalence classes, and record
rules that map the between the anchors of the equivalence classes. This
gives us fewer, smaller rewrite rules that (by construction) build correct
anchors.
2018-02-16 15:09:58 -08:00
Doug Gregor
3b7a53e208 [GSB] Fix a rogue "|| true that came in with the fix for rdar://problem/37283860. 2018-02-13 14:25:09 -08:00
Doug Gregor
89bc3a6de1 [GSB] Make conformance access paths robust against non-canonical signatures.
With specific type-checking interleavings in large projects, the generic
signature builder for the generic signature of a protocol might not have
been built from the requirement signature of the protocol, which would
lead to malformed conformance access paths. Make this code path more
robust by building a new generic signature builder when this happens.

This is a stop-gap solution that is suitable for the Swift 4.1 branch;
a better solution would be to re-canonicalize the generic signature
builder itself somehow, but this carries more risk in the short term.

Fixes rdar://problem/37335173.
2018-02-13 10:14:29 -08:00
David Zarzycki
3da6fe9c0d [AST] NFC: Do not reinterpret_cast pointers into CanTypeWrappers
This also introduces 'TypeArrayView' for when a 'Type' is statically
known to be a given TypeBase subclass.
2018-01-31 11:20:05 -05:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Doug Gregor
d18ecda796 [GSB] Ensure that we don't build an invalid potential archetype.
Queries against the generic signature might use types that are
ill-formed for that generic signature, e.g., because they refer to
associated types of unrelated protocols. Detect such conditions to
maintain GSB invariants that all potential archetypes in a well-formed
generic signature are well-formed.

Fixes the crash in SR-6797 / rdar://problem/36673825.
2018-01-23 13:52:06 -08:00
Doug Gregor
5cdf8f44aa [NFC] Fix spacing 2017-12-13 23:16:37 -08:00
Doug Gregor
e10ecbd80e [GSB] Only check protocol requirements not generated from the signature.
If we used the requirement signature to create a protocol requirement
element in a requirement source, there's no need to verify that it's
from the requirement signature (duh).
2017-12-13 20:17:18 -08:00
Doug Gregor
a77dec1714 [GSB] Canonicalize conformance access paths on-the-fly.
When forming a conformance access path, remove from consideration any
requirement sources that contain protocol requirements that aren't
found in the requirement signature. This ensure well-formedness of the
resulting conformance access path. Huge thanks to Slava for reducing
this one, and apologies to Arnold for having to track it down a second
time before I fixed it.

Fixes SR-6200 / rdar://problem/35113583.
2017-12-13 19:49:15 -08:00
Doug Gregor
e3a5318b97 [Type checker] Teach conformsToProtocol() to check conditional requirements.
conformsToProtocol() is the main way in which we check whether a given type
conforms to a given protocol. Extend it to check conditional requirements by
default, so that an unmodified caller will get the "does not conform" result
(with diagnostics when a location is present) rather than simply ignoring
the conditional requirements.

Some callers take responsibility for conditional requirements, e.g., to
push them into the constraint system. Allow those callers to opt out of
this checking, and do so wherever appropriate.

Fixes rdar://problem/35518088, where we were ignoring the conditional
requirements needed to verify that Equatable synthesis could be performed.
2017-11-21 21:02:00 -08:00
Doug Gregor
c5fe5c47c9 [AST] Verify canonicalization of generic signatures.
When we canonicalize a generic signature, ensure that the resulting
signature has canonical requirements in the appropriate order.
More validation for generic signature canonicalization as part of the
ABI, which is tracked by SR-3733 / rdar://problem/31412994.
2017-11-06 21:22:36 -08:00
Doug Gregor
e0aedef88a [AST] Handle superclass and concrete sources in conformance access paths.
If we encounter a superclass or concrete source within a conformance
access path, use the stored conformance to terminate the path. Fixes a
compiler crasher.
2017-10-27 23:41:08 -07:00
Doug Gregor
a510e9b56d [GSB] Eliminate most uses of PotentialArchetype::getBuilder().
The remaining two uses after this refactor are... stubborn.
2017-10-23 10:39:21 -07:00
Doug Gregor
aa9755d149 [GSB] Start moving RequirementSource off of potential archetypes.
Eliminate potential archetypes from most of the public interface of
RequirementSource.
2017-10-20 15:18:36 -07:00
Doug Gregor
3177edc911 [GSB] Eliminate an unnecessary archetype-anchor computation. 2017-10-17 21:00:24 -07:00
Doug Gregor
6db9cc8c54 [AST] Consolidate the generic signature "diff" algorithm used in two places.
Introduce GenericSignature::requirementsNotSatisfiedBy(otherSig) to
compute the set of requirements in a generic signature that aren't satisfied
by some other generic signature. This is used both for conditional
conformances (the conditional requirements) and for name mangling of
constrained extensions/protocol conformances.
2017-10-12 14:23:46 -07:00
Doug Gregor
e4ff3a5377 [Mangling] Mangle generic signature requirements not satisfied by parent context.
The mangler had some ad hoc logic for only mangling requirements in a
generic signature that are not requirements in the parent context's
generic signature. However, it was based on an heuristic that isn't
correct. Replace that logic with a check to determine whether
the requirement is satisfied by the parent generic signature, which is
far simpler.

Fixes rdar://problem/31889040 / SR-6107.
2017-10-11 08:46:01 -07:00
Huon Wilson
945f723d59 [AST] Compute conditional requirements in a conformance.
This allows determining which requirements make a conformance conditional; as
in, which requirements aren't known as part of the type itself.

Additionally, use this to assert that a few builtin protocols aren't
conditionally-conformed-to, something we won't support for now.
2017-10-10 20:17:39 -07:00
Doug Gregor
1f1b75a56d [AST] Eliminate ModuleDecl parameters from GenericSignature. 2017-10-10 10:01:39 -07:00
Doug Gregor
936a701b15 [AST] Stop uniquing canonical GSBs based on the module.
Now that the GenericSignatureBuilder is no longer sensitive to the input
module, stop uniquing the canonical GSBs based on that module. The main
win here is when deserializing a generic environment: we would end up 
creating a canonical GSB in the module we deserialized and another
canonical GSB in the module in which it is used.
2017-10-10 09:41:23 -07:00
Doug Gregor
6374a17df9 [GSB] Introduce EquivalenceClass::getAnchor().
The anchor of an equivalence class canonically represents that equivalence
class. Add API for computing the anchor directly, and switch a few more
clients off of `resolveArchetype()`.
2017-09-28 15:47:57 -07:00
Doug Gregor
684a484d81 SR-5753: Don't warn about constraints redundant with inferred constraints. 2017-09-26 17:22:43 -07:00
Doug Gregor
70d4e12285 [GSB] Introduce resolveEquivalenceClass() and start using it.
Queries through the GenericSignatureBuilder about a particular type
parameter only really need information about the equivalence class in which that type parameter resides. Introduce a new entry point
GenericSignatureBuilder::resolveEquivalenceClass() that only

For now, resolveEquivalanceClass() is a thin layer over
resolveArchetype().
2017-09-08 21:45:09 -07:00
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Robert Widmann
6a47d02ca5 Don't add ErrorType-containing substitutions to the map
As a side-effect, resolves compiler crasher 28815
2017-07-13 13:22:23 -07:00
Doug Gregor
ae5091b09a [GSB] Clean up and audit uses of ArchetypeResolutionKind.
Use ArchetypeResolutionKind::CompleteWellFormed whenever we need to
ask questions about the potential archetype, and
ArchetypeResolutionKind::WellFormed when we need only evaluate whether
there is a legitimate type with that name (and possibly get a handle
to it).
2017-06-30 10:05:12 -07:00
Doug Gregor
d5a55d9676 [GSB] Eliminate "allow unresolved" from PotentialArchetype::getDependentType().
We don't need this now that there are no more unresolved types.
2017-06-30 09:05:27 -07:00
Doug Gregor
623d72db3c [AST] Make the "requirement signature" of a protocol a flat array.
Rather than pretend that the requirement signature of a protocol is a
full, well-formed generic signature that one can meaningfully query,
treat it as a flat set of requirements. Nearly all clients already did
this, but make it official. NFC
2017-06-29 14:01:49 -07:00
Doug Gregor
b3207c832a [Conformance access paths] Use protocol signature for building paths.
When a requirement signature could not be used to construct the
requirement sources in a conformance access path (due to recursive
protocols), we rebuild the path based on knowledge of the
protocol. Instead of using the requirement signature for this (which
depends on a canonicalized generic signature that breaks our intended
invariants w.r.t. unresolved nested types), use the protocol's generic
signature instead. This requires one small adjustment at the root of
the path, but is otherwise NFC.

Eliminates the penultimate use of AlwaysPartial.
2017-06-29 14:01:49 -07:00
Doug Gregor
791ac7fad4 [GSB] Clean up the meaning of ArchetypeResolutionKind::(Complete)WellFormed. 2017-06-23 17:23:07 -07:00
Doug Gregor
a9260f2d9a [GSB] Don't warn about redundancies due to inference from result types.
When we infer a requirement from the result type of a function, don't
warn if that requirement was also stated explicitly. This has been a
point of confusion since we introduced the redundancy warnings,
because users don't consider to result type to be an "input" to the
function in the way the compiler does. So, while technically it is
"correct" to warn, it's unintuitive---so stop.

Fixes SR-5072 / rdar://problem/31357967.
2017-06-16 13:45:07 -07:00
Doug Gregor
773e14422d Eliminate most uses of ArchetypeResolutionKind::AlwaysPartial.
When resolving archetypes using the "always partial" resolution kind,
we allow the system to form potential archetypes which might be
invalid. Start limiting the use of this "always partial" resolution
kind, so that it can eventually be removed entirely to simplify the
invariants of the GenericSignatureBuilder.

Each of the callers should either be working with complete,
well-formed archetypes or they should not force any resolution this
early.
2017-05-30 11:00:24 -07:00
Doug Gregor
329fd0c728 [AST] Pass GenericSignature through getOrCreateCanonicalGenericEnvironment().
Rather than having `ASTContext:: getOrCreateCanonicalGenericEnvironment()`
ask its `GenericSignatureBuilder` parameter recompute the generic signature
at nontrivial cost, just pass the known signature through.
2017-05-15 17:16:50 -07:00
Slava Pestov
504343c66e AST: Check invariants in GenericSignature::getSubstitutionMap(SubstitutionList) 2017-05-02 02:29:56 -07:00
Slava Pestov
3130c3cbd7 AST: Remove an overload of GenericSignature::getSubstitutions() 2017-04-28 13:26:02 -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
practicalswift
797c2d8118 [gardening] Fix end of namespace comments 2017-04-20 22:01:01 +02:00
practicalswift
431e5a1440 [gardening] Use consistent end of namespace comments 2017-04-20 13:47:10 +02:00