mirror of
https://github.com/Noratrieb/cargo-minimize.git
synced 2026-01-14 16:35:01 +01:00
just works
This commit is contained in:
parent
dcd163aeda
commit
436546eaf5
7 changed files with 23 additions and 14 deletions
|
|
@ -5,6 +5,7 @@ exclude = ["test-cases/*"]
|
||||||
name = "cargo-minimize"
|
name = "cargo-minimize"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
about = "A tool for minimizing rustc ICEs"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,12 @@ enum BuildMode {
|
||||||
|
|
||||||
impl Build {
|
impl Build {
|
||||||
pub fn new(options: &Options) -> Self {
|
pub fn new(options: &Options) -> Self {
|
||||||
let mode = if options.cargo {
|
let mode = if options.rustc {
|
||||||
BuildMode::Cargo
|
BuildMode::Rustc
|
||||||
} else if let Some(script) = &options.verify_error_path {
|
} else if let Some(script) = &options.verify_error_path {
|
||||||
BuildMode::Script(script.clone())
|
BuildMode::Script(script.clone())
|
||||||
} else {
|
} else {
|
||||||
BuildMode::Rustc
|
BuildMode::Cargo
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
inner: Rc::new(BuildInner {
|
inner: Rc::new(BuildInner {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ impl VisitMut for Visitor<'_> {
|
||||||
match block.stmts.as_slice() {
|
match block.stmts.as_slice() {
|
||||||
[syn::Stmt::Expr(syn::Expr::Loop(syn::ExprLoop {
|
[syn::Stmt::Expr(syn::Expr::Loop(syn::ExprLoop {
|
||||||
body: loop_body, ..
|
body: loop_body, ..
|
||||||
}))] if loop_body.stmts.is_empty() => {}
|
}))] if loop_body.stmts.is_empty() && self.checker.can_process(&self.current_path) => {}
|
||||||
_ => {
|
_ => {
|
||||||
*block = self.loop_expr.clone();
|
*block = self.loop_expr.clone();
|
||||||
self.process_state = ProcessState::Changed;
|
self.process_state = ProcessState::Changed;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// this code is pretty neat i guess but i dont have a use for it right now
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use cargo::{
|
use cargo::{
|
||||||
core::{
|
core::{
|
||||||
|
|
|
||||||
16
src/lib.rs
16
src/lib.rs
|
|
@ -1,5 +1,3 @@
|
||||||
#![allow(dead_code)]
|
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod build;
|
mod build;
|
||||||
|
|
@ -15,25 +13,31 @@ use processor::Minimizer;
|
||||||
use crate::{everybody_loops::EverybodyLoops, privatize::Privatize, processor::Processor};
|
use crate::{everybody_loops::EverybodyLoops, privatize::Privatize, processor::Processor};
|
||||||
|
|
||||||
#[derive(clap::Parser)]
|
#[derive(clap::Parser)]
|
||||||
|
#[command(version, about, name = "cargo", bin_name = "cargo")]
|
||||||
|
enum Cargo {
|
||||||
|
Minimize(Options),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(clap::Args, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
verify_error_path: Option<PathBuf>,
|
verify_error_path: Option<PathBuf>,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
cargo: bool,
|
rustc: bool,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
no_verify: bool,
|
no_verify: bool,
|
||||||
|
|
||||||
|
#[arg(default_value = "src")]
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn minimize() -> Result<()> {
|
pub fn minimize() -> Result<()> {
|
||||||
let options = Options::parse();
|
let Cargo::Minimize(options) = Cargo::parse();
|
||||||
|
|
||||||
let build = build::Build::new(&options);
|
let build = build::Build::new(&options);
|
||||||
|
|
||||||
let mut minimizer = Minimizer::new_glob_dir(&options.path, build);
|
let mut minimizer = Minimizer::new_glob_dir(&options.path, build);
|
||||||
|
|
||||||
println!("{minimizer:?}");
|
|
||||||
|
|
||||||
minimizer.delete_dead_code().context("deleting dead code")?;
|
minimizer.delete_dead_code().context("deleting dead code")?;
|
||||||
|
|
||||||
minimizer.run_passes([
|
minimizer.run_passes([
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@ impl Minimizer {
|
||||||
.map(|entry| SourceFile {
|
.map(|entry| SourceFile {
|
||||||
path: entry.into_path(),
|
path: entry.into_path(),
|
||||||
})
|
})
|
||||||
|
.inspect(|file| {
|
||||||
|
println!("- {}", file.path.display());
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Self { files, build }
|
Self { files, build }
|
||||||
|
|
@ -94,7 +97,8 @@ impl Minimizer {
|
||||||
let mut krate = syn::parse_file(change.before_content())
|
let mut krate = syn::parse_file(change.before_content())
|
||||||
.with_context(|| format!("parsing file {file_display}"))?;
|
.with_context(|| format!("parsing file {file_display}"))?;
|
||||||
|
|
||||||
let has_made_change = pass.process_file(&mut krate, file, &mut ProcessChecker {});
|
let has_made_change =
|
||||||
|
pass.process_file(&mut krate, file, &mut ProcessChecker {});
|
||||||
|
|
||||||
match has_made_change {
|
match has_made_change {
|
||||||
ProcessState::Changed | ProcessState::FileInvalidated => {
|
ProcessState::Changed | ProcessState::FileInvalidated => {
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,6 @@ impl Processor for DeleteUnusedFunctions {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Unused {
|
struct Unused {
|
||||||
name: String,
|
|
||||||
line: usize,
|
line: usize,
|
||||||
column: Range<usize>,
|
column: Range<usize>,
|
||||||
}
|
}
|
||||||
|
|
@ -184,7 +183,6 @@ impl FindUnusedFunction {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = diag.message.split("`").nth(1)?.to_owned();
|
|
||||||
let span = &diag.spans[0];
|
let span = &diag.spans[0];
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -197,7 +195,6 @@ impl FindUnusedFunction {
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Unused {
|
Some(Unused {
|
||||||
name,
|
|
||||||
line: span.line_start,
|
line: span.line_start,
|
||||||
column: (span.column_start - 1)..(span.column_end - 1),
|
column: (span.column_start - 1)..(span.column_end - 1),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue