charon_lib::ast::expressions

Enum Rvalue

source
pub enum Rvalue {
Show 13 variants Use(Operand), Ref(Place, BorrowKind), RawPtr(Place, RefKind), BinaryOp(BinOp, Operand, Operand), UnaryOp(UnOp, Operand), NullaryOp(NullOp, Ty), Discriminant(Place, TypeDeclId), Aggregate(AggregateKind, Vec<Operand>), Global(GlobalDeclRef), GlobalRef(GlobalDeclRef, RefKind), Len(Place, Ty, Option<ConstGeneric>), Repeat(Operand, Ty, ConstGeneric), ShallowInitBox(Operand, Ty),
}
Expand description

TODO: we could factor out Rvalue and function calls (for LLBC, not ULLBC). We can also factor out the unops, binops with the function calls. TODO: move the aggregate kind to operands TODO: we should prefix the type variants with “R” or “Rv”, this would avoid collisions

Variants§

§

Use(Operand)

Lifts an operand as an rvalue.

§

Ref(Place, BorrowKind)

Takes a reference to the given place.

§

RawPtr(Place, RefKind)

Takes a raw pointer with the given mutability to the given place. This is generated by pointer casts like &v as *const _ or raw borrow expressions like &raw const v.

§

BinaryOp(BinOp, Operand, Operand)

Binary operations (note that we merge “checked” and “unchecked” binops)

§

UnaryOp(UnOp, Operand)

Unary operation (e.g. not, neg)

§

NullaryOp(NullOp, Ty)

Nullary operation (e.g. size_of)

§

Discriminant(Place, TypeDeclId)

Discriminant (for enumerations). Note that discriminant values have type isize. We also store the identifier of the type from which we read the discriminant.

This case is filtered in [crate::remove_read_discriminant]

§

Aggregate(AggregateKind, Vec<Operand>)

Creates an aggregate value, like a tuple, a struct or an enum:

l = List::Cons { value:x, tail:tl };

Note that in some MIR passes (like optimized MIR), aggregate values are decomposed, like below:

(l as List::Cons).value = x;
(l as List::Cons).tail = tl;

Because we may want to plug our translation mechanism at various places, we need to take both into accounts in the translation and in our semantics. Aggregate value initialization is easy, you might want to have a look at expansion of Bottom values for explanations about the other case.

Remark: in case of closures, the aggregated value groups the closure id together with its state.

§

Global(GlobalDeclRef)

Copy the value of the referenced global. Not present in MIR; introduced in [simplify_constants.rs].

§

GlobalRef(GlobalDeclRef, RefKind)

Reference the value of the global. This has type &T or *mut T depending on desired mutability. Not present in MIR; introduced in [simplify_constants.rs].

§

Len(Place, Ty, Option<ConstGeneric>)

Length of a memory location. The run-time length of e.g. a vector or a slice is represented differently (but pretty-prints the same, FIXME). Should be seen as a function of signature:

  • fn<T;N>(&[T;N]) -> usize
  • fn<T>(&[T]) -> usize

We store the type argument and the const generic (the latter only for arrays).

[Len] is automatically introduced by rustc, notably for the bound checks: we eliminate it together with the bounds checks whenever possible. There are however occurrences that we don’t eliminate (yet). For instance, for the following Rust code:

fn slice_pattern_4(x: &[()]) {
    match x {
        [_named] => (),
        _ => (),
    }
}

rustc introduces a check that the length of the slice is exactly equal to 1 and that we preserve.

§

Repeat(Operand, Ty, ConstGeneric)

[Repeat(x, n)] creates an array where [x] is copied [n] times.

We translate this to a function call.

§

ShallowInitBox(Operand, Ty)

Transmutes a *mut u8 (obtained from malloc) into shallow-initialized Box<T>. This only appears as part of lowering Box::new() in some cases. We reconstruct the original Box::new() call.

Implementations§

source§

impl Rvalue

source§

impl Rvalue

source

pub fn as_use(&self) -> Option<&Operand>

source

pub fn as_ref(&self) -> Option<(&Place, &BorrowKind)>

source

pub fn as_raw_ptr(&self) -> Option<(&Place, &RefKind)>

source

pub fn as_binary_op(&self) -> Option<(&BinOp, &Operand, &Operand)>

source

pub fn as_unary_op(&self) -> Option<(&UnOp, &Operand)>

source

pub fn as_nullary_op(&self) -> Option<(&NullOp, &Ty)>

source

pub fn as_discriminant(&self) -> Option<(&Place, &TypeDeclId)>

source

pub fn as_aggregate(&self) -> Option<(&AggregateKind, &Vec<Operand>)>

source

pub fn as_global(&self) -> Option<&GlobalDeclRef>

source

pub fn as_global_ref(&self) -> Option<(&GlobalDeclRef, &RefKind)>

source

pub fn as_len(&self) -> Option<(&Place, &Ty, &Option<ConstGeneric>)>

source

pub fn as_repeat(&self) -> Option<(&Operand, &Ty, &ConstGeneric)>

source

pub fn as_shallow_init_box(&self) -> Option<(&Operand, &Ty)>

source§

impl Rvalue

source

pub fn as_use_mut(&mut self) -> Option<&mut Operand>

source

pub fn as_ref_mut(&mut self) -> Option<(&mut Place, &mut BorrowKind)>

source

pub fn as_raw_ptr_mut(&mut self) -> Option<(&mut Place, &mut RefKind)>

source

pub fn as_binary_op_mut( &mut self, ) -> Option<(&mut BinOp, &mut Operand, &mut Operand)>

source

pub fn as_unary_op_mut(&mut self) -> Option<(&mut UnOp, &mut Operand)>

source

pub fn as_nullary_op_mut(&mut self) -> Option<(&mut NullOp, &mut Ty)>

source

pub fn as_discriminant_mut(&mut self) -> Option<(&mut Place, &mut TypeDeclId)>

source

pub fn as_aggregate_mut( &mut self, ) -> Option<(&mut AggregateKind, &mut Vec<Operand>)>

source

pub fn as_global_mut(&mut self) -> Option<&mut GlobalDeclRef>

source

pub fn as_global_ref_mut( &mut self, ) -> Option<(&mut GlobalDeclRef, &mut RefKind)>

source

pub fn as_len_mut( &mut self, ) -> Option<(&mut Place, &mut Ty, &mut Option<ConstGeneric>)>

source

pub fn as_repeat_mut( &mut self, ) -> Option<(&mut Operand, &mut Ty, &mut ConstGeneric)>

source

pub fn as_shallow_init_box_mut(&mut self) -> Option<(&mut Operand, &mut Ty)>

source§

impl Rvalue

source

pub fn is_use(&self) -> bool

source

pub fn is_ref(&self) -> bool

source

pub fn is_raw_ptr(&self) -> bool

source

pub fn is_binary_op(&self) -> bool

source

pub fn is_unary_op(&self) -> bool

source

pub fn is_nullary_op(&self) -> bool

source

pub fn is_discriminant(&self) -> bool

source

pub fn is_aggregate(&self) -> bool

source

pub fn is_global(&self) -> bool

source

pub fn is_global_ref(&self) -> bool

source

pub fn is_len(&self) -> bool

source

pub fn is_repeat(&self) -> bool

source

pub fn is_shallow_init_box(&self) -> bool

Trait Implementations§

source§

impl Clone for Rvalue

source§

fn clone(&self) -> Rvalue

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Rvalue

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Rvalue

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Rvalue

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Drive for Rvalue

source§

fn drive<V: Visitor>(&self, visitor: &mut V)

source§

impl DriveMut for Rvalue

source§

fn drive_mut<V: VisitorMut>(&mut self, visitor: &mut V)

source§

impl<C: AstFormatter> FmtWithCtx<C> for Rvalue

source§

fn fmt_with_ctx(&self, ctx: &C) -> String

source§

fn fmt_with_ctx_and_indent(&self, _tab: &str, _ctx: &C) -> String

source§

fn with_ctx<'a>(&'a self, ctx: &'a C) -> impl Display + 'a

Returns a struct that implements Display. This allows the following: Read more
source§

impl Serialize for Rvalue

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Rvalue

§

impl RefUnwindSafe for Rvalue

§

impl Send for Rvalue

§

impl Sync for Rvalue

§

impl Unpin for Rvalue

§

impl UnwindSafe for Rvalue

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<I, T> ExtractContext<I, ()> for T

§

fn extract_context(self, _original_input: I)

Given the context attached to a nom error, and given the original input to the nom parser, extract more the useful context information. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Indentable for T
where T: Display,

§

fn indented(self, indent: &str) -> Indented<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line of the formatted output will be prefixed with the indent. Read more
§

fn indented_skip_initial(self, indent: &str) -> IndentedSkipIntial<'_, Self>

Wrap this object so that its Display representation is indented with the given indent. Each non-empty line except for the first of the formatted output will be prefixed with the indent. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<I> RecreateContext<I> for I

§

fn recreate_context(_original_input: I, tail: I) -> I

Given the original input, as well as the context reported by nom, recreate a context in the original string where the error occurred. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,