diff --git a/compiler/can/src/constraint_soa.rs b/compiler/can/src/constraint_soa.rs index a25c630755..05e1652340 100644 --- a/compiler/can/src/constraint_soa.rs +++ b/compiler/can/src/constraint_soa.rs @@ -85,6 +85,28 @@ impl Constraints { Slice::new(start as _, length as _) } + pub fn exists(&mut self, flex_vars: I, defs_constraint: Constraint) -> Constraint + where + I: IntoIterator, + { + let defs_and_ret_constraint = Index::new(self.constraints.len() as _); + + self.constraints.push(defs_constraint); + self.constraints.push(Constraint::True); + + let let_contraint = LetConstraint { + rigid_vars: Slice::default(), + flex_vars: self.variable_slice(flex_vars), + def_types: Slice::default(), + defs_and_ret_constraint, + }; + + let let_index = Index::new(self.let_constraints.len() as _); + self.let_constraints.push(let_contraint); + + Constraint::Let(let_index) + } + pub fn let_contraint( &mut self, rigid_vars: I1, @@ -167,6 +189,12 @@ pub struct Slice { _marker: std::marker::PhantomData, } +impl Default for Slice { + fn default() -> Self { + Self::new(0, 0) + } +} + impl Slice { pub const fn new(start: u32, length: u16) -> Self { Self {