Skip to content

Move the definition of DefId to librustc #27856

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

Merged
merged 4 commits into from
Aug 24, 2015

Conversation

nikomatsakis
Copy link
Contributor

It doesn't really make sense for DefId to be in libsyntax -- it is concerned with a single crate only. It is the compiler that understands the idea of many crates. (At some point, there might be a useful intermediate point here.) This is a refactoring in support of incr. compilation, which will be adjusting the notion of a DefId to make it more durable across compilations.

This will probably be a [breaking-change] for every plugin ever. You need to adjust things as follows:

use rustc::middle::def_id::{DefId, LOCAL_CRATE}; // two most common definitions
ast_util::is_local(def_id) => def_id.is_local()
ast_util::local_def(node_id) => DefId::local(node_id)

@rust-highfive
Copy link
Contributor

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

}
}

impl DefId {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you have an as_local(&self) -> Option<NodeId> method instead of using .krate == LOCAL_CRATE everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arielb1

Could you have an as_local(&self) -> Option method instead of using .krate == LOCAL_CRATE everywhere?

We have is_local() as well, I could convert some code to use that.

But you just reminded me that I meant to purge the DEF_ID_DEBUG thing...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(But as_local would be nice too to be more type-safe)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I guess DEF_ID_DEBUG may still have value, I'm not sure if the tcx is ALWAYS available when DefIds are being debugged, and there doesn't seem to be a method for "conditionally" reading the current tcx.

Copy link
Member

Choose a reason for hiding this comment

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

I was going to mention it but I see you've already thought about doing it.
The only method that needs to be exposed is is_set.

@nikomatsakis
Copy link
Contributor Author

@eddyb what are your thoughts about DEF_ID_DEBUG. I wanted to purge it, but it seems like it may still play some role to me, as the tcx may not yet have been entered. I could add a method "tls::opt_with" or something, but I'm curious what you think is cleanest thing.

@eddyb
Copy link
Member

eddyb commented Aug 16, 2015

LGTM after the ty::tls::with_opt addition and the new Debug implementation for DefId.

@nikomatsakis
Copy link
Contributor Author

@arielb1 I investigated as_local_id(), but honestly the code felt kind of messier afterwards; frequently, the branches aren't using the node field, and other times, it just adds another identifier to the mix (versus def_id.node). So I'm inclined to leave that sort of refactoring for later.

@nikomatsakis
Copy link
Contributor Author

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned pnkfelix Aug 16, 2015
Some(ast_map::NodeTraitItem(..)) |
Some(ast_map::NodeVariant(..)) |
Some(ast_map::NodeStructCtor(..)) => {
return write!(f, " => {}", tcx.item_path_str(*self));
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure there's even a point to restricting this to only certain nodes anymore, if there ever was.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eddyb

I'm not sure there's even a point to restricting this to only certain nodes anymore, if there ever was.

perhaps not; looking over the code it seems like it will always gin up some kind of path, even if it's an empty or useless one.

@eddyb
Copy link
Member

eddyb commented Aug 16, 2015

r=me after optionally removing the node kind restriction (does something break if you do?) and maybe even printing DefId paths for non-local IDs.

@nikomatsakis nikomatsakis force-pushed the move-def-id-to-rustc branch 3 times, most recently from 755fbf7 to 3521bf3 Compare August 16, 2015 16:09
@nikomatsakis
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Collaborator

bors commented Aug 16, 2015

📌 Commit 3521bf3 has been approved by eddyb

@bors
Copy link
Collaborator

bors commented Aug 16, 2015

⌛ Testing commit 3521bf3 with merge 7d400d6...

@bors
Copy link
Collaborator

bors commented Aug 16, 2015

💔 Test failed - auto-mac-32-opt

@bors
Copy link
Collaborator

bors commented Aug 17, 2015

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

@nikomatsakis
Copy link
Contributor Author

Test failure looks like #27583. Hopefully #27892 will fix it.

@bors
Copy link
Collaborator

bors commented Aug 22, 2015

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

@nikomatsakis
Copy link
Contributor Author

@bors r=eddyb

@bors
Copy link
Collaborator

bors commented Aug 24, 2015

📌 Commit 1994875 has been approved by eddyb

@bors
Copy link
Collaborator

bors commented Aug 24, 2015

⌛ Testing commit 1994875 with merge db67cbe...

bors added a commit that referenced this pull request Aug 24, 2015
It doesn't really make sense for DefId to be in libsyntax -- it is concerned with a single crate only. It is the compiler that understands the idea of many crates. (At some point, there might be a useful intermediate point here.) This is a refactoring in support of incr. compilation, which will be adjusting the notion of a DefId to make it more durable across compilations.

This will probably be a [breaking-change] for every plugin ever. You need to adjust things as follows:

    use rustc::middle::def_id::{DefId, LOCAL_CRATE}; // two most common definitions
    ast_util::is_local(def_id) => def_id.is_local()
    ast_util::local_def(node_id) => DefId::local(node_id)
@bors bors merged commit 1994875 into rust-lang:master Aug 24, 2015
thepowersgang added a commit to thepowersgang/tag_safe that referenced this pull request Aug 27, 2015
@nikomatsakis nikomatsakis deleted the move-def-id-to-rustc branch March 30, 2016 16:16
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.

6 participants