diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f28da34..3799a83 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -5,6 +5,8 @@ on: pull_request: branches: [ master ] workflow_dispatch: + schedule: + - cron: '10 14 * * 6' env: CARGO_TERM_COLOR: always RUSTFLAGS: --deny warnings @@ -17,6 +19,7 @@ jobs: matrix: toolchain: - stable + - '1.66.1' # 2023-01-10, meant to be about 2 years ago - beta - nightly steps: @@ -25,7 +28,7 @@ jobs: run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - name: cargo version run: cargo --version - - name: install tools + - name: Install tools run: | cargo install cargo-expand cargo install cargo-bloat diff --git a/src/alpha.rs b/src/alpha.rs index a8c1f38..d96aa9b 100644 --- a/src/alpha.rs +++ b/src/alpha.rs @@ -17,7 +17,7 @@ pub fn g(env: &HashMap, e: KNormal, id_gen: &mut IdGen) -> KNorm }; let find_vec_mut = |vec: &mut [String]| { for v in vec.iter_mut() { - *v = find(std::mem::replace(v, String::new())); + *v = find(std::mem::take(v)); } }; match e { diff --git a/src/assoc.rs b/src/assoc.rs index 93a6ddd..b161bc4 100644 --- a/src/assoc.rs +++ b/src/assoc.rs @@ -16,10 +16,9 @@ fn insert(e: KNormal, xt: (String, Type), e2: KNormal) -> KNormal { } } -/// For example, let x = let y = 1 in y + 1 in x + 3 +/// For example, `let x = let y = 1 in y + 1 in x + 3` /// becomes -/// let y = 1 in let x = y + 1 in x + 3 - +/// `let y = 1 in let x = y + 1 in x + 3`. pub fn f(e: KNormal) -> KNormal { use self::KNormal::*; macro_rules! invoke { diff --git a/src/inline.rs b/src/inline.rs index 97aa239..458a308 100644 --- a/src/inline.rs +++ b/src/inline.rs @@ -60,7 +60,7 @@ fn g(env: &TypeEnv, e: KNormal, id_gen: &mut IdGen, inline_threshold: usize) -> KFundef { name: (x, t), args: yts, - body: Box::new(g(&env, *e1, id_gen, inline_threshold)), + body: Box::new(g(env, *e1, id_gen, inline_threshold)), }, // avoid further inlining in the body of recursive functions Box::new(g(&cp_env, *e2, id_gen, inline_threshold)), ) diff --git a/src/k_normal.rs b/src/k_normal.rs index 231e19d..be658b9 100644 --- a/src/k_normal.rs +++ b/src/k_normal.rs @@ -379,11 +379,12 @@ fn g( extfunname = Some(f.to_string()); } } - if extfunname == None { + if extfunname.is_none() { let g_e1 = invoke!(*e1); match g_e1.1.clone() { Type::Fun(_, t) => { // TODO very rough way to simulate an internal recursive function in the original code + #[allow(clippy::too_many_arguments)] fn bind( mut xs: Vec, p: usize, @@ -429,6 +430,7 @@ fn g( match extenv.get(&extfunname).unwrap().clone() { Type::Fun(_, t) => { // TODO very rough way to simulate an internal recursive function in the original code + #[allow(clippy::too_many_arguments)] fn bind( mut xs: Vec, p: usize, diff --git a/src/main.rs b/src/main.rs index b5d814e..7507dab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,7 @@ fn main() { } else { output_pathbuf = Path::new(&args[2]).to_path_buf(); } - let program = read_from_file(&path).unwrap(); + let program = read_from_file(path).unwrap(); run(&program, &output_pathbuf).unwrap(); } @@ -133,6 +133,6 @@ fn run(program: &[u8], output_path: &Path) -> Result<(), std::io::Error> { // Write to file let mut outfile = BufWriter::new(File::create(output_path)?); - write!(outfile, "{}\n", reg_alloc)?; + writeln!(outfile, "{}", reg_alloc)?; Ok(()) } diff --git a/src/parser.rs b/src/parser.rs index 3cb654c..3879517 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -342,7 +342,7 @@ named!(ident, ws!(do_parse!( ))); fn is_not_ident_u8(x: u8) -> bool { - !((b'0' <= x && x <= b'9') || (b'A' <= x && x <= b'Z') || (b'a' <= x && x <= b'z') || x == b'_') + !(x.is_ascii_alphanumeric() || x == b'_') } fn is_ident(x: CompleteByteSlice) -> bool { @@ -350,8 +350,8 @@ fn is_ident(x: CompleteByteSlice) -> bool { } fn is_ident_u8_slice(x: &[u8]) -> bool { - let keywords = vec![ - &b"let"[..], + let keywords = [ + b"let", &b"rec"[..], &b"in"[..], &b"true"[..], diff --git a/src/typing.rs b/src/typing.rs index 02f9a25..0c4c67c 100644 --- a/src/typing.rs +++ b/src/typing.rs @@ -145,13 +145,13 @@ fn occur(r1: usize, ty: &Type) -> bool { fn unify( t1: &Type, t2: &Type, - extenv: &mut HashMap, + _extenv: &mut HashMap, tyenv: &mut HashMap, ) -> Result<(), TypingError> { println!("unify {:?} {:?}", t1, t2); macro_rules! invoke { ($t1:expr, $t2:expr) => { - unify($t1, $t2, extenv, tyenv) + unify($t1, $t2, _extenv, tyenv) }; } macro_rules! unify_seq { @@ -377,7 +377,7 @@ pub fn f( } *extenv = extenv .iter() - .map(|(k, x)| (k.clone(), deref_typ(&x, &tyenv))) + .map(|(k, x)| (k.clone(), deref_typ(x, &tyenv))) .collect(); Ok(deref_term(e, &tyenv)) } diff --git a/src/x86/asm.rs b/src/x86/asm.rs index 4629f71..b717f13 100644 --- a/src/x86/asm.rs +++ b/src/x86/asm.rs @@ -274,7 +274,7 @@ pub const REG_SP: &str = "%ebp"; pub const REG_HP: &str = "min_caml_hp"; pub fn is_reg(x: &str) -> bool { - let c = x.chars().nth(0); + let c = x.chars().next(); c == Some('%') || x == REG_HP } diff --git a/src/x86/reg_alloc.rs b/src/x86/reg_alloc.rs index 302d3da..5e4748c 100644 --- a/src/x86/reg_alloc.rs +++ b/src/x86/reg_alloc.rs @@ -344,7 +344,7 @@ fn target_exp(src: &str, dest_t: &(String, Type), exp: &Exp) -> (bool, Vec { + Mov(ref x) if x == src && asm::is_reg(dest) => { assert_ne!(t, &Type::Unit); assert_ne!(t, &Type::Float); (false, vec![dest.clone()]) @@ -378,7 +378,7 @@ fn target_exp(src: &str, dest_t: &(String, Type), exp: &Exp) -> (bool, Vec Vec { let mut ans = vec![]; - assert!(ys.len() <= all.len() - 1); + assert!(ys.len() < all.len()); for i in 0..ys.len() { if ys[i] == src { ans.push(all[i].clone()); @@ -491,10 +491,8 @@ fn alloc(cont: Asm, regenv: &RegEnv, x: String, t: Type, preference: &[String]) for y in &free { if asm::is_reg(y) { live.insert(y.to_string()); - } else { - if let Some(result) = regenv.get(y) { - live.insert(result.to_string()); - } + } else if let Some(result) = regenv.get(y) { + live.insert(result.to_string()); } } // Find a register that is not alive