markUnknownOpDynamicallyLegal is not composable

I want to compose my ConversionTarget setup from calls to multiple populateSmthLegality(ConversionTarget &target). It work fine for trivial addLegalOp/addIllegalOp but for any non-trivial logic where markUnknownOpDynamicallyLegal is used this approach won’t work, as ConversionTarget can have only one (latest) markUnknownOpDynamicallyLegal callback.

My proposal is to change markUnknownOpDynamicallyLegal callback signature from bool(Operation*) to Optional<bool>(Operation*). Each markUnknownOpDynamicallyLegal will add callback to the list and when checking for legality this list will be traversed in reverse order until some callback return non-empty optional.

Sounds reasonable to me.

Another question: should we do this only for markUnknownOpDynamicallyLegal or for all other functions with callback too (addDynamicallyLegalOp, markOpRecursivelyLegal, addDynamicallyLegalDialect)?
I only have usecase for markUnknownOpDynamicallyLegal.

Some preparational refactoring ⚙ D105496 [mlir] ConversionTarget legality callbacks refactoring