salsa-rs / salsa

A generic framework for on-demand, incrementalized computation. Inspired by adapton, glimmer, and rustc's query system.
https://salsa-rs.netlify.app/
Apache License 2.0
2.13k stars 152 forks source link

Internal error with `discard_everything` #217

Open Shadlock0133 opened 4 years ago

Shadlock0133 commented 4 years ago

Version: 0.14.1

Error:

thread 'main' panicked at 'internal error: entered unreachable code', <::std::macros::panic macros>:2:4

Code:

#[salsa::query_group(CalcStorage)]
trait Calc: salsa::Database {
    fn fib(&self, x: u32) -> u32;
}

fn fib(db: &impl Calc, x: u32) -> u32 {
    eprint!("> {} ", x);
    if x < 2 { x } else { db.fib(x - 1) + db.fib(x - 2) }
}

#[salsa::database(CalcStorage)]
#[derive(Default)]
struct DatabaseStruct {
    runtime: salsa::Runtime<Self>,
}

impl salsa::Database for DatabaseStruct {
    fn salsa_runtime(&self) -> &salsa::Runtime<Self> {
        &self.runtime
    }

    fn salsa_runtime_mut(&mut self) -> &mut salsa::Runtime<Self> {
        &mut self.runtime
    }
}

fn main() {
    let db = DatabaseStruct::default();
    for i in 0..10 {
        if i == 7 {
            use salsa::Database;
            let strategy = salsa::SweepStrategy::default().discard_everything();
            db.salsa_runtime().sweep_all(&db, strategy);
        }
        let f = db.fib(i);
        eprintln!();
        println!("Fib: {}", f);
    }
}

Backtrace points somewhere in salsa::derived::slot::Slot<DB,Q,MP>::sweep. Can't currently run with debug, because for some reason while linking, clang exhausts memory.

mheiber commented 2 years ago

I reproduced this with 0.14.1. Is there still an issue with latest Salsa? The word "sweep" doesn't seem to appear in the source for 0.17.0-pre.2: no SweepStrategy or sweep_all.

mheiber commented 2 years ago

Looks like the sweep APIs were removed when garbage collection was removed: https://github.com/salsa-rs/salsa/blob/11c55b804d2f92606e753260/book/src/rfcs/RFC0008-Remove-Garbage-Collection.md