Skip to main content

Scope

Struct Scope 

Source
pub struct Scope { /* private fields */ }
Expand description

The scope represents the region currently being parsed, as well as the current insertion point. It is created from scratch for the initial codegen phase, or rebuilt from an existing scope and a rewriter for passes/conversions.

All state apart from the insertion point is shared. Global state like the type map and errors are stored in the context’s auxiliary storage, so they can be reconstructed from the rewriter state.

Implementations§

Source§

impl Scope

Source

pub fn device_properties(&self, properties: &DeviceProperties)

Set the device properties.

Source

pub fn state(&self) -> &GlobalState

Source

pub fn state_mut(&self) -> &mut GlobalState

Source

pub fn expand_state(&self) -> Ref<'_, ExpandState>

Source

pub fn expand_state_mut(&self) -> RefMut<'_, ExpandState>

Source

pub fn ctx(&self) -> &Context

Source

pub fn ctx_mut(&self) -> &mut Context

Source

pub fn inserter(&self) -> &mut dyn Inserter

Source

pub fn root(settings: KernelSettings) -> Scope

Create a parse scope that is at the root of a kernel definition.

A local scope can be created with the child method.

Source

pub fn dummy() -> Scope

Create a parse scope that only exists for type registration in the kernel builder. The state will be incomplete and should never be used for actual codegen.

Source

pub fn from_context_and_inserter( ctx: &mut Context, inserter: &mut (impl Inserter + 'static), ) -> Scope

Create a rewrite scope from an existing context and inserter/rewriter

Source

pub fn create_local_mut( &self, value_ty: impl Into<TypeHandle>, init: Option<Box<dyn Attribute>>, ) -> Value

Create a new mutable local variable of type specified by value_ty. initializer is a constant attribute and has the same rules as OpConstant. This is because SPIR-V does not allow non-constant (technically non-global, but constants are the only non-pointer globals) initializers.

Source

pub fn create_shared( &self, value_ty: impl Into<TypeHandle>, alignment: Option<usize>, ) -> Value

Create a shared variable of the given item type.

Source

pub fn func_ident(&self, label: Option<&str>) -> Identifier

Source

pub fn register_func(&self, func: FuncOp)

Create a new function.

Source

pub fn register(&self, op: &(dyn Op + 'static))

Register an [Instruction] into the scope.

Source

pub fn register_with_result( &self, op: &(dyn OneResultInterface + 'static), ) -> Value

Register an [Instruction] into the scope and return its result.

Source

pub fn terminate_yield(&self)

Terminate block with a cube.yield if not already terminated

Source

pub fn set_break_return(&self, children: &[Scope])

Source

pub fn set_may_return(&self, children: &[Scope])

Source

pub fn set_may_break(&self, children: &[Scope])

Source

pub fn create_kernel_ref<'a, T>(&self, value: T) -> &'a mut T
where T: 'a,

Add a value to the global arena so we can create a kernel-wide reference to it. The reference is the same as the type for simplicity, but is only valid for the duration of the root scope. Ensure the reference lifetime is shortened to the lifetime of the underlying variable being referenced.

Source

pub fn resolve_type<T>(&self) -> Option<ElemType>
where T: 'static,

Resolve the element type of the given generic type.

Source

pub fn resolve_size<T>(&self) -> Option<usize>
where T: 'static,

Resolve the comptime size of the given generic size.

Source

pub fn register_type<T>(&self, elem: ElemType)
where T: 'static,

Register the element type for the given generic type.

Source

pub fn register_size<T>(&self, size: usize)
where T: 'static,

Register the comptime size for the given generic size.

Source

pub fn register_value_type<T, N>(&self, value: impl Typed)
where T: 'static, N: 'static,

Register the type and size of a scalarizable type

Source

pub fn child(&self, inserter: impl Inserter + 'static) -> Scope

Create an empty child scope.

Source

pub fn loop_child(&self, inserter: impl Inserter + 'static) -> Scope

Create a child scope with a new break condition.

Source

pub fn func_child(&self, inserter: impl Inserter + 'static) -> Scope

Create a child that’s at the root of a new function

Source

pub fn push_error(&self, msg: impl Into<String>)

Source

pub fn pop_errors(&self) -> Vec<String>

Returns all validation errors.

Source

pub fn global( &self, buffer_pos: usize, ext_meta_pos: Option<usize>, value_ty: TypeHandle, ) -> Value

Obtain the index-th buffer

Source

pub fn tensor_map(&self, buffer_pos: usize, ext_meta_pos: usize) -> Value

Obtain the index-th tensor map

Source

pub fn kernel_arg(&self, idx: usize) -> Value

Source

pub fn extract_field(&self, aggregate: Value, field: usize) -> Value

Source

pub fn const_usize(&self, value: usize) -> Value

Source

pub fn const_bool(&self, value: bool) -> Value

Source

pub fn into_context(self) -> Option<Context>

Trait Implementations§

Source§

impl Debug for Scope

Source§

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

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

impl Display for Scope

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Scope

§

impl !RefUnwindSafe for Scope

§

impl !Send for Scope

§

impl !Sync for Scope

§

impl !UnwindSafe for Scope

§

impl Unpin for Scope

§

impl UnsafeUnpin for Scope

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

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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> 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> IntoComptime for T

Source§

fn comptime(self) -> Self

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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.