mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.01k stars 117 forks source link

Remaining miri failiures after #2439 #2453

Open Skgland opened 1 month ago

Skgland commented 1 month ago

In #2439 I eliminate most miri failures though various horrendously slow tests remain.

Most of these test spend a lot of time in Machine::new

With the following simplified test

#[test]
pub fn create_test_machine() {
    let machine = black_box(Machine::with_test_streams());
    drop(machine)
}

we get the following flamegraph using cargo-flamegraph with cargo flamegraph test -- create_test_machine

flamegraph.svg (Viewing the svg works better when downloaded as otherwise the inline js is blocked)

When executed with miri MIRIFLAGS="-Zmiri-report-progress" cargo miri test -- create_test_machine the test fails after executing for over 459_000_000 basic blocks (38.5 minutes). The miri execution failed as Machine::new calls wam.load_special_forms(); which ends up calling Path::is_file in machine::compiler::Loader<'a, LS>::listing_src_file_name.

This effects 24 of the 29 tests ignored for miri.

The other 5 test pass with enough patients, though for heap_stackless_iter_tests I reduced the iteration count from 200_000 to 20 when running miri

- for _ in 0..200000 {
+ let iter_count = if cfg!(miri) { 20 } else { 200_000 };
+ for _ in 0..iter_count {
bakaq commented 1 month ago

Is there any way of making a test in machine::compiler or other appropriate place that is smaller, self contained (in the sense that it doesn't need to have the whole Machine to run it), and still reproduces this? That would make this particular case easier to check.

Skgland commented 1 month ago

Replacing

if !load_context.path.is_file() {
   return None;
}

in machine::compiler::Loader<'a, LS>::listing_src_file_name with

if cfg!(not(miri)) && !load_context.path.is_file() {
   return None;
}

and running the simplified create_test_machine test over night passes miri

test helper::create_test_machine ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 13 filtered out; finished in 18776.98s

after about 5.2 hours, with the last executed basic block count at 3_755_000_000.

So creating the machine in miri is extremely slow, and that is before the actual test runs.