Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fake moxie::cache disables gc within passed function #238

Closed
zetanumbers opened this issue Jan 10, 2021 · 1 comment · Fixed by #266
Closed

Fake moxie::cache disables gc within passed function #238

zetanumbers opened this issue Jan 10, 2021 · 1 comment · Fixed by #266
Labels
core Related to the core `moxie` crate

Comments

@zetanumbers
Copy link
Contributor

Code to reproduce varying behavior (uncomment lines):

use moxie::{cache, once, runtime::RunLoop, Key};

fn main() {
    // let mut i = 0;
    let root = move || {
        // i += 1;
        // cache(&i, |_| {
        let (commit, key) = moxie::state(|| false);
        if *commit {
            once(|| print!("bonk"));
        }
        println!("");
        key
        // })
    };
    let mut rt = RunLoop::new(root);
    let mut i = 0;
    let mut count = move || {
        print!("{}: ", i);
        i += 1;
    };
    count();
    let key = rt.run_once();

    let mut conditional_run = move |c| {
        count();
        key.set(c);
        rt.run_once();
    };

    conditional_run(false);
    conditional_run(true);
    conditional_run(true);
    conditional_run(false);
    conditional_run(false);
    conditional_run(true);
}

This code produces:

0: 
1:
2: bonk
3: 
4:
5:
6: bonk

However if you uncomment every line of code, i.e. wrap root's body with moxie::cache, which would be recached on every run bc of argument counter i, you'll get:

0: 
1: 
2: bonk
3:
4:
5:
6:
@anp anp added core Related to the core `moxie` crate needs-investigation labels Feb 2, 2021
@anp
Copy link
Owner

anp commented Apr 25, 2021

I've reproduced this and I see the problem -- the DepNode for the once() call is unconditionally inheriting the liveness from the cache() node upon which its depended, but this is obviously incorrect in cases where the cache() call executes the closure on the same revision that once()'s DepNode hasn't been called.

I think the solution is to store when a node was last actively traversed, and to not inherit liveness until it's been "dormant" for at least one revision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to the core `moxie` crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants