]> git.proxmox.com Git - rustc.git/blob - src/librustc_mir/dataflow/move_paths/abs_domain.rs
New upstream version 1.20.0+dfsg1
[rustc.git] / src / librustc_mir / dataflow / move_paths / abs_domain.rs
1 // Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! The move-analysis portion of borrowck needs to work in an abstract
12 //! domain of lifted Lvalues. Most of the Lvalue variants fall into a
13 //! one-to-one mapping between the concrete and abstract (e.g. a
14 //! field-deref on a local-variable, `x.field`, has the same meaning
15 //! in both domains). Indexed-Projections are the exception: `a[x]`
16 //! needs to be treated as mapping to the same move path as `a[y]` as
17 //! well as `a[13]`, et cetera.
18 //!
19 //! (In theory the analysis could be extended to work with sets of
20 //! paths, so that `a[0]` and `a[13]` could be kept distinct, while
21 //! `a[x]` would still overlap them both. But that is not this
22 //! representation does today.)
23
24 use rustc::mir::LvalueElem;
25 use rustc::mir::{Operand, ProjectionElem};
26
27 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
28 pub struct AbstractOperand;
29 pub type AbstractElem<'tcx> =
30 ProjectionElem<'tcx, AbstractOperand>;
31
32 pub trait Lift {
33 type Abstract;
34 fn lift(&self) -> Self::Abstract;
35 }
36 impl<'tcx> Lift for Operand<'tcx> {
37 type Abstract = AbstractOperand;
38 fn lift(&self) -> Self::Abstract { AbstractOperand }
39 }
40 impl<'tcx> Lift for LvalueElem<'tcx> {
41 type Abstract = AbstractElem<'tcx>;
42 fn lift(&self) -> Self::Abstract {
43 match *self {
44 ProjectionElem::Deref =>
45 ProjectionElem::Deref,
46 ProjectionElem::Field(ref f, ty) =>
47 ProjectionElem::Field(f.clone(), ty.clone()),
48 ProjectionElem::Index(ref i) =>
49 ProjectionElem::Index(i.lift()),
50 ProjectionElem::Subslice {from, to} =>
51 ProjectionElem::Subslice { from: from, to: to },
52 ProjectionElem::ConstantIndex {offset,min_length,from_end} =>
53 ProjectionElem::ConstantIndex {
54 offset: offset,
55 min_length: min_length,
56 from_end: from_end
57 },
58 ProjectionElem::Downcast(a, u) =>
59 ProjectionElem::Downcast(a.clone(), u.clone()),
60 }
61 }
62 }