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

On demandify region mapping #41662

Merged
merged 11 commits into from
May 2, 2017

Conversation

nikomatsakis
Copy link
Contributor

This is an adaptation of @cramertj's PR. I am sort of tempted to keep simplifying it, but also tempted to land it so and we can refactor more in follow-up PRs. As is, it does the following things:

  • makes the region-maps an on-demand query, per function tcx.region_maps(def_id)
  • interns code extents instead of of having them be integers
  • remove the "root region extent" and (to some extent) item extents; instead we use Option<CodeExtent<'tcx>> in a few places (no space inefficiency since CodeExtent<'tcx> is now a pointer).

I'm not entirely happy with the way I have it setup though. Here are some of the changes I was considering (I'm not sure if they would work out well):

  1. Removing item_extents entirely -- they are rarely used now, because most of the relevant places now accept an Option<Region<'tcx>> or an Option<CodeExtent<'tcx>>, but I think still used in a few places.
  2. Merging RegionMaps into the typeck tables, instead of having it be its own query.
  3. Change CodeExtent<'tcx> to store the parent pointer. This would mean that fewer places in the code actually need a RegionMaps anyhow, since most of them just want to be able to walk "up the tree". On the other hand, you wouldn't be able to intern a CodeExtent<'tcx> for some random node-id, you'd need to look it up in the table (since there'd be more information).

Most of this code is semi-temporary -- I expect it to largely go away as we move to NLL -- so I'm also not that concerned with making it perfect.

r? @eddyb

cramertj and others added 6 commits April 30, 2017 17:02
Instead, thread around `Option<CodeExtent>` where applicable.
Make a `CodeExtent<'tcx>` be something allocated in an arena
instead of an index into the `RegionMaps`.
Instead of requesting the region maps for the entire crate, request for
a given item etc. Several bits of code were modified to take
`&RegionMaps` as input (e.g., the `resolve_regions_and_report_errors()`
function). I am not totally happy with this setup -- I *think* I'd
rather have the region maps be part of typeck tables -- but at least the
`RegionMaps` works in a "parallel" way to `FreeRegionMap`, so it's not
too bad. Given that I expect a lot of this code to go away with NLL, I
didn't want to invest *too* much energy tweaking it.
@@ -572,6 +572,18 @@ impl<'hir> Map<'hir> {
}
}

/// Check if the node is a non-closure function item
pub fn is_fn(&self, id: NodeId) -> bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this is_fn_or_method.

_ => {
let parent_id = tcx.hir.get_parent(fn_node_id);
let parent_def_id = tcx.hir.local_def_id(parent_id);
return tcx.region_maps(parent_def_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a way to get the surrounding fn DefId for a closure, I think that should be used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did not because I specifically wanted this to work for things that are not closures. However, in retrospect, I am not sure if that was right. That is, for things like the E in [T; E], perhaps they do want separate region-maps (as we've been saying on the other PR).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, only [x; n] may share an environment with the outer item and that's not supported today.

Copy link
Member

@eddyb eddyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me modulo nits

@carols10cents carols10cents added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 1, 2017
@eddyb
Copy link
Member

eddyb commented May 2, 2017

@bors r+

@bors
Copy link
Contributor

bors commented May 2, 2017

📌 Commit c008f05 has been approved by eddyb

frewsxcv added a commit to frewsxcv/rust that referenced this pull request May 2, 2017
…pping, r=eddyb

On demandify region mapping

This is an adaptation of @cramertj's PR. I am sort of tempted to keep simplifying it, but also tempted to land it so and we can refactor more in follow-up PRs. As is, it does the following things:

- makes the region-maps an on-demand query, per function `tcx.region_maps(def_id)`
- interns code extents instead of of having them be integers
- remove the "root region extent" and (to some extent) item extents; instead we use `Option<CodeExtent<'tcx>>` in a few places (no space inefficiency since `CodeExtent<'tcx>` is now a pointer).

I'm not entirely happy with the way I have it setup though. Here are some of the changes I was considering (I'm not sure if they would work out well):

1. Removing `item_extents` entirely -- they are rarely used now, because most of the relevant places now accept an `Option<Region<'tcx>>` or an `Option<CodeExtent<'tcx>>`, but I think still used in a few places.
2. Merging `RegionMaps` into the typeck tables, instead of having it be its own query.
3. Change `CodeExtent<'tcx>` to store the parent pointer. This would mean that fewer places in the code actually *need* a `RegionMaps` anyhow, since most of them just want to be able to walk "up the tree". On the other hand, you wouldn't be able to intern a `CodeExtent<'tcx>` for some random node-id, you'd need to look it up in the table (since there'd be more information).

Most of this code is semi-temporary -- I expect it to largely go away as we move to NLL -- so I'm also not *that* concerned with making it perfect.

r? @eddyb
bors added a commit that referenced this pull request May 2, 2017
Rollup of 6 pull requests

- Successful merges: #41661, #41662, #41673, #41688, #41692, #41693
- Failed merges:
@bors bors merged commit c008f05 into rust-lang:master May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants