or-patterns: Uniformly use PatKind::Or
in AST & Fix/Cleanup resolve by Centril · Pull Request #64111 · rust-lang/rust (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation25 Commits27 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Following up on work in #63693 and #61708, in this PR we:
- Uniformly use
PatKind::Or(...)
in AST:- Change
ast::Arm.pats: Vec<P<Pat>>
=>ast::Arm.pat: P<Pat>
- Change
ast::ExprKind::Let.0: Vec<P<Pat>>
=>ast::ExprKind::Let.0: P<Pat>
- Change
- Adjust
librustc_resolve/late.rs
to correctly handle or-patterns at any level of nesting as a result.
In particular, the already-bound check which rejects e.g.let (a, a);
now accounts for or-patterns. The consistency checking (ensures no missing bindings and binding mode consistency) also now accounts for or-patterns. In the process, a bug was found in the current compiler which allowed:
enum E { A(T, T), B(T) }
use E::*;
fn foo() {
match A(0, 1) {
B(mut a) | A(mut a, mut a) => {}
}
}
The new algorithms took a few iterations to get right. I tried several clever schemes but ultimately a version based on a stack of hashsets and recording product/sum contexts was chosen since it is more clearly correct. - Clean up
librustc_resolve/late.rs
by, among other things, using a newwith_rib
function to better ensure stack dicipline. - Do not push the change in AST to HIR for now to avoid doing too much in this PR. To cope with this, we introduce a temporary hack in
rustc::hir::lowering
(clearly marked in the diff).
cc #54883
cc @dlrobertson @matthewjasper
r? @petrochenkov
This comment has been minimized.
Centril 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
Addressed the comments, hopefully. :)
r=me with the remaining comment addressed
📌 Commit 359c3c0865c8a929925972675eb58200cec07133 has been approved by petrochenkov
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-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
This comment has been minimized.
Tested locally with ./x.py test src/liballoc --stage 1
before and after rebase. Cannot reproduce the failure. Let's see if rebase changes anything in CI.
Centril added a commit to Centril/rust that referenced this pull request
Centril added a commit to Centril/rust that referenced this pull request
📌 Commit 16ba502 has been approved by petrochenkov
Centril added a commit to Centril/rust that referenced this pull request
…ochenkov
or-patterns: Uniformly use PatKind::Or
in AST & Fix/Cleanup resolve
Following up on work in rust-lang#63693 and rust-lang#61708, in this PR we:
Uniformly use
PatKind::Or(...)
in AST:Change
ast::Arm.pats: Vec<P<Pat>>
=>ast::Arm.pat: P<Pat>
Change
ast::ExprKind::Let.0: Vec<P<Pat>>
=>ast::ExprKind::Let.0: P<Pat>
Adjust
librustc_resolve/late.rs
to correctly handle or-patterns at any level of nesting as a result.In particular, the already-bound check which rejects e.g.
let (a, a);
now accounts for or-patterns. The consistency checking (ensures no missing bindings and binding mode consistency) also now accounts for or-patterns. In the process, a bug was found in the current compiler which allowed:enum E<T> { A(T, T), B(T) } use E::*; fn foo() { match A(0, 1) { B(mut a) | A(mut a, mut a) => {} } }
The new algorithms took a few iterations to get right. I tried several clever schemes but ultimately a version based on a stack of hashsets and recording product/sum contexts was chosen since it is more clearly correct.
Clean up
librustc_resolve/late.rs
by, among other things, using a newwith_rib
function to better ensure stack dicipline.Do not push the change in AST to HIR for now to avoid doing too much in this PR. To cope with this, we introduce a temporary hack in
rustc::hir::lowering
(clearly marked in the diff).
cc rust-lang#54883 cc @dlrobertson @matthewjasper r? @petrochenkov
Centril added a commit to Centril/rust that referenced this pull request
…ochenkov
or-patterns: Uniformly use PatKind::Or
in AST & Fix/Cleanup resolve
Following up on work in rust-lang#63693 and rust-lang#61708, in this PR we:
Uniformly use
PatKind::Or(...)
in AST:Change
ast::Arm.pats: Vec<P<Pat>>
=>ast::Arm.pat: P<Pat>
Change
ast::ExprKind::Let.0: Vec<P<Pat>>
=>ast::ExprKind::Let.0: P<Pat>
Adjust
librustc_resolve/late.rs
to correctly handle or-patterns at any level of nesting as a result.In particular, the already-bound check which rejects e.g.
let (a, a);
now accounts for or-patterns. The consistency checking (ensures no missing bindings and binding mode consistency) also now accounts for or-patterns. In the process, a bug was found in the current compiler which allowed:enum E<T> { A(T, T), B(T) } use E::*; fn foo() { match A(0, 1) { B(mut a) | A(mut a, mut a) => {} } }
The new algorithms took a few iterations to get right. I tried several clever schemes but ultimately a version based on a stack of hashsets and recording product/sum contexts was chosen since it is more clearly correct.
Clean up
librustc_resolve/late.rs
by, among other things, using a newwith_rib
function to better ensure stack dicipline.Do not push the change in AST to HIR for now to avoid doing too much in this PR. To cope with this, we introduce a temporary hack in
rustc::hir::lowering
(clearly marked in the diff).
cc rust-lang#54883 cc @dlrobertson @matthewjasper r? @petrochenkov
bors added a commit that referenced this pull request
Rollup of 5 pull requests
Successful merges:
- #63676 (Use wasi crate for Core API)
- #64094 (Improve searching in rustdoc and add tests)
- #64111 (or-patterns: Uniformly use
PatKind::Or
in AST & Fix/Cleanup resolve) - #64156 (Assume non-git LLVM is fresh if the stamp file exists)
- #64175 (Fix invalid span generation when it should be div)
Failed merges:
- #63806 (Upgrade rand to 0.7)
r? @ghost
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request
…ochenkov
or-patterns: Uniformly use PatKind::Or
in AST & Fix/Cleanup resolve
Following up on work in rust-lang#63693 and rust-lang#61708, in this PR we:
Uniformly use
PatKind::Or(...)
in AST:Change
ast::Arm.pats: Vec<P<Pat>>
=>ast::Arm.pat: P<Pat>
Change
ast::ExprKind::Let.0: Vec<P<Pat>>
=>ast::ExprKind::Let.0: P<Pat>
Adjust
librustc_resolve/late.rs
to correctly handle or-patterns at any level of nesting as a result.In particular, the already-bound check which rejects e.g.
let (a, a);
now accounts for or-patterns. The consistency checking (ensures no missing bindings and binding mode consistency) also now accounts for or-patterns. In the process, a bug was found in the current compiler which allowed:enum E<T> { A(T, T), B(T) } use E::*; fn foo() { match A(0, 1) { B(mut a) | A(mut a, mut a) => {} } }
The new algorithms took a few iterations to get right. I tried several clever schemes but ultimately a version based on a stack of hashsets and recording product/sum contexts was chosen since it is more clearly correct.
Clean up
librustc_resolve/late.rs
by, among other things, using a newwith_rib
function to better ensure stack dicipline.Do not push the change in AST to HIR for now to avoid doing too much in this PR. To cope with this, we introduce a temporary hack in
rustc::hir::lowering
(clearly marked in the diff).
cc rust-lang#54883 cc @dlrobertson @matthewjasper r? @petrochenkov
Centril added a commit to Centril/rust that referenced this pull request
…ochenkov
or-patterns: Uniformly use PatKind::Or
in AST & Fix/Cleanup resolve
Following up on work in rust-lang#63693 and rust-lang#61708, in this PR we:
Uniformly use
PatKind::Or(...)
in AST:Change
ast::Arm.pats: Vec<P<Pat>>
=>ast::Arm.pat: P<Pat>
Change
ast::ExprKind::Let.0: Vec<P<Pat>>
=>ast::ExprKind::Let.0: P<Pat>
Adjust
librustc_resolve/late.rs
to correctly handle or-patterns at any level of nesting as a result.In particular, the already-bound check which rejects e.g.
let (a, a);
now accounts for or-patterns. The consistency checking (ensures no missing bindings and binding mode consistency) also now accounts for or-patterns. In the process, a bug was found in the current compiler which allowed:enum E<T> { A(T, T), B(T) } use E::*; fn foo() { match A(0, 1) { B(mut a) | A(mut a, mut a) => {} } }
The new algorithms took a few iterations to get right. I tried several clever schemes but ultimately a version based on a stack of hashsets and recording product/sum contexts was chosen since it is more clearly correct.
Clean up
librustc_resolve/late.rs
by, among other things, using a newwith_rib
function to better ensure stack dicipline.Do not push the change in AST to HIR for now to avoid doing too much in this PR. To cope with this, we introduce a temporary hack in
rustc::hir::lowering
(clearly marked in the diff).
cc rust-lang#54883 cc @dlrobertson @matthewjasper r? @petrochenkov
bors added a commit that referenced this pull request
Rollup of 10 pull requests
Successful merges:
- #63676 (Use wasi crate for Core API)
- #64094 (Improve searching in rustdoc and add tests)
- #64111 (or-patterns: Uniformly use
PatKind::Or
in AST & Fix/Cleanup resolve) - #64156 (Assume non-git LLVM is fresh if the stamp file exists)
- #64161 (Point at variant on pattern field count mismatch)
- #64174 (Add missing code examples on Iterator trait)
- #64175 (Fix invalid span generation when it should be div)
- #64186 (std: Improve downstream codegen in
Command::env
) - #64190 (fill metadata in rustc_lexer's Cargo.toml)
- #64198 (Add Fuchsia to actually_monotonic)
Failed merges:
r? @ghost
Centril deleted the ast-only-patkind-or branch
This was referenced
Sep 6, 2019
mati865 added a commit to mati865/rust-clippy that referenced this pull request
bors added a commit to rust-lang/rust-clippy that referenced this pull request
Centril added a commit to Centril/rust that referenced this pull request
or-patterns: Push PatKind/PatternKind::Or
at top level to HIR & HAIR
Following up on work in rust-lang#64111, rust-lang#63693, and rust-lang#61708, in this PR:
We change
hair::Arm.patterns: Vec<Pattern<'_>>
intohir::Arm.pattern: Pattern<'_>
.fn hair::Arm::top_pats_hack
is introduced as a temporary crutch in MIR building to avoid more changes.
We change
hir::Arm.pats: HirVec<P<Pat>>
intohir::Arm.pat: P<Pat>
.The hacks in
rustc::hir::lowering
are removed since the representation hack is no longer necessary.In some places,
fn hir::Arm::top_pats_hack
is introduced to leave some things as future work.Misc changes: HIR pretty printing is adjusted to behave uniformly wrt. top/inner levels, rvalue promotion is adjusted, regionck, and dead_code is also.
Type checking is adjusted to uniformly handle or-patterns at top/inner levels. To make things compile,
p_0 | ... | p_n
is redefined as a "reference pattern" infn is_non_ref_pat
for now. This is done so that reference types are not eagerly stripped from theexpected: Ty<'tcx>
.Liveness is adjusted wrt. the
unused_variables
andunused_assignments
lints to handle top/inner levels uniformly and the handling offn
parameters,let
locals, andmatch
arms are unified in this respect. This is not tested for now as exhaustiveness checks are reachable and will ICE.In
check_match
, checking@
and by-move bindings is adjusted. However, exhaustiveness checking is not adjusted the moment and is handled by @dlrobertson in rust-lang#63688.AST borrowck (
construct.rs
) is not adjusted as AST borrowck will be removed soon.
r? @matthewjasper cc @dlrobertson @varkor @oli-obk
bors added a commit that referenced this pull request
or-patterns: Push PatKind/PatternKind::Or
at top level to HIR & HAIR
Following up on work in #64111, #63693, and #61708, in this PR:
We change
hair::Arm.patterns: Vec<Pattern<'_>>
intohir::Arm.pattern: Pattern<'_>
.fn hair::Arm::top_pats_hack
is introduced as a temporary crutch in MIR building to avoid more changes.
We change
hir::Arm.pats: HirVec<P<Pat>>
intohir::Arm.pat: P<Pat>
.The hacks in
rustc::hir::lowering
are removed since the representation hack is no longer necessary.In some places,
fn hir::Arm::top_pats_hack
is introduced to leave some things as future work.Misc changes: HIR pretty printing is adjusted to behave uniformly wrt. top/inner levels, rvalue promotion is adjusted, regionck, and dead_code is also.
Type checking is adjusted to uniformly handle or-patterns at top/inner levels. To make things compile,
p_0 | ... | p_n
is redefined as a "reference pattern" infn is_non_ref_pat
for now. This is done so that reference types are not eagerly stripped from theexpected: Ty<'tcx>
.Liveness is adjusted wrt. the
unused_variables
andunused_assignments
lints to handle top/inner levels uniformly and the handling offn
parameters,let
locals, andmatch
arms are unified in this respect. This is not tested for now as exhaustiveness checks are reachable and will ICE.In
check_match
, checking@
and by-move bindings is adjusted. However, exhaustiveness checking is not adjusted the moment and is handled by @dlrobertson in #63688.AST borrowck (
construct.rs
) is not adjusted as AST borrowck will be removed soon.
r? @matthewjasper cc @dlrobertson @varkor @oli-obk
Centril added a commit to Centril/rust that referenced this pull request
or-patterns: Push PatKind/PatternKind::Or
at top level to HIR & HAIR
Following up on work in rust-lang#64111, rust-lang#63693, and rust-lang#61708, in this PR:
We change
hair::Arm.patterns: Vec<Pattern<'_>>
intohir::Arm.pattern: Pattern<'_>
.fn hair::Arm::top_pats_hack
is introduced as a temporary crutch in MIR building to avoid more changes.
We change
hir::Arm.pats: HirVec<P<Pat>>
intohir::Arm.pat: P<Pat>
.The hacks in
rustc::hir::lowering
are removed since the representation hack is no longer necessary.In some places,
fn hir::Arm::top_pats_hack
is introduced to leave some things as future work.Misc changes: HIR pretty printing is adjusted to behave uniformly wrt. top/inner levels, rvalue promotion is adjusted, regionck, and dead_code is also.
Type checking is adjusted to uniformly handle or-patterns at top/inner levels. To make things compile,
p_0 | ... | p_n
is redefined as a "reference pattern" infn is_non_ref_pat
for now. This is done so that reference types are not eagerly stripped from theexpected: Ty<'tcx>
.Liveness is adjusted wrt. the
unused_variables
andunused_assignments
lints to handle top/inner levels uniformly and the handling offn
parameters,let
locals, andmatch
arms are unified in this respect. This is not tested for now as exhaustiveness checks are reachable and will ICE.In
check_match
, checking@
and by-move bindings is adjusted. However, exhaustiveness checking is not adjusted the moment and is handled by @dlrobertson in rust-lang#63688.AST borrowck (
construct.rs
) is not adjusted as AST borrowck will be removed soon.
r? @matthewjasper cc @dlrobertson @varkor @oli-obk
Centril added a commit to Centril/rust that referenced this pull request
…etrochenkov
resolve: more declarative fresh_binding
Following up on rust-lang#64111, this PR redefines fresh_binding
wrt. already_bound_and
and already_bound_or
in a more declarative and simplified fashion.
Labels
`#![feature(or_patterns)]`
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.