diff options
Diffstat (limited to '')
-rw-r--r-- | dhall/src/operations/normalization.rs | 25 | ||||
-rw-r--r-- | dhall/src/operations/typecheck.rs | 24 |
2 files changed, 20 insertions, 29 deletions
diff --git a/dhall/src/operations/normalization.rs b/dhall/src/operations/normalization.rs index f147f85..dbd58f9 100644 --- a/dhall/src/operations/normalization.rs +++ b/dhall/src/operations/normalization.rs @@ -300,9 +300,7 @@ pub fn normalize_operation(opkind: &OpKind<Nir>) -> Ret { _ => nothing_to_do(), }, With(record, labels, expr) => { - use std::iter::FromIterator; - - let mut current_nk: Option<NirKind> = Some(record.kind().clone()); + let mut current_nir: Option<Nir> = Some(record.clone()); let mut visited: Vec<(&Label, HashMap<Label, Nir>)> = Vec::new(); let mut to_create = Vec::new(); @@ -310,19 +308,18 @@ pub fn normalize_operation(opkind: &OpKind<Nir>) -> Ret { let mut abstract_nir = None; for label in labels { - match current_nk { + match current_nir { None => to_create.push(label.clone()), - Some(nk) => match nk { + Some(nir) => match nir.kind() { RecordLit(kvs) => { - current_nk = - kvs.get(label).map(|nir| nir.kind().clone()); - visited.push((label, kvs)); + current_nir = kvs.get(label).cloned(); + visited.push((label, kvs.clone())); } // Handle partially abstract case - nir => { - abstract_nir = Some(Nir::from_kind(nir)); + _ => { + abstract_nir = Some(nir); to_create.push(label.clone()); - current_nk = None; + current_nir = None; } }, } @@ -335,10 +332,8 @@ pub fn normalize_operation(opkind: &OpKind<Nir>) -> Ret { // No abstract nir, creating singleton records None => { while let Some(label) = to_create.pop() { - let rec = RecordLit(FromIterator::from_iter(once(( - label.clone(), - nir, - )))); + let rec = + RecordLit(once((label.clone(), nir)).collect()); nir = Nir::from_kind(rec); } } diff --git a/dhall/src/operations/typecheck.rs b/dhall/src/operations/typecheck.rs index af6f706..6da7027 100644 --- a/dhall/src/operations/typecheck.rs +++ b/dhall/src/operations/typecheck.rs @@ -505,28 +505,27 @@ pub fn typecheck_operation( } With(record, labels, expr) => { use crate::syntax::Label; - use std::iter::{once, FromIterator}; + use std::iter::once; - let record_entries = |nk: &NirKind| { - match nk { + let record_entries = |nir: &Nir| { + match nir.kind() { NirKind::RecordType(kts) => Ok(kts.clone()), _ => mk_span_err(span.clone(), "WithMustBeRecord"), // TODO better error } }; - let mut current_nk: Option<NirKind> = - Some(record.ty().kind().clone()); + let mut current_nir: Option<Nir> = + Some(record.ty().as_nir().clone()); let mut visited: Vec<(&Label, HashMap<Label, Nir>)> = Vec::new(); let mut to_create = Vec::new(); for label in labels { - match current_nk { + match current_nir { None => to_create.push(label), - Some(nk) => { - let kts = record_entries(&nk)?; + Some(nir) => { + let kts = record_entries(&nir)?; - current_nk = - kts.get(label).map(|nir| nir.kind().clone()); + current_nir = kts.get(label).cloned(); visited.push((label, kts)); } } @@ -536,10 +535,7 @@ pub fn typecheck_operation( let mut nir = expr.ty().as_nir().clone(); while let Some(label) = to_create.pop() { - let rec = RecordType(FromIterator::from_iter(once(( - label.clone(), - nir, - )))); + let rec = RecordType(once((label.clone(), nir)).collect()); nir = Nir::from_kind(rec); } |