feat: introduce bag-of-constraints solver
The diff is very large, it is just because of a missing merge/rebase? I feel like I still dont understand git.
The diff is very large, it is just because of a missing merge/rebase? I feel like I still dont understand git.
Yeah, the git ghost is about. I'll fix it sometime.
Can you write me a short description of how to best review this?
Can you write me a short description of how to best review this?
No, but I can write a long one.
Before this PR
Unification of types is handled in two different places:
ConstraintSolveris called byTyperUnificationis called everywhere else:Monomorph,HoleCompletion,EffectVerifier,Instances,Stratifier, as well asConstraintSolveritself.Unificationis just a wrapper aroundOldStarUnification
This PR
This PR does 2 things:
- introduces
ConstraintSolver2, a bag-of-constraints, phase-based parser - changes
Unificationto callConstraintSolver2instead ofOldStarUnification
Other changes are administrative:
- Copy of
RecordConstraintSolverusingConstraintSolver2interface - ditto
SchemaConstraintSolver - ditto
TypeReduction - Cutting off
RecordUnificationandSchemaUnificationfrom the newUnification
ConstraintSolver2
This solver applies the unification rules as phases. The high-level algorithm is:
while progress:
for each phase:
for each constraint:
apply the phase's rule to the constraint
Each phase is represented by a function taking a type constraint and returning one of the following:
- a type constraint
- a set of type constraints
- a set of type constraints and a substitution tree
These phases are applied to a collection of constraints through an abstraction Soup, which allows a pipeline-like syntax for applying rules, while hiding management of substitutions.
The substitution tree is not used in this PR, as it is intended for Purification constraints, which do not arise from calling Unification functions. You can think of the substitution tree as a simple substitution for now.
After this PR
At least three PRs will follow.
- A PR to remove code made redundant by this PR. This includes:
RecordUnificationSchemaUnificationEqualityEnvironmentAssocTypeSubstitutionOldStarUnification- possibly more
- A PR to replace
ConstraintSolverwithConstraintSolver2. This will likely reveal some bugs. - A PR to remove code made redundant by PR 2. (By overwriting it with
ContraintSolver2's helpers. This includes:
TypeReductionRecordConstraintSolverSchemaConstraintSolver- probably more
In the final version, how will Monomorpher conduct unification?
Will it use constraints? One constraint? Or will it just call deeper into the solver (i.e. some specific unification procedure?)
In the final version, how will Monomorpher conduct unification?
Will it use constraints? One constraint? Or will it just call deeper into the solver (i.e. some specific unification procedure?)
It will use one constraint. That behavior is introduced by this PR, through an interface.
I still need to look at ConstraintSolver2
Adding some source comments for some of my comments might be useful.
Adding some source comments for some of my comments might be useful.
I do not know what this means.
I will review this soon again, but I need Jonathans PR to land first. So you should also harass him :)
@mlutze There are no conflicts. Does this mean I can merge this or do you want to experiment?
@mlutze There are no conflicts. Does this mean I can merge this or do you want to experiment?
Let's at least wait for one tick on the arewefast graph :)
Will this PR not use SetUnification.unifyAll? or is that later?
Will this PR not use
SetUnification.unifyAll? or is that later?
Later. This one only deals with one constraint at a time anyway.
@mlutze You can merge this tomorrow.