1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// RLX — versatile ML compiler + runtime.
// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Compile-time shape / rank assertions (plan #77).
//!
//! Borrowed from MAX's `comptime assert c.rank == 2, "c must be rank 2"`
//! pattern. Where shapes are known at the point of macro expansion,
//! verify them at compile time via `const fn` helpers; runtime
//! `Shape` checks remain for genuinely-dynamic cases.
//!
//! The Rust spelling uses `const fn` predicates plus a small
//! `static_assert!` macro that wraps a `const _: () = assert!(...)`
//! evaluation. Failures surface as compile errors with the full
//! const-evaluation chain, so the user sees exactly which check
//! tripped.
//!
//! These tools are most useful inside macros (e.g. a future
//! `tensor!{ shape: [8, 8] }` literal that wants to check the
//! shape is non-empty + has the expected rank). Today they're
//! exposed as building blocks.
/// Compile-time assert. Wraps the const-evaluation idiom in a
/// terse macro so call sites read like `static_assert!(cond)`.
///
/// ```
/// rlx_ir::static_assert!(1 + 1 == 2);
/// rlx_ir::static_assert!(usize::MAX > 0, "platform sanity");
/// ```
///
/// Failure is a compile error pointing at the macro call site.
/// Const-evaluable rank check.
pub const
/// Const-evaluable rank-at-least check.
pub const
/// Const product of a fixed-size dim array. Useful for asserting
/// a flat element count matches a structured shape at compile
/// time.
pub const
/// Const check that `lhs` and `rhs` shapes are broadcast-compat
/// per the standard rules: equal at every dim, or one of them is
/// 1 at that dim. Both shapes must have the same rank (left-pad
/// the shorter externally if the runtime shape supports it).
pub const
/// Const check for the matmul rank/dim contract:
/// `[m, k] @ [k, n] → [m, n]`. Returns true iff the inner dims
/// agree.
pub const