rapx::analysis::core::heap_item

Struct HeapItem

source
pub struct HeapItem;
Expand description

We encapsulate the interface for identifying heap items in a struct named HeapItem. This struct is a zero-sized type (ZST), so creating and using it does not incur any overhead. These interfaces typically take at least two fixed inputs. One is the context metadata of rCanary, which stores the cache for ADT analysis (of course, users do not need to know the specific information stored). The second input is the type that the user needs to process, along with other parameters.

Implementations§

source§

impl HeapItem

source

pub fn is_adt<'tcx>( rcx: &rCanary<'tcx>, ty: Ty<'tcx>, ) -> Result<bool, &'static str>

This method is used to check if one adt-def is already a heap item. It is a summary of one type which demonstrate that we will consider all the fields/variants, although the analyzer will not traverse them (thus overhead is cheap).

§Safety

If ty is not an adt, the result is Err.

§Case ty::Ty

Given the adt MyVec<T, A> the result is Ok(true).

pub struct MyVec<T, A: Allocator = Global> {
   buf: RawVec<T, A>, // this field is a heap item
   len: usize,
}
§Example:
 use rap::analysis::core::heap_item::HeapItem;
 let ans = HeapItem::is_adt(rcanary.rcx, vec.ty);
source

pub fn is_struct<'tcx>( rcx: &rCanary<'tcx>, ty: Ty<'tcx>, ) -> Result<bool, &'static str>

This method is used to check if one adt-def of the struct is already a heap item. It is a summary of one type which demonstrate that we will consider all the fields, although the analyzer will not traverse them (thus overhead is cheap).

§Safety

If ty is not an adt, the result is Err. If the input is the def of an enum type, the result is Err.

§Case ty::Ty

Given the adt MyVec<T, A> the result is Ok(true).

pub struct MyVec<T, A: Allocator = Global> {
   buf: RawVec<T, A>, // this field is a heap item
   len: usize,
}
§Example:
use rap::analysis::core::heap_item::HeapItem;
let ans = HeapItem::is_struct(rcanary.rcx, vec.ty);
source

pub fn is_enum<'tcx>( rcx: &rCanary<'tcx>, ty: Ty<'tcx>, ) -> Result<bool, &'static str>

This method is used to check if one adt-def of the enum is already a heap item. It is a summary of one type which demonstrate that we will consider all the variants, although the analyzer will not traverse them (thus overhead is cheap). Note that, even for each variance, the result also analyze all its fields. It can be referred to the enum with enum-type variance.

§Safety

If ty is not an adt, the result is Err. If the input is the def of a struct type, the result is Err.

§Case ty::Ty

Given the adt MyBuf<T> the result is Ok(true).

pub enum MyBuf<T> {
   Buf1(Vec<T>), // this variance is a heap item
   Buf2(Vec<T>), // this variance is a heap item
}
§Example:
use rap::analysis::core::heap_item::HeapItem;
let ans = HeapItem::is_enum(rcanary.rcx, vec.ty);
source

pub fn is_enum_vidx<'tcx>( rcx: &rCanary<'tcx>, ty: Ty<'tcx>, idx: usize, ) -> Result<bool, &'static str>

This method is used to check if one variance of the enum is already a heap item. It is a summary of one variance which demonstrate that we will consider all the fields of it, although the analyzer will not traverse them (thus overhead is cheap). It can be referred to the enum with enum-type variance.

§Safety

If ty is not an adt, the result is Err. If the input is the def of a struct type, the result is Err. If the index idx is not valid (out of bound), the result is Err.

§Case ty::Ty

Given the adt MyBuf<T> the result for idx: 0, 1 is Ok(true); the result for idx: 3 is Err.

pub enum MyBuf<T> {
   Buf1(Vec<T>), // this variance is a heap item
   Buf2(Vec<T>), // this variance is a heap item
}
§Example:
use rap::analysis::core::heap_item::HeapItem;
let ans = HeapItem::is_enum_vidx(rcanary.rcx, vec.ty, 1);
source

pub fn is_enum_flattened<'tcx>( rcx: &rCanary<'tcx>, ty: Ty<'tcx>, ) -> Result<Vec<bool>, &'static str>

This method is used to give the result of all the variances of the enum. For each variance, it is a summary that we will consider all the fields of it, although the analyzer will not traverse them (thus overhead is cheap). It can be referred to the enum with enum-type variance.

§Safety

If ty is not an adt, the result is Err. If the input is the def of a struct type, the result is Err.

§Case ty::Ty

Given the adt MyBuf<T> the result is [true, false].

pub enum MyBuf<T> {
   Buf1(Vec<T>), // this variance is a heap item
   Buf2(()), // this variance is a heap item
}
§Example:
use rap::analysis::core::heap_item::HeapItem;
let ans = HeapItem::is_enum_flattened(rcanary.rcx, vec.ty);

Trait Implementations§

source§

impl Clone for HeapItem

source§

fn clone(&self) -> HeapItem

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 HeapItem

source§

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

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

impl Copy for HeapItem

Auto Trait Implementations§

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
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, 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.