Sarek_ir_namesNames of a kernel that the target language cannot take as written.
OCaml lets a kernel rebind a name (let s = s +. 1.0 in ..., two let t in one block), call a variable half or x', and the IR carries those names through to the generators. In C-family source the first two declare a name twice (or, in float s = s + 1.0f, read the variable being declared); the others are keywords, types or not identifiers. The device compiler rejects the source, or, when the name hides a built-in function, a later call resolves to the variable.
legalize is a renaming that runs once at the entry of a generator, before any other pass. A reference resolves to the innermost binder that can be its own: a variable whose var_id and the binder's are both set and differ does not reach it (a later binder of the same name in the same target block, renamed, does not capture a reference to an earlier one); array references, which carry a name only, reach arrays and never scalars, and the innermost array of that name in the IR scope: an array bound by a let is out of scope after the let's own body, although its declaration stays in the target block (so its name is renamed away from a parameter's). A shader vector parameter is a buffer of its name: a local must avoid it, the parameter itself is never renamed.
The renaming:
reserved) or already names a binder in scope becomes <name>_<k> (the smallest k that no name of the kernel uses), and every reference in its scope follows;length, step or dot, the get_, half_ and quad_ families): a kernel using one gets a new source.Binders are let/let mut variables, for indices, pattern variables, parameters, locals, shared arrays and helper functions. Record fields, constructors, intrinsics, the names of record and variant types and cooperative-matrix fragment names are neither renamed nor avoided. A kernel containing SNative (opaque source text) is returned unchanged: this pass could not rename the identifiers inside it.
val legalize :
reserved:(string -> bool) ->
rename_params:bool ->
Sarek_ir_types.kernel ->
Sarek_ir_types.kernellegalize ~reserved ~rename_params k.
reserved name says name cannot be declared in the target language. rename_params says whether kernel parameters may be renamed (C-family targets: yes, an argument is bound by position). Helper parameters are real function parameters on every target: they are always renamable and always counted among the binders a local must avoid (a shader helper's vector parameter, a buffer of its name, is the exception: never renamed). When false, kernel parameters keep their names and are not counted among the binders a local must avoid, because the target exposes them by name (GLSL push-constant macros, WGSL uniform fields) and has its own pass for a local that shadows one (Sarek_ir_codegen.rename_shadowing_locals).
val legalize_shader : Sarek_ir_types.kernel -> Sarek_ir_types.kernellegalize for GLSL and WGSL: only names that are not identifiers (Sarek_reserved_words.invalid_identifier) and locals that redeclare a local in scope are renamed; reserved words and parameter shadowing stay with the target's own escaper.