mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
exploiting exactsizeiterator
This commit is contained in:
parent
54c6292b4b
commit
8d2e0a738c
2 changed files with 21 additions and 8 deletions
|
@ -217,6 +217,7 @@ impl Constraints {
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = Variable>,
|
I: IntoIterator<Item = Variable>,
|
||||||
C: IntoIterator<Item = Constraint>,
|
C: IntoIterator<Item = Constraint>,
|
||||||
|
C::IntoIter: ExactSizeIterator,
|
||||||
{
|
{
|
||||||
let defs_constraint = self.and_constraint(defs_constraint);
|
let defs_constraint = self.and_constraint(defs_constraint);
|
||||||
|
|
||||||
|
@ -268,20 +269,28 @@ impl Constraints {
|
||||||
Constraint::Let(let_index)
|
Constraint::Let(let_index)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
|
||||||
pub fn and_constraint<I>(&mut self, constraints: I) -> Constraint
|
pub fn and_constraint<I>(&mut self, constraints: I) -> Constraint
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = Constraint>,
|
I: IntoIterator<Item = Constraint>,
|
||||||
|
I::IntoIter: ExactSizeIterator,
|
||||||
{
|
{
|
||||||
let start = self.constraints.len() as u32;
|
let mut it = constraints.into_iter();
|
||||||
|
|
||||||
self.constraints.extend(constraints);
|
match it.len() {
|
||||||
|
0 => Constraint::True,
|
||||||
|
1 => it.next().unwrap(),
|
||||||
|
_ => {
|
||||||
|
let start = self.constraints.len() as u32;
|
||||||
|
|
||||||
let end = self.constraints.len() as u32;
|
self.constraints.extend(it);
|
||||||
|
|
||||||
let slice = Slice::new(start, (end - start) as u16);
|
let end = self.constraints.len() as u32;
|
||||||
|
|
||||||
Constraint::And(slice)
|
let slice = Slice::new(start, (end - start) as u16);
|
||||||
|
|
||||||
|
Constraint::And(slice)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup(
|
pub fn lookup(
|
||||||
|
|
|
@ -1091,8 +1091,10 @@ pub fn constrain_expr(
|
||||||
|
|
||||||
let category = Category::LowLevelOpResult(*op);
|
let category = Category::LowLevelOpResult(*op);
|
||||||
|
|
||||||
|
// Deviation: elm uses an additional And here
|
||||||
let eq = constraints.equal_types(ret_type, expected, category, region);
|
let eq = constraints.equal_types(ret_type, expected, category, region);
|
||||||
constraints.exists_many(vars, arg_cons.into_iter().chain(std::iter::once(eq)))
|
arg_cons.push(eq);
|
||||||
|
constraints.exists_many(vars, arg_cons)
|
||||||
}
|
}
|
||||||
ForeignCall {
|
ForeignCall {
|
||||||
args,
|
args,
|
||||||
|
@ -1132,8 +1134,10 @@ pub fn constrain_expr(
|
||||||
|
|
||||||
let category = Category::ForeignCall;
|
let category = Category::ForeignCall;
|
||||||
|
|
||||||
|
// Deviation: elm uses an additional And here
|
||||||
let eq = constraints.equal_types(ret_type, expected, category, region);
|
let eq = constraints.equal_types(ret_type, expected, category, region);
|
||||||
constraints.exists_many(vars, arg_cons.into_iter().chain(std::iter::once(eq)))
|
arg_cons.push(eq);
|
||||||
|
constraints.exists_many(vars, arg_cons)
|
||||||
}
|
}
|
||||||
RuntimeError(_) => {
|
RuntimeError(_) => {
|
||||||
// Runtime Errors have no constraints because they're going to crash.
|
// Runtime Errors have no constraints because they're going to crash.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue