Uh oh!
There was an error while loading. Please reload this page.
resolve: improve import resolution - #31461
Conversation
828bd48 to
6a2f81eComparejseyfried
commented
Feb 7, 2016
6a2f81e to
eb1a9b6Comparepetrochenkov
commented
Feb 7, 2016
jseyfried
commented
Feb 7, 2016
The second one was supposed to be #31404, edited.
Awesome, I look forward to any feedback. |
petrochenkov
commented
Feb 7, 2016
Ok, I give up, too many things are happening here at the same time. By the way, how much of the code treating imports and extern crates specially is caused only by error message compatibility? |
There was a problem hiding this comment.
So, if we try to define a shadowable binding (1) conflicting with another existing shadowable binding (2), then (2) wins or the conflict is reported somewhere else?
There was a problem hiding this comment.
Yeah, binding (2) would win (since the first match arm would be taken) and the conflict would not be reported (it would also not be reported in the original code). This isn't a problem since the only SHADOWABLE bindings are from the special prelude import, so there can't be conflicts.
There was a problem hiding this comment.
Perhaps I should rename SHADOWABLE to PRELUDE.
There was a problem hiding this comment.
Perhaps I should rename SHADOWABLE to PRELUDE.
That would be much clearer, because prelude and shadowable glob imports would behave differently (I suppose).
The resolution result depending on the resolution order is still pretty bad, even if the concern is theoretical at the moment due to absence of user-defined preludes.
There was a problem hiding this comment.
True, I'll make it an error to have duplicate SHADOWABLE / PRELUDE imports.
jseyfried
commented
Feb 7, 2016
I'll split the first commit into more smaller commits.
The special treatment in |
eb1a9b6 to
fe6ecd7Comparejseyfried
commented
Feb 8, 2016
I addressed @gereeter's and @petrochenkov's comments and rewrote history to make the biggest commit a little cleaner and easier to review. |
85afd8e to
a847317CompareNameBinding now encodes these directly with binding.is_public() and (binding.is_public() && binding.is_import()) (respectively)
…ame ImportResolution to NameResolution
…tanding_references_for
…valued map. Refactor away resolve_name_in_module in resolve_imports.rs Rewrite and improve the core name resolution procedure in NameResolution::result and Module::resolve_name Refactor the duplicate checking code into NameResolution::try_define
a847317 to
3c62d90Comparepetrochenkov
commented
Feb 8, 2016
Reviewed everything except for jseyfried@7000e70 |
69635f0 to
3c62d90Compare…sts) Derive the Default impl for NameResolution
1e71fc0 to
3df40c0Comparenrc
commented
Feb 11, 2016
@bors: r+ |
bors
commented
Feb 11, 2016
📌 Commit 3df40c0 has been approved by |
bors
commented
Feb 11, 2016
This PR adds to `NameBinding` so it can more fully represent bindings from imports as well from items, refactors away `Target`, generalizes `ImportResolution` to a simpler type `NameResolution`, and uses a single `NameResolution`-valued map in place the existing maps `children` and `import_resolutions` (of `NameBinding`s and `ImportResolution`s, respectively), simplifying duplicate checking and name resolution. It also unifies the `resolve_name_in_module` in `lib.rs` with its namesake in `resolve_imports.rs`, clarifying and improving the core logic (fixes#31403 and fixes#31404) while maintaining clear future-comparability with shadowable globs (i.e., never reporting that a resolution is a `Success` or is `Failing` unless this would also be knowable with shadowable globs). Since it fixes#31403, this is technically a [breaking-change], but it is exceedingly unlikely to cause breakage in practice. The following is an example of code that would break: ```rust mod foo { pub mod bar {} // This defines bar in the type namespace pub use alpha::bar; // This defines bar in the value namespace // This should define baz in both namespaces, but it only defines baz in the type namespace. pub use self::bar as baz; pub fn baz() {} // This should collide with baz, but now it does not. } pub fn f() {} mod alpha { pub use self::f as bar; // Changing this to `pub fn bar() {}` causes the collision right now. pub use super::*; } ``` r? @nrc
jseyfried
commented
Feb 11, 2016
@nrc Thanks! |
This PR adds to
NameBindingso it can more fully represent bindings from imports as well from items, refactors awayTarget, generalizesImportResolutionto a simpler typeNameResolution, and uses a singleNameResolution-valued map in place the existing mapschildrenandimport_resolutions(ofNameBindings andImportResolutions, respectively), simplifying duplicate checking and name resolution.It also unifies the
resolve_name_in_moduleinlib.rswith its namesake inresolve_imports.rs, clarifying and improving the core logic (fixes#31403 and fixes#31404) while maintaining clear future-comparability with shadowable globs (i.e., never reporting that a resolution is aSuccessor isFailingunless this would also be knowable with shadowable globs).Since it fixes#31403, this is technically a [breaking-change], but it is exceedingly unlikely to cause breakage in practice. The following is an example of code that would break:
r? @nrc