Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCorrectly walk import lists in AST visitors #28364
Conversation
rust-highfive
assigned
eddyb
Sep 11, 2015
This comment has been minimized.
This comment has been minimized.
|
Awesome fix - look at all that fallout! |
brson
added
the
relnotes
label
Sep 11, 2015
eefriedman
reviewed
Sep 11, 2015
| identifier: name, | ||
| parameters: PathParameters::none() | ||
| }); | ||
| visitor.visit_path(unsafe{&*(&path as *const _)}, id); |
This comment has been minimized.
This comment has been minimized.
eefriedman
Sep 11, 2015
Contributor
visit_path is defined as fn visit_path(&mut self, path: &'v Path, _id: NodeId) {, i.e. the lifetime of the path is tied to the the lifetime of the visitor, not the lifetime of the callback. Also, the current PR visits both the path's components and the path as a whole. Also, cloning the prefix is a bunch of extra computation which is unlikely to be useful
Probably the most straightforward thing to do would be to add a method visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) to Visitor and let the callee do the right thing.
Related issue: we probably also want a method on Visitor to visit the prefix; it would be useful for fixing the handling of use std::foobar::{};.
This comment has been minimized.
This comment has been minimized.
petrochenkov
Sep 12, 2015
Author
Contributor
Yes, the prefix is cloned and components of the prefix are visited repeatedly. I supposed this couldn't be done optimally without introducing a new visit_xxx method, but introducing it seemed.. intrusive and too far away from stability.rs. I'll surely do it if it's acceptable.
I also had an idea to desugar use a::{b, c}; into use a::b; use a::b; during lowering to HIR, it would avoid repeated cloning of the prefix, but checks of the prefix components would still be duplicated.
This comment has been minimized.
This comment has been minimized.
eddyb
Sep 12, 2015
Member
The way the visitor is designed is so that certain visitors can "opt in" to observe the original AST/HIR lifetime and be able to hold onto those references.
Unsafe code here is just wrong.
You have two options: if the HIR map builder doesn't override this particular method, you can drop the lifetime.
Otherwise, you'll have go the explicit route @eefriedman mentioned, with one extra tip: you can always write some sort of iterator for the expansions.
petrochenkov
force-pushed the
petrochenkov:usegate
branch
from
8f62647
to
ac660cd
Sep 12, 2015
petrochenkov
changed the title
[WIP] Correctly walk import lists in the default AST visitor
Correctly walk import lists in AST visitors
Sep 12, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated with accordance to the @eefriedman 's advice and rebased.
|
eddyb
reviewed
Sep 12, 2015
| } | ||
| } else { | ||
| // FIXME: uncomment this and fix the resulting ICE | ||
| // visitor.visit_path(prefix, item.id); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@brson This bug was discovered when we removed a gated function. With this fix, we add new breaking changes by disallowing imports of still present, unused, unstable functionality. Maybe it deserves a crater run? If the fallout is bad, maybe even a warning cycle (even if that sounds extreme). |
This comment has been minimized.
This comment has been minimized.
So, fixing this issue would likely require going to librustc_resolve, resolving the prefix and assigning |
petrochenkov
referenced this pull request
Sep 13, 2015
Closed
Privacy, stability etc. are not respected in imports with empty braces #28388
This comment has been minimized.
This comment has been minimized.
|
Done. |
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov
force-pushed the
petrochenkov:usegate
branch
from
a57386c
to
a69a520
Sep 13, 2015
This comment has been minimized.
This comment has been minimized.
|
Rebased. |
This comment has been minimized.
This comment has been minimized.
|
@brson Can we get a crater run? |
This comment has been minimized.
This comment has been minimized.
|
I've scheduled crater runs. |
This comment has been minimized.
This comment has been minimized.
|
Looks like this has some relatively significant breakage. The cause of all the root regressions appears to be that we have an unstable I would personally think, however, that we could submit PRs to update all those crates, rebuild the other non-root-regressions to make sure there's no more fallout, and then land this while publishing information about how to migrate. The breakage here may be largely limited to the thoughts @brson? |
petrochenkov
force-pushed the
petrochenkov:usegate
branch
from
a69a520
to
d60c936
Sep 15, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated with a fix for #28388 |
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov
force-pushed the
petrochenkov:usegate
branch
from
d60c936
to
355daea
Sep 16, 2015
This comment has been minimized.
This comment has been minimized.
|
Rebased. |
This comment has been minimized.
This comment has been minimized.
|
Yeah, let's submit PR's downstream. I can look into it tomorrow. |
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov
added some commits
Sep 12, 2015
petrochenkov
force-pushed the
petrochenkov:usegate
branch
from
355daea
to
1599c16
Sep 17, 2015
This comment has been minimized.
This comment has been minimized.
|
Rebased. |
This comment has been minimized.
This comment has been minimized.
|
I have submitted PRs upstream to affected crates: |
alexcrichton
reviewed
Sep 18, 2015
|
|
||
| // Prefix in imports with empty braces should be resolved and checked privacy, stability, etc. | ||
|
|
||
| use std::rt::{}; //~ ERROR use of unstable library feature 'rt' |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 18, 2015
Member
Can you tweak this test to use an aux-build with an unstable module instead? This module in theory may be removed over time.
alexcrichton
reviewed
Sep 18, 2015
|
|
||
| #![allow(unused_imports)] | ||
|
|
||
| use std::thread::{catch_panic, ScopedKey}; //~ ERROR use of unstable library feature 'catch_panic' |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 18, 2015
Member
Similarly to down below, can you make an auxiliary file for this instead of relying on particular features in the standard library being unstable? (these will change over time)
This comment has been minimized.
This comment has been minimized.
|
Once those PRs have been merged/released I think we'll want to do another crater run here now that more bugs have been fixed. |
alexcrichton
referenced this pull request
Sep 18, 2015
Merged
Avoid using the std::intrinsics module #803
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton |
This comment has been minimized.
This comment has been minimized.
|
Ok, a new crater run indicates that this has 4 root regressions, 2 of which were spurious because of timeouts and 2 of which were because libraries are depending on an older version of gfx which did not get the fix in gfx-rs/gfx#803. @brson, how do you feel about merging? I'm comfortable with the breakage here and I think we may want to make a post on internals and such to ensure that everyone knows about this, but I think this should be good to go. |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton Yes, I feel ok about it. Thanks for doing the downstream work. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
bors
added a commit
that referenced
this pull request
Sep 22, 2015
This comment has been minimized.
This comment has been minimized.
bors
merged commit b44cb01
into
rust-lang:master
Sep 22, 2015
petrochenkov
deleted the
petrochenkov:usegate
branch
Sep 23, 2015
petrochenkov
referenced this pull request
Sep 28, 2015
Merged
Fill in some missing parts in the default AST and HIR visitors #28715
bors
added a commit
that referenced
this pull request
Sep 29, 2015
This comment has been minimized.
This comment has been minimized.
mod some_module {
enum _Enum { A, B, _Dummy }
pub type Enum = self::_Enum;
pub use self::_Enum::{A, B};
}
fn to_string(e: some_module::Enum) -> String {
match e {
some_module::A => 'A'.to_string(),
some_module::B => 'B'.to_string(),
_ => "_not_supported".to_string()
}
}We might need to apply the privacy rule to EDIT: I checked the PR again and find that above problem is sort of unrelated. |
petrochenkov commentedSep 11, 2015
Closes #28075
Closes #28388
r? @eddyb
cc @brson