Commit Graph

9 Commits

Author SHA1 Message Date
Slava Pestov
dd6a569754 RequirementMachine: Fix use-after-free detected by ASAN
We're adding new rules to the Rules list while iterating over it, which
is not good.
2021-07-14 18:42:28 -04:00
Slava Pestov
f0d59d5d4d RequirementMachine: Handle equivalence classes that both have a concrete type and protocol requirements
If a type parameter has a protocol conformance and a concrete type,
we want to map associated types of the conformance to their concrete
type witnesses.

This is implemented as a post-processing pass in the completion
procedure that runs after the equivalence class map has been built.

If we have an equivalence class T => { conforms_to: [ P ], concrete: Foo },
then for each associated type A of P, we generate a new rule:

    T.[P:A].[concrete: Foo.A] => T.[P:A]  (if Foo.A is concrete)
    T.[P:A] => T.(Foo.A)                  (if Foo.A is abstract)

If this process introduced any new rules, we check for any new
overlaps by re-running Knuth-Bendix completion; this may in turn
introduce new concrete associated type overlaps, and so on.

The overall completion procedure now alternates between Knuth-Bendix
and rebuilding the equivalence class map; the rewrite system is
complete when neither step is able to introduce any new rules.
2021-07-09 00:04:36 -04:00
Slava Pestov
8ee58cd02c RequirementMachine: Fix assertion in mergeAssociatedTypes()
We used to assert that the merged protocol set was larger than or
equal to in size to both the left hand side and the right hand
side.

However, there is a counter-example:

    protocol P {}
    protocol Q {}
    protocol R : P, Q {}

    LHS = [P&Q:T], RHS = [R:T]

The merged atom is `[R:T]` which has fewer protocols than the
left hand side.
2021-07-08 23:31:53 -04:00
Slava Pestov
56700983de RequirementMachine: Completion step and depth limits also apply to equivalence class map 2021-07-08 23:31:53 -04:00
Slava Pestov
f28d9b3dbf RequirementMachine: Stub out the equivalence class map 2021-06-30 01:34:20 -04:00
Slava Pestov
3803767c0c RequirementMachine: Fix logic error in mergeAssociatedTypes() 2021-06-30 01:34:07 -04:00
Slava Pestov
8107cea766 RequirementMachine: Define operator<< overloads 2021-06-29 13:09:11 -04:00
Slava Pestov
e4faf73005 RequirementMachine: Fix another bug in checkForOverlap()
The `if (other.size() > size())` check was bogus; we can still have an
overlap of the second kind if the other term is longer than this term.

Remove this check, and rewrite the algorithm to be clearer in general.
2021-06-28 23:34:50 -04:00
Slava Pestov
6c164f682e RequirementMachine: Move files to a new subdirectory under lib/AST/
Also move a all headers other than RequirementMachine.h there, since
I don't expect they will be used outside of the rewrite system
implementation itself.
2021-06-25 00:04:09 -04:00