pub trait Dialect {
Show 23 methods
// Required methods
fn name(&self) -> &'static str;
fn prologue(&self, layout: &Layout) -> String;
fn epilogue(&self) -> &'static str;
fn lit(&self, v: i64, signed: bool) -> String;
fn index(&self, name: &str, idx: &str, is_buffer: bool) -> String;
fn exec(&self, id: ExecId, signed: bool) -> Option<String>;
fn binary(
&self,
op: BinaryOp,
a: &str,
b: &str,
signed: bool,
) -> Option<String>;
fn select(&self, cond: &str, a: &str, b: &str, signed: bool) -> String;
fn temp(&self, name: &str, rhs: &str, signed: bool) -> String;
fn bound(&self, name: &str, rhs: &str, signed: bool) -> String;
fn barrier(&self, scope: Scope) -> Option<String>;
fn fence(&self, scope: Scope, order: MemoryOrder) -> Option<String>;
// Provided methods
fn wide(&self) -> bool { ... }
fn cast_to_compute(&self, _x: &str, _from: ElementKind) -> Option<String> { ... }
fn arith(&self, op: ArithOp, a: &str, b: &str) -> Option<String> { ... }
fn truthy(&self, value: &str, signed: bool) -> String { ... }
fn atomic_rmw(
&self,
_op: AtomicOp,
_elem: &str,
_value: &str,
) -> Option<String> { ... }
fn atomic_cas(
&self,
_elem: &str,
_expected: &str,
_desired: &str,
) -> Option<String> { ... }
fn typed_atomics(&self) -> bool { ... }
fn atomic_scope_ok(&self, _scope: Scope) -> bool { ... }
fn atomic_load(&self, _elem: &str) -> Option<String> { ... }
fn atomic_store(&self, _elem: &str, _value: &str) -> Option<String> { ... }
fn atomic_cas_lines(
&self,
elem: &str,
expected: &str,
desired: &str,
dest: Option<&str>,
) -> Option<Vec<String>> { ... }
}Expand description
The spellings of one target language.
A method that cannot spell something returns None (or an Err text), and the walker turns that
into a typed decline naming it; nothing is approximated.
Required Methods§
Sourcefn prologue(&self, layout: &Layout) -> String
fn prologue(&self, layout: &Layout) -> String
The header, buffer and shared declarations and the opening of the entry function, with the locals declared (one line each) at the top of the entry.
Sourcefn index(&self, name: &str, idx: &str, is_buffer: bool) -> String
fn index(&self, name: &str, idx: &str, is_buffer: bool) -> String
The element idx of the buffer or shared array name.
Sourcefn exec(&self, id: ExecId, signed: bool) -> Option<String>
fn exec(&self, id: ExecId, signed: bool) -> Option<String>
The spelling of an execution id, or None when the dialect has none.
Sourcefn binary(&self, op: BinaryOp, a: &str, b: &str, signed: bool) -> Option<String>
fn binary(&self, op: BinaryOp, a: &str, b: &str, signed: bool) -> Option<String>
A binary op on two integers, or None when there is no spelling.
Sourcefn temp(&self, name: &str, rhs: &str, signed: bool) -> String
fn temp(&self, name: &str, rhs: &str, signed: bool) -> String
A hoisted temporary declaration line (no indentation, no newline).
Sourcefn bound(&self, name: &str, rhs: &str, signed: bool) -> String
fn bound(&self, name: &str, rhs: &str, signed: bool) -> String
The For counter’s bound and step constants, declared once before the loop.
Provided Methods§
Sourcefn wide(&self) -> bool
fn wide(&self) -> bool
Whether this dialect instance lowers 64-bit integer kernels (I64/U64). The default is no:
such a kernel is then a typed decline naming the dialect. A dialect that says yes types every
spelling at 64 bits and spells Self::cast_to_compute; an execution id stays the u32 the IR
types it as, reached through a Cast.
Sourcefn cast_to_compute(&self, _x: &str, _from: ElementKind) -> Option<String>
fn cast_to_compute(&self, _x: &str, _from: ElementKind) -> Option<String>
x, of integer type from, converted (wrapping) to the compute dtype, or None when there is
no spelling. Only asked of a dialect whose Self::wide is true.
Sourcefn arith(&self, op: ArithOp, a: &str, b: &str) -> Option<String>
fn arith(&self, op: ArithOp, a: &str, b: &str) -> Option<String>
a + b, a - b, a * b (wrapping); None for a division.
Sourcefn atomic_rmw(&self, _op: AtomicOp, _elem: &str, _value: &str) -> Option<String>
fn atomic_rmw(&self, _op: AtomicOp, _elem: &str, _value: &str) -> Option<String>
An expression applying atomic op to the element elem with value, giving the old value;
None when the dialect has no spelling (the default).
Sourcefn atomic_cas(
&self,
_elem: &str,
_expected: &str,
_desired: &str,
) -> Option<String>
fn atomic_cas( &self, _elem: &str, _expected: &str, _desired: &str, ) -> Option<String>
An expression compare-exchanging the element elem, giving the value found; None when
the dialect has no spelling (the default).
Sourcefn typed_atomics(&self) -> bool
fn typed_atomics(&self) -> bool
Whether the dialect declares an atomically accessed buffer or array with a different type (WGSL
atomic<u32>), so plain access to it goes through Self::atomic_load / Self::atomic_store.
Sourcefn atomic_scope_ok(&self, _scope: Scope) -> bool
fn atomic_scope_ok(&self, _scope: Scope) -> bool
Whether an atomic at scope can be spelled (the default: every scope).
Sourcefn atomic_load(&self, _elem: &str) -> Option<String>
fn atomic_load(&self, _elem: &str) -> Option<String>
An expression reading the element elem of an atomically typed buffer or array.
Sourcefn atomic_store(&self, _elem: &str, _value: &str) -> Option<String>
fn atomic_store(&self, _elem: &str, _value: &str) -> Option<String>
A statement writing value to the element elem of an atomically typed buffer or array.
Sourcefn atomic_cas_lines(
&self,
elem: &str,
expected: &str,
desired: &str,
dest: Option<&str>,
) -> Option<Vec<String>>
fn atomic_cas_lines( &self, elem: &str, expected: &str, desired: &str, dest: Option<&str>, ) -> Option<Vec<String>>
The lines compare-exchanging elem and writing the value found to dest, if any. The default
is one assignment of Self::atomic_cas; a dialect whose exchange can fail spuriously
overrides it with a retry loop, because the IR’s compare-exchange cannot.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".