Skip to content

Commit

Permalink
Remove the branch merging optimisations for slice patterns
Browse files Browse the repository at this point in the history
They were only correct in the simplest case. Some of the optimisations
are certainly possible but should be introduced carefully and only
when the whole pattern codegen infrastructure is in a better shape.

Fixes #16648.
  • Loading branch information
Jakub Wieczorek committed Aug 30, 2014
1 parent d398eb7 commit 6f35ede
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 364 deletions.
22 changes: 12 additions & 10 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use syntax::codemap::{Span, Spanned, DUMMY_SP};
use syntax::fold::{Folder, noop_fold_pat};
use syntax::print::pprust::pat_to_string;
use syntax::parse::token;
use syntax::visit;
use syntax::visit::{Visitor, FnKind};
use syntax::visit::{mod, Visitor, FnKind};
use util::ppaux::ty_to_string;

struct Matrix(Vec<Vec<Gc<Pat>>>);
Expand Down Expand Up @@ -103,7 +102,9 @@ pub enum Constructor {
/// Ranges of literal values (2..5).
ConstantRange(const_val, const_val),
/// Array patterns of length n.
Slice(uint)
Slice(uint),
/// Array patterns with a subslice.
SliceWithSubslice(uint, uint)
}

#[deriving(Clone, PartialEq)]
Expand Down Expand Up @@ -270,13 +271,6 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
}
}

fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
match p.node {
PatIdent(_, _, Some(s)) => { raw_pat(s) }
_ => { p }
}
}

fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
match is_useful(cx, matrix, [wild()], ConstructWitness) {
UsefulWithWitness(pats) => {
Expand Down Expand Up @@ -821,6 +815,14 @@ pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
pats.push_all(after.as_slice());
Some(pats)
},
SliceWithSubslice(prefix, suffix)
if before.len() == prefix
&& after.len() == suffix
&& slice.is_some() => {
let mut pats = before.clone();
pats.push_all(after.as_slice());
Some(pats)
}
_ => None
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ pub fn wild() -> Gc<Pat> {
box (GC) Pat { id: 0, node: PatWild(PatWildSingle), span: DUMMY_SP }
}

pub fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
match p.node {
PatIdent(_, _, Some(s)) => { raw_pat(s) }
_ => { p }
}
}

pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
ty::with_path(tcx, id, |mut path| Path {
global: false,
Expand Down
Loading

5 comments on commit 6f35ede

@bors
Copy link
Contributor

@bors bors commented on 6f35ede Sep 4, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on 6f35ede Sep 4, 2014

Choose a reason for hiding this comment

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

merging jakub-/rust/issue-16648 = 6f35ede into auto

@bors
Copy link
Contributor

@bors bors commented on 6f35ede Sep 4, 2014

Choose a reason for hiding this comment

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

jakub-/rust/issue-16648 = 6f35ede merged ok, testing candidate = 5924937

@bors
Copy link
Contributor

@bors bors commented on 6f35ede Sep 4, 2014

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 5924937

Please sign in to comment.