rapx::analysis::core::heap_item

Struct IsolatedParameter

source
pub struct IsolatedParameter;
Expand description

We encapsulate the interface for identifying isolated parameters in a struct named IsolatedParameter. 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 IsolatedParameter

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 has at least one isolated parameter. It is a summary of one type which demonstrate that we will consider all the generics. Those generic parameters can be located in different fields/variants, and some of them can be found in multiple fields/variants. The analyzer will not traverse them to generate the result (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> { // parameter A is an isolated parameter
   buf: RawVec<T, A>,  // parameter A inside in RawVec
   len: usize,
}
§Example:
 use rap::analysis::core::heap_item::IsolatedParameter;
 let ans = IsolatedParameter::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 has at least one isolated parameter. It is a summary of one type which demonstrate that we will consider all the generics. Those generic parameters can be located in different fields, and some of them can be found in multiple fields. The analyzer will not traverse them to generate the result (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> { // parameter A is an isolated parameter
   buf: RawVec<T, A>, // parameter A inside in RawVec
   len: usize,
}
§Example:
 use rap::analysis::core::heap_item::IsolatedParameter;
 let ans = IsolatedParameter::is_adt(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 has at least one isolated parameter. It is a summary of one type which demonstrate that we will consider all the generics in all the variants. Those generic parameters can be located in different fields, and some of them can be found in multiple fields. 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, S, F> the result is Ok(true).

pub enum MyBuf<T, S, F> { // parameter S F are an isolated parameters
   Buf1(Vec<T>),
   Buf2(S), // this variance is an isolated parameter
   Buf3((F,S)), // this variance has 2 isolated parameters
}
§Example:
 use rap::analysis::core::heap_item::IsolatedParameter;
 let ans = IsolatedParameter::is_adt(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 has at least one isolated parameter. It is a summary of one type which demonstrate that we will consider all the generics in the given variance. Note that, even for this 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. If the index idx is not valid (out of bound), the result is Err.

§Case ty::Ty

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

pub enum MyBuf<T, S, F> { // parameter S F are an isolated parameters
   Buf1(Vec<T>),
   Buf2(S), // this variance is an isolated parameter
   Buf3((F,S)), // this variance has 2 isolated parameters
}
§Example:
 use rap::analysis::core::heap_item::IsolatedParameter;
 let ans = IsolatedParameter::is_enum_vidx(rcanary.rcx, vec.ty, 1);
source

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

This method is used to check if one adt-def of the enum has at least one isolated parameter. It is a summary of one type which demonstrate that we will consider all the generics in all the variants. Those generic parameters can be located in different fields, and some of them can be found in multiple fields. 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 Vec<T, A> the result is Ok(true).

pub enum MyBuf<T, S, F> { // parameter S F are an isolated parameters
   Buf1(Vec<T>),
   Buf2(S), // this variance is an isolated parameter
   Buf3((F,S)), // this variance has 2 isolated parameters
}
§Example:
 use rap::analysis::core::heap_item::IsolatedParameter;
 let ans = IsolatedParameter::is_enum_flattened(rcanary.rcx, vec.ty);

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