The SingleBlockImplicitTerminator op trait provides a function
ensureRegionTerminator that injects an appropriate terminator into the block
if necessary, which is used during operation constructing and parsing.
Currently, this function directly modifies the IR using low-level APIs on
Operation and Block. If this function is called from a conversion pattern,
these manipulations are not reflected in the ConversionPatternRewriter and thus
cannot be undone or, worse, lead to tricky memory errors and malformed IR.
Change ensureRegionTerminator to take an instance of OpBuilder instead of
Builder, and use it to construct the block and the terminator when required.
Maintain overloads taking an instance of Builder and creating a simple
OpBuilder to use in parsers, which don't have an OpBuilder and cannot
interact with the dialect conversion mechanism. This change was one of the
reasons to make <OpTy>::build accept an OpBuilder.
Depends On D80137
would it be better to make it explicit by having a small wrapper class and force users to cast?
Making the non-safe use case hard here and everywhere else would have likely saved many hours of engineering,