wgsl_rs/linkage/mod.rs
1//! Linkage machinery for `wgsl-rs`.
2//!
3//! ## wgpu linkage
4//! Runtime wgpu linkage analysis lives in the `wgpu` submodule, gated
5//! behind the `linkage-wgpu` feature. The runtime analyzer walks the IR
6//! produced by a `#[wgsl]` source (post-instantiation for templates) and
7//! produces bind group layouts, pipeline state descriptors, and buffer
8//! descriptors without any compile-time code generation from the
9//! proc-macro. See the `wgpu` module for details.
10//!
11//! ## Source instantiation
12//! When a `#[wgsl]` source contains generic linkage variables (e.g.
13//! `storage!(group(0), binding(0), BINS: impl std::any::Any)`) that are
14//! accessed via `get!(BINS, T)` or `get_mut!(BINS, T)`, the generated
15//! `instantiate` function needs to enforce that every entry point agrees on
16//! the concrete type of each linkage variable.
17//!
18//! The [`Type`] trait provides a type-level equality constraint:
19//! `T: Type<Is = U>` is satisfied iff `T` and `U` are the same type.
20//! This is used in the `where` clause of the generated `instantiate`
21//! function to catch conflicting specialisations at compile time.
22
23#[cfg(feature = "linkage-wgpu")]
24pub mod wgpu;
25
26/// A trivial trait for type equality checking.
27///
28/// `T: Type<Is = U>` is satisfied iff `T == U`.
29///
30/// This is used by the generated `instantiate` function's `where` clause
31/// to enforce that a linkage variable's type is consistent across all
32/// entry points that use it.
33pub trait Type {
34 /// The associated type, which for the blanket impl is the type itself.
35 type Is;
36}
37
38impl<T> Type for T {
39 type Is = T;
40}