Commit Graph

583 Commits

Author SHA1 Message Date
Doug Gregor
10ebdcd50a [GSB] Broaden the Boolean result of "add a constraint" operations.
Rather than true (an error occurred) or false (the constraint was
resolved), introduce ConstraintResult to better model what
happened. NFC for now, but the intent here is to report unresolved
constraints through this mechanism.
2017-04-11 14:15:45 -07:00
Slava Pestov
d7c1d817e3 AST: Update GenericSignatureBuilder for subclass existentials 2017-04-10 17:04:38 -07:00
Doug Gregor
fb8023736f [GSB] Eliminate unnecessary "dependentType" parameters throughout.NFC
Now that ProtocolRequirement sources can compute their own stored
types, stop propagating that information through the GSB.
2017-04-10 10:14:01 -07:00
Doug Gregor
7900decb09 [GSB] Compute the dependent type for ProtocolRequirement sources.
The dependent type that is the subject of a ProtocolRequirement
source is independently computable based on the root potential
archetype of the source and the potential archetype to which the
requirement applies, i.e., it's just the dependent member type that
gets from the former to the later. Compute this directly, rather than
relying on the passed-down dependent type.

This is possible now because we no longer capriciously rebase
requirements onto the representatives of equivalence classes, nor
destroy any other structural information in the formation of potential
archetypes.
2017-04-10 09:21:44 -07:00
Doug Gregor
7b19bb4c16 [GSB] Use "direct" requirement terminology for same-type requirement handling.
NFC
2017-04-07 16:53:11 -07:00
Doug Gregor
c522bb5239 [GSB] Separate out "unresolved" and "direct" type requirement handling.
As we've done with layout requirements, introduce a new entry point
(addTypeRequirement) that handles unresolved type requirements of the
form `T: U`, resolves the types, and then can

1. Diagnose any immediate problems with the types,
2. Delay the type requirement if one of the types cannot be resolved,
or
3. Break it into one or more "direct" requirements.

This allows us to clean up and centralize a bunch of checking that was
scattered/duplicated across the GSB and type checker.
2017-04-07 16:53:11 -07:00
Doug Gregor
68efffd4b8 [GSB] Separate out the "unresolved" and "direct" layout constraint entrypoints.
More staging for delayed resolution of constraints.
2017-04-07 16:53:10 -07:00
Doug Gregor
6991a8c261 [GSB] Basic infrastructure to allow type resolution to fail.
When we resolve() a type that is being used in a constraint, allow
that resolution to fail. If it does fail, then record the constraint
we were trying to address (via a stub that, currently, just drops it)
and continue on. NFC for now; this is intended to allow us to limit
the explosion of types in recursive systems.
2017-04-07 16:53:10 -07:00
Doug Gregor
25f3b3dd4b [GSB] Remove unused "from generic typealias" hack. 2017-04-07 16:53:10 -07:00
Doug Gregor
44c2f849d6 [Type checker] Continue validating requirements after an error.
We want to validate both type in same-type or conformance constraints,
even when the first type is ill-formed, so we don't leave null types
around for later phases to crash on.

Fixes rdar://problem/31093854.
2017-04-05 14:05:59 -07:00
Doug Gregor
5c89eb84f0 [AST] Drop substitutions from type witnesses.
Nobody is using the actual substitutions, but we sure did a lot of
work to cope with them.
2017-04-05 11:21:38 -07:00
Doug Gregor
8841f04ea8 [GSB] Properly compute archetype anchor during same-type DFS.
This would cause spurious idempotency failures with generic signature canonicalization.
2017-04-04 14:07:13 -07:00
Slava Pestov
37491e63ac AST: Refactor existential type accessors on TypeBase and CanType 2017-04-03 23:14:25 -07:00
Doug Gregor
50b18eef36 [GSB] Free RequirementSources.
Fixes rdar://problem/31282645, but nothing will fix my bruised ego.
2017-04-03 14:27:14 -07:00
Doug Gregor
74075c1952 [GSB] Don't emit same-type-to-concrete requirements for nested types.
When enumerating same-type-to-concrete requirements, don't emit a
same-type-to-concrete requirement for a nested archetype anchor when
it's parent also is equivalent to a concrete type, because the former
can always be derived from the latter.

Fixes SR-4456 / rdar://problem/31286125.
2017-04-03 13:42:18 -07:00
practicalswift
66eccecbdf [gardening] Remove accidental \t 2017-03-28 21:37:52 +02:00
Doug Gregor
78d64cc508 [GSB] Suppress same-type-to-concrete constraints for nested types.
When a nested type is within the same equivalence class as its parent,
don't emit a redundant same-type-to-concrete constraint for the
corresponding potential archetype. The nested type's constraint will
be derived from the parent... which is technically a self-derived
constraint, yet needs to be suppressed.
2017-03-24 15:20:12 -07:00
swift-ci
ba9546dc13 Merge pull request #8312 from DougGregor/generic-sig-concrete-type-params 2017-03-24 00:22:19 -07:00
Doug Gregor
584e023b3f [GSB] Never drop type-parameter-to-concrete requirements.
Generic signature canonicalization/minimization never removes type
parameters, so we cannot suppress type-parameter-to-concrete
requirements even when they are derived.

Fixes the rest of the known cases of rdar://problem/30478915.
2017-03-23 23:45:44 -07:00
Doug Gregor
8bd863e645 [GSB] Reimplement self-derived checking for conformance constraints.
The general self-derived check doesn't really make sense for
conformance constraints, because we want to distinguish among
different protocol conformances.
2017-03-23 23:45:43 -07:00
Doug Gregor
607732fb1f Merge pull request #8281 from DougGregor/redundant-explicit-via-inferred
[GSB] Diagnose explicit constraints made redundant by inferred ones.
2017-03-22 20:50:20 -07:00
Roman Levenstein
e3bc23cc09 Merge pull request #8253 from swiftix/wip-gsb-layout-constrains-fixes
[GSB] Improve handling of layout constraints
2017-03-22 17:36:05 -07:00
Doug Gregor
d9fa16bccb [GSB] Diagnose explicit constraints made redundant by inferred ones. 2017-03-22 17:35:11 -07:00
Roman Levenstein
e1403c6dc2 [GSB] Improve handling of layout constraints
This PR addresses TODOs from #8241.

- It supports merging for layout constraints, e.g., if both a _Trivial constraint and a _Trivial(64) constraint appear on a type parameter, we keep only _Trivial(64) as a more specific layout constraint. We do a similar thing for ref-counted/native-ref-counted. The overall idea is to keep the more specific of two compatible layout constraints.
- The presence of a superclass constraint implies a layout constraint, e.g., a superclass constraint implies _Class or _NativeClass
2017-03-22 16:39:02 -07:00
Doug Gregor
7763e96e26 [GSB] Fix compile error with libstdc++ 2017-03-22 06:50:46 -07:00
Doug Gregor
ddc2775530 [GSB] Diagnose redundant same-type constraints.
Diagnose redundant same-type constraints using most of the same
machinery for diagnosing other redundant constraints. However,
same-type constraints are particularly interesting because
redundancies can be spelled in a number of different ways. Address
this using the connected components of the subgraph involving only
derived requirements (which is already used for the minimized generic
signature). Then, separate all of the non-derived requirements into
the intracomponent requirements and intercomponent requirements:

* All of the intracomponent requirements are redundant by definition,
  because the components are defined by derived constraints.

* For the intercomponent requirements, form a spanning tree among the
  various components and diagnose as redundant any edges that do not
  extend the spanning tree.
2017-03-21 23:02:04 -07:00
Doug Gregor
343c99302b [GSB] Compute derived same-type components when checking same-type constraints.
It's better to compute this information once while we're sorting
through all of the same-type constraints, so we can use it later when
performing queries (e.g., enumerating requirements).
2017-03-21 16:32:51 -07:00
swift-ci
82d295f618 Merge pull request #8242 from DougGregor/redundant-superclass-constraints 2017-03-21 07:48:20 -07:00
Doug Gregor
cb788d7daa [GSB] Don't emit redundant superclass constraints.
We were emitting a superclass constraint for each connected component
of derived same-type constraints within an equivalence class, when in
fact we only need one superclass constraint for the entire equivalence
class.
2017-03-21 07:32:43 -07:00
swift-ci
9ad340e2ef Merge pull request #8241 from DougGregor/all-layout-constraints 2017-03-21 07:30:54 -07:00
Doug Gregor
9385849dc0 [GSB] Don't emit redundant superclass constraints.
We were emitting a superclass constraint for each connected component
of derived same-type constraints within an equivalence class, when in
fact we only need one superclass constraint for the entire equivalence
class.
2017-03-21 07:25:35 -07:00
Doug Gregor
5aa51e9532 [GSB] Keep track of all layout constraints.
As we've done with all of the other kinds of constraints, keep track
of all of the layout constraints on the equivalence class. Use the
normal mechanism to diagnose conflicts between different layout
constraints, warn about duplicate layout constraints, etc.
2017-03-21 06:59:40 -07:00
swift-ci
7811dc753d Merge pull request #8239 from DougGregor/all-same-type-constraints 2017-03-21 06:39:24 -07:00
Doug Gregor
0f4c14b22e [GSB] checkRedundantSuperclassConstraints() -> checkSuperclassConstraints() 2017-03-21 06:19:22 -07:00
Doug Gregor
094b0f8f54 [GSB] Rename checkRedundantConcreteTypeConstraints() to checkConcreteTypeConstraints() 2017-03-21 06:18:46 -07:00
Doug Gregor
4686801c2f Remove the now-unused GenericSignatureBuilder::updateRequirementSource(). 2017-03-21 06:14:37 -07:00
Doug Gregor
f429712253 [GSB] Track all same-type constraint requirement sources.
As we've been doing with other kinds of constraints, track *all* of
the requirement sources for deriving same-type constraints within the
equivalence class, then remove self-derived constraints at the end.

There is no checking for duplicated same-type constraints yet.
2017-03-21 06:11:05 -07:00
Hugh Bellamy
d9879522fb Fix top of tree Clang unused lambda capture warnings 2017-03-21 19:15:08 +07:00
Doug Gregor
9aed438f27 [GSB] Use isDerivedRequirement() for same-type connected components 2017-03-19 22:26:39 -07:00
Doug Gregor
eaee4add8a [GSB] Track all conformance constraint sources.
Move the storage for the protocols to which a particular potential
archetype conforms into EquivalenceClass, so that it is more easily
shared. More importantly, keep track of *all* of the constraint
sources that produced a particular conformance requirement, so we can
revisit them later, which provides a number of improvements:

* We can drop self-derived requirements at the end, once we've
  established all of the equivalence classes
* We diagnose redundant conformance requirements, e.g., "T: Sequence"
  is redundant if "T: Collection" is already specified.
* We can choose the best path when forming the conformance access
  path.
2017-03-16 23:15:37 -10:00
Doug Gregor
c443739d68 [GSB] Centralize reporting of same-type conflicts.
This eliminates a bunch of code repetition and handles "typealias"
conflict diagnostics more uniformly.
2017-03-15 22:33:38 -10:00
Doug Gregor
3c9f7a4c83 [GSB] Don't recursively resolve concrete types.
Resolving to a potential archetype with a concrete type maintains more
useful information in the GenericSignatureBuilder.
2017-03-15 22:33:38 -10:00
Doug Gregor
372d7bbf60 [GSB] Rework construction of nested types.
Our handling of nested types was scattered in several places, and
(worse) correct computation of archetype anchors required us to
"explode" out all of the potential archetypes for every associated
type with the given name to ensure that we get the right one.

Make nested type construction somewhat more lazy: if asked for a
nested type for a specific associated type, just create the nested
type for that associated type (instead of *all* of them). If asked for
a nested type by name, either return the one we already have or create
the one that's most likely to be the archetype anchor. Overall, this
should result in many fewer potential archetypes being constructed.
2017-03-15 22:33:38 -10:00
Doug Gregor
ce106bc98f [GSB] Abstract the storage for the nested types of a potential archetype
NFC so far; we're going to track more information here.
2017-03-15 22:33:38 -10:00
Huon Wilson
ca3a398b4a Merge pull request #8021 from huonw/protocol-where-clause
Parse/typecheck/print where clauses on protocols
2017-03-15 11:00:46 -07:00
swift-ci
2ba4f03d8a Merge pull request #8023 from huonw/tweak 2017-03-10 17:06:39 -08:00
Huon Wilson
a9299802bb Factor out first = true; ... if (first) first = false; else ....
There's an `interleave` function for this: let's use it.
2017-03-10 15:44:12 -08:00
Doug Gregor
3e80a616c4 [GSB] Hack the ordering of adding requirements for a signature.
This hack is papering over other issues in the generic signature
builder, where canonicalizing an existing generic signature---in which
we already know the specific associated type declarations---could
introduce "inferred" requirements, breaking the resulting requirement
signatures by producing too-short paths. By delaying same-type
requirements, we make this case less likely.

The correct solution is to eliminate
PotentialArchtype::getNestedType()'s injection of an inferred
requirement, but doing so requires a bit more surgery.
2017-03-09 21:57:54 -08:00
Doug Gregor
7809118f5e [GSB] Insert superclass constraints into the right place. 2017-03-09 21:55:40 -08:00
Doug Gregor
bca51d1186 [GSB] Fix a broken assertion. 2017-03-09 21:55:39 -08:00