summaryrefslogtreecommitdiff
path: root/dhall/src/semantics
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
parent681dad33cf27b2be4f4b3cefd83998af1d7eefb2 (diff)
Run clippy
Diffstat (limited to 'dhall/src/semantics')
-rw-r--r--dhall/src/semantics/builtins.rs6
-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
-rw-r--r--dhall/src/semantics/resolve/env.rs2
-rw-r--r--dhall/src/semantics/resolve/hir.rs6
-rw-r--r--dhall/src/semantics/resolve/resolve.rs22
-rw-r--r--dhall/src/semantics/tck/env.rs12
-rw-r--r--dhall/src/semantics/tck/typecheck.rs2
9 files changed, 54 insertions, 53 deletions
diff --git a/dhall/src/semantics/builtins.rs b/dhall/src/semantics/builtins.rs
index 61de0c7..803630b 100644
--- a/dhall/src/semantics/builtins.rs
+++ b/dhall/src/semantics/builtins.rs
@@ -33,7 +33,7 @@ impl BuiltinClosure<Nir> {
pub fn apply(&self, a: Nir) -> NirKind {
use std::iter::once;
- let args = self.args.iter().cloned().chain(once(a.clone())).collect();
+ let args = self.args.iter().cloned().chain(once(a)).collect();
apply_builtin(self.b, args, self.env.clone())
}
/// This doesn't break the invariant because we already checked that the appropriate arguments
@@ -415,7 +415,7 @@ fn apply_builtin(b: Builtin, args: Vec<Nir>, env: NzEnv) -> NirKind {
(Builtin::ListBuild, [t, f]) => {
let list_t = Nir::from_builtin(Builtin::List).app(t.clone());
Ret::Nir(
- f.app(list_t.clone())
+ f.app(list_t)
.app(
make_closure(make_closure!(
λ(T : Type) ->
@@ -443,7 +443,7 @@ fn apply_builtin(b: Builtin, args: Vec<Nir>, env: NzEnv) -> NirKind {
let optional_t =
Nir::from_builtin(Builtin::Optional).app(t.clone());
Ret::Nir(
- f.app(optional_t.clone())
+ f.app(optional_t)
.app(
make_closure(make_closure!(
λ(T : Type) ->
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()),
}
}
diff --git a/dhall/src/semantics/resolve/env.rs b/dhall/src/semantics/resolve/env.rs
index 5a7f139..fe8c178 100644
--- a/dhall/src/semantics/resolve/env.rs
+++ b/dhall/src/semantics/resolve/env.rs
@@ -51,7 +51,7 @@ impl NameEnv {
.nth(*idx)?;
Some(AlphaVar::new(idx))
}
- pub fn label_var(&self, var: &AlphaVar) -> V {
+ pub fn label_var(&self, var: AlphaVar) -> V {
let name = &self.names[self.names.len() - 1 - var.idx()];
let idx = self
.names
diff --git a/dhall/src/semantics/resolve/hir.rs b/dhall/src/semantics/resolve/hir.rs
index 317708a..fa2989f 100644
--- a/dhall/src/semantics/resolve/hir.rs
+++ b/dhall/src/semantics/resolve/hir.rs
@@ -30,7 +30,7 @@ impl AlphaVar {
pub(crate) fn new(idx: usize) -> Self {
AlphaVar { idx }
}
- pub(crate) fn idx(&self) -> usize {
+ pub(crate) fn idx(self) -> usize {
self.idx
}
}
@@ -100,7 +100,7 @@ fn hir_to_expr(
) -> NormalizedExpr {
let kind = match hir.kind() {
HirKind::Var(v) if opts.alpha => ExprKind::Var(V("_".into(), v.idx())),
- HirKind::Var(v) => ExprKind::Var(env.label_var(v)),
+ HirKind::Var(v) => ExprKind::Var(env.label_var(*v)),
HirKind::Import(hir, _) => {
return hir_to_expr(hir, opts, &mut NameEnv::new())
}
@@ -110,7 +110,7 @@ fn hir_to_expr(
env.insert_mut(l);
}
let e = hir_to_expr(hir, opts, env);
- if let Some(_) = l {
+ if l.is_some() {
env.remove_mut();
}
e
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs
index d29271d..f3fda4b 100644
--- a/dhall/src/semantics/resolve/resolve.rs
+++ b/dhall/src/semantics/resolve/resolve.rs
@@ -46,13 +46,13 @@ impl ImportLocation {
) -> Result<ImportLocation, Error> {
Ok(match target {
ImportTarget::Local(prefix, path) => {
- self.chain_local(prefix, path)?
+ self.chain_local(*prefix, path)?
}
ImportTarget::Remote(remote) => {
if sanity_check {
if let ImportLocation::Remote(..) = self {
// TODO: allow if CORS check passes
- Err(ImportError::SanityCheck)?
+ return Err(ImportError::SanityCheck.into());
}
}
let mut url = Url::parse(&format!(
@@ -66,7 +66,7 @@ impl ImportLocation {
ImportTarget::Env(var_name) => {
if sanity_check {
if let ImportLocation::Remote(..) = self {
- Err(ImportError::SanityCheck)?
+ return Err(ImportError::SanityCheck.into());
}
}
ImportLocation::Env(var_name.clone())
@@ -77,7 +77,7 @@ impl ImportLocation {
fn chain_local(
&self,
- prefix: &FilePrefix,
+ prefix: FilePrefix,
path: &FilePath,
) -> Result<ImportLocation, Error> {
Ok(match self {
@@ -146,11 +146,11 @@ impl ImportLocation {
ImportLocation::Env(var_name) => {
let val = match env::var(var_name) {
Ok(val) => val,
- Err(_) => Err(ImportError::MissingEnvVar)?,
+ Err(_) => return Err(ImportError::MissingEnvVar.into()),
};
Parsed::parse_str(&val)?
}
- ImportLocation::Missing => Err(ImportError::Missing)?,
+ ImportLocation::Missing => return Err(ImportError::Missing.into()),
})
}
@@ -162,9 +162,9 @@ impl ImportLocation {
}
ImportLocation::Env(var_name) => match env::var(var_name) {
Ok(val) => val,
- Err(_) => Err(ImportError::MissingEnvVar)?,
+ Err(_) => return Err(ImportError::MissingEnvVar.into()),
},
- ImportLocation::Missing => Err(ImportError::Missing)?,
+ ImportLocation::Missing => return Err(ImportError::Missing.into()),
})
}
@@ -199,7 +199,7 @@ fn make_aslocation_uniontype() -> Expr {
let mut union = DupTreeMap::default();
union.insert("Local".into(), Some(text_type.clone()));
union.insert("Remote".into(), Some(text_type.clone()));
- union.insert("Environment".into(), Some(text_type.clone()));
+ union.insert("Environment".into(), Some(text_type));
union.insert("Missing".into(), None);
mkexpr(ExprKind::UnionType(union))
}
@@ -298,7 +298,7 @@ fn traverse_resolve_expr(
name_env.insert_mut(l);
}
let hir = traverse_resolve_expr(name_env, e, f)?;
- if let Some(_) = l {
+ if l.is_some() {
name_env.remove_mut();
}
Ok::<_, Error>(hir)
@@ -395,7 +395,7 @@ impl<SE: Copy> Canonicalize for ImportTarget<SE> {
authority: url.authority.clone(),
path: url.path.canonicalize(),
query: url.query.clone(),
- headers: url.headers.clone(),
+ headers: url.headers,
}),
ImportTarget::Env(name) => ImportTarget::Env(name.to_string()),
ImportTarget::Missing => ImportTarget::Missing,
diff --git a/dhall/src/semantics/tck/env.rs b/dhall/src/semantics/tck/env.rs
index 17b3cfe..6dd5076 100644
--- a/dhall/src/semantics/tck/env.rs
+++ b/dhall/src/semantics/tck/env.rs
@@ -21,18 +21,18 @@ impl VarEnv {
pub fn from_size(size: usize) -> Self {
VarEnv { size }
}
- pub fn size(&self) -> usize {
+ pub fn size(self) -> usize {
self.size
}
- pub fn insert(&self) -> Self {
+ pub fn insert(self) -> Self {
VarEnv {
size: self.size + 1,
}
}
- pub fn lookup(&self, var: &NzVar) -> AlphaVar {
+ pub fn lookup(self, var: NzVar) -> AlphaVar {
self.lookup_fallible(var).unwrap()
}
- pub fn lookup_fallible(&self, var: &NzVar) -> Option<AlphaVar> {
+ pub fn lookup_fallible(self, var: NzVar) -> Option<AlphaVar> {
let idx = self.size.checked_sub(var.idx() + 1)?;
Some(AlphaVar::new(idx))
}
@@ -67,8 +67,8 @@ impl TyEnv {
items: self.items.insert_value(e, ty),
}
}
- pub fn lookup(&self, var: &AlphaVar) -> Type {
- self.items.lookup_ty(&var)
+ pub fn lookup(&self, var: AlphaVar) -> Type {
+ self.items.lookup_ty(var)
}
}
diff --git a/dhall/src/semantics/tck/typecheck.rs b/dhall/src/semantics/tck/typecheck.rs
index 319bb9d..365df25 100644
--- a/dhall/src/semantics/tck/typecheck.rs
+++ b/dhall/src/semantics/tck/typecheck.rs
@@ -712,7 +712,7 @@ pub(crate) fn type_with<'hir>(
annot: Option<Type>,
) -> Result<Tir<'hir>, TypeError> {
let tir = match hir.kind() {
- HirKind::Var(var) => Tir::from_hir(hir, env.lookup(var)),
+ HirKind::Var(var) => Tir::from_hir(hir, env.lookup(*var)),
HirKind::Import(_, ty) => Tir::from_hir(hir, ty.clone()),
HirKind::Expr(ExprKind::Var(_)) => {
unreachable!("Hir should contain no unresolved variables")