summaryrefslogtreecommitdiff
path: root/dhall/src/semantics/nze
diff options
context:
space:
mode:
authorNadrieril2020-03-17 23:01:35 +0000
committerNadrieril2020-03-17 23:14:32 +0000
commitc22e161f7bd97d4f6c063513cc051f6af2683d84 (patch)
tree7ebb20c3e9db1657a731c5871716e82685dcab6d /dhall/src/semantics/nze
parent681dad33cf27b2be4f4b3cefd83998af1d7eefb2 (diff)
Run clippy
Diffstat (limited to 'dhall/src/semantics/nze')
-rw-r--r--dhall/src/semantics/nze/env.rs4
-rw-r--r--dhall/src/semantics/nze/nir.rs10
-rw-r--r--dhall/src/semantics/nze/normalize.rs43
3 files changed, 29 insertions, 28 deletions
diff --git a/dhall/src/semantics/nze/env.rs b/dhall/src/semantics/nze/env.rs
index 55050ed..ef2bee6 100644
--- a/dhall/src/semantics/nze/env.rs
+++ b/dhall/src/semantics/nze/env.rs
@@ -72,14 +72,14 @@ impl<Type: Clone> ValEnv<Type> {
env.items.push(EnvItem::Replaced(e, ty));
env
}
- pub fn lookup_val(&self, var: &AlphaVar) -> NirKind {
+ pub fn lookup_val(&self, var: AlphaVar) -> NirKind {
let idx = self.items.len() - 1 - var.idx();
match &self.items[idx] {
EnvItem::Kept(_) => NirKind::Var(NzVar::new(idx)),
EnvItem::Replaced(x, _) => x.kind().clone(),
}
}
- pub fn lookup_ty(&self, var: &AlphaVar) -> Type {
+ pub fn lookup_ty(&self, var: AlphaVar) -> Type {
let idx = self.items.len() - 1 - var.idx();
match &self.items[idx] {
EnvItem::Kept(ty) | EnvItem::Replaced(_, ty) => ty.clone(),
diff --git a/dhall/src/semantics/nze/nir.rs b/dhall/src/semantics/nze/nir.rs
index 4ed66b7..32ef590 100644
--- a/dhall/src/semantics/nze/nir.rs
+++ b/dhall/src/semantics/nze/nir.rs
@@ -162,8 +162,8 @@ impl Nir {
)
};
- let hir = match &*self.kind() {
- NirKind::Var(v) => HirKind::Var(venv.lookup(v)),
+ let hir = match self.kind() {
+ NirKind::Var(v) => HirKind::Var(venv.lookup(*v)),
NirKind::AppliedBuiltin(closure) => closure.to_hirkind(venv),
self_kind => HirKind::Expr(match self_kind {
NirKind::Var(..) | NirKind::AppliedBuiltin(..) => {
@@ -317,13 +317,13 @@ impl NirKind {
}
}
NirKind::UnionType(kts) | NirKind::UnionConstructor(_, kts) => {
- for x in kts.values().flat_map(|opt| opt) {
+ for x in kts.values().flatten() {
x.normalize();
}
}
NirKind::UnionLit(_, v, kts) => {
v.normalize();
- for x in kts.values().flat_map(|opt| opt) {
+ for x in kts.values().flatten() {
x.normalize();
}
}
@@ -503,7 +503,7 @@ impl std::fmt::Debug for Nir {
if let NirKind::Const(c) = kind {
return write!(fmt, "{:?}", c);
}
- let mut x = fmt.debug_struct(&format!("Nir@WHNF"));
+ let mut x = fmt.debug_struct("Nir");
x.field("kind", kind);
x.finish()
}
diff --git a/dhall/src/semantics/nze/normalize.rs b/dhall/src/semantics/nze/normalize.rs
index 27862ee..08e3e87 100644
--- a/dhall/src/semantics/nze/normalize.rs
+++ b/dhall/src/semantics/nze/normalize.rs
@@ -209,6 +209,7 @@ fn apply_binop<'a>(o: BinOp, x: &'a Nir, y: &'a Nir) -> Option<Ret<'a>> {
})
}
+#[allow(clippy::cognitive_complexity)]
pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
use LitKind::Bool;
use NirKind::{
@@ -286,17 +287,17 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
None => Ret::Expr(expr),
},
- ExprKind::Field(ref v, ref l) => match v.kind() {
- RecordLit(kvs) => match kvs.get(l) {
+ ExprKind::Field(ref v, ref field) => match v.kind() {
+ RecordLit(kvs) => match kvs.get(field) {
Some(r) => Ret::Nir(r.clone()),
None => Ret::Expr(expr),
},
UnionType(kts) => {
- Ret::NirKind(UnionConstructor(l.clone(), kts.clone()))
+ Ret::NirKind(UnionConstructor(field.clone(), kts.clone()))
}
PartialExpr(ExprKind::Projection(x, _)) => {
return normalize_one_layer(
- ExprKind::Field(x.clone(), l.clone()),
+ ExprKind::Field(x.clone(), field.clone()),
env,
)
}
@@ -305,31 +306,31 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
x,
y,
)) => match (x.kind(), y.kind()) {
- (_, RecordLit(kvs)) => match kvs.get(l) {
+ (_, RecordLit(kvs)) => match kvs.get(field) {
Some(r) => Ret::Nir(r.clone()),
None => {
return normalize_one_layer(
- ExprKind::Field(x.clone(), l.clone()),
+ ExprKind::Field(x.clone(), field.clone()),
env,
)
}
},
- (RecordLit(kvs), _) => match kvs.get(l) {
+ (RecordLit(kvs), _) => match kvs.get(field) {
Some(r) => Ret::Expr(ExprKind::Field(
Nir::from_kind(PartialExpr(ExprKind::BinOp(
BinOp::RightBiasedRecordMerge,
Nir::from_kind(RecordLit(
- Some((l.clone(), r.clone()))
+ Some((field.clone(), r.clone()))
.into_iter()
.collect(),
)),
y.clone(),
))),
- l.clone(),
+ field.clone(),
)),
None => {
return normalize_one_layer(
- ExprKind::Field(y.clone(), l.clone()),
+ ExprKind::Field(y.clone(), field.clone()),
env,
)
}
@@ -338,42 +339,42 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
},
PartialExpr(ExprKind::BinOp(BinOp::RecursiveRecordMerge, x, y)) => {
match (x.kind(), y.kind()) {
- (RecordLit(kvs), _) => match kvs.get(l) {
+ (RecordLit(kvs), _) => match kvs.get(field) {
Some(r) => Ret::Expr(ExprKind::Field(
Nir::from_kind(PartialExpr(ExprKind::BinOp(
BinOp::RecursiveRecordMerge,
Nir::from_kind(RecordLit(
- Some((l.clone(), r.clone()))
+ Some((field.clone(), r.clone()))
.into_iter()
.collect(),
)),
y.clone(),
))),
- l.clone(),
+ field.clone(),
)),
None => {
return normalize_one_layer(
- ExprKind::Field(y.clone(), l.clone()),
+ ExprKind::Field(y.clone(), field.clone()),
env,
)
}
},
- (_, RecordLit(kvs)) => match kvs.get(l) {
+ (_, RecordLit(kvs)) => match kvs.get(field) {
Some(r) => Ret::Expr(ExprKind::Field(
Nir::from_kind(PartialExpr(ExprKind::BinOp(
BinOp::RecursiveRecordMerge,
x.clone(),
Nir::from_kind(RecordLit(
- Some((l.clone(), r.clone()))
+ Some((field.clone(), r.clone()))
.into_iter()
.collect(),
)),
))),
- l.clone(),
+ field.clone(),
)),
None => {
return normalize_one_layer(
- ExprKind::Field(x.clone(), l.clone()),
+ ExprKind::Field(x.clone(), field.clone()),
env,
)
}
@@ -452,7 +453,7 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
}
RecordLit(kvs) => Ret::NirKind(NEListLit(
kvs.iter()
- .sorted_by_key(|(k, _)| k.clone())
+ .sorted_by_key(|(k, _)| *k)
.map(|(k, v)| {
let mut rec = HashMap::new();
rec.insert("mapKey".into(), Nir::from_text(k));
@@ -476,13 +477,13 @@ pub(crate) fn normalize_one_layer(expr: ExprKind<Nir>, env: &NzEnv) -> NirKind {
/// Normalize Hir into WHNF
pub(crate) fn normalize_hir_whnf(env: &NzEnv, hir: &Hir) -> NirKind {
match hir.kind() {
- HirKind::Var(var) => env.lookup_val(var),
+ HirKind::Var(var) => env.lookup_val(*var),
HirKind::Import(hir, _) => normalize_hir_whnf(env, hir),
HirKind::Expr(ExprKind::Lam(binder, annot, body)) => {
let annot = annot.eval(env);
NirKind::LamClosure {
binder: Binder::new(binder.clone()),
- annot: annot,
+ annot,
closure: Closure::new(env, body.clone()),
}
}