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
impl HeapItem
sourcepub fn is_adt<'tcx>(
rcx: &rCanary<'tcx>,
ty: Ty<'tcx>,
) -> Result<bool, &'static str>
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);
sourcepub fn is_struct<'tcx>(
rcx: &rCanary<'tcx>,
ty: Ty<'tcx>,
) -> Result<bool, &'static str>
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);
sourcepub fn is_enum<'tcx>(
rcx: &rCanary<'tcx>,
ty: Ty<'tcx>,
) -> Result<bool, &'static str>
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);
sourcepub fn is_enum_vidx<'tcx>(
rcx: &rCanary<'tcx>,
ty: Ty<'tcx>,
idx: usize,
) -> Result<bool, &'static str>
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);
sourcepub fn is_enum_flattened<'tcx>(
rcx: &rCanary<'tcx>,
ty: Ty<'tcx>,
) -> Result<Vec<bool>, &'static str>
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§
Auto Trait Implementations§
impl Freeze for HeapItem
impl RefUnwindSafe for HeapItem
impl Send for HeapItem
impl Sync for HeapItem
impl Unpin for HeapItem
impl UnwindSafe for HeapItem
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
)