Commit Graph

12 Commits

Author SHA1 Message Date
Slava Pestov
cc3d02b975 RequirementMachine: Reduction order on terms compares number of name symbols first
We want a term with more name symbols to order after a term with
fewer name symbols, even if the term with more name symbols is
shorter. That is,

    [P].A > [P:X].[Q:Y].[R:Z]

This is in support of handling protocol typealiases.
2022-02-13 00:24:23 -05:00
Slava Pestov
8406d44db8 RequirementMachine: Allow MutableTerm::rewriteSubTerm() to make the term longer
I'm about to change the reduction order so that terms with more
name symbols always order after terms with fewer name symbols,
so for example

    [P].A > [P:T].[Q:U].[R:V]

This will be used to implement protocol typealiases.
2022-02-13 00:24:23 -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
8468c14dbc RequirementMachine: Add overload of PropertyMap::lookUpProperties() that takes a pair of iterators 2022-01-20 12:48:48 -05:00
Slava Pestov
0571b65cb8 RequirementMachine: Move protocol linear order from ProtocolGraph to RewriteContext 2021-10-21 19:00:10 -04:00
Slava Pestov
3185fd8606 RequirementMachine: Introduce Term::compare() to complement MutableTerm::compare() 2021-10-15 15:13:22 -04:00
Slava Pestov
371366eb4b RequirementMachine: Assert that non-redundant rules are fully resolved 2021-10-08 14:28:27 -04:00
Slava Pestov
2fc6ec551b RequirementMachine: Use trie for left hand side simplification
In a confluent rewrite system, if the left hand side of a rule
X => Y can be reduced by some other rule X' => Y', then it is
permissible to delete the original rule X => Y altogether.

Confluence means that rewrite rules can be applied in any
order, so it is always valid to apply X' => Y' first, thus
X => Y is obsolete.

This was previously done in the completion procedure via a
quadratic algorithm that attempted to reduce each existing
rule via the newly-added rule obtained by resolving a critical
pair. Instead, we can do this in the post-processing pass
where we reduce right hand sides using a trie to speed up
the lookup.

This increases the amount of work performed by the
completion procedure, but eliminates the quadratic algorithm,
saving time overall.
2021-08-07 01:51:31 -04:00
Slava Pestov
156fa2cc04 RequirementMachine: Speed up term simplification with a prefix trie
Previously RewriteSystem::simplify() would attempt to apply every
rewrite rule at every position in the original term, which was
obviously a source of overhead.

The trie itself is somewhat unoptimized; for example, with a bit of
effort it could merge a node with its only child, if nodes stored
a range of elements to compare rather than a single element.
2021-08-05 21:42:50 -04:00
Slava Pestov
92ac06a25b RequirementMachine: Rules store uniqued Terms 2021-08-05 21:42:50 -04:00
Slava Pestov
ed966e7337 RequirementMachine: Add histograms for symbol kinds and term length 2021-08-05 21:42:50 -04:00
Slava Pestov
7adfd86e37 RequirementMachine: Split off Symbol.cpp and Term.cpp from RewriteSystem.cpp 2021-08-05 21:42:49 -04:00