Skip to main content

SsaType

Enum SsaType 

pub enum SsaType {
Show 30 variants Void, Bool, I8, U8, I16, U16, I32, U32, I64, U64, NativeInt, NativeUInt, F32, F64, Char, Object, String, Class(TypeRef), ValueType(TypeRef), GenericInst(Box<SsaType>, Vec<SsaType>), Array(Box<SsaType>, u32), Pointer(Box<SsaType>), ByRef(Box<SsaType>), TypedReference, GenericParam(u32), MethodGenericParam(u32), FnPtr(Box<FnPtrSig>), Null, Unknown, Varying,
}
Expand description

SSA type representation for CIL types.

This enum provides a simplified view of .NET types suitable for SSA analysis. It captures the essential type information without requiring full metadata resolution for common operations.

§Examples

use dotscope::analysis::SsaType;

let int_type = SsaType::I32;
let string_type = SsaType::String;
let array_type = SsaType::Array(Box::new(SsaType::I32), 1);

assert!(int_type.is_primitive());
assert!(string_type.is_reference());
assert!(array_type.is_array());

Variants§

§

Void

No return value (void).

§

Bool

Boolean type (System.Boolean).

§

I8

Signed 8-bit integer (System.SByte).

§

U8

Unsigned 8-bit integer (System.Byte).

§

I16

Signed 16-bit integer (System.Int16).

§

U16

Unsigned 16-bit integer (System.UInt16).

§

I32

Signed 32-bit integer (System.Int32).

§

U32

Unsigned 32-bit integer (System.UInt32).

§

I64

Signed 64-bit integer (System.Int64).

§

U64

Unsigned 64-bit integer (System.UInt64).

§

NativeInt

Native-sized signed integer (System.IntPtr).

§

NativeUInt

Native-sized unsigned integer (System.UIntPtr).

§

F32

32-bit floating point (System.Single).

§

F64

64-bit floating point (System.Double).

§

Char

Unicode character (System.Char).

§

Object

System.Object reference.

§

String

System.String reference.

§

Class(TypeRef)

Reference to a specific class type.

§

ValueType(TypeRef)

Value type (struct) - stored inline, not by reference.

§

GenericInst(Box<SsaType>, Vec<SsaType>)

Generic instantiation of a type with concrete type arguments.

For example, List<int> is GenericInst(Class(List), [I32]).

§

Array(Box<SsaType>, u32)

Single-dimensional or multi-dimensional array.

The u32 is the rank (number of dimensions). Rank 1 is a vector (SZ array).

§

Pointer(Box<SsaType>)

Unmanaged pointer to a type.

§

ByRef(Box<SsaType>)

Managed reference (byref) to a type.

§

TypedReference

Typed reference (System.TypedReference).

§

GenericParam(u32)

Generic type parameter (e.g., !0, !1).

The u32 is the parameter index.

§

MethodGenericParam(u32)

Generic method parameter (e.g., !!0, !!1).

The u32 is the parameter index.

§

FnPtr(Box<FnPtrSig>)

Function pointer type.

§

Null

Known null constant (more precise than Object).

§

Unknown

Type not yet inferred or unknown.

This is used during type inference before a type is determined.

§

Varying

Type that varies depending on control flow (for incomplete inference).

Implementations§

§

impl SsaType

pub const fn is_primitive(&self) -> bool

Returns true if this is a primitive numeric or boolean type.

pub const fn is_integer(&self) -> bool

Returns true if this is an integer type (signed or unsigned).

pub const fn is_float(&self) -> bool

Returns true if this is a floating-point type.

pub fn is_reference(&self) -> bool

Returns true if this is a reference type (can be null).

pub const fn is_value_type(&self) -> bool

Returns true if this is a value type (struct).

pub const fn is_array(&self) -> bool

Returns true if this is an array type.

pub const fn is_pointer(&self) -> bool

Returns true if this is a pointer type (managed or unmanaged).

pub const fn is_void(&self) -> bool

Returns true if this is the void type.

pub const fn is_unknown(&self) -> bool

Returns true if this type is unknown or not yet inferred.

pub const fn is_null(&self) -> bool

Returns true if this is the null type.

pub const fn is_generic_param(&self) -> bool

Returns true if this is a generic parameter.

pub fn array_element_type(&self) -> Option<&SsaType>

Returns the element type if this is an array.

pub const fn array_rank(&self) -> Option<u32>

Returns the array rank (number of dimensions) if this is an array.

pub fn pointee_type(&self) -> Option<&SsaType>

Returns the pointed-to type if this is a pointer or byref.

pub const fn size_bytes(&self) -> Option<u32>

Returns the size in bytes for primitive types, if known.

Returns None for reference types and types with platform-dependent sizes.

pub fn stack_type(&self) -> SsaType

Returns the stack slot type for this SSA type.

CIL uses a normalized set of types on the evaluation stack:

  • All integer types smaller than 32 bits become I32
  • Float types stay as-is (F32 becomes F64 in some contexts)
  • References stay as references

pub fn storage_class(&self) -> TypeClass

Returns the storage class of this type.

Used for local variable coalescing to determine which types can share the same storage slot without requiring conversion.

pub fn is_compatible_for_storage(&self, other: &SsaType) -> bool

Checks if this type can share a local slot with another type.

Two types are compatible for storage if they have the same size and alignment requirements, meaning they can be stored in the same local variable slot without data corruption.

§Examples
use dotscope::analysis::SsaType;

// Same types are compatible
assert!(SsaType::I32.is_compatible_for_storage(&SsaType::I32));

// 32-bit integers can share slots
assert!(SsaType::I32.is_compatible_for_storage(&SsaType::U32));
assert!(SsaType::I32.is_compatible_for_storage(&SsaType::Bool));

// Reference types can share slots
assert!(SsaType::Object.is_compatible_for_storage(&SsaType::String));

// Different sizes are incompatible
assert!(!SsaType::I32.is_compatible_for_storage(&SsaType::I64));

pub fn merge(&self, other: &SsaType) -> SsaType

Merges two types at a control flow join point.

Returns the common type if compatible, or Varying if incompatible.

pub fn to_type_signature(&self) -> TypeSignature

Converts this SSA type to a TypeSignature for signature encoding.

This enables generating local variable signatures from SSA type information. Analysis-only types (Unknown, Null, Varying) are converted to Object as a safe fallback.

§Returns

The corresponding TypeSignature that can be used for signature encoding.

pub fn from_cil_flavor(flavor: &CilFlavor, token: Token) -> Self

Creates an SsaType from a CilFlavor.

This converts the metadata type flavor to the SSA type representation. For complex types (arrays, pointers, generic instances), a token is needed to create a proper type reference.

§Arguments
  • flavor - The CIL type flavor to convert
  • token - The metadata token for creating type references

pub fn from_type_signature( signature: &TypeSignature, assembly: &CilObject, ) -> Self

Creates an SsaType from a TypeSignature.

This converts a metadata type signature to the SSA type representation. For class and value types, the assembly context is used to resolve type tokens to determine if they are primitives.

§Arguments
  • signature - The type signature to convert
  • assembly - Assembly context for resolving type tokens

pub fn from_type_token(token: Token, assembly: &CilObject) -> Self

Creates an SsaType from a type token by resolving it in the assembly.

Handles TypeDef (0x02), TypeRef (0x01), and TypeSpec (0x1B) tokens.

Trait Implementations§

§

impl Clone for SsaType

§

fn clone(&self) -> SsaType

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
§

impl Debug for SsaType

§

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

Formats the value using the given formatter. Read more
§

impl Display for SsaType

§

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

Formats the value using the given formatter. Read more
§

impl Eq for SsaType

§

impl Hash for SsaType

§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for SsaType

§

fn eq(&self, other: &SsaType) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for SsaType

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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, A> IntoAst<A> for T
where T: Into<A>, A: Ast,

Source§

fn into_ast(self, _a: &A) -> A

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

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

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

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§

fn to_string(&self) -> String

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

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

Source§

fn try_clone(&self) -> Result<T, Error>

Clones self, possibly returning an error.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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