Optional MLIR numeric kernels

radlang run --mlir [--release] file.rad and radlang build --mlir file.rad enable compiler-verified CPU kernels. The first supported operation is row-major f64 matrix multiplication:

float[] product = math.matmul([1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], 2, 2, 2)
// [19, 22, 43, 50]

The dimensions are rows, shared dimension, columns. Inputs must be float[] (or num[]) and dimensions int or long. Both lengths must match the shapes exactly. Negative dimensions or byte-count overflow throw before kernel execution. Zero dimensions are valid; a zero shared dimension produces a zero-filled output. The output is fresh; inputs may alias each other and are never modified. Allocation and lifetime behavior is the same with and without the flag.

Without the flag, this API uses a checked native implementation. With the flag, only positive literal dimensions fitting checked storage arithmetic and known f64 list element types are specialized. Dynamic/empty shapes use the native fallback. Specialization applies to calls emitted in the current compilation module; existing precompiled .rlc/.rlp objects are not rewritten or reinterpreted. Arbitrary application loops and opaque LibTorch operations are not automatically transformed.

The compiler requires matching LLVM/MLIR 20.1.x tools, a supported native 64-bit little-endian macOS/Linux x86-64/AArch64 ABI, verified lowered LLVM IR and the exact three-descriptor C function signature. It lowers linalg.matmul through loops to LLVM without fast-math/reassociation/contraction. It reports activation explicitly. Missing/incompatible tools, unsupported code, invalid IR or an invalid kernel ABI produce a warning and retain the ordinary backend. A link failure after successful verification is a compile error; a partially linked module is never executed.

RADLANG_MLIR_OPT and RADLANG_MLIR_TRANSLATE select explicit tool executables. Otherwise the LLVM20 Homebrew tools, if installed, or tools on PATH are used. These are compiler build-time dependencies only. Produced binaries contain native code and need no MLIR installation. No tool download or installation is automatic. Both hermetic native-object and classic clang links are covered by acceptance tests.

Pass application arguments after --, for example radlang run --mlir main.rad -- --mlir. The second flag then belongs to the application.

This is a compatible first numeric surface, not a whole-language replacement or automatic Metal/autograd backend. Specialized buffer kernels can avoid list-index overhead, but a speedup over the checked native matrix fallback is not guaranteed. The earlier preallocated microbenchmarks and their limits are in the implementation findings.

Run python3 tests/runners/mlir-backend.py /absolute/path/to/radlang with compatible tools installed for strict numerical, shape, CLI, toolchain, IR/ABI fallback and link-mode checks. Run heavy builds/tests serially with memory/storage monitoring.