Skip to content

Commit

Permalink
Fix expect_beq_free
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanBrouwer committed May 22, 2024
1 parent ad6b3d4 commit f2bf205
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
21 changes: 13 additions & 8 deletions prism-compiler/src/lang/expect_beq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,27 @@ impl TcEnv {
/// `rt` should be free.
pub fn expect_beq_fn_type(&mut self, ft: UnionIndex, at: UnionIndex, rt: UnionIndex, s: &Env) {
let (fr, sr) = self.beta_reduce_head(ft, s.clone());
let mut var_map1 = HashMap::new();
let mut var_map2 = HashMap::new();


match self.values[fr.0] {
PartialExpr::FnType(f_at, f_rt) => {
if !self.expect_beq_internal((f_at, &sr, &mut var_map1), (at, s, &mut var_map2)) {
if !self.expect_beq_internal((f_at, &sr, &mut HashMap::new()), (at, s, &mut HashMap::new())) {
self.errors.push(TypeError::ExpectFnArg {
function_type: ft,
function_arg_type: f_at,
arg_type: at,
})
}

let mut var_map1 = HashMap::new();
let mut var_map2 = HashMap::new();
let id = self.new_tc_id();
var_map1.insert(id, sr.len());
var_map2.insert(id, s.len());
_ = self.expect_beq_free(
let is_beq_free = self.expect_beq_free(
(f_rt, &sr.cons(RType(id)), &mut var_map1),
(rt, &s.cons(RType(id)), &mut var_map2),
);
debug_assert!(is_beq_free);
}
PartialExpr::Free => {
let f_at = self.store(PartialExpr::Free, FreeSub(fr));
Expand All @@ -65,15 +66,19 @@ impl TcEnv {
})
}

self.toxic_values.insert(fr);
let is_beq_free = self.expect_beq_free((at, s, &mut HashMap::new()), (f_at, &sr, &mut HashMap::new()));
debug_assert!(is_beq_free);

let mut var_map1 = HashMap::new();
let mut var_map2 = HashMap::new();
let id = self.new_tc_id();
var_map1.insert(id, sr.len());
var_map2.insert(id, s.len());

_ = self.expect_beq_free(
let is_beq_free = self.expect_beq_free(
(f_rt, &sr.cons(RType(id)), &mut var_map1),
(rt, &s.cons(RType(id)), &mut var_map2),
);
debug_assert!(is_beq_free);
}
_ => self.errors.push(TypeError::ExpectFn(ft)),
}
Expand Down
3 changes: 1 addition & 2 deletions prism-compiler/src/lang/expect_beq_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,9 @@ impl TcEnv {
}
}

//TODO handle queued type constraints
// if let Some((s, t2)) = self.queued_tc.remove(&i2) {
// let t1 = self._type_check(i2, &s);
// self.expect_beq(t1, t2, &s);
// eq &= self.expect_beq_internal((t1, &s, &mut HashMap::new()), (t2, &s, &mut HashMap::new()));
// }

eq
Expand Down
2 changes: 1 addition & 1 deletion prism-compiler/src/lang/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct TcEnv {

// Queues
queued_beq_free: HashMap<UnionIndex, Vec<QueuedConstraint>>,
//TODO readd queued_tc: HashMap<UnionIndex, (Env, UnionIndex)>,
// queued_tc: HashMap<UnionIndex, (Env, UnionIndex)>,
}

#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion prism-compiler/src/lang/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl TcEnv {
let ft = self._type_check(f, s);
if self.errors.len() == err_count {
self.expect_beq_fn_type(ft, at, rt, s)
};
}

PartialExpr::Let(a, rt)
}
Expand Down
5 changes: 3 additions & 2 deletions prism-compiler/tests/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ fn test_fail([test]: [&str; 1]) {
env.index_to_br_string(input),
env.index_to_sm_string(typ),
env.index_to_br_string(typ));
panic!()
}
Err(errs) => errs.eprint(&mut env, test).unwrap(),
Err(_) => {},
}
}

test_each_file! { for ["test"] in "prism-compiler/programs/type_check_fails" as fails => test_fail }
test_each_file! { for ["test"] in "prism-compiler/programs/type_check_fails" as type_check_fails => test_fail }

#[test]
fn placeholder() {}

0 comments on commit f2bf205

Please sign in to comment.