In LLVM, we have a pretty hard rule that it should not be possible to trigger a crash or assertion by feeding verifer-valid IR to a pass. How hard of a line does it make sense to draw for this in the wider context of MLIR?
One example of where this can come up is with tensors. Our tensor type can model unranked tensors as well as various ranked cases up to the fully static case. Say we have a pass that only makes sense to run on ranked tensors (perhaps a code generation pass). Throughout this pass though one is constantly needing to do
value.getType().cast<RankedTensorType>() to access the underlying RankedTensorType’s (perhaps on a std.addf op). It seems difficult to be able to avoid triggering assertions from verifier-valid input (which could include unranked tensors on the std.addf) for such a pass without littering the entire pass with
rankedTensorType = ...dyn_cast<RankedTensorType>(); if (!rankedTensorType) return failure() type of noise code that “should never happen”.
I wonder if we could reuse the concept of a legalization target to help with this. For example, a pass could associate with itself an mlir::ConversionTarget, and when the verifier is enabled the addition of such a pass to a pipeline creates a “verify satisfies conversion target” pass in addition to a regular verifier pass.