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

regression: hang with -Zsave-analysis #101505

Closed
matthiaskrgr opened this issue Sep 6, 2022 · 4 comments · Fixed by #101688
Closed

regression: hang with -Zsave-analysis #101505

matthiaskrgr opened this issue Sep 6, 2022 · 4 comments · Fixed by #101688
Assignees
Labels
A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Sep 6, 2022

Code

I tried this code:

fn next_letter_position(&self, x_index: f32, y_index: f32, width: f32) -> (f32, f32) {
    let vwidth = &self.viewport.x / 2.0;

    match x_index * width {
        0.0 ... vwidth => {
            (x_index + 1.0, y_index)
        },
        _ => (0.0, y_index - 1.0)
    }
}

with rustc rustc 1.65.0-nightly (c07a8b4e0 2022-08-26) this runs in a couple ms:
rustc ./a.rs --crate-type=lib -Zsave-analysis -Ztime=yes -Ztime-passes=yes

with rustc rustc 1.65.0-nightly (3c7278846 2022-09-06) this seems to hang somewhere in save-analysis

  26,77%  librustc_driver-0f3b2583c1b011ce.so  [.] <rustc_middle::hir::map::Map>::get
  24,00%  librustc_driver-0f3b2583c1b011ce.so  [.] <rustc_middle::hir::map::Map>::get_parent_node
   5,76%  librustc_driver-0f3b2583c1b011ce.so  [.] <rustc_save_analysis::SaveContext>::get_path_res

( I killed the process after waiting for 5 minutes 🙃 )

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Sep 6, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 6, 2022
@matthiaskrgr
Copy link
Member Author

reduced:

fn a(self) {}

RIP -Zsave-analysis

@matthiaskrgr matthiaskrgr added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. labels Sep 6, 2022
@matthiaskrgr
Copy link
Member Author

I think this is caused by #101228 cc @nnethercote

@nnethercote nnethercote self-assigned this Sep 7, 2022
@nnethercote
Copy link
Contributor

nnethercote commented Sep 7, 2022

Clearly a well tested feature 😛 I'll take a look.

@nnethercote
Copy link
Contributor

nnethercote commented Sep 7, 2022

The old code looked like this:

Node::PathSegment(seg) => match seg.res {
    Some(res) if res != Res::Err => res,
    _ => { 
        let parent_node = self.tcx.hir().get_parent_node(hir_id);
        self.get_path_res(parent_node)
    }
},  

The new code looks like this:

Node::PathSegment(seg) => {
    if seg.res != Res::Err {
        seg.res
    } else {
        let parent_node = self.tcx.hir().get_parent_node(hir_id);
        self.get_path_res(parent_node)
    }   
}   

because seg.res is no longer optional.

The infinite recursion happens because the get_parent_node call returns a parent_node that is the same as the hir_id. When I printed that ID out it looks like this:

HirId { owner: DefId(0:4 ~ s[5740]::a), local_id: 5 } 

An easy fix is to check if parent_node is the same as hir_id and return Res:Err if so. But I don't know if that's just papering over a deeper problem.

@petrochenkov: Is it an underlying bug that get_parent_node can return the same node it is given?

nnethercote added a commit to nnethercote/rust that referenced this issue Sep 7, 2022
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 8, 2022
@bors bors closed this as completed in fa521a4 Sep 12, 2022
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants