diff options
| author | tslil <tslil@posteo.de> | 2026-04-27 14:17:53 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-04-27 15:07:51 +0100 |
| commit | 250078ef4955f46e93882b9383e3443d50f8d61b (patch) | |
| tree | a480efd0c7c780efa51ecfa5001df1d4f5654c48 /src/checker_set.rs | |
| parent | 47bb6052919a4266cf47f47c6e6d387baf6e39b0 (diff) | |
refactor equality checking and fields as we start to build towards signatures
Diffstat (limited to 'src/checker_set.rs')
| -rw-r--r-- | src/checker_set.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/checker_set.rs b/src/checker_set.rs index 93ba4b3..2ea0c3d 100644 --- a/src/checker_set.rs +++ b/src/checker_set.rs @@ -6,12 +6,12 @@ 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) => { let fields = fields - .iter() + .into_iter() .map(|RecordField { name, set }| { let set = self.check_set(set)?; Ok(RecordField { @@ -24,7 +24,7 @@ impl CheckerState { } Set::Variant(fields) => { let fields = fields - .iter() + .into_iter() .map(|VariantField { name, set }| { let set = self.check_set(set)?; Ok(VariantField { @@ -37,7 +37,7 @@ impl CheckerState { } Set::ClaimedSet(_) => Err(CheckerError::Unimplemented("instances as sets".to_string())), Set::Var(v) => { - let deref = self.lookup_set(v)?; + let deref = self.lookup_set(&v)?; Ok(deref.clone()) } } @@ -49,7 +49,7 @@ impl CheckerState { claimed: &Set, should_be: Set, ) -> Result<(), CheckerError> { - if !self.set_equal(claimed, &should_be) { + if !self.equal(claimed, &should_be) { Err(CheckerError::WrongSetForElement { value: value.clone(), claimed: claimed.clone(), @@ -72,7 +72,7 @@ impl CheckerState { // check_element, we can safely ignore its payload. I'll point this // out later as (*) ElementValue::Hypothetical(ref h_set) => { - if !self.set_equal(set, &h_set) { + if !self.equal(set, &h_set) { Err(CheckerError::WrongSetForElement { value: value.clone(), claimed: set.clone(), @@ -108,7 +108,7 @@ impl CheckerState { 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! - if !self.set_equal(set, &lookup.set) { + if !self.equal(set, &lookup.set) { return Err(CheckerError::WrongSetForElement { value: value.clone(), claimed: set.clone(), @@ -179,13 +179,13 @@ impl CheckerState { }) => { // globally unique projections mean we know what the sets going // in and out must be - let SetField { - field_set, - owner_set, + let Field { + field: field_set, + owner: owner_set, } = self.lookup_record_field(&field)?; // enforce the correct typing of the claimed result - if !self.set_equal(set, field_set) { + if !self.equal(set, field_set) { return Err(CheckerError::WrongSetForElement { value, claimed: set.clone(), @@ -225,13 +225,13 @@ impl CheckerState { // globally unique injections mean that we know what the sets // going in and out must be, but compared to projections their // roles are here interchanged - let SetField { - field_set, - owner_set, + let Field { + field: field_set, + owner: owner_set, } = self.lookup_variant_field(&field)?; // enforce the correct typing of the claimed result - if !self.set_equal(set, owner_set) { + if !self.equal(set, owner_set) { return Err(CheckerError::WrongSetForElement { value, claimed: set.clone(), @@ -270,10 +270,10 @@ impl CheckerState { // arms agree on the set to which the scrutinee should belong let arm_owners = arms .iter() - .map(|ca| self.lookup_variant_field(&ca.tag).map(|sf| &sf.owner_set)) + .map(|ca| self.lookup_variant_field(&ca.tag).map(|sf| &sf.owner)) .collect::<Result<Vec<_>, _>>()?; let owner = arm_owners[0]; // safe because of the above decision about bottom - if !arm_owners.iter().all(|o| self.set_equal(owner, o)) { + if !arm_owners.iter().all(|o| self.equal(owner, o)) { return Err(CheckerError::IncosistentCaseScrutineeSet(element.clone())); } @@ -323,7 +323,9 @@ impl CheckerState { // case record the end result let mut computed_output = None; for arm in arms { - let SetField { field_set, .. } = self.lookup_variant_field(&arm.tag)?; + let Field { + field: field_set, .. + } = self.lookup_variant_field(&arm.tag)?; // TODO: if we were worried about overhead we'd have a separate // locals stack, though truly if we were worried about overhead |
