Commit Graph

583 Commits

Author SHA1 Message Date
Doug Gregor
0a7b977597 [GSB] "Self: P" in requirement signatures aren't self-derived.
When determining whether a conformance requirement source is
self-derived, ignore the top-level "Self: P" requirement in a
requirement signature.

Fixes SR-5485 / rdar://problem/33360699.
2017-07-25 15:02:51 -07:00
Doug Gregor
6177f83f01 [GSB] SE-0157: Reprocess delayed requirements when we need a complete PA.
Whenever we need a complete, well-formed potential archetype,
reprocess any delayed requirements, so that we pick up additional
requirements on that potential archetype.

This relies on us tracking a generation count for the GSB instance as
a whole, which gets bumped each time we add some new requirement or
create a new potential archetype, and only actually reprocessing
delayed requirements when the generation count exceeds the point at
which we last processed delayed requirements.

This gets the most basic recursive protocol constraint working
end-to-end and doesn't seem to break things.
2017-07-25 12:56:50 -07:00
Doug Gregor
1b2a2c9b90 [GSB/IRGen] Allow redundant inheritance of the JSExport protocol.
Inheritance of a protocol from JavaScriptCore's JSExport protocol is
used to indicate that the methods and properties of that protocol
should be exported to JavaScript. The actual check to determine
whether a protocol (directly) inherits JSExport is performed via the
Objective-C runtime. Note that the presence of JSExport in the
protocol hierarchy is not sufficient; the protocol must directly
inherit JSExport.

Swift warns about redundant conformance requirements and eliminates
them from the requirement signature (and, therefore, the Objective-C
metadata). This behavior is incorrect for JSExport, because the
conformance is actually needed for this API to work properly.

Recognize a protocol's inheritance JSExport specifically (by
name) when computing the requirement signature of the protocol. When
we find such a redundancy, suppress the "redundant conformance
constraint" diagnostic and add a new (hidden) attribute
@_restatedObjCConformance(proto). The attribute is used only by Objective-C
protocol metadata emission to ensure that we get the expected metadata
in the Objective-C runtime.

Fixes rdar://problem/32674145.
2017-07-24 17:02:34 -07:00
Slava Pestov
469d1f78ed AST: Check return value of ProtocolConformance::getTypeWitness()
This method returns an empty Type if the conformance is currently
being checked. The other caller of this method in the
GenericSignatureBuilder checked the return value and bailed out,
but one place did not.

This is probably not the right long-term fix, but it matches what
the other caller of getTypeWitness() does in this file.

I don't have a reduced test case either; the repro involves
building a specific revision of the standard library with a patch
applied. However, the fix can't really do any harm, since passing
an empty Type here quickly crashes.

Fixes <rdar://problem/32296747>, <https://bugs.swift.org/browse/SR-4945>.
2017-07-19 23:02:37 -07:00
Mark Lacey
5acc14022a Revert "[GSB] SE-0157: Reprocess delayed requirements when we need a complete PA."
This reverts commit ded45a6e1c.

This seems to slow down type checking of Swift.o by more than 3x.
2017-07-13 16:07:01 -07:00
Mark Lacey
ed23eb3761 Revert "SE-0157: Enable recursive protocol constraints by default."
This reverts commit afbdbae9d9.

Commit ded45a6e1c more than triples the
type checking time when building Swift.o, so I am going to revert that ,
and it looks like this needs to be reverted as well if that commit is
reverted.
2017-07-13 16:05:03 -07:00
Doug Gregor
afbdbae9d9 SE-0157: Enable recursive protocol constraints by default.
We don't know if they work in general, but specific cases of recursive
protocol constraints are working, and enabling them doesn't break
anything.
2017-07-13 13:01:11 -07:00
Doug Gregor
ded45a6e1c [GSB] SE-0157: Reprocess delayed requirements when we need a complete PA.
Whenever we need a complete, well-formed potential archetype,
reprocess any delayed requirements, so that we pick up additional
requirements on that potential archetype.

This relies on us tracking a generation count for the GSB instance as
a whole, which gets bumped each time we add some new requirement or
create a new potential archetype, and only actually reprocessing
delayed requirements when the generation count exceeds the point at
which we last processed delayed requirements.

This gets the most basic recursive protocol constraint working
end-to-end and doesn't seem to break things.
2017-07-12 17:23:23 -07:00
Doug Gregor
70b75491a0 SE-0157: Add a frontend flag -enable-recursive-constraints.
Introduce `-enable-recursive-constraints` to disable the error about
direct recursion within a protocol definition. The implementation of
recursive protocol constraints is incomplete, but might be useful for
experimentation.
2017-07-12 14:55:55 -07:00
Doug Gregor
250243c698 [GSB] Delete an unused metric. 2017-07-05 23:09:01 -07:00
Doug Gregor
1c6c51d137 [GSB] Cope with elided conformance requirements in concrete nested types.
If we encounter an associated type reference within a concrete type, but
haven't seen a specific protocol requirement, add the protocol
conformance.

Fixes rdar://problem/33139928 and another crasher.
2017-07-05 23:08:41 -07:00
Doug Gregor
ea343925a9 [GSB] Eliminate the ridiculous ad hoc recursion-breaking code.
We're now properly delaying all recursive requirements, so we no
longer need to compute `grossCount`.
2017-06-30 16:26:45 -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
84e3efa228 [GSB] Delete the "invalid" bit on potential archetypes.
We no longer set this bit anywhere, so remove it. NFC
2017-06-29 16:52:46 -07:00
Doug Gregor
a24a139d10 [GSB] Rip out all of the code related to unresolved potential archetypes.
All of this is dead code now that we don't use
ArchetypeResolutionKind::AlwaysPartial and, therefore, cannot ever
produce an unresolved potential archetype.
2017-06-29 16:52:46 -07:00
Doug Gregor
e3b09f3850 [GSB] Remove typo correction. NFC
Remove typo correction and all notions of "renamed" potential
archetypes from the generic signature builder. They're no longer used
anywhere.
2017-06-29 16:52:46 -07:00
Doug Gregor
ac8e8aa1b3 [GSB] Stop creating unresolved potential archetypes; rework typo correction.
The small-but-significant change to the generic signature builder is
to refuse to create unresolved potential archetypes. Instead, delay
any requirement that depends on such type, to be reprocessed once
we've seen all of the other requirements. If the type can be resolved
later, it will be; Otherwise, the type checker will complain when it
sees an unresolvable type. By itself, this fixes the crash in SR-2796.

Doing this by itself regresses diagnostics because typo correction in
the generic signature builder no longer kicks in. Therefore, implement
typo correction for these cases in the type checker proper, using its
existing facilities for typo correction. The result is more consistent
code with a better result.

Fixes SR-2796 / rdar://problem/28544316.
2017-06-29 16:52:46 -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
cb93331f66 [GSB] Distinguish archetype resolution kind for getNestedType().
PotentiallArchetype::getNestedType(Identifier...) was using
ArchetypeResolutionKind::AlwaysPartial, even though only one client
(the code that itself handles AlwaysPartial) needed it. Add an
ArchetypeResolutionKind parameter to pass through, updating clients
accordingly.

Eliminates 5 effective uses of AlwaysPartial. Only two left!
2017-06-28 09:41:06 -07:00
Doug Gregor
c226ff8dc4 [GSB] Eliminate some duplicated code. NFC 2017-06-28 06:39:46 -07:00
Doug Gregor
be5bc3fd07 [GSB] Eliminate two more uses of ArchetypeResolutionKind::AlwaysPartial.
We don't need to force the creation of potential archetypes when
finding anchors, because new potential archetypes will only be created
by this process in ill-formed generic signatures. Tolerate failure
whenever this happens (for now) and the failure paths will become dead
once AlwaysPartial is eliminated fully.
2017-06-28 06:23:52 -07:00
Doug Gregor
d9b9604326 [GSB] Don't use archetype anchor ordering when merging equivalence classes.
When we merge equivalence classes (by choosing a new representative),
we already prefer the potential archetype with the shorter nesting
depth. However, barring that, we were preferring the potential
archetype that is a better archetype anchor. At one point we depended
on this, but now it's an extra cost that has the side effect of
building more potential archetypes than we really need at this stage.

Eliminate the compareDependentTypes() check when merging equivalence
classes. The intent is that we only need to form archetype anchors
when enumerating requirements or canonicalizing---not during the
normal "solving" path of the GSB.
2017-06-27 22:53:33 -07:00
Doug Gregor
deef22fc7f [GSB] Don't crash when substitution fails to produce a type.
Fixes two more recently-found GSB crashers.
2017-06-26 09:43:13 -07:00
Doug Gregor
239a0f5f4c [GSB] Ensure that we have superclass constraints from merged equiv class.
Fixes one recently-found crasher.
2017-06-26 08:40:40 -07:00
Doug Gregor
dd3869739e [GSB] Don't add invalid concrete requirements.
When a concrete requirement is invalid due to the concrete type
lacking a conformance to a particular, required protocol, don't emit
that incorrect requirement---it causes invalid states further down the
line.

Fixes SR-5014 / rdar://problem/32402482.

While here, fix a comment that Huon noticed trailed off into oblivion.
2017-06-23 22:23:46 -07:00
Doug Gregor
aeb5b0172b [GSB] When retrieving the archetype anchor, allow partial results.
Specifically, we need to be able to add a new potential archetype for
the anchor. This API might need refinement.
2017-06-23 17:25:52 -07:00
Doug Gregor
c47aea7150 [GSB] Cope with typealiases within protocol hierarchies.
When we see two type(aliase)s with the same name in a protocol
hierarchy, make them equal with an implied same-type requirement. This
detects inconstencies in typealiases across different protocols, and
eliminates the need for ad hoc consistency checking. This is a step
toward simplifying away the need for direct-diagnosis operations
involving concrete type mismatches.

While here, warn when we see an associated type with the same as a
typealias from an inherited protocol; in this case, the associated
type is basically useless, because it's going to be equivalent to the
typealias.
2017-06-23 17:25:45 -07:00
Doug Gregor
b51529f9e7 [GSB] Diagnose all same-type-to-concrete conflicts consistently. 2017-06-23 17:25:37 -07:00
Doug Gregor
bf730fff08 [GSB] Concretize nested types when merging two potential archetypes.
When two potential archetypes are merged and only one of them was a
concrete type beforehand, concretize the nested types in the
equivalence class of the non-concrete potential archetype. Otherwise,
we're liable to miss redundancies.

This feels like an ad hoc extension to an ad hoc mechanism, but gets
us back to parity with this patch series.
2017-06-23 17:25:05 -07:00
Doug Gregor
c879b95917 [GSB] Centralize diagnosis of concrete types and conformance requirements.
Ensures that we don't admit invalid cases where the concrete type does
not conform to the required protocol.
2017-06-23 17:24:02 -07:00
Doug Gregor
791ac7fad4 [GSB] Clean up the meaning of ArchetypeResolutionKind::(Complete)WellFormed. 2017-06-23 17:23:07 -07:00
Doug Gregor
a72a2bf730 [GSB] Avoid recursively growing increasingly-nested potential archetypes.
In some circumstances, we could end up growing increasingly-nested
potential archetypes due to a poor choice of representatives and
anchors. Address this in two places:

* Always prefer to use the potential archetype with a lower nesting
  depth (== number of nested types) to one with a greater nesting
  depth, so we don't accumulate more nested types onto the
  already-longer potential archetypes, and

* Prefer archetype anchors with a lower nesting depth *except* that we
  always prefer archetype anchors comprised of a sequence of
  associated types (i.e., no concrete type declarations), which is
  important for canonicalization.

Fixes SR-4757 / rdar://problem/31912838, as well as a regression
involving infinitely-recursive potential archetypes caused by the
previous commit.
2017-06-23 16:58:56 -07:00
Doug Gregor
b095c8af2a [GSB] Break recursion based on the “root” type we’re creating requirements for. 2017-06-23 10:00:16 -07:00
Doug Gregor
a4e35ed151 [GSB] Remove unused form of addSameTypeRequirementDirect() 2017-06-23 10:00:11 -07:00
Doug Gregor
52e52b564b [GSB] Improve handling of conformances resolved by concrete types.
Centralize and simplify the handling of conformance requirements
resolved by same-type-to-concrete requirements in a few ways:

* Always store a ProtocolConformanceRef in via-superclass and
  via-concrete requirement sources, so we never lose this information.

* When concretizing a nested type based on its parent, use the
  via-concrete conformance information rather than performing lookup
  again, simplifying this operation considerably and avoiding
  redundant lookups.

* When adding a conformance requirement to a potential archetype that
  is equivalent to a concrete type, attempt to find and record the
  conformance.

Fixes SR-4295 / rdar://problem/31372308.
2017-06-23 09:34:57 -07:00
Doug Gregor
ffea1b35ca [GSB] Separate out a "structurally derived" requirement source kind.
Rather than abusing the "superclass" requirement source with a null
protocol conformance, introduce a separate "structurally derived"
requirement source kind for structurally-derived requirements that
don't need any additional information, e.g., the class layout
requirement derived from a superclass requirement.
2017-06-23 09:32:03 -07:00
Doug Gregor
fafeec0037 [GSB] Eliminate PotentialArchetype::NestedTypeUpdate.
NestedTypeUpdate was mostly just the internal name for
ArchetypeResolutionKind, but the translation was a bit lossy and there
was no point in having separate enums. Standardize on
ArchetypeResolutionKind, adding a new case (WellFormed) to capture the
idea that we can create a new potential archetype only when we know
there is a nested type with that name---and avoid creating unresolved
potential archetypes.
2017-06-23 09:31:58 -07:00
Huon Wilson
61b3bff72a [NFC] Reduce duplication/special cases in GSB typo correction. 2017-06-21 14:06:14 -07:00
swift-ci
ffcca776a2 Merge pull request #10398 from DougGregor/gsb-unresolved-types 2017-06-20 06:56:12 -07:00
Doug Gregor
fe7ba8b79b [GSB] Pull typo correction for nested types into delayed reqs handling.
Rather than performing typo correction at the very end of finalize(),
do it as part of delayed requirement handling when we cannot otherwise
make progress. This is a cleaner way to cope with typo correction that
gives us a better chance of getting to a sane result.

Fixes rdar://problem/31048352 by eliminating the need for tracking the
number of unresolved potential archetypes altogether. Fixes
rdar://problem/32077627.
2017-06-19 22:47:33 -07:00
Doug Gregor
4860607700 [GSB] Record unresolved potential archetypes as delayed requirements.
Whenever we form a potential archetype that is unresolved (because it
names a member wasn't known at the time the potential archetype was
formed), create a corresponding delayed requirement to resolve the
potential archetype. This ensures that all potential archetypes get a
chance to be resolve, fixing the

  nested type should have matched associated type

assertion in rdar://problem/31401161 (and others).
2017-06-19 22:20:21 -07:00
Doug Gregor
aac05746c0 [GSB] Separate out the kind of DelayedRequirement.
DelayedRequirements were using the general RequirementKind, which was
at best an approximation (we smoothed over the difference between
Superclass and Conformance requirements). Split out the Kind into its
own type, so we can extend it with GSB-specific kinds.
2017-06-19 16:23:54 -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
6a2b6c271f [AST] Add TypeBase::findUnresolvedDependentMemberType() and use it 3x.
NFC: Eliminate some duplicated "search for an unresolved dependent
member type" code scattered around.
2017-06-15 23:23:07 -07:00
swift-ci
d84d85a817 Merge pull request #10182 from DougGregor/sr-5165 2017-06-09 15:50:27 -07:00
Doug Gregor
610ffd5680 [GSB] Fall back to "abstract" requirements when we don't find a match.
The previous commit tightened up our choice of requirement sources for
superclass and layout constraints, but always assumed a match
existed. In cases where it does not, don't fail; rather, use an
abstract source, which we do elsewhere when we're synthesizing
requirements.

This is a defensive approach to cope with cases where we might not
have precisely the same value within one of our recorded
constraints. This currently only occurs when there are errors (hence
the elimination of the odd "hasError()"), but will come up more often
when we're deriving information from a combination of constraints.
2017-06-09 15:23:06 -07:00
Doug Gregor
969163f6ea [GSB] Only use matching superclass constraints in enumerated requirements.
Fixes SR-5165 / rdar://problem/32658705.
2017-06-09 00:00:17 -07:00
Slava Pestov
c152fee9f8 Sema: A couple of recursion-breaking hacks 2017-06-07 17:19:09 -07:00
Doug Gregor
4fbb3ec611 [GSB] Resolve nested types by looking into superclass constraints.
This was previously handled very late, by the type checker, which led
to weird ordering dependencies and meant that we could end up with
well-formed code where the GSB was left with unresolved types. We want
such states to never exist, so make sure we can resolve everything in
the GSB.
2017-06-01 22:29:46 -07:00