diff options
| author | tslil <tslil@posteo.de> | 2026-04-29 16:36:13 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-04-29 16:51:55 +0100 |
| commit | 79a612f4983d1f2b59c653fb0c21879eb191457e (patch) | |
| tree | ed9100fa4a211e2937c58801c52e83a55abc0219 /src/checker_set.rs | |
| parent | 87266db229c7f14527c85b06abcf074cf861f6f9 (diff) | |
switch to references in many places for check_*, complete logic of Var case for App
Diffstat (limited to 'src/checker_set.rs')
| -rw-r--r-- | src/checker_set.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/checker_set.rs b/src/checker_set.rs index 2bd011d..10f9b28 100644 --- a/src/checker_set.rs +++ b/src/checker_set.rs @@ -6,7 +6,7 @@ use tracing::instrument; impl CheckerState { #[instrument(skip(self), level = "debug", fields(%set))] - pub fn check_set(&self, set: Set) -> Result<Set, CheckerError> { + pub fn check_set(&self, set: &Set) -> Result<Set, CheckerError> { match set { Set::BuiltIn(_) => Ok(set.clone()), Set::Record(fields) => { @@ -16,7 +16,10 @@ impl CheckerState { .map(|RecordField { name, set }| { let set = ctx.check_set(set)?; ctx.make_element_binding(name.clone(), set.clone())?; - Ok(RecordField { name, set }) + Ok(RecordField { + name: name.clone(), + set, + }) }) .collect::<Result<Vec<_>, _>>()?; Ok(Set::Record(fields)) @@ -41,7 +44,7 @@ impl CheckerState { Set::Var(v) => { let deref = self.lookup_set(&v)?; match deref { - SetValue::Hypothetical => Ok(Set::Var(v)), + SetValue::Hypothetical => Ok(Set::Var(v.clone())), SetValue::Concrete(deref) => Ok(deref.clone()), } } @@ -66,9 +69,9 @@ impl CheckerState { } #[instrument(skip(self), level = "debug", fields(%element, %set))] - pub fn check_element(&self, element: Element, set: &Set) -> Result<Element, CheckerError> { + pub fn check_element(&self, element: &Element, set: &Set) -> Result<Element, CheckerError> { match element { - Element::Literal(ref lit) => { + Element::Literal(lit) => { let value = element.clone(); // we may infer the type from the element match lit { @@ -90,7 +93,7 @@ impl CheckerState { } Ok(element.clone().into()) } - Element::Var(ref v) => { + Element::Var(v) => { let lookup = self.lookup_element(&v)?; // we have previously done the work to discover the type of // this element, so what we're claiming now must match! @@ -111,7 +114,7 @@ impl CheckerState { Ok(Element::Var(v.clone())) } } - Element::Record(ref assignations) => { + Element::Record(assignations) => { let rej = |reason| CheckerError::ElementDoesNotBelong { element: element.clone(), claimed: set.clone(), @@ -151,7 +154,7 @@ impl CheckerState { // recurse, sets have already been completely expanded let sub_els = zip(element_felements, set_fsets) - .map(|(e_f, e_s)| self.check_element(e_f.clone().into(), &e_s)) + .map(|(e_f, e_s)| self.check_element(e_f.into(), &e_s)) .collect::<Result<Vec<_>, _>>()?; // rebuild let assignations = zip(element_fnames, sub_els) @@ -161,8 +164,8 @@ impl CheckerState { Ok(Element::Record(assignations)) } Element::Project { - element: ref inner, - ref field, + element: inner, + field, } => { // globally unique projections mean we know what the sets going // in and out must be @@ -181,7 +184,7 @@ impl CheckerState { } // enforce the correct typing of the element - let inner = self.check_element(*inner.clone(), owner_set)?; + let inner = self.check_element(inner, owner_set)?; // Unfortunately we still have to do something nasty here to // obtain the data @@ -210,8 +213,8 @@ impl CheckerState { } } Element::Inject { - element: ref inner, - ref field, + element: inner, + field, } => { // globally unique injections mean that we know what the sets // going in and out must be, but compared to projections their @@ -231,17 +234,14 @@ impl CheckerState { } // enforce the correct typing of the element - let element = self.check_element(*inner.clone(), field_set)?; + let element = self.check_element(inner, field_set)?; Ok(Element::Inject { element: Box::new(element), field: field.clone(), }) } - Element::Case { - ref arms, - ref scrutinee, - } => { + Element::Case { arms, scrutinee } => { // TODO: do we allow mapping out of bottom? if arms.is_empty() { return Err(CheckerError::Unimplemented( @@ -286,7 +286,7 @@ impl CheckerState { // scrutinee must be of the same set that all the arms are // implying, in particular this implies that the following holds // `inner : self.lookup_variant_field(field).field_set` - let scrutinee = self.check_element(*scrutinee.clone(), owner)?; + let scrutinee = self.check_element(scrutinee, owner)?; // which variant are we, if any @@ -322,7 +322,7 @@ impl CheckerState { { let canonical = ctx.make_element_definition(binding_name, inner.clone(), binding_set)?; - let output = ctx.check_element(arm.body.clone().into(), set)?; + let output = ctx.check_element((&arm.body).into(), set)?; if matches!(computed_output, Some(_)) { panic!( "invariant violation: we somehow matched multiple arms in case analysis" @@ -336,7 +336,7 @@ impl CheckerState { } } else { let canonical = ctx.make_element_binding(binding_name, binding_set)?; - let body = ctx.check_element(arm.body.clone().into(), set)?; + let body = ctx.check_element((&arm.body).into(), set)?; CaseArm { tag: arm.tag.clone(), bound: canonical, |
