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

Less maybe_whole_expr, take 2 #126571

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Jun 17, 2024

I first tried this in #107550. I now think it's worth doing again, as a precursor to #124141.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 17, 2024
@petrochenkov
Copy link
Contributor

This needs a crater run because the error is now reported even under #[cfg(FALSE)].
@bors try

@petrochenkov petrochenkov added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 17, 2024
@bors
Copy link
Contributor

bors commented Jun 17, 2024

⌛ Trying commit 74a18a0 with merge 397f895...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 17, 2024
… r=<try>

Less `maybe_whole_expr`, take 2

I first tried this in rust-lang#107550. I now think it's worth doing again, as a precursor to #1241414.

r? `@petrochenkov`
@bors
Copy link
Contributor

bors commented Jun 17, 2024

☀️ Try build successful - checks-actions
Build commit: 397f895 (397f8958d101b259f6baaf92d107d770c95c3ce0)

@petrochenkov
Copy link
Contributor

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-126571 created and queued.
🤖 Automatically detected try build 397f895
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🚧 Experiment pr-126571 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-126571 is completed!
📊 927 regressed and 7 fixed (473144 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jun 20, 2024
@nnethercote
Copy link
Contributor Author

nnethercote commented Jun 20, 2024

Lots of crater failures. A quick scan indicates that the unic-ucd-segment crate is responsible for most of the failures. I checked and found that it builds ok with the first commit applied, but fails with the second commit. It has some complicated multi-level declarative macros. If I change parse_literal_maybe_minus to also handle ExprKind::MacCall (in the same way it handles ExprKind::Lit) then unic-ucd-segment compiles again.

@nnethercote
Copy link
Contributor Author

rustsec also fails, and it needs ExprKind::Path to be handled in parse_literal_maybe_minus.

It's interesting that can_begin_literal_maybe_minus does not include ExprKind::{MacCall,Path}.

@petrochenkov
Copy link
Contributor

In the token based model neither mac!() nor path::to::somewhere are any close to literals, so I don't expect this to work even if the none-delimited groups become "untyped" some time after the removal of nonterminals.
So these cases should probably report a deprecation lint.

@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 Jun 20, 2024
@nnethercote
Copy link
Contributor Author

The ExprKind::MacCall case for unic-ucd-segment looks like stringify!(CR).

The ExprKind::Path case in rustsec is just an identifier YEAR_MIN, not a full path.

I will update the code to allow these two ExprKinds, and then do another crater run on the failing crates, to see if there are any other ExprKinds occurring.

@nnethercote
Copy link
Contributor Author

Hmm, looking at the ExprKind::Path case some more, I think the real problem is in rustc. Consider this code:

macro_rules! range {
    ($min:expr, $max:expr) => {
        $min ..= $max
    }
}

const MAX: u32 = 10;

fn main() {
    match 3 {
        range!(0, MAX) => {}
        _ => {}
    }
}

It compiles fine with stable rustc. With the original version of this PR applied (i.e. without ExprKind::Path handling added to parse_maybe_literal_minus) it fails like this:

error: unexpected token: expression `MAX`
  --> p.rs:3:18
   |
3  |         $min ..= $max
   |                  ^^^^
...
11 |         range!(0, MAX) => {}
   |         --------------
   |         |
   |         this macro call doesn't expand to a pattern
   |         in this macro invocation
   |
   = note: this error originates in the macro `range` (in Nightly builds, run with -Z macro-backtrace for more info)

Adding ExprKind::Path handling to parse_maybe_literal_minus makes it compile again, but that's not the right solution. The real problem is in parse_pat_range_end:

let bound = if self.check_inline_const(0) {
self.parse_const_block(self.token.span, true)
} else if self.check_path() {
let lo = self.token.span;
let (qself, path) = if self.eat_lt() {
// Parse a qualified path
let (qself, path) = self.parse_qpath(PathStyle::Pat)?;
(Some(qself), path)
} else {
// Parse an unqualified path
(None, self.parse_path(PathStyle::Pat)?)
};
let hi = self.prev_token.span;
Ok(self.mk_expr(lo.to(hi), ExprKind::Path(qself, path)))
} else {
self.parse_literal_maybe_minus()
}?;

What happens in check_path? It fails! Because it relies on Token::is_path_start, which relies on Token::is_whole_path, which succeeds for NtPath but not for NtExpr(... ExprKind::Path ...).

So then we fall through to parse_maybe_literal_minus, which succeeds on stable because it accepts any NtExpr, but fails with this PR because it doesn't accept NtExpr(... ExprKind::Path ...).

The real solution is that parse_pat_range_end should handle NtExpr(... ExprKind::Path ...) before calling parse_maybe_literal_minus. There's almost certainly a similar problem for the start of pattern ranges.

I don't know yet if the MacCall case is like this or not.

@nnethercote
Copy link
Contributor Author

While looking at the ExprKind::Path stuff more closely, I found this in parse_path_inner:

maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner()));
if let token::Interpolated(nt) = &self.token.kind {
if let token::NtTy(ty) = &**nt {
if let ast::TyKind::Path(None, path) = &ty.kind {
let path = path.clone();
self.bump();
return Ok(reject_generics_if_mod_style(self, path));
}
}
}

It accepts NtPath and NtTy(... TyKind::Path ...). @dtolnay added the latter part in #91150. I think it will need to allow NtExpr(... ExprKind::Path ...) to address the problem I described in the previous comment. And then I wonder if NtPat(... PatKind::Path ...) should also be allowed.

And remove the `NtPath` and `NtBlock` cases in
`parse_literal_maybe_minus`, because they are unnecessary.
@nnethercote
Copy link
Contributor Author

@bors try

@bors
Copy link
Contributor

bors commented Jun 25, 2024

⌛ Trying commit 379b761 with merge 0ecd73a...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 25, 2024
… r=<try>

Less `maybe_whole_expr`, take 2

I first tried this in rust-lang#107550. I now think it's worth doing again, as a precursor to rust-lang#124141.

r? `@petrochenkov`
@bors
Copy link
Contributor

bors commented Jun 25, 2024

☀️ Try build successful - checks-actions
Build commit: 0ecd73a (0ecd73ac69e42f0c7915911f31169e93143ae55d)

@nnethercote
Copy link
Contributor Author

Getting the path stuff right is a bit tricky, so I think it's worth merging just the first commit here. Let's re-do the failures from the last crater run:

@craterbot check p=1 crates=https://crater-reports.s3.amazonaws.com/pr-126571/retry-regressed-list.txt

@craterbot
Copy link
Collaborator

👌 Experiment pr-126571-1 created and queued.
🤖 Automatically detected try build 0ecd73a
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 25, 2024
@craterbot
Copy link
Collaborator

🚧 Experiment pr-126571-1 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-126571-1 is completed!
📊 0 regressed and 0 fixed (927 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jun 26, 2024
@nnethercote
Copy link
Contributor Author

No failures when re-running the crater failures with just the first commit applied. I think it's worth merging now and thinking about the additional restrictions on ExprKind in a follow-up. @petrochenkov, what do you think?

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 26, 2024

📌 Commit 379b761 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2024
@nnethercote
Copy link
Contributor Author

@bors rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 26, 2024
…2, r=petrochenkov

Less `maybe_whole_expr`, take 2

I first tried this in rust-lang#107550. I now think it's worth doing again, as a precursor to rust-lang#124141.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 26, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#125016 (Update compiler_builtins to 0.1.113)
 - rust-lang#126571 (Less `maybe_whole_expr`, take 2)
 - rust-lang#126721 (coverage: Make `#[coverage(..)]` apply recursively to nested functions)
 - rust-lang#126928 (Some `Nonterminal` removal precursors)
 - rust-lang#126929 (Remove `__rust_force_expr`.)
 - rust-lang#126941 (Migrate `run-make/llvm-ident` to `rmake.rs`)
 - rust-lang#126970 (Simplify `str::clone_into`)
 - rust-lang#126980 (set self.is_known_utf8 to false in extend_from_slice)
 - rust-lang#126983 (Remove `f16` and `f128` ICE paths from smir)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 26, 2024
…2, r=petrochenkov

Less `maybe_whole_expr`, take 2

I first tried this in rust-lang#107550. I now think it's worth doing again, as a precursor to rust-lang#124141.

r? ``@petrochenkov``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 26, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#125016 (Update compiler_builtins to 0.1.113)
 - rust-lang#126571 (Less `maybe_whole_expr`, take 2)
 - rust-lang#126692 (patch `rust-lld` and `ld.lld` on NixOS)
 - rust-lang#126721 (coverage: Make `#[coverage(..)]` apply recursively to nested functions)
 - rust-lang#126928 (Some `Nonterminal` removal precursors)
 - rust-lang#126929 (Remove `__rust_force_expr`.)
 - rust-lang#126970 (Simplify `str::clone_into`)
 - rust-lang#126980 (set self.is_known_utf8 to false in extend_from_slice)
 - rust-lang#126983 (Remove `f16` and `f128` ICE paths from smir)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 27, 2024
Rollup of 6 pull requests

Successful merges:

 - rust-lang#126571 (Less `maybe_whole_expr`, take 2)
 - rust-lang#126721 (coverage: Make `#[coverage(..)]` apply recursively to nested functions)
 - rust-lang#126928 (Some `Nonterminal` removal precursors)
 - rust-lang#126929 (Remove `__rust_force_expr`.)
 - rust-lang#126980 (set self.is_known_utf8 to false in extend_from_slice)
 - rust-lang#126983 (Remove `f16` and `f128` ICE paths from smir)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5ec93b8 into rust-lang:master Jun 27, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jun 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 27, 2024
Rollup merge of rust-lang#126571 - nnethercote:less-maybe_whole-expr-2, r=petrochenkov

Less `maybe_whole_expr`, take 2

I first tried this in rust-lang#107550. I now think it's worth doing again, as a precursor to rust-lang#124141.

r? ```@petrochenkov```
@nnethercote nnethercote deleted the less-maybe_whole-expr-2 branch June 27, 2024 23:33
nnethercote added a commit to nnethercote/rust that referenced this pull request Jul 16, 2024
princess-entrapta pushed a commit to princess-entrapta/rust that referenced this pull request Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants