Bringing a discord chat here:
module {
%c = constant 1 : index
func @scope() -> (index) {
%c = constant 1 : index
return %c
}
}
results in the verifier failing:
test.mlir:5:7: error: redefinition of SSA value '%c'
%c = constant 1 : index
This is somewhat unintuitive, since functions can’t access variables outside their scope. While this may not be a great decision, it’s unclear whether the above code (which is clearly well-defined) should actually be illegal.
@mehdi_amini pointed out that code like this could be confusing:
%c = constant 1 : index
func @scope() -> (index) {
...
return %c
...
^bb13:
%c = constant 1 : index
...
}
Note that a similar message appears with arguments:
module {
%c = constant 1 : index
func @scope(%c : index) -> (index) {
return %c
}
}
producing
test.mlir:3:15: error: region entry argument '%c' is already in use
func @scope(%c : index) -> (index) {
^
test.mlir:2:3: note: previously referenced here
%c = constant 1 : in
Currently, the behavior of the verifier does depend on Traits and Interfaces (in particular, GraphRegions change the behavior of the verifier). @mehdi_amini pointed out that we want to ensure that IR can be round-tripped without loading any dialects. In this case, the IR that is generated by mlir-opt --mlir-print-op-generic would still be round-trippable, since the above cases would never be generated.
So: should we change the behavior of the verifier/parser to understand IsolatedFromAbove, expanding the space of valid programs to include the cases above? Does anyone feel strongly that this is a bad idea?
Edit: I realize that this may be more of a parsing problem than a verification problem, which makes it a bigger deal, I think.