Commit Graph

859 Commits

Author SHA1 Message Date
Holly Borla
de41a58051 Merge pull request #42257 from hborla/concrete-generic-params
[RequirementMachine] Diagnose type parameters that are made concrete by a same-type requirement.
2022-04-12 18:27:43 -07:00
Slava Pestov
7aee5b6cf8 Merge pull request #42324 from slavapestov/rqm-superclass-vs-objc-existential
RequirementMachine: Allow 'any C & P' to satisfy a superclass requirement 'C' if 'P' is an @objc protocol
2022-04-12 21:05:52 -04:00
Slava Pestov
4204e20508 RequirementMachine: Allow 'any C & P' to satisfy a superclass requirement 'C' if 'P' is an @objc protocol
The GenericSignatureBuilder did not actually allow this, but it's conflict
detection was imperfect so it did not flag the example in the radar;
variations on this code were rejected by the GenericSignatureBuilder.

Since the Requirement Machine finds all conflicts correctly, relax the
logic here to make this example work.

Fixes rdar://problem/91637621.
2022-04-12 16:43:56 -04:00
Holly Borla
7f30f5b039 [RequirementMachine] Downgrade concrete type parameter diagnostics to a
warning.

These diagnostics are stricter in the RequirementMachine than in the GSB,
and there's code that relies on the more relaxed diagnostics in the source
compatibility suite. Downgrade these diagnostics to a warning using
warnUntilSwiftVersion(6).
2022-04-11 19:18:00 -07:00
Slava Pestov
9170378d25 RequirementMachine: Fix handling of Sendable conformances for superclass requirements
Don't set allowMissing to true when checking conformance of a superclass requirement
to a protocol, since this prevents us from being able to express something like
'T : C, T : Sendable' to mean 'T can be any subclass of C which is also Sendable'.

Fixes rdar://problem/91530343.
2022-04-11 14:52:32 -04:00
Holly Borla
e26497a644 [RequirementMachine] Remove unnecessary conditions in concrete type parameter
diagnostics code.
2022-04-09 13:10:36 -07:00
Holly Borla
236e8e2b1d [RequirementMachine] Diagnose type parameters that are made concrete by a
same-type requirement.
2022-04-08 18:16:23 -07:00
Doug Gregor
f3fd64a71b Support missing Sendable conformances everywhere in the requirement machine 2022-04-08 16:10:38 -07:00
Doug Gregor
45c7d6f4b8 Allow missing Sendable conformances when type parametesr are made concrete.
Fixes rdar://91174106.
2022-04-08 15:42:33 -07:00
Slava Pestov
094130b9c7 RequirementMachine: Diagnose redundant concrete conformance requirements
A conformance requirement on a concrete type parameter is redundant if the
concrete type conforms to the protocol.

The replacement path for the conformance rule is based on a concrete
conformance rule introduced by the property map. Since the concrete
conformance rule is not associated with a requirement ID, this would
normally muffle the redundancy warning, because we don't want to
suggest removing a rule that depends on a non-redundant, non-explicit
rule.

However, concrete conformance rules don't actually appear in the
minimal signature, so skip them when computing the set of non-redundant,
non-explicit rules to ensure that the original conformance requirement
is still diagnosed as redundant.
2022-04-05 21:12:51 -04:00
Slava Pestov
4d15fa0087 RequirementMachine: Don't diagnose trivial circularity 'protocol P : P' as redundant
Every protocol gets an 'identity conformance' rule [P].[P] => [P].
A trivially-stated circularity is always redundant because of this
rule, and we diagnose circular inheritance elsewhere as a hard
error, so just add a special case to skip adding such a rule here
to avoid the useless warning on top of the existing error.
2022-04-05 21:12:51 -04:00
Slava Pestov
bc43cdd104 RequirementMachine: Generalize hack that allows associated type inheritance clauses to reference protocol typealiases
We want to allow this for all conformance requirements written in protocols
or the `where` clause of protocol extensions.

Fixes rdar://problem/91304291.
2022-04-05 18:42:35 -04:00
Slava Pestov
85e73ed021 RequirementMachine: Move a bit of code in computeCompletion() for clarity 2022-04-05 00:04:39 -04:00
Slava Pestov
c0c109d3f5 RequirementMachine: Tighten verifyRewriteRules() further
We should never have a rule with a protocol symbol on the *right* hand
side, like (T => U.[P]).
2022-04-04 23:52:58 -04:00
Slava Pestov
4c7fc73d4a RequirementMachine: Try harder to ensure completion only introduces property-like rules
When computing an overlap between a property-like rule (T.[p] => T for some
property symbol [p]) and another rule, try harder to ensure that the new
rule is a property-like rule.

In a conformance-valid rewrite system, all rules that are not LHS- or RHS-
simplified will eventually either be property-like or same-type rules, but
we need to maintain this invariant for that rules that become simplified
as well, to ensure that rewrite loops have a certain structure that is
important for the minimal conformances algorithm.

I don't quite understand why to be honest, but I'm close to figuring it
out.

Fixes rdar://problem/91232987.
2022-04-04 23:41:07 -04:00
Slava Pestov
41c04c5f7b RequirementMachine: Add a comment explaining a recent change to concrete contraction 2022-04-04 12:41:57 -04:00
Slava Pestov
6b48eb6549 RequirementMachine: More debug output from RewritePath::RewriteSystem::propagateRedundantRequirementIDs() 2022-04-04 12:41:57 -04:00
Slava Pestov
7d51fa9f62 RequirementMachine: RewriteSystem::dump() prints out written requirements 2022-04-04 12:41:57 -04:00
Slava Pestov
5bff2a02c5 RequirementMachine: Rename RewritePath::getRulesInEmptyContext() to findRulesAppearingOnceInEmptyContext() 2022-04-04 12:41:57 -04:00
Slava Pestov
deaeb36f57 RequirementMachine: Make RewritePath::getRulesInEmptyContext() const 2022-04-04 12:41:57 -04:00
Slava Pestov
02bfb79935 RequirementMachine: Concrete contraction discards errors from inferred requirements 2022-04-01 23:55:19 -04:00
Slava Pestov
175d5860cf RequirementMachine: Don't substitute unsatisfied layout requirements in concrete contraction 2022-04-01 23:06:19 -04:00
Slava Pestov
06b181a099 RequirementMachine: Don't record duplicate conflicts in PropertyMap::checkConcreteTypeRequirements() 2022-04-01 22:38:42 -04:00
Slava Pestov
d385b73cd6 RequirementMachine: Plumb source locations through concrete contraction 2022-04-01 22:33:03 -04:00
Slava Pestov
0e297b0fbb RequirementMachine: Use Requirement::hasError() method 2022-04-01 21:40:55 -04:00
Slava Pestov
4e89f73e90 RequirementMachine: Allow markConflicting() on already-conflicting frozen rules 2022-04-01 01:05:54 -04:00
Slava Pestov
a8190d81da RequirementMachine: Don't record duplicate superclass conflicts 2022-04-01 01:05:54 -04:00
Slava Pestov
d212041dfb RequirementMachine: Fold RewriteSystem::processConflicts() into recordConflict() and add debug output 2022-04-01 01:05:54 -04:00
Slava Pestov
75161ce6b0 RequirementMachine: Tweak fixit that turns 'T : Int' into 'T == Int' slightly to match GSB 2022-04-01 01:05:54 -04:00
Slava Pestov
22f0f40a30 RequirementMachine: Copy over GSB logic where inheritance of JSExport protocol can be re-stated redundantly 2022-04-01 01:04:54 -04:00
Slava Pestov
01fea564fb RequirementMachine: Skip emitting diagnostics containing ErrorTypes 2022-04-01 01:04:54 -04:00
Holly Borla
ce600d8728 Merge pull request #41971 from hborla/conflicting-requirement-diagnostics
[RequirementMachine] Diagnose conflicting requirements.
2022-03-31 09:14:11 -07:00
Holly Borla
85be43f18f [RequirementMachine] Omit duplicate conflict diagnostics. 2022-03-30 22:50:13 -07:00
Holly Borla
7e5c48382d [RequirementMachine] When computing requirements for conflict diagnostics,
adjust the concrete type symbol for the suffix rule by applying the prefix
from the subject rule.
2022-03-30 22:30:45 -07:00
Holly Borla
78b07565b6 [RequirementMachine] Use PropertyMap::getTypeFromSubstitutionSchema when
computing a concrete same-type or superclass for conflict diagnostics.

Otherwise, diagnostics will show fresh type parameters when the concrete
type is generic.
2022-03-30 14:09:06 -07:00
Holly Borla
5296fbdf45 [NFC][RequirementMachine] Stylistic changes for computing confict
diagnostics.

Move computing requirements from rules into a static function, make
a few variables const, etc.
2022-03-30 14:09:06 -07:00
Holly Borla
f52593be68 [RequirementMachine] Record the sugared 'Self' type parameter when
initializing a RequirementMachine for a written protocol signature.

These generic parameters are used for re-sugaring when computing a
type from a term, so if the recorded 'Self' parameter is canonicalized,
it shows up in diagnostics as 'tau_0_0'.
2022-03-29 18:27:45 -07:00
Holly Borla
a4230a6061 [RequirementMachine] Simplify computing and emitting conflict diagnostics.
Instead of computing different combinations of conflicting requirement kinds,
emit the same error message for all of them.
2022-03-29 18:27:45 -07:00
Holly Borla
31028e5a9f [RequirementMachine] When computing conflict diagnostics, only compute the
type for the longer subject term between the two conflicting rules.
2022-03-29 18:27:45 -07:00
Holly Borla
964c11a4d0 [RequirementMachine] Consolidate the various RequirementError::Kind cases
that represent conflict diagnostics.
2022-03-29 18:27:45 -07:00
Holly Borla
caee699560 [RequirementMachine] Mention the type parameter that is the subject of
two conflicting requirements in diagnostics where possible.
2022-03-29 18:27:45 -07:00
Holly Borla
deb62f7e3c [RequirementMachine] Add a helper method to RequirementMachine to compute
all requirement diagnostics from the minimal rewrite system.
2022-03-29 18:27:44 -07:00
Holly Borla
99f5e365cc [RequirementMachine] Compute and diagnose conflicting rules in the minimal
rewrite system of a generic/requirement signature.
2022-03-29 18:26:26 -07:00
Holly Borla
e512e7a824 [RequirementMachine] Add a RequirementError for diagnosing a conflicting
same-type requirement.
2022-03-29 18:23:53 -07:00
Slava Pestov
ad2f73af44 RequirementMachine: More comments 2022-03-29 12:10:33 -04:00
Slava Pestov
3cfbe037ee RequirementMachine: Simplify getTypeForSymbolRange() a bit 2022-03-29 00:43:41 -04:00
Slava Pestov
a631d8aa3a RequirementMachine: Write some comments 2022-03-28 22:16:09 -04:00
Slava Pestov
132334cda9 RequirementMachine: Add debugging flag to disable re-using requirement machines 2022-03-27 11:54:28 -04:00
Slava Pestov
b859ac1444 RequirementMachine: Unwrap outer TypeAliasType on protocol typealiases
A protocol typealias 'typealias T = X' introduces a same-type requirement
'Self.T == Self.X'. However the right hand side of the requirement was
wrapped in a sugared TypeAliasType.

This meant if the requirement surfaced in a redundancy diagnostic, it
would print as 'Self.T == Self.T'. It could also trigger a request cycle
via isInterestingTypealias() in DiagnosticEngine.cpp.
2022-03-26 19:06:20 -04:00
Slava Pestov
e2a509c483 RequirementMachine: Freeze machines built from signatures immediately 2022-03-26 00:56:41 -04:00