[mlir][IR] Refactor the getChecked and verifyConstructionInvariants methods on Attributes/Types
verifyConstructionInvariants is intended to allow for verifying the invariants of an attribute/type on construction, and getChecked is intended to enable more graceful error handling aside from an assert. There are a few problems with the current implementation of these methods:
- verifyConstructionInvariants requires an mlir::Location for emitting errors, which is prohibitively costly in the situations that would most likely use them, e.g. the parser.
This creates an unfortunate code duplication between the verifier code and the parser code, given that the parser operates on llvm::SMLoc and it is an undesirable overhead to pre-emptively convert from that to an mlir::Location.
- getChecked effectively requires duplicating the definition of the get method, creating a quite clunky workflow due to the subtle different in its signature.
This revision aims to talk the above problems by refactoring the implementation to use a callback for error emission. Using a callback allows for deferring the costly part of error emission until it is actually necessary.
Due to the necessary signature change in each instance of these methods, this revision also takes this opportunity to cleanup the definition of these methods by:
- restructuring the signature of getChecked such that it can be generated from the same code block as the get method.
- renaming verifyConstructionInvariants to verify to match the naming scheme of the rest of the compiler.
Differential Revision: https://reviews.llvm.org/D97100