Is `cf.assert` a compile-time or runtime assertion?

I am attempting to use cf.assert MLIR operation within Mojo to raise compile time error in a Mojo program.

Just want to confirm cf.assert is capable of raising compile time error and halt the compilation of a program with LLVM backend.

Thank you.

No, it is not capable of raising a compile-time error. It is a runtime assertion, similarly to assert in Python or assert() in C++. It wouldn’t be possible to do compile-time assertion without interpreting the IR that defines the operand of the assert at compile time, by the way.


Clarified the behavior in [MLIR][Doc] Clarify the cf.asssert doc that this is a runtime assertion · llvm/llvm-project@cba4e7e · GitHub

1 Like