Skip to content

Commit 2f00086

Browse files
committed
WIP -- enable slice patterns and enable building rustdoc
1 parent 99f3bfc commit 2f00086

File tree

6 files changed

+208
-108
lines changed

6 files changed

+208
-108
lines changed

mk/main.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ RUSTFLAGS2_$(1) += -Z always-build-mir
182182
endef
183183
$(foreach crate,$(TARGET_CRATES),$(eval $(call ADD_MIR_FLAG,$(crate))))
184184
$(foreach crate,$(RUSTC_CRATES),$(eval $(call ADD_MIR_FLAG,$(crate))))
185-
$(foreach crate,syntax,$(eval $(call ADD_MIR_FLAG,$(crate))))
185+
$(foreach crate,$(HOST_CRATES),$(eval $(call ADD_MIR_FLAG,$(crate))))
186186

187187
# platform-specific auto-configuration
188188
include $(CFG_SRC_DIR)mk/platform.mk

src/librustc_mir/build/matches/mod.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<H:Hair> Builder<H> {
116116
}
117117

118118
pub fn lvalue_into_pattern(&mut self,
119-
block: BasicBlock,
119+
mut block: BasicBlock,
120120
var_extent: H::CodeExtent,
121121
irrefutable_pat: PatternRef<H>,
122122
initializer: &Lvalue<H>)
@@ -132,7 +132,7 @@ impl<H:Hair> Builder<H> {
132132

133133
// Simplify the candidate. Since the pattern is irrefutable, this should
134134
// always convert all match-pairs into bindings.
135-
self.simplify_candidate(&mut candidate);
135+
unpack!(block = self.simplify_candidate(block, &mut candidate));
136136

137137
if !candidate.match_pairs.is_empty() {
138138
self.hir.span_bug(
@@ -233,15 +233,7 @@ enum TestKind<H:Hair> {
233233
#[derive(Debug)]
234234
struct Test<H:Hair> {
235235
span: H::Span,
236-
237-
// the kind of test to be performed,
238236
kind: TestKind<H>,
239-
240-
// the outcome we expect,
241-
outcome: usize,
242-
243-
// and the match pairs that will result
244-
match_pairs: Vec<MatchPair<H>>
245237
}
246238

247239
///////////////////////////////////////////////////////////////////////////
@@ -261,7 +253,7 @@ impl<H:Hair> Builder<H> {
261253
// complete, all the match pairs which remain require some
262254
// form of test, whether it be a switch or pattern comparison.
263255
for candidate in &mut candidates {
264-
self.simplify_candidate(candidate);
256+
unpack!(block = self.simplify_candidate(block, candidate));
265257
}
266258

267259
// The candidates are inversely sorted by priority. Check to
@@ -293,14 +285,16 @@ impl<H:Hair> Builder<H> {
293285
debug!("match_candidates: test={:?} match_pair={:?}", test, match_pair);
294286
let target_blocks = self.perform_test(block, &match_pair.lvalue, &test);
295287

296-
for (outcome, target_block) in target_blocks.into_iter().enumerate() {
288+
for (outcome, mut target_block) in target_blocks.into_iter().enumerate() {
297289
let applicable_candidates: Vec<Candidate<H>> =
298290
candidates.iter()
299291
.filter_map(|candidate| {
300-
self.candidate_under_assumption(&match_pair.lvalue,
301-
&test.kind,
302-
outcome,
303-
candidate)
292+
unpack!(target_block =
293+
self.candidate_under_assumption(target_block,
294+
&match_pair.lvalue,
295+
&test.kind,
296+
outcome,
297+
candidate))
304298
})
305299
.collect();
306300
self.match_candidates(span, var_extent, applicable_candidates, target_block);

src/librustc_mir/build/matches/simplify.rs

+24-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
//! sort of test: for example, testing which variant an enum is, or
2323
//! testing a value against a constant.
2424
25-
use build::Builder;
25+
use build::{BlockAnd, Builder};
2626
use build::matches::{Binding, MatchPair, Candidate};
2727
use hair::*;
2828
use repr::*;
@@ -31,20 +31,25 @@ use std::mem;
3131

3232
impl<H:Hair> Builder<H> {
3333
pub fn simplify_candidate(&mut self,
34+
mut block: BasicBlock,
3435
candidate: &mut Candidate<H>)
36+
-> BlockAnd<()>
3537
{
3638
// repeatedly simplify match pairs until fixed point is reached
3739
loop {
3840
let match_pairs = mem::replace(&mut candidate.match_pairs, vec![]);
3941
let mut progress = match_pairs.len(); // count how many were simplified
4042
for match_pair in match_pairs {
41-
if let Err(match_pair) = self.simplify_match_pair(match_pair, candidate) {
42-
candidate.match_pairs.push(match_pair);
43-
progress -= 1; // this one was not simplified
43+
match self.simplify_match_pair(block, match_pair, candidate) {
44+
Ok(b) => { block = b; }
45+
Err(match_pair) => {
46+
candidate.match_pairs.push(match_pair);
47+
progress -= 1; // this one was not simplified
48+
}
4449
}
4550
}
4651
if progress == 0 {
47-
return; // if we were not able to simplify any, done.
52+
return block.unit(); // if we were not able to simplify any, done.
4853
}
4954
}
5055
}
@@ -54,14 +59,15 @@ impl<H:Hair> Builder<H> {
5459
/// have been pushed into the candidate. On failure (if false is
5560
/// returned), no changes are made to candidate.
5661
fn simplify_match_pair(&mut self,
62+
mut block: BasicBlock,
5763
match_pair: MatchPair<H>,
5864
candidate: &mut Candidate<H>)
59-
-> Result<(), MatchPair<H>> // returns Err() if cannot simplify
65+
-> Result<BasicBlock, MatchPair<H>> // returns Err() if cannot simplify
6066
{
6167
match match_pair.pattern.kind {
6268
PatternKind::Wild(..) => {
6369
// nothing left to do
64-
Ok(())
70+
Ok(block)
6571
}
6672

6773
PatternKind::Binding { name, mutability, mode, var, ty, subpattern } => {
@@ -81,24 +87,22 @@ impl<H:Hair> Builder<H> {
8187
candidate.match_pairs.push(MatchPair::new(match_pair.lvalue, subpattern));
8288
}
8389

84-
Ok(())
90+
Ok(block)
8591
}
8692

8793
PatternKind::Constant { .. } => {
8894
// FIXME normalize patterns when possible
8995
Err(match_pair)
9096
}
9197

92-
PatternKind::Array { prefix, slice: None, suffix } => {
93-
self.append_prefix_suffix_pairs(
94-
&mut candidate.match_pairs, match_pair.lvalue.clone(), prefix, suffix);
95-
Ok(())
96-
}
97-
98-
PatternKind::Array { prefix: _, slice: Some(_), suffix: _ } => {
99-
self.hir.span_bug(
100-
match_pair.pattern.span,
101-
&format!("slice patterns not implemented in MIR"));
98+
PatternKind::Array { prefix, slice, suffix } => {
99+
unpack!(block = self.prefix_suffix_slice(&mut candidate.match_pairs,
100+
block,
101+
match_pair.lvalue.clone(),
102+
prefix,
103+
slice,
104+
suffix));
105+
Ok(block)
102106
}
103107

104108
PatternKind::Slice { .. } |
@@ -112,14 +116,14 @@ impl<H:Hair> Builder<H> {
112116
// tuple struct, match subpats (if any)
113117
candidate.match_pairs.extend(
114118
self.field_match_pairs(match_pair.lvalue, subpatterns));
115-
Ok(())
119+
Ok(block)
116120
}
117121

118122
PatternKind::Deref { subpattern } => {
119123
let lvalue = match_pair.lvalue.deref();
120124
let subpattern = self.hir.mirror(subpattern);
121125
candidate.match_pairs.push(MatchPair::new(lvalue, subpattern));
122-
Ok(())
126+
Ok(block)
123127
}
124128
}
125129
}

0 commit comments

Comments
 (0)