mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Record problems in unification
This commit is contained in:
parent
e949c56f70
commit
ca219a1b64
8 changed files with 114 additions and 113 deletions
23
src/solve.rs
23
src/solve.rs
|
@ -3,11 +3,16 @@ use crate::collections::ImMap;
|
|||
use crate::subs::{Content, Descriptor, FlatType, Subs, Variable};
|
||||
use crate::types::Constraint::{self, *};
|
||||
use crate::types::Type::{self, *};
|
||||
use crate::unify::unify;
|
||||
use crate::unify::{unify, Problems};
|
||||
|
||||
type Env = ImMap<Symbol, Variable>;
|
||||
|
||||
pub fn solve(vars_by_symbol: &Env, subs: &mut Subs, constraint: &Constraint) {
|
||||
pub fn solve(
|
||||
vars_by_symbol: &Env,
|
||||
problems: &mut Problems,
|
||||
subs: &mut Subs,
|
||||
constraint: &Constraint,
|
||||
) {
|
||||
match constraint {
|
||||
True => (),
|
||||
Eq(typ, expected_type, _region) => {
|
||||
|
@ -15,7 +20,7 @@ pub fn solve(vars_by_symbol: &Env, subs: &mut Subs, constraint: &Constraint) {
|
|||
let actual = type_to_var(subs, typ.clone());
|
||||
let expected = type_to_var(subs, expected_type.clone().get_type());
|
||||
|
||||
unify(subs, actual, expected);
|
||||
unify(subs, problems, actual, expected);
|
||||
}
|
||||
Lookup(symbol, expected_type, _region) => {
|
||||
// TODO use region?
|
||||
|
@ -29,11 +34,11 @@ pub fn solve(vars_by_symbol: &Env, subs: &mut Subs, constraint: &Constraint) {
|
|||
}));
|
||||
let expected = type_to_var(subs, expected_type.clone().get_type());
|
||||
|
||||
unify(subs, actual, expected);
|
||||
unify(subs, problems, actual, expected);
|
||||
}
|
||||
And(sub_constraints) => {
|
||||
for sub_constraint in sub_constraints.iter() {
|
||||
solve(vars_by_symbol, subs, sub_constraint);
|
||||
solve(vars_by_symbol, problems, subs, sub_constraint);
|
||||
}
|
||||
}
|
||||
Pattern(_region, _category, typ, expected) => {
|
||||
|
@ -41,18 +46,18 @@ pub fn solve(vars_by_symbol: &Env, subs: &mut Subs, constraint: &Constraint) {
|
|||
let actual = type_to_var(subs, typ.clone());
|
||||
let expected = type_to_var(subs, expected.clone().get_type());
|
||||
|
||||
unify(subs, actual, expected);
|
||||
unify(subs, problems, actual, expected);
|
||||
}
|
||||
Let(let_con) => {
|
||||
match &let_con.ret_constraint {
|
||||
True => {
|
||||
// If the return expression is guaranteed to solve,
|
||||
// solve the assignments themselves and move on.
|
||||
solve(vars_by_symbol, subs, &let_con.defs_constraint)
|
||||
solve(vars_by_symbol, problems, subs, &let_con.defs_constraint)
|
||||
}
|
||||
ret_con => {
|
||||
// Solve the assignments' constraints first.
|
||||
solve(vars_by_symbol, subs, &let_con.defs_constraint);
|
||||
solve(vars_by_symbol, problems, subs, &let_con.defs_constraint);
|
||||
|
||||
// Add a variable for each assignment to the vars_by_symbol.
|
||||
let mut new_vars_by_symbol = vars_by_symbol.clone();
|
||||
|
@ -69,7 +74,7 @@ pub fn solve(vars_by_symbol: &Env, subs: &mut Subs, constraint: &Constraint) {
|
|||
|
||||
// Now solve the body, using the new vars_by_symbol which includes
|
||||
// the assignments' name-to-variable mappings.
|
||||
solve(&new_vars_by_symbol, subs, &ret_con);
|
||||
solve(&new_vars_by_symbol, problems, subs, &ret_con);
|
||||
|
||||
// TODO do an occurs check for each of the assignments!
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue