Commit Graph

845 Commits

Author SHA1 Message Date
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
Slava Pestov
08aab383e8 RequirementMachine: Don't record rewrite loops for protocol signature machines
A requirement machine built from existing protocol requirement signatures only
exists to cache those rules and allow them to be inherited by other machines.

Recording loops is unnecessary in this case, since no minimization will be
performed.
2022-03-26 00:56:41 -04:00
Slava Pestov
4d097da73c RequirementMachine: Re-use requirement machines constructed by minimization for queries
Fixes rdar://problem/88135641.
2022-03-26 00:56:41 -04:00
Slava Pestov
3d2559f79e RequirementMachine: Don't skip subst-simplified rules when importing
Property map construction is still not incremental, and considers
all rules. Skipping subst-simplified rules here violates invariants
checked by the next commit.
2022-03-26 00:56:41 -04:00
Slava Pestov
3777054c1c RequirementMachine: Fix dump() output for a recent change
Protocol machines now have the 'Self' generic parameter in 'Params', so
we have to change the order of the two 'if' statements.
2022-03-26 00:56:41 -04:00
Slava Pestov
af99ac55de RequirementMachine: Add -debug-requirement-machine=timers 2022-03-26 00:56:41 -04:00
Slava Pestov
6110866065 RequirementMachine: Propagate requirement IDs only once 2022-03-25 22:28:11 -04:00
Slava Pestov
06a25fa452 RequirementMachine: Don't normalize replacement paths for redundant rules 2022-03-25 22:28:11 -04:00
Slava Pestov
d8215bb155 RequirementMachine: Rework 'implied rules' computation in computeRedundantRequirementDiagnostics()
For efficiency I want to keep replacement paths for redundant rules
unsubstituted, so that earlier replacement paths can reference
redundant rules that appear later in the RedundantRules array.

Right now we expand replacement paths so that their RewriteSteps
only mention non-redundant rules.

This patch refactors the computeRedundantRequirementDiagnostics()
method a bit:

The impliedRequirements set is now named nonExplicitNonRedundantRules,
and in addition to storing these rules themselves, the set also
stores any _redundant_ rules that reference these rules via their
replacement paths.

Since this is computing a transitive closure, we walk the
RedundantRules array in reverse. A replacement path can only
reference a redundant rule if that redundant rule appears later
in the array.
2022-03-25 22:28:03 -04:00
Slava Pestov
81f49a863f Merge pull request #42018 from slavapestov/rqm-assoc-type-inference-cycle
RequirementMachine: Fix subtle bug in isRecursivelyConstructingRequirementMachine()
2022-03-25 11:45:16 -04:00
Slava Pestov
7d0215e6e0 RequirementMachine: Tweak rule limit non-termination heuristic
Add the length of the longest *initial* rule to the rule length limit
before comparing.

Fixes https://bugs.swift.org/browse/SR-16024.
2022-03-25 01:00:49 -04:00
Slava Pestov
3fe4aaae5a RequirementMachine: Fix subtle bug in isRecursivelyConstructingRequirementMachine()
I don't have a reduced test case. It was possible for computing the requirement
signatures of a connected component to have finished, and yet for the
ProtocolDecl::hasComputedRequirementSignature() method to return false, if
we had evaluated a RequirementSignatureRequestRQM but not the top-level
RequirementSignatureRequest.

Instead, track whether we've computed the signatures for a component directly.

I don't have a reduced test case. It would arise with associated type inference,
which uses this predicate to break nasty cycles.
2022-03-24 23:45:32 -04:00
Slava Pestov
57d1600b99 RequirementMachine: Better tests for concrete type requirements with opaque archetypes
Also fix a weird latent bug. In lookupConcreteNestedType(), we would
push nullptr onto the concreteDecls vector if the opaque archetype
did not have a nested type with this name. However, this did not
turn out to be a problem, since in this code path we would only
have a single element in this vector, and the later call to
std::min_element() did not end up dereferencing the null pointer.

However this is very dodgy, so tweak the code to prevent this from
happening and add a test case (which already passed anyway).
2022-03-22 23:53:40 -04:00
Slava Pestov
5c5d2eadf6 Merge pull request #41945 from slavapestov/rqm-split-concrete-equiv-class-improvements
RequirementMachine: Improve the 'split concrete equivalence classes' hack a bit
2022-03-22 20:59:07 -04:00
Slava Pestov
02e402721d RequirementMachine: Print opaque archetypes using the 'stable' representation 2022-03-22 17:20:48 -04:00