From b38faccaacee8410e4e24a70b48cce8a375042cb Mon Sep 17 00:00:00 2001 From: mehbark Date: Mon, 12 Jun 2023 11:41:12 -0400 Subject: [PATCH] told you so --- Cargo.lock | 16 ---------------- Cargo.toml | 1 - src/main.rs | 31 ++++++++----------------------- 3 files changed, 8 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0e113c8..66d2970 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,20 +36,4 @@ dependencies = [ "intaglio", "itertools", "once_cell", - "tinyvec", ] - -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" diff --git a/Cargo.toml b/Cargo.toml index 2353505..b9e379d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,3 @@ edition = "2021" intaglio = "1.8.0" itertools = "0.10.5" once_cell = "1.18.0" -tinyvec = { version = "1.6.0", features = ["alloc"] } diff --git a/src/main.rs b/src/main.rs index b26c80f..04c35b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,6 @@ use std::{ use intaglio::{Symbol, SymbolTable}; use itertools::Itertools; use once_cell::sync::Lazy; -use tinyvec::TinyVec; static TABLE: Lazy> = Lazy::new(|| Mutex::new(SymbolTable::new())); static FORALL: Lazy = Lazy::new(|| TABLE.lock().unwrap().intern("forall").unwrap()); @@ -41,23 +40,15 @@ fn do_it() -> Option { )) } -type SexpVec = TinyVec<[Sexp; 8]>; - #[derive(Debug, Clone, PartialEq, Eq, Hash)] enum Sexp { Atom(Symbol), - List(Box), -} - -impl Default for Sexp { - fn default() -> Self { - Self::nil() - } + List(Vec), } impl Sexp { fn nil() -> Self { - Self::List(Box::new(TinyVec::new())) + Self::List(Vec::new()) } /// Returns `true` if the sexp is [`Atom`]. @@ -121,7 +112,7 @@ impl Sexp { out } Sexp::List(xs) => { - let mut out = HashSet::from_iter(xs.iter()); + let mut out = HashSet::from_iter(xs); out.extend(xs.iter().flat_map(Sexp::concretion_targets)); out } @@ -227,7 +218,7 @@ fn at_depth(depth: usize, sexp: &mut Sexp) -> &mut Sexp { } } -fn parse<'src>(tokens: &'src [Token<'src>]) -> Option { +fn parse<'src>(tokens: &'src [Token<'src>]) -> Option> { let mut out = Sexp::nil(); let mut depth = 0; @@ -251,7 +242,7 @@ fn parse<'src>(tokens: &'src [Token<'src>]) -> Option { } match out { - Sexp::List(xs) => Some(*xs), + Sexp::List(xs) => Some(xs), Sexp::Atom(_) => unreachable!(), } } @@ -415,7 +406,7 @@ fn matches(vars: Option<&Vec>, lhs: &Sexp, expr: &Sexp) -> bool { (Sexp::Atom(a), Sexp::Atom(b)) => a == b || is_var(a), (Sexp::Atom(a), Sexp::List(_)) => is_var(a), (Sexp::List(a), Sexp::List(b)) => { - a.len() == b.len() && a.iter().zip(b.iter()).all(|(a, b)| matches(vars, a, b)) + a.len() == b.len() && a.iter().zip(b).all(|(a, b)| matches(vars, a, b)) } _ => false, } @@ -434,10 +425,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp { } else { match sexp { Sexp::Atom(_) => sexp.clone(), - Sexp::List(xs) => { - let inner: SexpVec = xs.iter().map(|s| s.rw(rule)).collect(); - Sexp::List(Box::new(inner)) - } + Sexp::List(xs) => Sexp::List(xs.iter().map(|s| s.rw(rule)).collect()), } } } @@ -447,10 +435,7 @@ fn rw(rule: &Rule, sexp: &Sexp) -> Sexp { } else { match sexp { Sexp::Atom(_) => sexp.clone(), - Sexp::List(xs) => { - let inner: SexpVec = xs.iter().map(|s| s.rw(rule)).collect(); - Sexp::List(Box::new(inner)) - } + Sexp::List(xs) => Sexp::List(xs.iter().map(|s| s.rw(rule)).collect()), } } }