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

Stack overflow when displaying the derivation tree #293

Open
x-hgg-x opened this issue Dec 11, 2024 · 1 comment
Open

Stack overflow when displaying the derivation tree #293

x-hgg-x opened this issue Dec 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@x-hgg-x
Copy link
Contributor

x-hgg-x commented Dec 11, 2024

When importing in pubgrub the cargo test from https://github.com/rust-lang/cargo/blob/bf79c8b154fa6b3e4d781c26935429948cbd9b2b/crates/resolver-tests/tests/resolve.rs#L529, I get a stack overflow in the test when displaying the derivation tree:

#[test]
fn resolving_with_constrained_cousins_backtrack() {
    const DEPTH: u32 = 100;
    const BRANCHING_FACTOR: u32 = 50;

    let mut dependency_provider =
        OfflineDependencyProvider::<String, Ranges<SemanticVersion>>::new();

    let root_deps = [
        ("backtrack_trap_v0_0".into(), Ranges::full()),
        ("cloaking".into(), Ranges::full()),
    ];
    dependency_provider.add_dependencies("root".into(), (0, 0, 0), root_deps);

    dependency_provider.add_dependencies(
        "cloaking".into(),
        (0, 0, 0),
        [("constrained".into(), Ranges::between((1, 0, 0), (1, 1, 0)))],
    );

    for v in 1..BRANCHING_FACTOR + 10 {
        dependency_provider.add_dependencies("constrained".into(), (1, 0, v), []);
    }
    dependency_provider.add_dependencies("constrained".into(), (1, 1, 0), []);

    for n in 0..DEPTH {
        for v in 1..BRANCHING_FACTOR {
            let v = (1, 0, v);
            dependency_provider.add_dependencies(
                format!("backtrack_trap_v0_{n}"),
                v,
                [(format!("backtrack_trap_v1_{n}"), Ranges::singleton(v))],
            );
            dependency_provider.add_dependencies(
                format!("backtrack_trap_v1_{n}"),
                v,
                [(format!("backtrack_trap_v2_{n}"), Ranges::singleton(v))],
            );
            dependency_provider.add_dependencies(
                format!("backtrack_trap_v2_{n}"),
                v,
                [(format!("backtrack_trap_v0_{}", n + 1), Ranges::full())],
            );
        }
    }
    for v in 1..BRANCHING_FACTOR {
        let v = (1, 0, v);
        dependency_provider.add_dependencies(
            format!("backtrack_trap_v0_{DEPTH}"),
            v,
            [("constrained".into(), Ranges::between((1, 1, 0), (2, 0, 0)))],
        );
    }

    let res = pubgrub::resolve(&dependency_provider, "root".into(), (0, 0, 0));

    if let Err(PubGrubError::NoSolution(error)) = res {
        // Stack overflow here
        let _out = format!("{error:?}");
        let _out = DefaultStringReporter::report(&error).to_string();
    };
}
@konstin konstin added the bug Something isn't working label Dec 11, 2024
@x-hgg-x x-hgg-x changed the title Stack overflow when displaying derivation tree Stack overflow when displaying the derivation tree Dec 11, 2024
@x-hgg-x
Copy link
Contributor Author

x-hgg-x commented Dec 11, 2024

A variation of the test also causes Pubgrub to consume 20+ GB of RAM when constructing the derivation tree (see https://github.com/x-hgg-x/pubgrub-bench/blob/a8591cd68f77a8396023b7abec2995d8fec1fb98/tests/tests/mod.rs#L411).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants