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

rustc: remove unnecessary extern_prelude logic from ty::item_path. #56655

Closed
wants to merge 1 commit into from

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Dec 9, 2018

The checks added in 02357e4 effectively turned crate::std into std, but they were too general (affecting any crate::foo where foo was in the extern prelude, not just extern crates), and unnecessary, as only the extern crates created by "std injection" need any special-casing.

I've replaced the check for an extern prelude name with not printing the full path to an extern crate if the span inside the middle::cstore::ExternCrate is a dummy one.

Since this only affects the user-facing "relative" mode, it shouldn't have interactions with linking, and the only observable effect should be sometimes-shorter paths in diagnostics.

r? @nikomatsakis cc @davidtwco

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 9, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Do we want some sort of test?

r=me with the comments + (ideally) a test

direct: true,
span,
..
}) if !span.is_dummy() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a comment would be good here -- it's pretty non-obvious what's going on.

..
}) => {
debug!("try_push_visible_item_path: def_id={:?}", def_id);
self.push_item_path(buffer, def_id, pushed_prelude_crate);
if !span.is_dummy() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, comment here -- or maybe we can pull this into some kind of common helper function with the code above?

Copy link
Member Author

Choose a reason for hiding this comment

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

So in a different branch I was able to deduplicate this by moving the local mode logic from push_krate_path to try_push_visible_item_path and relying on the fact that try_push_visible_item_path can override the behavior of push_item_path. But maybe we can avoid the dummy span check here by some other means.

@nikomatsakis
Copy link
Contributor

@eddyb

I guess that this means that if you have an extern crate and something in the prelude, you will get .. what?

@eddyb
Copy link
Member Author

eddyb commented Dec 10, 2018

@nikomatsakis You will get whatever is preferred by the rest of the system, likely the extern crate (with a path like crate::foo) - maybe we can fix all of this separately by making extern crate items unpreferred when they're in the extern prelude?

cc @petrochenkov

@petrochenkov petrochenkov self-assigned this Dec 10, 2018
@petrochenkov
Copy link
Contributor

@eddyb
Values in the GlobalCtxt::extern_prelude map are bool flags telling whether the crate was introduced by an extern crate item or not.
(Not accidentally introduced, like passed with both --extern and extern crate foo;, but really introduced only with extern crate foo;.)

I'm not sure what exactly ty::item_path needs, but hope that helps.

@petrochenkov petrochenkov removed their assignment Dec 11, 2018
@eddyb
Copy link
Member Author

eddyb commented Dec 11, 2018

@petrochenkov That's perhaps useful, but what's needed here is something tied to the CrateNum, not (just) the name of the crate, i.e. what this method records:

fn update_extern_crate(&mut self,

And its calls in that module, e.g.:
self.update_extern_crate(
cnum,
ExternCrate {
src: ExternCrateSource::Path,
span,
// to have the least priority in `update_extern_crate`
path_len: usize::max_value(),
direct: true,
},
&mut FxHashSet::default(),
);

Right now we track what caused a crate to be loaded, which used to always be an extern crate item, but I think with Rust 2018, that's the wrong perspective.

We should instead record whether the crate can be referred to by name (and specifically by which name), or that we have to spell out the path to an extern crate that loaded the crate.

ExternCrateSource appears to be used only in ty::item_path, so we don't have to consider other usecases if we change how this "simplest way to refer to a crate" tracking system works.

(random aside, ExternCrateSource::Use is dead, we should remove it, I might do it later)

@petrochenkov
Copy link
Contributor

something tied to the CrateNum, not (just) the name of the crate

Then ExternCrate/ExternCrateSource tied to the CrateNum probably need to keep a flag similar to introduced_by_item in ExternPreludeEntry tied to the name.

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 19, 2018
@nikomatsakis
Copy link
Contributor

@eddyb @petrochenkov -- I can't quite tell what's the status of this PR. I wrote r=me above, modulo testing. Do we think we want to alter the behavior in this case, though?

I guess that this means that if you have an extern crate and something in the prelude, you will get .. what?

@petrochenkov
Copy link
Contributor

petrochenkov commented Dec 29, 2018

Relevant issue - #55779 (infinite recursion in fn push_item_path).

While printing the trait helper::Trait the inner extern crate helper item is (incorrectly) considered "the introducer" of helper crate (ExternCrateSource::Extern), and to print the introducer we need to print its parent - the trait impl including helper::Trait, and so on.

@nikomatsakis
Copy link
Contributor

I'm just going to change this to r? @petrochenkov =)

@stokhos
Copy link

stokhos commented Jan 14, 2019

Ping from triage @petrochenkov : This PR requires your review.

@stokhos stokhos added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 14, 2019
@petrochenkov
Copy link
Contributor

This PR requires eddyb's return.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 14, 2019
@TimNN
Copy link
Contributor

TimNN commented Jan 22, 2019

Ping from triage @eddyb: What is the status of this PR?

@TimNN TimNN added A-allocators Area: Custom and system allocators and removed A-allocators Area: Custom and system allocators labels Jan 29, 2019
@petrochenkov
Copy link
Contributor

This seems to be included into #57967

@eddyb
Copy link
Member Author

eddyb commented Jan 30, 2019

This seems to be included into #57967

Right, I made this PR while starting work on the refactoring #57967 is based on.

IIRC, @nikomatsakis' comments are addressed in that, by moving the "relative extern crate path" logic into the "visible path" part of path printing (since they're somewhat related).

Do you still want to do #56655 (comment), before landing #57967, or can it wait?

@petrochenkov
Copy link
Contributor

@eddyb

Do you still want to do #56655 (comment), before landing #57967, or can it wait?

Whatever is more convenient.

@bors
Copy link
Contributor

bors commented Feb 10, 2019

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

@Dylan-DPC-zz
Copy link

ping from triage @eddyb any updates on this?

@Dylan-DPC-zz
Copy link

ping from triage @eddyb
Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again!

@Dylan-DPC-zz Dylan-DPC-zz added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 11, 2019
@eddyb eddyb deleted the item-path-prelude branch May 2, 2019 02:02
@eddyb eddyb restored the item-path-prelude branch January 13, 2020 15:21
@eddyb eddyb reopened this May 7, 2020
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. labels May 7, 2020
@crlf0710
Copy link
Member

Needs a rebase here.

@joelpalmer joelpalmer added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 26, 2020
@Elinvynia Elinvynia added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 3, 2020
@Elinvynia Elinvynia added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 25, 2020
@Dylan-DPC-zz
Copy link

Closing this due to inactivity after a discussion with the author.

@Dylan-DPC-zz Dylan-DPC-zz added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.