Skip to content

Commit

Permalink
precise error measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
Medowhill committed Jul 12, 2024
1 parent 438ac33 commit afb176d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/bin/simcrat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ async fn main() {
}

if args.show_error_num {
println!("{}", translator.errors());
let (v, f) = translator.errors();
let (vf, vwo, vo, ff, fwo, fo) = translator.item_errors();
println!("{} {} {} {} {} {} {} {}", v, f, vf, vwo, vo, ff, fwo, fo);
}

if args.show_per_stage {
Expand Down
57 changes: 50 additions & 7 deletions src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ struct TranslationResult {
stage: usize,
errors: usize,
too_long: bool,
failed: bool,
}

impl TranslationResult {
Expand Down Expand Up @@ -465,15 +466,47 @@ impl<'ast> Translator<'ast> {
.collect()
}

pub fn errors(&self) -> usize {
pub fn errors(&self) -> (usize, usize) {
let inner = self.inner.read().unwrap();
inner
.translated_types
let v = inner
.translated_variables
.values()
.chain(inner.translated_variables.values())
.chain(inner.translated_functions.values())
.map(|res| res.errors)
.sum()
.sum();
let f = inner
.translated_functions
.values()
.map(|res| res.errors)
.sum();
(v, f)
}

pub fn item_errors(&self) -> (usize, usize, usize, usize, usize, usize) {
let inner = self.inner.read().unwrap();
fn aux<I: Iterator<Item = (bool, usize)>>(i: I) -> (usize, usize, usize) {
let mut failed = 0;
let mut wo_error = 0;
let mut w_error = 0;
for (f, e) in i {
if f {
failed += 1;
} else if e == 0 {
wo_error += 1;
} else {
w_error += 1;
}
}
(failed, wo_error, w_error)
}
let (vf, vwo, vw) = aux(inner
.translated_variables
.values()
.map(|res| (res.failed, res.errors)));
let (ff, fwo, fw) = aux(inner
.translated_functions
.values()
.map(|res| (res.failed, res.errors)));
(vf, vwo, vw, ff, fwo, fw)
}

pub fn per_stage(&self) -> String {
Expand Down Expand Up @@ -1020,6 +1053,7 @@ impl<'ast> Translator<'ast> {
stage: compiler::MAX_STAGE,
errors: 0,
too_long: false,
failed: false,
}
.code();
if ctxt.code == fix {
Expand Down Expand Up @@ -1437,6 +1471,7 @@ impl<'ast> Translator<'ast> {
stage: compiler::MAX_STAGE,
errors: 0,
too_long: false,
failed: false,
};
self.fix_types_after_translation(new_names, translated, prefixes)
.await
Expand Down Expand Up @@ -1552,7 +1587,7 @@ impl<'ast> Translator<'ast> {
if !self.config.quiet {
println!("Variable not translated: {}", new_name);
}
format!("const {}: usize = 0;", new_name)
format!("const {}:usize=0;", new_name)
};

let translated = self
Expand Down Expand Up @@ -1607,6 +1642,7 @@ impl<'ast> Translator<'ast> {
stage: compiler::MAX_STAGE,
errors: 0,
too_long,
failed: false,
};
tracing::info!(
"translate_variable translated ({})\n{}",
Expand Down Expand Up @@ -1658,6 +1694,9 @@ impl<'ast> Translator<'ast> {
translated.stage = compiler::MAX_STAGE;
translated.errors = 0;
}
if translated.code().ends_with(":usize=0;") {
translated.failed = true;
}

tracing::info!(
"translate_variable result ({})\n{}",
Expand Down Expand Up @@ -1702,6 +1741,7 @@ impl<'ast> Translator<'ast> {
stage: compiler::MAX_STAGE,
errors: 0,
too_long: false,
failed: false,
}
};
(var, translated)
Expand Down Expand Up @@ -1785,6 +1825,7 @@ impl<'ast> Translator<'ast> {
stage: compiler::MAX_STAGE,
errors: 0,
too_long: false,
failed: false,
}
}

Expand Down Expand Up @@ -1946,6 +1987,7 @@ impl<'ast> Translator<'ast> {
stage: compiler::MAX_STAGE,
errors: 0,
too_long: false,
failed: true,
}
});
translated.too_long = too_long;
Expand Down Expand Up @@ -2107,6 +2149,7 @@ impl<'ast> Translator<'ast> {
stage: compiler::MAX_STAGE,
errors: 0,
too_long: false,
failed: false,
};
tracing::info!(
"try_signature translated ({})\n{}\n{}",
Expand Down

0 comments on commit afb176d

Please sign in to comment.