Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up[beta] resolve: Implement edition hygiene for imports and absolute paths #56053
Conversation
This comment has been minimized.
This comment has been minimized.
|
r? @nikomatsakis |
rust-highfive
assigned
nikomatsakis
Nov 19, 2018
petrochenkov
added
the
beta-nominated
label
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
|
It would be good to run crater on this if we still have time. @bors try |
This comment has been minimized.
This comment has been minimized.
added a commit
that referenced
this pull request
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov How many other parts of the compiler check the "global" edition? |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
The changes make a lot of sense. To get the ball rolling, pending crater run and code review (I mostly checked tests), I propose that we stabilize the behavior described in #56053 (comment). |
Centril
added
the
T-lang
label
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
|
@rfcbot merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 19, 2018
•
|
Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
|
Assuming crater passes: wow. Incredible work, @petrochenkov! |
This comment has been minimized.
This comment has been minimized.
I'm not sure, will check today. |
This comment has been minimized.
This comment has been minimized.
What I'm concerned most is macro crates using imports and absolute paths to refer solely to extern crates and assuming // Macro crate 2015 (procedural or declarative)
macro mac2015() {
use my_crate::foo;
fn do_things() {
::my_crate::bar();
}
}
---
// User crate 2015
extern crate my_crate;
mac2015!();
---
// User crate 2018 (without hygiene)
mac2015!();In this case despite the change in resolution behavior the macro still works on 2018 edition, and even in more idiomatic way -
With edition hygiene as implemented in this PR, 2018 crates will still need an item referring to the extern crate in the root module when using 2015 macro crates using absolute paths and imports in this way. // User crate 2018 (with hygiene)
use my_crate;
mac2015!();(However, imports |
This comment was marked as outdated.
This comment was marked as outdated.
|
@craterbot run start=master#d08a0a89c6ed1d7c66cfbee2f85721a2d1696885 end=try#4f24eba9a9b426a262d22d2ce72a4139c3860eb6 mode=check-only |
This comment was marked as outdated.
This comment was marked as outdated.
|
|
craterbot
added
the
S-waiting-on-crater
label
Nov 19, 2018
This comment was marked as outdated.
This comment was marked as outdated.
|
|
nikomatsakis
added this to the Rust 2018 Release milestone
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
|
Argh, there's much worse issue - 2015 macros using Possible solutions:
@craterbot abort |
This comment has been minimized.
This comment has been minimized.
|
|
craterbot
added
S-waiting-on-review
and removed
S-waiting-on-crater
labels
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov in solution 1, would we also introduce |
This comment has been minimized.
This comment has been minimized.
|
@Centril |
This comment has been minimized.
This comment has been minimized.
|
@petrochenkov Seems like the cleanest solution to me also; and making it work with |
This comment has been minimized.
This comment has been minimized.
|
One non-spurious regression ( @bors r=nikomatsakis,alexcrichton p=1 |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Nov 26, 2018
This comment was marked as off-topic.
This comment was marked as off-topic.
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
added a commit
that referenced
this pull request
Nov 26, 2018
This comment has been minimized.
This comment has been minimized.
|
@bors retry r- |
bors
added
S-waiting-on-author
S-waiting-on-bors
and removed
S-waiting-on-bors
S-waiting-on-author
labels
Nov 26, 2018
This comment has been minimized.
This comment has been minimized.
|
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
added a commit
to nikomatsakis/rust
that referenced
this pull request
Nov 26, 2018
This comment has been minimized.
This comment has been minimized.
|
Rolled up in #56240. |
added a commit
that referenced
this pull request
Nov 26, 2018
bors
merged commit 581b683
into
rust-lang:beta
Nov 26, 2018
This comment has been minimized.
This comment has been minimized.
|
|
petrochenkov commentedNov 19, 2018
•
edited
The changes in behavior of imports and absolute paths are the most significant breaking changes of 2018 edition.
However, these changes are not covered by edition hygiene, so macros defined by 2015 edition crates expanded in 2018 edition crates are still interpreted in the 2018 edition way when they contain imports or absolute paths.
This means the promise of seamless integration of crates built with different editions, including use of macros, doesn't hold fully.
This PR fixes that and implements edition hygiene for imports and absolute paths, so they behave according to the edition in which they were written, even in macros.
Detailed rules (mostly taken from #50376)
Preface
We keep edition data per-span in the compiler. This means each span knows its edition.
Each identifier has a span, so each identifier knows its edition.
Absolute paths
Explicitly written absolute paths
::ident::...are desugared into something like{{root}}::ident::...in the compiler, where{{root}}is also treated as an identifier.{{root}}inherits its span/hygienic-context from the token::.If the span is from 2015 edition, then
{{root}}is interpreted as the current crate root (crate::...with same hygienic context).If the span is from 2018 edition, then
{{root}}is interpreted as "crate universe" (extern::...).Imports
To resolve an import
use ident::...we need to resolveidentfirst.The idea in this PR is that
identfully knows how to resolve itself.If
ident's span is from 2015 edition, then the identifier is resolved in the current crate root (effectivelycrate::ident::...wherecratehas the same hygienic context asident).If
ident's span is from 2018 edition, then the identifier is resolved in the current scope, without prepending anything (well, at least with uniform paths).There's one corner case in which there's no identifier - prefix-less glob import
use *;.In this case the span is inherited from the token
*.use *;&&is_2015(span(*))->use crate::*;&&span(crate) == span(*).use *;&&is_2018(span(*))-> error.UPDATE
After crater run the rules were updated to include fallback from 2015 edition behavior to 2018 edition behavior, see #56053 (comment) for more details.
Why beta:
- Compatibility of 2015 edition crates with 2018 edition crates, including macros, is one of the main promises of the edition initiative.
- This is technically a breaking change for 2018 edition crates or crates depending on 2018 edition crates.
-
This PR is based on #55884 which hasn't landed on nightly yet :)No longer true (#56042).Previous attempt #50999
Closes #50376
Closes #52848
Closes #53007
r? @ghost