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 upChanges to name resolution #1560
Conversation
This comment has been minimized.
This comment has been minimized.
|
I am especially excited about the implications for macro resolution, since these are, as of now, really annoying. Having them fitting better into the module system would be an awesome change. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
This RFC, specifically the ability to import the same item multiple times without conflict, solves one of the bigger unresolved pains in Diesel. The ability to have a local name shadow an import feels like a loss to me, though. When you take macros into account, it's possible for defining a struct to silently break something, with a fairly non-local error. I'd much prefer something akin to
|
This comment has been minimized.
This comment has been minimized.
|
Would this be legal as a result of this RFC? mod foo {
pub mod apple {
use super::*;
pub type Carrot = u32;
}
pub mod banana {
use super::*;
pub type Carrot = u32;
}
pub use self::apple::*;
pub use self::banana::*;
}
fn main() {
let x: foo::Carrot = 5;
} |
This comment has been minimized.
This comment has been minimized.
|
@retep998
(Or even nicer, on >=1.9 with two levels of indirection: gist) |
petrochenkov
reviewed
Mar 29, 2016
|
|
||
| ### Privacy | ||
|
|
||
| In order to resolve imports (and in the future for macro privacy), we must be |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Mar 29, 2016
Contributor
To clarify, this RFC doesn't propose the ability to leak private items through macros, right? I.e.
struct S;
pub macro s {
// Still an error, privacy is checked in the context
// of macro expansion and not macro definition,
// private `S` cannot be leaked.
() => (S)
}
This comment has been minimized.
This comment has been minimized.
nrc
Mar 29, 2016
Author
Member
No, there are no user-visible changes to privacy or macros in this RFC. I do plan to propose this later though.
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov The reason I ask is due to winapi, where sometimes two (or more!) headers will both define the same typedef, and I'd rather not have to pick a header to be the canonical one (nevermind that if I want to be able to cfg out some modules, I'd have really complex cfg conditions to re-enable the non-canonical typedefs). If I define a typedef via |
nrc
added
the
T-lang
label
Mar 29, 2016
nrc
self-assigned this
Mar 29, 2016
This comment has been minimized.
This comment has been minimized.
|
@retep998 There is a difference between One could imagine erasing aliases earlier in the compilation process and thus making them transparent to name resolution (and the shadowing rules). I think that should be a separate RFC and I'm not sure if it is a good idea or not. |
This comment has been minimized.
This comment has been minimized.
|
I suspect that would be a bad idea if extended to generic |
alexcrichton
referenced this pull request
Mar 30, 2016
Merged
Add support for 128-bit integers #1504
eddyb
reviewed
Apr 2, 2016
| the lowering from AST to HIR, so the HIR is a name-resolved data structure. Or, | ||
| name lookup could be done lazily (probably with some caching) so no tables | ||
| binding names to definitions are kept. I prefer the first option, but this is | ||
| not really in scope for this RFC. |
This comment has been minimized.
This comment has been minimized.
eddyb
Apr 2, 2016
Member
When in doubt, combine your options: lazy lowering (similar to HIR+Ty -> HAIR for MIR building), triggered by type collection (top-level items) or type inference (expressions inside functions) that uses binding tables to determine what nodes to produce.
Ericson2314
reviewed
Apr 5, 2016
| where name resolution currently takes place. | ||
|
|
||
| To resolve imports, the algorithm proceeds as follows: we start by parsing as | ||
| much of the program as we can; like today we don't parse macros. When we find |
This comment has been minimized.
This comment has been minimized.
Ericson2314
Apr 5, 2016
Contributor
What exactly does this mean? Don't parse macro definitions? invocations? the result of macro expansion?
This comment has been minimized.
This comment has been minimized.
eddyb
Apr 6, 2016
Member
We don't attempt to parse the invocations of a macro in any way (other than storing them as TTs).
This comment has been minimized.
This comment has been minimized.
Ericson2314
Apr 6, 2016
•
Contributor
Ok, that of the 3 makes the most sense but just wanted to check :)
This comment has been minimized.
This comment has been minimized.
I think this is required for basic soundness, not just peace of mind. Say two macro use sites, |
This comment has been minimized.
This comment has been minimized.
|
Worse yet, if |
xeno-by
reviewed
Apr 8, 2016
|
|
||
| The macro changes are not backwards compatible, which means having a macro | ||
| system 2.0. If users are reluctant to use that, we will have two macro systems | ||
| forever. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Would this be a good time to fix rust-lang/rust#26775 ? |
This comment has been minimized.
This comment has been minimized.
jseyfried
commented
Apr 10, 2016
|
@Ericson2314 #26775 was fixed by #31362. |
This comment has been minimized.
This comment has been minimized.
|
Also does https://github.com/nrc/rfcs/blob/aac02932e3c3b5749d1c15b83813ca1c3ef00281/text/0000-name-resolution.md#non-public-imports apply to (non-pub) |
This comment has been minimized.
This comment has been minimized.
jseyfried
commented
Apr 10, 2016
|
@Ericson2314 Perhaps you are using stable? The fix is on beta but hasn't landed on stable yet. If it doesn't work for you on beta or nightly, could you provide an example?
|
This comment has been minimized.
This comment has been minimized.
|
@jseyfried edited my comment but my mistake it does indeed work; for the record I am on nightly. |
This comment has been minimized.
This comment has been minimized.
|
Ah and yes I somehow also missed the current semantics of |
This comment has been minimized.
This comment has been minimized.
|
I'm finding it hard to reason about the precise model proposed here, I admit. I wonder if there is a way to make the write up a bit more declarative. In any case, I think the only change here that I found problematic when working on my name resolution prototype was this one:
I think the problem had to do with the possibility that, in some round, we would bring in a name from a glob that would later have to be shadowed, but we didn't know at the time whether it ought to be shadowed or not. I'll try to see if I can come up with a precise example. |
This comment has been minimized.
This comment has been minimized.
jseyfried
commented
Apr 12, 2016
•
This is primarily why we currently distinguish between mod bar {
pub fn foo() {}
pub use baz::*;
}
mod baz {
pub use bar::*;
}
pub mod foo {}
mod quux {
pub use super::*; // This defines `quux::foo` in the type namespace ...
pub use bar::foo;
//^ ... but we can't know that until we know that `bar::foo` fails in the type namespace,
//| which requires us to detect that `bar -> baz -> bar -> ...` is a glob cycle.
}If we changed the semantics so that a single import (and perhaps also an ordinary item for consistency) always shadowed glob imports in both namespaces (even if it only defined one of them), then we wouldn't need to distinguish between failing and indeterminate resolutions. I think this change would cause too much breakage to be practical, but if you'd like I could implement it and we could do a crater run to see if doing a warning cycle would be feasible. |
This comment has been minimized.
This comment has been minimized.
jseyfried
commented
Apr 12, 2016
|
Also, while the complexity is unfortunate, it does generalize well in the presence of unexpanded macros -- we would just have to report that an otherwise failing name in a module with unexpanded macros is indeterminate. |
This was referenced Apr 14, 2016
nikomatsakis
referenced this pull request
Jul 29, 2016
Closed
Tracking issue for changes to name resolution (RFC 1560) #35120
This comment has been minimized.
This comment has been minimized.
|
Tracking issue: rust-lang/rust#35120 If you'd like to keep following the development of this feature, please subscribe to that issue, thanks! :) |
nikomatsakis
merged commit 6098278
into
rust-lang:master
Jul 29, 2016
jseyfried
referenced this pull request
Jul 29, 2016
Merged
resolve: Exclude inaccessible names from single imports #35063
petrochenkov
reviewed
Jul 29, 2016
| ### Multiple imports of the same binding | ||
|
|
||
| A name may be imported multiple times and used if both names bind to the same | ||
| item. E.g., |
This comment has been minimized.
This comment has been minimized.
petrochenkov
Jul 29, 2016
Contributor
I forgot to mention a drawback - names (and paths) don't have a definitive "point of introduction" anymore.
I.e. you can't say "the name was defined/imported here", there is always can be >1 of such definition/import points.
Unless all of these points are tracked, this complicates, for example, stability checking for reexports or error reporting if errors refer to these points.
nrc commentedMar 29, 2016
•
edited
Some internal and language-level changes to name resolution.
Internally, name resolution will be split into two parts - import resolution and
name lookup. Import resolution is moved forward in time to happen in the same
phase as parsing and macro expansion. Name lookup remains where name resolution
currently takes place (that may change in the future, but is outside the scope
of this RFC). However, name lookup can be done earlier if required (importantly
it can be done during macro expansion to allow using the module system for
macros, also outside the scope of this RFC). Import resolution will use a new
algorithm.
The observable effects of this RFC (i.e., language changes) are some increased
flexibility in the name resolution rules, especially around globs and shadowing.
rendered