diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2017-02-02 06:44:30 +0200 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2017-02-10 19:42:41 +0200 |
| commit | a00a0adc7913152bff626d6dbebfa2cfdbb93d0a (patch) | |
| tree | 4848312f6e9657f06bf6d15bddef8cdd63cbf6ca /src/librustc/mir | |
| parent | aac82d9b13f8ba1baebc5a2a1a673831e6f6fbe7 (diff) | |
| download | rust-a00a0adc7913152bff626d6dbebfa2cfdbb93d0a.tar.gz rust-a00a0adc7913152bff626d6dbebfa2cfdbb93d0a.zip | |
Only SwitchInt over integers, not all consts
Also use a Cow to avoid full Vec for all SwitchInts
Diffstat (limited to 'src/librustc/mir')
| -rw-r--r-- | src/librustc/mir/mod.rs | 8 | ||||
| -rw-r--r-- | src/librustc/mir/visit.rs | 19 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index b0a6784c3c3..28990fd323f 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -446,6 +446,9 @@ pub struct Terminator<'tcx> { pub kind: TerminatorKind<'tcx> } +/// For use in SwitchInt, for switching on bools. +pub static BOOL_SWITCH_TRUE: Cow<'static, [ConstInt]> = Cow::Borrowed(&[ConstInt::Infer(1)]); + #[derive(Clone, RustcEncodable, RustcDecodable)] pub enum TerminatorKind<'tcx> { /// block should have one successor in the graph; we jump there @@ -464,8 +467,7 @@ pub enum TerminatorKind<'tcx> { /// Possible values. The locations to branch to in each case /// are found in the corresponding indices from the `targets` vector. - // FIXME: ConstVal doesn’t quite make any sense here? Its a Switch*Int*. - values: Vec<ConstVal>, + values: Cow<'tcx, [ConstInt]>, /// Possible branch sites. The length of this vector should be /// equal to the length of the `values` vector plus 1 -- the @@ -696,7 +698,7 @@ impl<'tcx> TerminatorKind<'tcx> { values.iter() .map(|const_val| { let mut buf = String::new(); - fmt_const_val(&mut buf, const_val).unwrap(); + fmt_const_val(&mut buf, &ConstVal::Integral(*const_val)).unwrap(); buf.into() }) .chain(iter::once(String::from("otherwise").into())) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index ca20cf6236b..be3c43db7ba 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -223,6 +223,12 @@ macro_rules! make_mir_visitor { self.super_const_val(const_val); } + fn visit_const_int(&mut self, + const_int: &ConstInt, + _: Location) { + self.super_const_int(const_int); + } + fn visit_const_usize(&mut self, const_usize: & $($mutability)* ConstUsize, _: Location) { @@ -364,12 +370,12 @@ macro_rules! make_mir_visitor { TerminatorKind::SwitchInt { ref $($mutability)* discr, ref $($mutability)* switch_ty, - ref $($mutability)* values, + ref values, ref targets } => { self.visit_operand(discr, source_location); self.visit_ty(switch_ty); - for value in values { - self.visit_const_val(value, source_location); + for value in &values[..] { + self.visit_const_int(value, source_location); } for &target in targets { self.visit_branch(block, target); @@ -698,10 +704,13 @@ macro_rules! make_mir_visitor { _substs: & $($mutability)* ClosureSubsts<'tcx>) { } - fn super_const_val(&mut self, _substs: & $($mutability)* ConstVal) { + fn super_const_val(&mut self, _const_val: & $($mutability)* ConstVal) { + } + + fn super_const_int(&mut self, _const_int: &ConstInt) { } - fn super_const_usize(&mut self, _substs: & $($mutability)* ConstUsize) { + fn super_const_usize(&mut self, _const_usize: & $($mutability)* ConstUsize) { } // Convenience methods |
