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

Change DefId to be based on a path, and not a NodeId #28742

Merged
merged 17 commits into from
Oct 1, 2015

Conversation

nikomatsakis
Copy link
Contributor

As described in rust-lang/rfcs#1298, the idea here is to make DefIds independent of changes to the content of other items. They are also mostly independent from ordering, so e.g. reordering two functions will change the defids, but it will not change the paths that they expand into (but this is not the case for some things, such as impls).

This is a major refactoring, so I did it in slices. The final commit is in some sense The Big One where most of the work is done. The earlier commits just pave the way by gradually refactoring accesses to the node field.

This is a [breaking-change] for plugin authors. The things you need to do to migrate your code are as follows:

  1. For local def-ids, rather than do def_id.node, call tcx.map.as_local_node_id(def_id).
  2. To construct a local def-id, call tcx.map.local_def_id(node_id).
  3. Note that you cannot make def-ids for any node, but only for "definitions" -- which include all items, as well as a number of other things, but not e.g. arbitrary expressions.
  4. You can get the path to a def-id by calling tcx.def_path(def_id).

One thing that is NOT part of this PR, but which I plan do in a follow-up, is converting uses of the existing with_path API to use def_path, which is basically the same.

r? @eddyb (or @nrc)

@nikomatsakis
Copy link
Contributor Author

OK, so I scheduled a crater run to see whether the "creepy case" that I changed to span_bug occurs in practice anywhere. The answer is yes, a few crates regress due to that change. I will investigate. I have to go refresh my memory, but I think I'm inclined to just remove that code and always yield None.

@nikomatsakis
Copy link
Contributor Author

OK, so, I've verified that always returning None does work. I think perhaps the "rightest" thing to do here is to fetch the discriminant value out of the ADT definition, but I'm not inclined to extend const_eval right now.

@nikomatsakis
Copy link
Contributor Author

pushed a fix.

}

pub fn def_to_string(did: DefId) -> String {
format!("{}:{}", did.krate, did.node)
format!("{}:{}", did.krate, did.index.as_usize())
Copy link
Member

Choose a reason for hiding this comment

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

I don't think def_to_string should exist, at all, especially if we have def_to_u64.

@eddyb
Copy link
Member

eddyb commented Sep 30, 2015

LGTM, modulo the few nits above.
Do you have any performance numbers? I'm curious if compilation times are at all impacted by the extra work.

@nikomatsakis
Copy link
Contributor Author

@eddyb

Do you have any performance numbers? I'm curious if compilation times are at all impacted by the extra work.

I didn't measure, but I can.

@bors
Copy link
Contributor

bors commented Oct 1, 2015

☔ The latest upstream changes (presumably #28778) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor Author

I measured time to build libstd and observed:

  • master: 24.46 user 0.40 system 0:15.82 elapsed 157%CPU
  • my branch: 24.52 user 0.38 system 0:15.83 elapsed 157%CPU

they are being used as an opaque "position identifier"
were returned, either the trait or the *self type itself*, were not
particularly representative of what the Def is (a type parameter).
Rewrite paths to handle this case specially, just as they handle the
primitive case specifically. This entire `def_id` codepath is kind of a
mess.
paths, and construct paths for all definitions. Also, stop rewriting
DefIds for closures, and instead just load the closure data from
the original def-id, which may be in another crate.
have always been returning None anyway, since it was comparing node-ids
across crates incorrectly -- and remove the now unused map
`extern_const_variants`
@nikomatsakis
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Oct 1, 2015

📌 Commit f0dc7bd has been approved by eddyb

@bors
Copy link
Contributor

bors commented Oct 1, 2015

⌛ Testing commit f0dc7bd with merge e82faeb...

bors added a commit that referenced this pull request Oct 1, 2015
As described in rust-lang/rfcs#1298, the idea here is to make DefIds independent of changes to the content of other items. They are also *mostly* independent from ordering, so e.g. reordering two functions will change the defids, but it will not change the paths that they expand into (but this is not the case for some things, such as impls).

This is a major refactoring, so I did it in slices. The final commit is in some sense The Big One where most of the work is done. The earlier commits just pave the way by gradually refactoring accesses to the `node` field.

This is a [breaking-change] for plugin authors. The things you need to do to migrate your code are as follows:

1. For local def-ids, rather than do `def_id.node`, call `tcx.map.as_local_node_id(def_id)`.
2. To construct a local def-id, call `tcx.map.local_def_id(node_id)`.
3. Note that you cannot make def-ids for any node, but only for "definitions" -- which include all items, as well as a number of other things, but not e.g. arbitrary expressions.
4. You can get the path to a def-id by calling `tcx.def_path(def_id)`.

One thing that is NOT part of this PR, but which I plan do in a follow-up, is converting uses of the existing `with_path` API to use `def_path`, which is basically the same.

r? @eddyb (or @nrc)
@bors bors merged commit f0dc7bd into rust-lang:master Oct 1, 2015
thepowersgang added a commit to thepowersgang/tag_safe that referenced this pull request Oct 4, 2015
@nikomatsakis nikomatsakis deleted the def-id-encapsulate branch March 30, 2016 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants