]> git.proxmox.com Git - rustc.git/blob - src/librustc_borrowck/borrowck/mir/abs_domain.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc_borrowck / borrowck / mir / 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::repr::{Lvalue, LvalueElem};
25 use rustc::mir::repr::{Operand, Projection, ProjectionElem};
26
27 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
28 pub struct AbstractOperand;
29 pub type AbstractProjection<'tcx> =
30 Projection<'tcx, Lvalue<'tcx>, AbstractOperand>;
31 pub type AbstractElem<'tcx> =
32 ProjectionElem<'tcx, AbstractOperand>;
33
34 pub trait Lift {
35 type Abstract;
36 fn lift(&self) -> Self::Abstract;
37 }
38 impl<'tcx> Lift for Operand<'tcx> {
39 type Abstract = AbstractOperand;
40 fn lift(&self) -> Self::Abstract { AbstractOperand }
41 }
42 impl<'tcx> Lift for LvalueElem<'tcx> {
43 type Abstract = AbstractElem<'tcx>;
44 fn lift(&self) -> Self::Abstract {
45 match *self {
46 ProjectionElem::Deref =>
47 ProjectionElem::Deref,
48 ProjectionElem::Field(ref f, ty) =>
49 ProjectionElem::Field(f.clone(), ty.clone()),
50 ProjectionElem::Index(ref i) =>
51 ProjectionElem::Index(i.lift()),
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 }