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 upRefer to types using the local identifier #44642
Conversation
rust-highfive
assigned
nikomatsakis
Sep 17, 2017
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
estebank
force-pushed the
estebank:local-alias
branch
6 times, most recently
from
c28a79a
to
154d971
Sep 17, 2017
This comment has been minimized.
This comment has been minimized.
|
|
estebank
force-pushed the
estebank:local-alias
branch
from
154d971
to
01cbfca
Sep 17, 2017
estebank
added some commits
Sep 16, 2017
estebank
force-pushed the
estebank:local-alias
branch
from
01cbfca
to
6877688
Sep 17, 2017
arielb1
reviewed
Sep 17, 2017
| @@ -1179,6 +1179,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |||
| self.all_crate_nums(LOCAL_CRATE) | |||
| } | |||
|
|
|||
| pub fn cstore(&self) -> &CrateStore { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
I'm sure. This was a quick fix after rebasing against master to get the code as I had written it working. I fully intend to clean this up before attempting to merge this PR.
arielb1
reviewed
Sep 17, 2017
| @@ -357,7 +359,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
| // for imported and non-imported crates | |||
| if exp_path == found_path | |||
| || exp_abs_path == found_abs_path { | |||
| let crate_name = self.tcx.crate_name(did1.krate); | |||
| let crate_name = self.tcx.cstore().crate_name_untracked(did1.krate); | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
This is a spurious change that should not have happened. I introduced it after hastily rebasing to HEAD of master when the moving of cstore from sess to tcx happened. I'll revert.
arielb1
reviewed
Sep 17, 2017
| full_imports: FxHashMap<String, String>, | ||
| } | ||
|
|
||
| impl<'a, 'gcx, 'tcx> ImportVisitor<'a, 'gcx, 'tcx> { |
This comment has been minimized.
This comment has been minimized.
arielb1
Sep 17, 2017
Contributor
This looks likely to be buggy - you are reimplementing half of name resolution. Could name resolution be made to supply a types_in_scope map?
This comment has been minimized.
This comment has been minimized.
arielb1
Sep 17, 2017
Contributor
cc @jseyfried - is there a way for resolution to be called after it is complete?
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
I figured that was the case, but it was the closest I've been in any of my approaches to get this working. Once I saw that the suggestion machinery used a visitor it gave me enough context to get this. Having this also allowed me to identify the unit tests that would need to change. It is definitely less than ideal and fully expect there to be a way to do this using existing datastructures, but I feel it is much easier for me to point at this code and saw "this is what I want to do, is there a better way?". :)
This comment has been minimized.
This comment has been minimized.
jseyfried
Sep 21, 2017
Contributor
There's not a way to do name resolution after lowering to HIR (i.e. after we drop the Resolver). A naive solution would be to keep the Resolver for longer, but that would hog memory and isn't ideal since the Resolver has needless complexity used for import resolution and is based on the AST.
@nikomatsakis and I have discussed creating and saving some name resolution structures for this purpose before destroying the Resolver, but we haven't made detailed designs.
arielb1
reviewed
Sep 17, 2017
| struct ImportVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { | ||
| tcx: TyCtxt<'a, 'gcx, 'tcx>, | ||
| /// All the `Item`s from other scopes visible from this `TyCtxt`, as well as their local name. | ||
| full_imports: FxHashMap<String, String>, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
This is an artifact from the exploratory way I wrote this code, as while working on this I didn't have access to DefIds from other crates. Very sensible suggestion.
arielb1
reviewed
Sep 17, 2017
| } | ||
| } | ||
|
|
||
| /// This struct knows how to print out a single type for human consumption, compare two types and |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
That is my eventual objective. I have moved the type argument elision code away from TyCtxt in order to isolate as much from it as possible in order to unify it with the code in ppaux. Do you think I should strive to do it in this PR?
arielb1
reviewed
Sep 17, 2017
| s.push_str(&self.ty_str(ty_and_mut.ty)); | ||
| s | ||
| } | ||
| _ => format!("{}", ty), |
This comment has been minimized.
This comment has been minimized.
arielb1
Sep 17, 2017
Contributor
You really want to replace the entirety of ppaux here. Otherwise e.g. everything within a trait object will go back to ugly.
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
Yes, that is indeed true. Given how big this PR was getting I thought that it was a good idea to put it out there to get feedback before going further down this rabbit hole. That being said, this covered a big enough percentage of cases that allowed me to test this approach.
alexcrichton
reviewed
Sep 17, 2017
| } | ||
| } else { | ||
| // Importing from a different crate. | ||
| for child in self.tcx.cstore().item_children_untracked(def_id, |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Sep 17, 2017
Member
Ah so the "untracked" here means that it's not tracked by incremental compilation, so this is something that we're going to want to handle as this is all happening after the tcx is created. If you need help turning this into a query though just let me know!
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
Could you point me in the right direction of a query being performed? I haven't worked in that part of the compiler yet and would appreciate having a thread to pull from to unravel that sweater.
This comment has been minimized.
This comment has been minimized.
estebank
reviewed
Sep 17, 2017
|
TL;DR: Some of the weird code is the result of hastily rebasing against master and pushing the code out without reworking it to fit the current state of the compiler, and some is the result of the exploratory way I was writing the code without going back to clean it up after the reasons for the current state were no longer there. |
| @@ -357,7 +359,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { | |||
| // for imported and non-imported crates | |||
| if exp_path == found_path | |||
| || exp_abs_path == found_abs_path { | |||
| let crate_name = self.tcx.crate_name(did1.krate); | |||
| let crate_name = self.tcx.cstore().crate_name_untracked(did1.krate); | |||
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
This is a spurious change that should not have happened. I introduced it after hastily rebasing to HEAD of master when the moving of cstore from sess to tcx happened. I'll revert.
| struct ImportVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { | ||
| tcx: TyCtxt<'a, 'gcx, 'tcx>, | ||
| /// All the `Item`s from other scopes visible from this `TyCtxt`, as well as their local name. | ||
| full_imports: FxHashMap<String, String>, |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
This is an artifact from the exploratory way I wrote this code, as while working on this I didn't have access to DefIds from other crates. Very sensible suggestion.
| } | ||
| } | ||
|
|
||
| /// This struct knows how to print out a single type for human consumption, compare two types and |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
That is my eventual objective. I have moved the type argument elision code away from TyCtxt in order to isolate as much from it as possible in order to unify it with the code in ppaux. Do you think I should strive to do it in this PR?
| s.push_str(&self.ty_str(ty_and_mut.ty)); | ||
| s | ||
| } | ||
| _ => format!("{}", ty), |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
Yes, that is indeed true. Given how big this PR was getting I thought that it was a good idea to put it out there to get feedback before going further down this rabbit hole. That being said, this covered a big enough percentage of cases that allowed me to test this approach.
| @@ -1179,6 +1179,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |||
| self.all_crate_nums(LOCAL_CRATE) | |||
| } | |||
|
|
|||
| pub fn cstore(&self) -> &CrateStore { | |||
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
I'm sure. This was a quick fix after rebasing against master to get the code as I had written it working. I fully intend to clean this up before attempting to merge this PR.
| --> $DIR/local-ident.rs:16:28 | ||
| | | ||
| 16 | let y: Option<usize> = Ok(2); | ||
| | ^^^^^ expected enum `std::option::Option`, found enum `std::result::Result` |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
This is an open question: Do we want to show the fully qualified path here? I don't think length is as much of an issue here as this label doesn't print the type arguments, keeping the line relatively short. Alternatively it might be jarring to have two different things being shown here...
| | ^^^^^ expected enum `std::option::Option`, found enum `std::result::Result` | ||
| | | ||
| = note: expected type `Option<usize>` | ||
| found type `Result<{integer}, _>` |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
Should we add a note here stating Option: std::option::Option and Result: std::result::Result? This could become a very long list for cases like the one put forward in #40186.
| } | ||
| } else { | ||
| // Importing from a different crate. | ||
| for child in self.tcx.cstore().item_children_untracked(def_id, |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
Could you point me in the right direction of a query being performed? I haven't worked in that part of the compiler yet and would appreciate having a thread to pull from to unravel that sweater.
| full_imports: FxHashMap<String, String>, | ||
| } | ||
|
|
||
| impl<'a, 'gcx, 'tcx> ImportVisitor<'a, 'gcx, 'tcx> { |
This comment has been minimized.
This comment has been minimized.
estebank
Sep 17, 2017
Author
Contributor
I figured that was the case, but it was the closest I've been in any of my approaches to get this working. Once I saw that the suggestion machinery used a visitor it gave me enough context to get this. Having this also allowed me to identify the unit tests that would need to change. It is definitely less than ideal and fully expect there to be a way to do this using existing datastructures, but I feel it is much easier for me to point at this code and saw "this is what I want to do, is there a better way?". :)
This comment has been minimized.
This comment has been minimized.
|
What about shadowing? For example: struct Result;
fn main() {
let res: Result = Ok(());
}This PR produces the following note:
(the full path for |
carols10cents
added
the
S-waiting-on-author
label
Sep 18, 2017
This comment has been minimized.
This comment has been minimized.
|
ping @estebank just want to make sure this doesn't fall off your radar! |
This comment has been minimized.
This comment has been minimized.
rust-highfive
assigned
arielb1
and unassigned
nikomatsakis
Sep 21, 2017
This comment has been minimized.
This comment has been minimized.
|
Still waiting on resolution coordination with @jseyfried. |
This comment has been minimized.
This comment has been minimized.
|
Not clear what the status here is - is there an issue that triagers can visit to see progress of any blockers? Just wondering who's 'responsible' for pushing this along :) |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@arielb1 / @jseyfried / @estebank - can anyone clarify what/who this PR is waiting on at the moment (aside from a rebase)? I'm not sure how to triage this at the moment as I don't know what's blocking or if there's an issue we can track! |
This comment has been minimized.
This comment has been minimized.
|
@aidanhs I need to rework the PR to use queries, but I haven't had time available to do so. If people prefer, I can close this PR and resubmit once I've reworked it. |
This comment has been minimized.
This comment has been minimized.
|
@estebank ok great, thanks for clarifying! If you reckon you might get to this in the next couple of weeks then I'd be fine with keeping it open - up to you. |
This comment has been minimized.
This comment has been minimized.
|
Here for triage again! I'm going to go ahead and close this now to help clear out the queue, but @estebank of course feel free to resubmit once it's reworked! |
estebank commentedSep 17, 2017
•
edited
On type errors, refer to types using the locally available name when
they have been imported into scope instead of the fully qualified path.
Re: #21934.