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

optimize the way that loans are killed in borrowck dataflow #50934

Closed
nikomatsakis opened this issue May 21, 2018 · 1 comment
Closed

optimize the way that loans are killed in borrowck dataflow #50934

nikomatsakis opened this issue May 21, 2018 · 1 comment
Labels
NLL-performant Working towards the "performance is good" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

Profiling reveals that kill_loans_out_of_scope_at_location is a pretty major hot spot. It is pretty naive right now: for each point, it iterates over all borrows to check if that point is included. In fact, it seems to do that twice (@davidtwco opened #50891 to deal with that).

I am not sure the best way to handle this computation. One option that is not theoretically better but seems likely to be much better in practice would be:

  • Iterate over each borrow expression B, with associated region 'a:
    • For each borrow B, do a depth-first search starting at the location of the borrow
    • When this DFS reaches a point P that is not in 'a, end the walk, but add B to kill set for P

This is still O(n^2), but I think it seems likely to be much better in practice, and I can't think of a better way.

@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-compiler-nll NLL-performant Working towards the "performance is good" goal labels May 21, 2018
@nikomatsakis
Copy link
Contributor Author

What we would want to do is to build up a side-index somewhere of type

Location -> Set<BorrowIndex>

with this being the set of borrows that go out of scope on entry to the location. We'd probably store this in the Borrows structure:

pub struct Borrows<'a, 'gcx: 'tcx, 'tcx: 'a> {

We'd presumably compute it in Borrows::new:

crate fn new(
tcx: TyCtxt<'a, 'gcx, 'tcx>,
mir: &'a Mir<'tcx>,
nonlexical_regioncx: Rc<RegionInferenceContext<'tcx>>,
def_id: DefId,
body_id: Option<hir::BodyId>,
borrow_set: &Rc<BorrowSet<'tcx>>
) -> Self {

bors added a commit that referenced this issue May 30, 2018
Optimize the way that loans are killed in borrowck dataflow

Fixes #50934.
r? @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NLL-performant Working towards the "performance is good" goal T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant