vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
//! Cast validation table for IR expressions.
//!
//! Not every type pair can be cast safely or meaningfully in GPU shaders.
//! This module defines the closed set of supported casts so that the
//! validator can reject programs that would emit invalid conversion
//! instructions on the backend. The table is intentionally conservative:
//! missing casts can be added later without breaking existing programs.

use crate::ir::DataType;

/// Returns true if `source -> target` is a supported cast per `casts.md`.
///
/// The supported cast matrix is frozen: frontends and backends can rely
/// on it remaining stable across minor version bumps.
#[inline]
pub(crate) fn cast_is_valid(source: DataType, target: DataType) -> bool {
    if source == target {
        return true;
    }
    matches!(
        (source, target),
        (DataType::U32, DataType::I32)
            | (DataType::U32, DataType::Bool)
            | (DataType::U32, DataType::U64)
            | (DataType::U32, DataType::Vec2U32)
            | (DataType::U32, DataType::Vec4U32)
            | (DataType::I32, DataType::U32)
            | (DataType::I32, DataType::Bool)
            | (DataType::I32, DataType::U64)
            | (DataType::I32, DataType::Vec2U32)
            | (DataType::I32, DataType::Vec4U32)
            | (DataType::Bool, DataType::U32)
            | (DataType::Bool, DataType::I32)
            | (DataType::Bool, DataType::U64)
            | (DataType::Bool, DataType::Vec2U32)
            | (DataType::Bool, DataType::Vec4U32)
            | (DataType::U64, DataType::U32)
            | (DataType::U64, DataType::I32)
            | (DataType::U64, DataType::Bool)
            | (DataType::U64, DataType::Vec2U32)
            | (DataType::Vec2U32, DataType::U32)
            | (DataType::Vec2U32, DataType::I32)
            | (DataType::Vec2U32, DataType::U64)
            | (DataType::Vec2U32, DataType::Bool)
            | (DataType::Vec4U32, DataType::U32)
            | (DataType::Vec4U32, DataType::I32)
            | (DataType::Vec4U32, DataType::Vec2U32)
            | (DataType::Vec4U32, DataType::Bool)
            | (DataType::Vec4U32, DataType::U64)
            | (DataType::U32, DataType::F32)
            | (DataType::F32, DataType::U32)
    )
}