Skip to content

Commit

Permalink
print unions
Browse files Browse the repository at this point in the history
  • Loading branch information
Medowhill committed Jul 25, 2024
1 parent e55384d commit 0d707ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bin/urcrat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ enum Command {
dump: Option<PathBuf>,
},
Must {
#[arg(long)]
print_unions: bool,
#[arg(short, long)]
may: Option<PathBuf>,
#[arg(short, long)]
Expand Down Expand Up @@ -69,6 +71,7 @@ fn main() {
}
}
Command::Must {
print_unions,
may,
r#union,
output,
Expand All @@ -92,6 +95,7 @@ fn main() {
may_analysis::deserialize_solutions(&arr)
});
let conf = tag_analysis::Config {
print_unions,
solutions,
unions: r#union.into_iter().collect(),
transform,
Expand Down
14 changes: 14 additions & 0 deletions src/tag_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::*;

#[derive(Debug, Clone)]
pub struct Config {
pub print_unions: bool,
pub solutions: Option<may_analysis::Solutions>,
pub unions: HashSet<String>,
pub transform: bool,
Expand Down Expand Up @@ -578,6 +579,19 @@ pub fn analyze(tcx: TyCtxt<'_>, conf: &Config) -> Statistics {
stat.tagged_unions = tagged_unions.len();
stat.must_analysis = start.elapsed().as_millis() as usize;

if conf.print_unions {
println!("Tagged unions");
for u in tagged_unions.keys() {
println!("{}", tcx.def_path_str(*u));
}
println!("Others");
for u in &unions {
if !tagged_unions.contains_key(u) {
println!("{}", tcx.def_path_str(*u));
}
}
}

if tagged_unions.is_empty() {
if conf.verbose {
println!("No tagged union identified");
Expand Down

0 comments on commit 0d707ed

Please sign in to comment.