Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
koba-e964 committed Dec 12, 2024
1 parent 3675f76 commit 9c0d660
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
pull_request:
branches: [ master ]
workflow_dispatch:
schedule:
- cron: '10 14 * * 6'
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: --deny warnings
Expand All @@ -17,6 +19,7 @@ jobs:
matrix:
toolchain:
- stable
- '1.66.1' # 2023-01-10, meant to be about 2 years ago
- beta
- nightly
steps:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn g(env: &HashMap<String, String>, 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 {
Expand Down
5 changes: 2 additions & 3 deletions src/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
Expand Down
4 changes: 3 additions & 1 deletion src/k_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
p: usize,
Expand Down Expand Up @@ -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<String>,
p: usize,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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(())
}
6 changes: 3 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,16 @@ named!(ident<CompleteByteSlice, String>, 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 {
is_ident_u8_slice(&x)
}

fn is_ident_u8_slice(x: &[u8]) -> bool {
let keywords = vec![
&b"let"[..],
let keywords = [
b"let",
&b"rec"[..],
&b"in"[..],
&b"true"[..],
Expand Down
6 changes: 3 additions & 3 deletions src/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ fn occur(r1: usize, ty: &Type) -> bool {
fn unify(
t1: &Type,
t2: &Type,
extenv: &mut HashMap<String, Type>,
_extenv: &mut HashMap<String, Type>,
tyenv: &mut HashMap<usize, Type>,
) -> 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 {
Expand Down Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion src/x86/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 4 additions & 6 deletions src/x86/reg_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ fn target_exp(src: &str, dest_t: &(String, Type), exp: &Exp) -> (bool, Vec<Strin
use self::Exp::*;
let (ref dest, ref t) = dest_t;
match exp {
Mov(ref x) if x == src && asm::is_reg(&dest) => {
Mov(ref x) if x == src && asm::is_reg(dest) => {
assert_ne!(t, &Type::Unit);
assert_ne!(t, &Type::Float);
(false, vec![dest.clone()])
Expand Down Expand Up @@ -378,7 +378,7 @@ fn target_exp(src: &str, dest_t: &(String, Type), exp: &Exp) -> (bool, Vec<Strin

fn target_args(src: &str, all: &[String], ys: &[String]) -> Vec<String> {
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());
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9c0d660

Please sign in to comment.