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
impl Rvalue
pub fn to_use(self) -> Option<Operand>
pub fn to_ref(self) -> Option<(Place, BorrowKind)>
pub fn to_raw_ptr(self) -> Option<(Place, RefKind)>
pub fn to_binary_op(self) -> Option<(BinOp, Operand, Operand)>
pub fn to_unary_op(self) -> Option<(UnOp, Operand)>
pub fn to_nullary_op(self) -> Option<(NullOp, Ty)>
pub fn to_discriminant(self) -> Option<(Place, TypeDeclId)>
pub fn to_aggregate(self) -> Option<(AggregateKind, Vec<Operand>)>
pub fn to_global(self) -> Option<GlobalDeclRef>
pub fn to_global_ref(self) -> Option<(GlobalDeclRef, RefKind)>
pub fn to_len(self) -> Option<(Place, Ty, Option<ConstGeneric>)>
pub fn to_repeat(self) -> Option<(Operand, Ty, ConstGeneric)>
pub fn to_shallow_init_box(self) -> Option<(Operand, Ty)>
source§impl Rvalue
impl Rvalue
pub fn as_use(&self) -> Option<&Operand>
pub fn as_ref(&self) -> Option<(&Place, &BorrowKind)>
pub fn as_raw_ptr(&self) -> Option<(&Place, &RefKind)>
pub fn as_binary_op(&self) -> Option<(&BinOp, &Operand, &Operand)>
pub fn as_unary_op(&self) -> Option<(&UnOp, &Operand)>
pub fn as_nullary_op(&self) -> Option<(&NullOp, &Ty)>
pub fn as_discriminant(&self) -> Option<(&Place, &TypeDeclId)>
pub fn as_aggregate(&self) -> Option<(&AggregateKind, &Vec<Operand>)>
pub fn as_global(&self) -> Option<&GlobalDeclRef>
pub fn as_global_ref(&self) -> Option<(&GlobalDeclRef, &RefKind)>
pub fn as_len(&self) -> Option<(&Place, &Ty, &Option<ConstGeneric>)>
pub fn as_repeat(&self) -> Option<(&Operand, &Ty, &ConstGeneric)>
pub fn as_shallow_init_box(&self) -> Option<(&Operand, &Ty)>
source§impl Rvalue
impl Rvalue
pub fn as_use_mut(&mut self) -> Option<&mut Operand>
pub fn as_ref_mut(&mut self) -> Option<(&mut Place, &mut BorrowKind)>
pub fn as_raw_ptr_mut(&mut self) -> Option<(&mut Place, &mut RefKind)>
pub fn as_binary_op_mut( &mut self, ) -> Option<(&mut BinOp, &mut Operand, &mut Operand)>
pub fn as_unary_op_mut(&mut self) -> Option<(&mut UnOp, &mut Operand)>
pub fn as_nullary_op_mut(&mut self) -> Option<(&mut NullOp, &mut Ty)>
pub fn as_discriminant_mut(&mut self) -> Option<(&mut Place, &mut TypeDeclId)>
pub fn as_aggregate_mut( &mut self, ) -> Option<(&mut AggregateKind, &mut Vec<Operand>)>
pub fn as_global_mut(&mut self) -> Option<&mut GlobalDeclRef>
pub fn as_global_ref_mut( &mut self, ) -> Option<(&mut GlobalDeclRef, &mut RefKind)>
pub fn as_len_mut( &mut self, ) -> Option<(&mut Place, &mut Ty, &mut Option<ConstGeneric>)>
pub fn as_repeat_mut( &mut self, ) -> Option<(&mut Operand, &mut Ty, &mut ConstGeneric)>
pub fn as_shallow_init_box_mut(&mut self) -> Option<(&mut Operand, &mut Ty)>
source§impl Rvalue
impl Rvalue
pub fn is_use(&self) -> bool
pub fn is_ref(&self) -> bool
pub fn is_raw_ptr(&self) -> bool
pub fn is_binary_op(&self) -> bool
pub fn is_unary_op(&self) -> bool
pub fn is_nullary_op(&self) -> bool
pub fn is_discriminant(&self) -> bool
pub fn is_aggregate(&self) -> bool
pub fn is_global(&self) -> bool
pub fn is_global_ref(&self) -> bool
pub fn is_len(&self) -> bool
pub fn is_repeat(&self) -> bool
pub fn is_shallow_init_box(&self) -> bool
Trait Implementations§
source§impl<'de> Deserialize<'de> for Rvalue
impl<'de> Deserialize<'de> for Rvalue
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<C: AstFormatter> FmtWithCtx<C> for Rvalue
impl<C: AstFormatter> FmtWithCtx<C> for Rvalue
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<I, T> ExtractContext<I, ()> for T
impl<I, T> ExtractContext<I, ()> for T
§fn extract_context(self, _original_input: I)
fn extract_context(self, _original_input: I)
§impl<T> Indentable for Twhere
T: Display,
impl<T> Indentable for Twhere
T: Display,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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