pub struct LLVMSumType<'c>(/* private fields */);Expand description
The opaque representation of a HugrSumType.
Provides an impls of BasicType, allowing interoperation with other
inkwell tools.
To obtain an LLVMSumType corresponding to a HugrSumType use LLVMSumType::try_new or LLVMSumType::try_from_hugr_type.
Any such LLVMSumType has a fixed underlying LLVM type, which can be obtained by BasicType::as_basic_type_enum or LLVMSumType::value_type. Note this type is unspecified, and we go to some effort to ensure that it is minimal and efficient. Users should not expect this type to remain the same across versions.
Unit types such as empty structs({}) are elided from the LLVM type where
possible. See elidable_type for the specification of which types are
elided.
Each LLVMSumType has an associated IntType tag type, which can be obtained via LLVMSumType::tag_type.
The value type LLVMSumValue represents values of this type. To obtain an LLVMSumValue use LLVMSumType::build_tag or LLVMSumType::value.
Implementations§
Source§impl<'c> LLVMSumType<'c>
impl<'c> LLVMSumType<'c>
Sourcepub fn value_type(&self) -> BasicTypeEnum<'c>
pub fn value_type(&self) -> BasicTypeEnum<'c>
The underlying LLVM type.
Sourcepub fn tag_type(&self) -> IntType<'c>
pub fn tag_type(&self) -> IntType<'c>
The type of the value that would be returned by LLVMSumValue::build_get_tag.
Sourcepub fn num_variants(&self) -> usize
pub fn num_variants(&self) -> usize
The number of variants in the represented HugrSumType.
Sourcepub fn num_fields_for_variant(&self, tag: usize) -> usize
pub fn num_fields_for_variant(&self, tag: usize) -> usize
The number of fields in the tagth variant of the represented HugrSumType.
Panics if tag is out of bounds.
Sourcepub fn fields_for_variant(&self, tag: usize) -> &[BasicTypeEnum<'c>]
pub fn fields_for_variant(&self, tag: usize) -> &[BasicTypeEnum<'c>]
The LLVM types representing the fields in the tag variant of the represented HugrSumType.
Panics if tag is out of bounds.
Sourcepub fn try_from_hugr_type(
session: &TypingSession<'c, '_>,
sum_type: HugrSumType,
) -> Result<Self>
pub fn try_from_hugr_type( session: &TypingSession<'c, '_>, sum_type: HugrSumType, ) -> Result<Self>
Constructs a new LLVMSumType from a HugrSumType, using session to
determine the types of the fields.
Returns an error if the type of any field cannot be converted by
session, or if sum_type has no variants.
Sourcepub fn try_new(
context: &'c Context,
variant_types: impl Into<Vec<Vec<BasicTypeEnum<'c>>>>,
) -> Result<Self>
pub fn try_new( context: &'c Context, variant_types: impl Into<Vec<Vec<BasicTypeEnum<'c>>>>, ) -> Result<Self>
Constructs a new LLVMSumType from a Vec of variants.
Each variant is a Vec of LLVM types each corresponding to a field in the sum.
Returns an error if variant_types is empty;
Sourcepub fn get_undef(&self) -> impl BasicValue<'c>
pub fn get_undef(&self) -> impl BasicValue<'c>
Returns an constant undef value of the underlying LLVM type.
Sourcepub fn get_poison(&self) -> impl BasicValue<'c>
pub fn get_poison(&self) -> impl BasicValue<'c>
Returns an constant poison value of the underlying LLVM type.
Sourcepub fn build_tag(
&self,
builder: &Builder<'c>,
tag: usize,
vs: Vec<BasicValueEnum<'c>>,
) -> Result<LLVMSumValue<'c>>
pub fn build_tag( &self, builder: &Builder<'c>, tag: usize, vs: Vec<BasicValueEnum<'c>>, ) -> Result<LLVMSumValue<'c>>
Emits instructions to construct an LLVMSumValue of this type. The
value will represent the tagth variant.
Sourcepub fn value(&self, value: impl BasicValue<'c>) -> Result<LLVMSumValue<'c>>
pub fn value(&self, value: impl BasicValue<'c>) -> Result<LLVMSumValue<'c>>
Returns an LLVMSumValue of this type.
Returns an error if value.get_type() != self.value_type().
Trait Implementations§
Source§impl<'c> AnyType<'c> for LLVMSumType<'c>
impl<'c> AnyType<'c> for LLVMSumType<'c>
Source§fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx>
fn as_any_type_enum(&self) -> AnyTypeEnum<'ctx>
AnyTypeEnum that represents the current type.Source§fn print_to_string(&self) -> LLVMString
fn print_to_string(&self) -> LLVMString
LLVMString.Source§impl AsTypeRef for LLVMSumType<'_>
impl AsTypeRef for LLVMSumType<'_>
Source§fn as_type_ref(&self) -> LLVMTypeRef
fn as_type_ref(&self) -> LLVMTypeRef
Source§impl<'c> BasicType<'c> for LLVMSumType<'c>
impl<'c> BasicType<'c> for LLVMSumType<'c>
Source§fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx>
fn as_basic_type_enum(&self) -> BasicTypeEnum<'ctx>
BasicTypeEnum that represents the current type.Source§fn fn_type(
&self,
param_types: &[BasicMetadataTypeEnum<'ctx>],
is_var_args: bool,
) -> FunctionType<'ctx>
fn fn_type( &self, param_types: &[BasicMetadataTypeEnum<'ctx>], is_var_args: bool, ) -> FunctionType<'ctx>
Source§fn is_sized(&self) -> bool
fn is_sized(&self) -> bool
BasicType is sized or not.
For example, opaque structs are unsized. Read moreSource§fn size_of(&self) -> Option<IntValue<'ctx>>
fn size_of(&self) -> Option<IntValue<'ctx>>
BasicType. Value may vary depending on the target architecture. Read moreSource§fn array_type(&self, size: u32) -> ArrayType<'ctx>
fn array_type(&self, size: u32) -> ArrayType<'ctx>
Source§fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx>
fn ptr_type(&self, address_space: AddressSpace) -> PointerType<'ctx>
Source§impl<'c> Clone for LLVMSumType<'c>
impl<'c> Clone for LLVMSumType<'c>
Source§fn clone(&self) -> LLVMSumType<'c>
fn clone(&self) -> LLVMSumType<'c>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'c> Debug for LLVMSumType<'c>
impl<'c> Debug for LLVMSumType<'c>
Auto Trait Implementations§
impl<'c> Freeze for LLVMSumType<'c>
impl<'c> RefUnwindSafe for LLVMSumType<'c>
impl<'c> !Send for LLVMSumType<'c>
impl<'c> !Sync for LLVMSumType<'c>
impl<'c> Unpin for LLVMSumType<'c>
impl<'c> UnwindSafe for LLVMSumType<'c>
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§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.