-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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_resolve: refactor NameBindings and fix issue #4952 #29530
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Aatch (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
(I saw @Aatch mention on IRC that he did not feel familiar enough with resolve to review) |
Sorry for being slow. I'll try to take a look at this now. I'm also not super familiar with this code, but I figure this is a good time to refresh my memory. :) |
@jseyfried to be clear, this is a pure refactoring, right? That is, it's not supposed to fix any bugs? |
type_def: Option<Def>, | ||
type_span: Option<Span> | ||
def: Option<Def>, | ||
module: Option<Rc<Module>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments here would be good. e.g. what does it mean if both def
and module
are Some
? The function def
below seems to suggest that def
"takes precedence" -- does this mean that module
should always be None
when def
is Some
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(edited) see my comment in the main conversation
☔ The latest upstream changes (presumably #29778) made this pull request unmergeable. Please resolve the merge conflicts. |
@nikomatsakis Thanks for the feedback. Yes, this is a pure refactoring. |
☔ The latest upstream changes (presumably #29387) made this pull request unmergeable. Please resolve the merge conflicts. |
Define a newtype `NameBinding` for `Rc<RefCell<Option<NsDef>>>` and refactor `NameBindings` to be a `NameBinding` for each namespace. Replace uses of `NameBindings` with `NameBinding` where only one binding is being used (in `NamespaceResult`, `Target,` etc). Refactor away `resolve_definition_of_name_in_module` and `NameDefinition`.
Rebased |
@nikomatsakis Regarding your question about the When I was writing the first commit, I wasn't exactly sure what it meant when the It turns out the meaning of these fields is fairly complex.
The This redundancy seems like a bad idea, so I refactored the Thus ideally exactly one of However, we sometimes allow It looks like it was decided that there would be one warning cycle before the warnings become errors. Once they are errors, I can refactor the The warnings are currently in the beta branch. Does this mean they are ready to be made errors now in nightly? If so I could do that and refactor the fields in this PR. |
Change build_reduced_graph.rs so the fields def and module of NsDef are never both Some unless the NsDef represents a duplicate definition (see issue 26421).
Yes, it does mean that. That'd be nice! |
@nikomatsakis Done |
value_ns: NameBinding, // < Meaning in value namespace. | ||
} | ||
|
||
impl ::std::ops::Index<Namespace> for NameBindings { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creative use of Index
btw.
self.def.get().as_ref().map(Def::def_id) | ||
} | ||
|
||
fn is_normal(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment explaining what makes this a "normal" module? I guess this means "a module declared by the user", and not a "pseudo-module" that we create for some other reason?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Module
probably should be named something like Scope
since it represents scopes corresponding to traits, enums, and blocks as well as actual mod
modules.
In this case a "normal" Module
(formerly NormalModuleKind
) is a Module
that corresponds to a actual module or a foreign module.
@jseyfried ok, I've read this through. I think it looks really nice, definitely seems cleaner, and I like cleaning up the semantics. r+ if you add a comment on |
@bors r+ (I decided insisting on a comment on Thanks @jseyfried, this is nice! |
@jseyfried no. |
@bors r- |
@bors r+ |
📌 Commit 6a6e1db has been approved by |
Replace `TypeNsDef` and `ValueNsDef` with a more general type `NsDef`. Define a newtype `NameBinding` for `Rc<RefCell<Option<NsDef>>>` and refactor `NameBindings` to be a `NameBinding` for each namespace. Replace uses of `NameBindings` with `NameBinding` where only one binding is being used (in `NamespaceResult`, `Target,` etc). Refactor away `resolve_definition_of_name_in_module` and `NameDefinition`, fixing issue #4952.
This breaks rust-jsonrpc and there isn't any workaround short of me breaking my API to force users to pass garbage to my macros. Why wasn't there a warning? |
With help from @bluss I was able to find a workaround that does not change the API. However, the warning PR and this PR were merged less than four weeks apart. My crate is publicly available on crates.io and has transitioned from "working" to "not compiling" in such a short period, with no notification other than that one of my users who I know IRL happened to be using nightly with my library. |
Some additional detail from @apoelstra on IRC: This breakage wasn't found by the crater run because the error occurs in a macro expansion, and doesn't happen during The code that broke in jsonrpc was using a pattern that may be found in other macros, so there might be other broken crates that were missed by crater for the same reason. Should we try harder to determine the real impact before converting this warning to an error? |
@apoelstra @mbrubeck I am confused. I thought that the warnings had been available for some time. Perhaps I misunderstood what @jseyfried meant by "in the beta branch" -- if the warnings were only available for six hours, that does seem like a policy failure, since you ought to have time to react. |
The warning landed in 1.5 and became an error in 1.6, so developers using the stable channel will have one release cycle (six weeks) to react to them. On the nightly channel, developers had four weeks to react. |
We could detect this type of breakage in test code by making crater do |
@mbrubeck If crater does do |
@nikomatsakis Sorry, I misunderstood how the release cycle worked. I thought that because nightly had a hard error before stable had even a warning, that stable would not get even the warning. |
@mbrubeck it seems like I misunderstood. Re-reading the comments, I'm not sure where I got the notion that the span-between-warning-and-breakage was 6 hours. In any case, 4 weeks seems like a pretty reasonable span of time (for Nightly), but I don't think we've made a firm policy here. Regarding the crater run, perhaps |
On Thu, Dec 10, 2015 at 06:23:19PM -0800, Andrew Poelstra wrote:
Not to worry. Thanks for raising the point in any case, better safe |
As mentioned by bhsausabsha on IRC, |
Are there any other links relevant to the regression reported here? Maybe an issue? |
Since #30089 was fixed, I'm assuming it is a different regression than the one reported by @apoelstra. |
Replace
TypeNsDef
andValueNsDef
with a more general typeNsDef
.Define a newtype
NameBinding
forRc<RefCell<Option<NsDef>>>
and refactorNameBindings
to be aNameBinding
for each namespace.Replace uses of
NameBindings
withNameBinding
where only one binding is being used (inNamespaceResult
,Target,
etc).Refactor away
resolve_definition_of_name_in_module
andNameDefinition
, fixing issue #4952.