WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.6% of users enabled 2FA.

ptr.rs 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! The AST pointer
//!
//! Provides `P<T>`, a frozen owned smart pointer, as a replacement for `@T` in
//! the AST.
//!
//! # Motivations and benefits
//!
//! * **Identity**: sharing AST nodes is problematic for the various analysis
//!   passes (e.g. one may be able to bypass the borrow checker with a shared
//!   `ExprAddrOf` node taking a mutable borrow). The only reason `@T` in the
//!   AST hasn't caused issues is because of inefficient folding passes which
//!   would always deduplicate any such shared nodes. Even if the AST were to
//!   switch to an arena, this would still hold, i.e. it couldn't use `&'a T`,
//!   but rather a wrapper like `P<'a, T>`.
//!
//! * **Immutability**: `P<T>` disallows mutating its inner `T`, unlike `Box<T>`
//!   (unless it contains an `Unsafe` interior, but that may be denied later).
//!   This mainly prevents mistakes, but can also enforces a kind of "purity".
//!
//! * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`,
//!   the latter even when the input and output types differ (as it would be the
//!   case with arenas or a GADT AST using type parameters to toggle features).
//!
//! * **Maintainability**: `P<T>` provides a fixed interface - `Deref`,
//!   `and_then` and `map` - which can remain fully functional even if the
//!   implementation changes (using a special thread-local heap, for example).
//!   Moreover, a switch to, e.g. `P<'a, T>` would be easy and mostly automated.

qinsoon's avatar
qinsoon committed
39 40 41 42
//use std::fmt::{self, Display, Debug};
//use std::hash::{Hash, Hasher};
//use std::ops::Deref;
//use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
43

44 45
use std::sync::Arc;

qinsoon's avatar
qinsoon committed
46
use ir::MuEntity;
47

qinsoon's avatar
qinsoon committed
48 49 50
pub type P<T> = Arc<T>;
//pub struct P<T: MuEntity> {
//    ptr: Arc<T>
51
//}
52 53 54

#[allow(non_snake_case)]
/// Construct a `P<T>` from a `T` value.
qinsoon's avatar
qinsoon committed
55
pub fn P<T>(value: T) -> P<T> {
qinsoon's avatar
qinsoon committed
56
//    P {ptr: Arc::new(value)}
57
    Arc::new(value)
58 59
}

qinsoon's avatar
qinsoon committed
60
//impl<T: MuEntity> Deref for P<T> {
61 62 63 64 65 66 67
//    type Target = T;
//
//    fn deref<'a>(&'a self) -> &'a T {
//        &*self.ptr
//    }
//}
//
qinsoon's avatar
qinsoon committed
68
//impl<T: MuEntity> Clone for P<T> {
69
//    fn clone(&self) -> P<T> {
qinsoon's avatar
qinsoon committed
70
//        P {ptr: self.ptr.clone()}
71 72 73
//    }
//}
//
qinsoon's avatar
qinsoon committed
74
//impl<T: MuEntity + PartialEq> PartialEq for P<T> {
75 76 77 78 79
//    fn eq(&self, other: &P<T>) -> bool {
//        **self == **other
//    }
//}
//
qinsoon's avatar
qinsoon committed
80
//impl<T: MuEntity + Eq> Eq for P<T> {}
81
//
qinsoon's avatar
qinsoon committed
82
//impl<T: MuEntity + Debug> Debug for P<T> {
83 84 85 86
//    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//        Debug::fmt(&**self, f)
//    }
//}
qinsoon's avatar
qinsoon committed
87
//impl<T: MuEntity + Display> Display for P<T> {
88 89 90 91 92
//    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//        Display::fmt(&**self, f)
//    }
//}
//
qinsoon's avatar
qinsoon committed
93
//impl<T: MuEntity> fmt::Pointer for P<T> {
94 95 96 97 98
//    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
//        fmt::Pointer::fmt(&self.ptr, f)
//    }
//}
//
qinsoon's avatar
qinsoon committed
99
//impl<T: MuEntity + Hash> Hash for P<T> {
100 101 102 103
//    fn hash<H: Hasher>(&self, state: &mut H) {
//        (**self).hash(state);
//    }
//}
qinsoon's avatar
qinsoon committed
104 105 106 107 108 109

//impl<T: MuEntity> Encodable for P<T> {
//    fn encode<S: Encoder> (&self, s: &mut S) -> Result<(), S::Error> {
//        s.emit_usize(self.id())
//    }
//}