Skip to content
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

Edition-gated keywords #49611

Closed
wants to merge 7 commits into from
Closed

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Apr 3, 2018

This implements edition-gated keywords as discussed in #49610 .

Currently only does async.

@TimNN
Copy link
Contributor

TimNN commented Apr 3, 2018

Your PR failed on Travis. 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.
[00:00:51] configure: rust.quiet-tests     := True
---
[00:42:10] .........................................................................i..........................
[00:42:16] ................i...................................................................................
---
[00:42:52] ............................................................................................i.......
[00:42:59] ................................................................i...................................
---
[00:43:54] .............................................i......................................................
---
[00:47:51] .............................i......................................................................
[00:48:05] ..............................................................i.....................................
[00:48:21] ...............................................i....................................................
[00:48:41] ....................................................................................................
[00:49:03] ....................................................................................................
[00:49:24] ....................................................................................................
[00:49:49] .i................................................................................................i.
[00:50:16] .................................................................................test [run-pass] run-pass/mir_heavy_promoted.rs has been running for over 60 seconds
[00:50:26] ...................
[00:50:57] ....................................................................................................
[00:51:34] ...............................................................ii...................................
[00:52:18] ..........................i....................................................i.ii...test [run-pass] run-pass/saturating-float-casts.rs has been running for over 60 seconds
[00:52:23] ..............
[00:53:04] .......................................................................................iiiiiii......
---
[00:55:03] ....................................i...............................................................
[00:55:11] ....................................................................................................
[00:55:19] ..................i............................................................ii.iii...............
[00:55:26] ....................................................................................................
[00:55:34] ........i..............................i............................................................
[00:55:42] ....................................................................................................
[00:55:49] .....................i..............................................................................
[00:55:57] ....................................................................................................
[00:56:07] ....................................................................................................
[00:56:17] ....................................................................................................
[00:56:29] ....................................................................................................
[00:56:43] ....................................................................................................
[00:56:51] ..............i.....................................................................................
[00:57:01] .................i..ii..............................................................................
[00:57:11] ....................................................................................................
[00:57:21] ....................................................................................................
[00:57:31] ....................................................................................i...............
[00:57:42] ..............................i.....................................................................
---
[00:58:20] ...........................i........................................................................
[00:58:21] ....................................................................i...............................
[00:58:23] ................i.......................................................
---
[00:58:37] ...........i........................
---
[00:59:08] i...i..ii....i.............ii........iii......i..i...i...ii..i..i..ii.....
---
[00:59:11] i.......i......................i......
---
[00:59:49] iiii.......i..i........i..i.i.............i..........iiii...........i...i..........ii.i.i.......ii..
[00:59:50] ....ii...
---
[01:09:06] ...i................................................................................................
---
[01:11:04] ......................................i.............................................................
[01:11:24] ....................................................................................................
[01:11:44] .............................................i......................................................
---
[01:13:18] ........................................................ii..........................................
---
[01:14:23] .............................................................i......................................
---
[01:19:19] ii..................................................................................................
[01:19:38] ....................................................................................................
[01:19:54] ...................iii......i......i...i......i.....................................................
[01:20:04] ....................................................................................................
[01:20:19] ........................................iiii........ii..............................................
[01:20:31] ....................................................................................................
[01:20:47] .......................................................................................i............
---
[01:26:16] error[E0063]: missing field `edition` in initializer of `parse::ParseSess`
[01:26:16]     --> libsyntax/parse/lexer/mod.rs:1800:9
[01:26:16]      |
[01:26:16] 1800 |         ParseSess {
[01:26:16]      |         ^^^^^^^^^ missing `edition`
---
56744 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/incremental/syntax-33oa6nnkk1g08
56740 ./obj/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/incremental/syntax-33oa6nnkk1g08/s-ezrchhwqc2-6lud8n-er8i1tbvu0kw
---
$ cat obj/tmp/sccache.log
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: cannot access /home/travis/Library/Logs/DiagnosticReports/: No such file or directory
travis_time:end:0523cc98:start=1522723986050176972,finish=1522723986063780051,duration=13603079
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:00da3363
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
find: `/home/travis/Library/Logs/DiagnosticReports': No such file or directory
travis_time:end:00da3363:start=1522723986071838592,finish=1522723986080551175,duration=8712583
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0243cb82
$ dmesg | grep -i kill
[   11.753602] init: failsafe main process (1092) killed by TERM signal

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 @TimNN.

@Manishearth
Copy link
Member Author

Ah, made a mistake, these need to parse as keywords not contextual keywords.

@pietroalbini pietroalbini added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 3, 2018
@Manishearth Manishearth force-pushed the edition-kw branch 4 times, most recently from 02403a6 to 62cdeb9 Compare April 4, 2018 16:13
@TimNN
Copy link
Contributor

TimNN commented Apr 4, 2018

Your PR failed on Travis. 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.
Resolving deltas: 100% (611417/611417), completed with 4858 local objects.
---
[00:00:55] configure: rust.quiet-tests     := True
---
[00:05:25] error[E0425]: cannot find value `Await` in module `keywords`
[00:05:25]   --> libsyntax/edition.rs:62:66
[00:05:25]    |
[00:05:25] 62 |             if sym == keywords::Async.name() || sym == keywords::Await.name() {
[00:05:25]    |                                                                  ^^^^^ not found in `keywords`
[00:05:25]
-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libserialize-f27fded04dd31022.rlib --extern log=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblog-7eebd272275b441b.rlib --extern rustc_cratesio_shim=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_cratesio_shim-ea44e45cdc9f4609.so --extern bitflags=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libbitflags-e01ce88b04783514.rlib` (exit code: 101)
[00:05:32] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:05:32] expected success, got: exit code: 101
[00:05:32] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1064:9
[00:05:32] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:05:32] travis_fold:end:stage0-rustc
[00:05:32] travis_time:end:stage0-rustc:start=1522858929934602757,finish=1522858983087959890,duration=53153357133
[00:05:32] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:05:32] Build completed unsuccessfully in 0:01:06
[00:05:32] make: *** [all] Error 1
[00:05:32] Makefile:28: recipe for target 'all' failed
---
113676 ./obj/build/bootstrap/debug/incremental/bootstrap-171j8p2wafl95/s-ezt3nltf6k-zosvln-gd1ykehqltr2

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 @TimNN.

@Manishearth Manishearth force-pushed the edition-kw branch 2 times, most recently from d81e221 to b1d099f Compare April 4, 2018 16:39
@TimNN
Copy link
Contributor

TimNN commented Apr 4, 2018

Your PR failed on Travis. 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.
Resolving deltas: 100% (611426/611426), completed with 4858 local objects.
---
[00:00:46] configure: rust.quiet-tests     := True
---
[00:17:00] error[E0425]: cannot find function `is_reserved_ident` in module `token`
[00:17:00]   --> librustc_passes/ast_validation.rs:44:20
[00:17:00]    |
[00:17:00] 44 |             token::is_reserved_ident(lifetime.ident.without_first_quote()) {
[00:17:00]    |                    ^^^^^^^^^^^^^^^^^ not found in `token`
[00:17:00]
[00:17:00] error[E0425]: cannot find function `is_reserved_ident` in module `token`
[00:17:00]   --> librustc_passes/ast_validation.rs:50:19
[00:17:00]    |
[00:17:00] 50 |         if token::is_reserved_ident(label.without_first_quote()) {
[00:17:00]    |                   ^^^^^^^^^^^^^^^^^ not found in `token`
---
[00:17:00]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name rustc_passes librustc_passes/lib.rs --color always --error-format json --crate-type dylib --emit=dep-info,link -C prefer-dynamic -C opt-level=2 -C metadata=d6aeea102ad4d097 -C extra-filename=-d6aeea102ad4d097 --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps --extern rustc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc-b061046bb39a474d.so --extern syntax_pos=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_pos-069d1433ad059ff1.so --extern log=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblog-7eebd272275b441b.rlib --extern syntax=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax-67023beb7edf290b.so --extern rustc_errors=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_errors-d823127e323fa243.so --extern rustc_const_math=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_const_math-2cbdd37d611532dc.so --extern rustc_data_structures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_data_structures-1e725c22de2888b8.so --extern rustc_mir=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_mir-1b4c3b4ba4ec5832.so -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/backtrace-sys-751752dec0960570/out/.libs -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/miniz-sys-07c608814ba8d6ba/out` (exit code: 101)
[00:17:00] warning: build failed, waiting for other jobs to finish...
[00:17:13] error: build failed
[00:17:13] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1064:9
[00:17:13] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:17:13] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:17:13] expected success, got: exit code: 101
[00:17:13] travis_fold:end:stage0-rustc
[00:17:13] travis_time:end:stage0-rustc:start=1522859599377471700,finish=1522860352901180311,duration=753523708611
[00:17:13] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:17:13] Build completed unsuccessfully in 0:12:46
[00:17:13] Makefile:28: recipe for target 'all' failed
[00:17:13] make: *** [all] Error 1
---
$ dmesg | grep -i kill
[   10.155019] init: failsafe main process (1096) killed by TERM signal

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 @TimNN.

@TimNN
Copy link
Contributor

TimNN commented Apr 4, 2018

Your PR failed on Travis. 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.
Resolving deltas: 100% (611428/611428), completed with 4859 local objects.
---
[00:00:48] configure: rust.quiet-tests     := True
---
[00:16:29] error: unused import: `syntax::parse::token`
[00:16:29]   --> librustc_passes/ast_validation.rs:24:5
---
[00:16:29]    = note: #[deny(unused_imports)] implied by #[deny(warnings)]
---
[00:16:30]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name rustc_passes librustc_passes/lib.rs --color always --error-format json --crate-type dylib --emit=dep-info,link -C prefer-dynamic -C opt-level=2 -C metadata=d6aeea102ad4d097 -C extra-filename=-d6aeea102ad4d097 --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps --extern syntax_pos=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax_pos-069d1433ad059ff1.so --extern rustc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc-b061046bb39a474d.so --extern rustc_mir=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_mir-1b4c3b4ba4ec5832.so --extern rustc_const_math=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_const_math-2cbdd37d611532dc.so --extern rustc_errors=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_errors-d823127e323fa243.so --extern log=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/liblog-7eebd272275b441b.rlib --extern rustc_data_structures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/librustc_data_structures-1e725c22de2888b8.so --extern syntax=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps/libsyntax-67023beb7edf290b.so -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/backtrace-sys-751752dec0960570/out/.libs -L native=/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/build/miniz-sys-07c608814ba8d6ba/out` (exit code: 101)
[00:16:30] warning: build failed, waiting for other jobs to finish...
[00:16:51] error: build failed
[00:16:51] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1064:9
[00:16:51] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:16:51] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "--release" "--locked" "--color" "always" "--features" " jemalloc" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
[00:16:51] expected success, got: exit code: 101
[00:16:51] travis_fold:end:stage0-rustc
[00:16:51] travis_time:end:stage0-rustc:start=1522860389190946911,finish=1522861126535917553,duration=737344970642
[00:16:51] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:16:51] Build completed unsuccessfully in 0:12:30
[00:16:51] Makefile:28: recipe for target 'all' failed
[00:16:51] make: *** [all] Error 1
---
$ ls -lat $HOME/Library/Logs/DiagnosticReports/
ls: cannot access /home/travis/Library/Logs/DiagnosticReports/: No such file or directory
travis_time:end:065d2f3e:start=1522861127184583367,finish=1522861127192401713,duration=7818346
travis_fold:end:after_failure.2
travis_fold:start:after_failure.3
travis_time:start:00093b00
$ find $HOME/Library/Logs/DiagnosticReports -type f -name '*.crash' -not -name '*.stage2-*.crash' -not -name 'com.apple.CoreSimulator.CoreSimulatorService-*.crash' -exec printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" {} \; -exec head -750 {} \; -exec echo travis_fold":"end:crashlog \; || true
find: `/home/travis/Library/Logs/DiagnosticReports': No such file or directory
travis_time:end:00093b00:start=1522861127200332776,finish=1522861127209253374,duration=8920598
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:17f6e5e3
$ dmesg | grep -i kill
[   11.461824] init: failsafe main process (1097) killed by TERM signal

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 @TimNN.

@Manishearth Manishearth changed the title [WIP] Edition-gated keywords Edition-gated keywords Apr 4, 2018
@TimNN
Copy link
Contributor

TimNN commented Apr 4, 2018

Your PR failed on Travis. 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.
Resolving deltas: 100% (611484/611484), completed with 4863 local objects.
---
[00:00:47] configure: rust.quiet-tests     := True
---
[00:04:38] tidy error: /checkout/src/test/run-pass/edition-keywords-2018.rs:24: trailing whitespace
[00:04:40] some tidy checks failed
[00:04:40]
[00:04:40]
[00:04:40] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:40] expected success, got: exit code: 1
[00:04:40]
[00:04:40]
[00:04:40] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:40] Build completed unsuccessfully in 0:01:54
[00:04:40] Makefile:79: recipe for target 'tidy' failed
[00:04:40] make: *** [tidy] Error 1

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 @TimNN.

@Manishearth
Copy link
Member Author

Manishearth commented Apr 4, 2018

No longer WIP

r? @nikomatsakis or @estebank

I'm going to handle the lint elsewhere; because it's got some impl challenges that we have to work out.

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 5, 2018
@bors
Copy link
Contributor

bors commented Apr 6, 2018

☔ The latest upstream changes (presumably #49154) made this pull request unmergeable. Please resolve the merge conflicts.

// After modifying this list adjust `is_special_ident`, `is_used_keyword`/`is_unused_keyword`,
// this should be rarely necessary though if the keywords are kept in alphabetic order.
// After modifying this list adjust `is_special`, `is_used_keyword`/`is_unused_keyword`
// velow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*below

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks basically good, except I think we need some more tests... am I wrong? It feels like we're not testing all the combinations. For example, there is no Epoch 2018 code testing macros created by an Epoch 2018 auxiliary crate, and vice versa. I'd like to have those tests.

@@ -41,13 +40,13 @@ impl<'a> AstValidator<'a> {
keywords::StaticLifetime.name(),
keywords::Invalid.name()];
if !valid_names.contains(&lifetime.ident.name) &&
token::is_reserved_ident(lifetime.ident.without_first_quote()) {
lifetime.ident.without_first_quote().is_reserved() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Pre-existing, but can you move the { to the next line (and/or move the && to next line)? I find the condition blends in with body in this scenario. (I think rustfmt puts the && on next line and the {...? but I forget)

self.name <= self::keywords::Underscore.name()
}

/// Returns `true` if the token is a keyword used in the language.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused about this. At minimum, can we update the comments to describe how this interacts with editions...? It seems like this is "assuming 2015 Edition"?

pub fn main() {
let mut r#async = 1;

r#async = consumes_async!(r#async);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a compile-fail test with consumes_async!(async)? and so forth?

/// Returns `true` if the token is a keyword used in the language.
#[inline]
pub fn is_used_keyword(self) -> bool {
self.name >= self::keywords::As.name() && self.name <= self::keywords::While.name()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus...oh dear this is brittle. But ok, pre-existing. =) Feels like the macro should be able to generate these constants though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought hard about figuring out a way to do that; it's possible with dummy symbols but otherwise not really. Easier with a proc macro.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dummy symbols doesn't necessarily seem so bad to me though -- but anyway separate.

@Manishearth
Copy link
Member Author

Updated

@nikomatsakis
Copy link
Contributor

r=me but it occurs to me that @petrochenkov would probably like to take a look at this

r? @petrochenkov

@Manishearth
Copy link
Member Author

@petrochenkov (poke)

#[inline]
pub fn is_reserved(self) -> bool {
self.is_special() || self.is_used_keyword() || self.is_unused_keyword()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these functions are moved to methods, then they should rather become methods of Symbol (aka Name) than Ident.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we let that be a mentored followup?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.


pub fn main() {
let _ = consumes_async!(async);
//~^ ERROR no rules expected the token `async`
Copy link
Contributor

@petrochenkov petrochenkov Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct behavior, macros' left hand sides don't care about keywordy-ness status of tokens they match. They can equally well match tokens from code snippets written in any Rust editions or even in C++, Java or mix of both. (See #49520)
So the "pretend these are raw even if they aren't" shortcut doesn't generally work.

The correct solution requires a bit more effort, but not significantly more, thankfully:

  • Tweak all instances of is_keyword involving edition-dependent keywords (no such instances right now! hurray)
  • Make all instances of is_reserved_ident (maybe all 13 of them) edition-dependent if the result makes difference for edition-dependent keywords.
  • Probably tweak metadata serialization/deserialization code for macros' right sides, not sure about details of this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree; we're going to ask macro consumers to rustfix usages of async in macro invocations as well, because crates may be using those tokens verbatim (slurping them via tt and then pasting them out) as well as using them to match keywords.

I find it would be inconsistent if some macros stopped working in the 2018 epoch when fed async but not others.

thoughts, @nikomatsakis ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, FWIW for the lint we're going to have to tristate the bool field anyway, as a "specified raw, keyword but not on current epoch, and keyword on current epoch", and we can have the macro matcher consider the last two to be equal. But I'm not certain.

Copy link
Contributor

@petrochenkov petrochenkov Apr 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not only about macros, what bothers me is that the "pretend these are raw" implementation works on fundamentally wrong level. There are no keywords in the token world, that's why neither lexer nor macros weren't concerned about keywords previously. Keywords appear only when we introduce some grammar on those tokens, so the edition-keyword problem need to be solved on grammar/syntax level as well.

This means is_reserved_ident locally and I think deserialization (or/and maybe expansion?) of macros from other crates. Any cross-crate-cross-edition compatibility for keywords would involve some amount of guessing (including this PR's) but we should be able to guess better if we are doing it at the right level.

I need some time to flesh this out, maybe make a prototype (this shouldn't be a large change), I'm not satisfied with what this PR does at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so --- in the changes I haven't made yet (but planned to for the linting step once we figure that out better), there will be three states:

  • actually raw
  • allowed to be an ident (specified as non-raw on an edition where it is not keyword)
  • not allowed to be an ident (specified as non-raw on an edition where it is a keyword)

This will mean that we no longer pretend things are raw, and we can do equality differently in different contexts.

For epoch hygiene to work we basically have to do this at the token level, though. I don't like having keywords pollute the lexer, but I don't see a better way of doing this that handles macros well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting what exactly? Identifiers that are not keywords in this edition, but will be keywords in the next edition?
Lints are attached to NodeIds and we don't have those in the parser yet and we don't have lint attribute "scopes" in the parser either.
I think we can just visit all identifiers remaining in the AST again during the early lint pass and report those with zero hygiene context (current crate) and "keywordy" name. This may leave some identifiers unreported, but that's not a big deal probably.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd also need to lint stuff in macro defs and invocations, which complicates things.

As an edition breakage it's important that we lint everything.

Copy link
Contributor

@petrochenkov petrochenkov Apr 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding reporting "really everything", I think this is more of a problem with lint infrastructure rather than with edition keywords specifically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but it's not clear how to fix it.

The proposal we had was that the parser can keep track of lint levels for specific lints and we just lint in the parser.

We can also stash lints by span as suggested by @oli-obk

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(though that still requires some way of visiting them)

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2018
@Manishearth Manishearth added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 13, 2018
@bors
Copy link
Contributor

bors commented Apr 17, 2018

☔ The latest upstream changes (presumably #50033) made this pull request unmergeable. Please resolve the merge conflicts.

@Manishearth Manishearth mentioned this pull request Apr 18, 2018
5 tasks
@kennytm kennytm added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 30, 2018
@nikomatsakis
Copy link
Contributor

How does this relate to #50307?

@Manishearth
Copy link
Member Author

moved to #50307

@Manishearth Manishearth closed this May 3, 2018
bors added a commit that referenced this pull request May 18, 2018
Implement edition hygiene for keywords

Determine "keywordness" of an identifier in its hygienic context.
cc #49611

I've resurrected `proc` as an Edition-2015-only keyword for testing purposes, but it should probably be buried again. EDIT: `proc` is removed again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants