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
|
||||
I: IntoIterator<Item = Variable>,
|
||||
C: IntoIterator<Item = Constraint>,
|
||||
C::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
let defs_constraint = self.and_constraint(defs_constraint);
|
||||
|
||||
|
@ -268,14 +269,20 @@ impl Constraints {
|
|||
Constraint::Let(let_index)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn and_constraint<I>(&mut self, constraints: I) -> Constraint
|
||||
where
|
||||
I: IntoIterator<Item = Constraint>,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
let mut it = constraints.into_iter();
|
||||
|
||||
match it.len() {
|
||||
0 => Constraint::True,
|
||||
1 => it.next().unwrap(),
|
||||
_ => {
|
||||
let start = self.constraints.len() as u32;
|
||||
|
||||
self.constraints.extend(constraints);
|
||||
self.constraints.extend(it);
|
||||
|
||||
let end = self.constraints.len() as u32;
|
||||
|
||||
|
@ -283,6 +290,8 @@ impl Constraints {
|
|||
|
||||
Constraint::And(slice)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lookup(
|
||||
&mut self,
|
||||
|
|
|
@ -1091,8 +1091,10 @@ pub fn constrain_expr(
|
|||
|
||||
let category = Category::LowLevelOpResult(*op);
|
||||
|
||||
// Deviation: elm uses an additional And here
|
||||
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 {
|
||||
args,
|
||||
|
@ -1132,8 +1134,10 @@ pub fn constrain_expr(
|
|||
|
||||
let category = Category::ForeignCall;
|
||||
|
||||
// Deviation: elm uses an additional And here
|
||||
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(_) => {
|
||||
// Runtime Errors have no constraints because they're going to crash.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue