Commit Graph

101 Commits

Author SHA1 Message Date
Slava Pestov
6b48eb6549 RequirementMachine: More debug output from RewritePath::RewriteSystem::propagateRedundantRequirementIDs() 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
d212041dfb RequirementMachine: Fold RewriteSystem::processConflicts() into recordConflict() and add debug output 2022-04-01 01:05:54 -04:00
Slava Pestov
ad2f73af44 RequirementMachine: More comments 2022-03-29 12:10:33 -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
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
Holly Borla
98beadf8f5 Merge pull request #41833 from hborla/redundant-requirement-tweak
[RequirementMachine] Suppress redundant requirement warnings for inferred requirements.
2022-03-16 09:00:24 -07:00
Slava Pestov
9704168351 RequirementMachine: Skip imported rules in various places when iterating over all rules 2022-03-16 00:58:30 -04:00
Holly Borla
6b64ac26f4 [RequirementMachine] Suppress redundant requirement warnings for inferred
requirements.
2022-03-15 21:14:43 -07:00
Slava Pestov
2a634ba468 RequirementMachine: Optimize RewriteSystem::normalizeRedundantRules() 2022-03-15 13:35:34 -04:00
Slava Pestov
d4732f5a19 RequirementMachine: Move RewritePath and RewriteLoop methods from HomotopyReduction.cpp to RewriteLoop.cpp 2022-03-15 13:35:34 -04:00
Slava Pestov
7b01ff60f0 RequirementMachine: Simplify RewriteSystem::processConflicts()
Remove the logic which incorrectly attempted to simulate the
GenericSignatureBuilder's minimization behavior in the presence
of conflicts, since it doesn't matter anymore.
2022-03-14 12:33:18 -04:00
Slava Pestov
f5b3d19703 RequirementMachine: Replace hadError() with getErrors() returning an OptionSet
This gives us more fine-grained information which will be plumbed
through the various requests.
2022-03-14 12:33:18 -04:00
Slava Pestov
762bf1e7d0 RequirementMachine: Refine 'derived via protocol typealias' criterion
Preserves concrete type rules on associated types that were derived
from rules indirectly formed from protocol typealias rules.

That is, if you have a pair of rules in another minimization domain:

    [P].A.[concrete: C] => [P].A
    [Q:T].[P] => [Q:T]

Then completion will introduce a new rule:

    [Q:T].A.[concrete: C] => [Q:T].A

Since this rule is outside of our minimization domain, we don't record
a rewrite loop for it, and it will never become redundant.

Now if we have a rule in our own minimization domain:

    T.[Q:T].A => T.[Q:U]

Then we get a new rule:

    T.[Q:U].[concrete: C] => T.[Q:U]

Make sure we keep this rule around on account of it being derived from
([Q:T].A.[concrete: C] => [Q:T].A).
2022-03-14 12:33:18 -04:00
Slava Pestov
1f83cd0b49 RequirementMachine: Don't eliminate a rule via a path involving a protocol typealias rule
If a rule is not a protocol typealias rule, and does not contain any unresolved
symbols, do not attempt to eliminate it via a protocol typealias rule.

This fixes a bunch of cases where the RequirementMachine was overly-eager to
remove rules.
2022-03-11 17:28:01 -05:00
Slava Pestov
a259844803 RequirementMachine: Record those rewrite loops involving protocol typealiases 2022-03-11 17:28:01 -05:00
Slava Pestov
3641b77c21 RequirementMachine: Split up first pass of homotopy reduction into two
Add a separate pass to consider rules with unresolved names which are
not simplified.
2022-03-11 17:28:01 -05:00
Slava Pestov
f082c02e42 RequirementMachine: Plumb through the loop candidate to isRedundantRuleFn 2022-03-11 17:28:01 -05:00
Holly Borla
0085eb0dfe [RequirementMachine] Separate setting the explicit bit and the requirement
ID for a rewrite rule.
2022-03-09 21:22:53 -08:00
Holly Borla
b5d7a0152b [RequirementMachine] Factor the 'rules once in empty context' computation out
into a method on RewritePath.
2022-03-09 16:17:55 -08:00
Holly Borla
a154641288 [RequirementMachine] Propagate explicit requirement IDs from redundant
rules in a separate pass after homotopy reduction.

RewriteSystem::propagateExplicitBits was too eager in propagating
IDs from explicit rules within rewrite loops, which resulted in bogus
redundancy warnings when the canonical form of an explicit rule was
given a different requirement ID. Instead, propagate requirement IDs
after homotopy reduction when redundant rules are computed and rewrite
loops are simplified.
2022-03-09 12:14:58 -08:00
Holly Borla
3c95cac5e8 [RequirementMachine] Store a requirement ID for explicit rules in the
rewrite system.

This ID can be used to index into the WrittenRequirements array in the
rewrite system to retrieve the structural requirement, e.g. for the
purpose of diagnostics.
2022-03-09 12:14:58 -08:00
Slava Pestov
95f122f105 RequirementMachine: Add -enable-requirement-machine-loop-normalization flag 2022-03-08 22:47:22 -05:00
Slava Pestov
a0c3045709 RequirementMachine: Relax criterion for deleting a useless loop
Distinguish a loop with elimination candidates, which are rules
appearing in empty context and exactly once, from a useful loop,
which contains at least one rule in empty context (but the same
rule might appear more than once).

Normalizing a useful loop might produce a loop with elimination
candidates, but normalizing a useless loop never does.
2022-03-08 22:47:22 -05:00
Slava Pestov
713e0a4a6d RequirementMachine: Reduce replacement paths for redundant rules to left-canonical normal form
This brings back the code I deleted in 1bf6102f1e
but repurposes it to simplify the replacement paths recorded for
redundant rewrite rules only.
2022-03-08 22:47:22 -05:00
Slava Pestov
b497c790fa RequirementMachine: Check invariants in noassert builds 2022-03-03 14:05:02 -05:00
Slava Pestov
d3c224bb26 RequirementMachine: RewriteSystem::hadError() should ignore rules outside our minimization domain 2022-02-28 18:43:53 -05:00
Slava Pestov
a69ac78482 RequirementMachine: Rework PropertyMap::recordConflict() for GSB compatibility
We want to prefer explicit rules when an explicit rule and non-explicit
rule conflict. Since the explicit bit hasn't been computed yet when
building the property map, save conflicting rule pairs in a side table,
and then process them later in homotopy reduction.

The side table will also be useful for diagnostics later.
2022-02-17 19:40:58 -05:00
Slava Pestov
ee410b4fe3 RequirementMachine: Another elimination order hack 2022-02-17 19:40:58 -05:00
Slava Pestov
e8503021fd RequirementMachine: Add a check to RewriteSystem::verifyMinimizedRules() 2022-02-17 19:40:58 -05:00
Slava Pestov
991fe1dbd8 RequirementMachine: Preserve replacement paths for redundant rules 2022-02-16 16:28:08 -05:00
Slava Pestov
426df360b0 RequirementMachine: More elimination order tweaking
- Prefer rewrite loops not involving Decompose
- Prefer more deeply nested concrete types
2022-02-15 04:02:46 -05:00
Slava Pestov
0deacdc7b1 RequirementMachine: Fix silly typo in RewriteSystem::findRuleToDelete()
This was regressing a couple of validation tests after the
seemingly-unrelated introduction of protocol typealias support.
2022-02-13 09:50:16 -05:00
Slava Pestov
fa65fd0e05 RequirementMachine: Plumb protocol typealiases through minimization
Now that we can detect protocol typealias rules, collect and keep
track of them so that they can be recorded in protocol requirement
signatures.

For now, this is all NFC since nothing introduces such rules into
the rewrite system, except for invalid requirements which are
diagnosed anyway.
2022-02-13 00:24:23 -05:00
Slava Pestov
65fda8092f RequirementMachine: Small fix for debug output 2022-02-13 00:24:23 -05:00
Slava Pestov
d39c667e26 RequirementMachine: New elimination order based on projection count
We want to prefer to eliminate rules that are not concrete type rules,
unless non-concrete type rule in question is a projection. For example,
suppose that this rule comes from a protocol:

    T.T == G<T.U, T.V>

And these three rules are in our minimization domain:

    a) T.T == G<Int, W>
    b) T.U == Int
    c) T.V == W

Then a) implies both b) and c), and vice versa.

In this case, we want to keep T.U == Int and T.V == W, and eliminate
T.T == G<Int, W>.

T.T == G<Int, W> is concrete and T.V == W is not, but because T.V == W
is defined by a projection, we still prefer to eliminate T.T == G<Int, W>
over T.V == W.
2022-02-09 11:31:35 -05:00
Slava Pestov
aeceda3cfa RequirementMachine: Introduce RewriteLoop::getProjectionCount() 2022-02-09 10:45:09 -05:00
Slava Pestov
50f84cb4bf RequirementMachine: Tweak debug output 2022-02-09 00:26:04 -05:00
Slava Pestov
0d0bcb2ff1 RequirementMachine: Simplify the Symbol API for removal of merged associated types 2022-02-07 18:57:45 -05:00
Slava Pestov
2c355de71b RequirementMachine: Introduce RewriteStep::{Left,Right}ConcreteProjection 2022-02-07 08:20:59 -05:00
Slava Pestov
06d4770adb RequirementMachine: Teach homotopy reduction to better deal with incomparable rules 2022-02-07 08:20:59 -05:00
Slava Pestov
037dc98845 RequirementMachine: Generalize compare() methods to return None instead of asserting on incomparable symbols 2022-02-07 08:20:59 -05:00
Slava Pestov
7e4a5876d1 RequirementMachine: Introduce RewriteStep::DecomposeConcrete 2022-02-07 08:20:58 -05:00
Slava Pestov
d8aa79c5e5 RequirementMachine: Rename RewriteStep::AdjustConcreteType to ::PrefixSubstitutions 2022-02-07 08:20:58 -05:00
Slava Pestov
a11151a7e3 RequirementMachine: Fix up some comments 2022-02-04 22:49:28 -05:00
Slava Pestov
3790bba7a0 RequirementMachine: Verify loops immediately when they're added to aid debugging 2022-02-04 22:48:35 -05:00
Slava Pestov
04f9bce79a RequirementMachine: Treat LHS-simplified and RHS-simplified/substitution-simplified rules separately in minimization 2022-01-27 18:54:03 -05:00
Slava Pestov
106896228e RequirementMachine: Split up Rule::isSimplified() into three predicates
We have three simplification passes, give each one its own predicate:
- Left hand side simplification
- Right hand side simplification
- Substitution simplification

This is for debugging output and will also allow me to tighten up
some invariants.
2022-01-27 18:54:03 -05:00
Slava Pestov
f3b8bedf1f RequirementMachine: Fix assertion failure when conflicting rules are also redundant
We can end up with two redundant concrete type rules on the same
term, but we would crash in homotopy reduction because the rules
were incomparable due to the concrete type symbol at the end.

If one of them is conflicting though, we don't really care about
the homotopy reduction order, so skip the check if the other
rule was already marked conflicting.
2022-01-25 00:32:25 -05:00