The default exception handling isn't very user friendly and does not
point accurately to the issue. Instead we can indicate which of the
operands isn't valid and provide contextual information in the error
message.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
mlir/lib/Bindings/Python/IRModules.cpp | ||
---|---|---|
939 | This is a lot of boilerplate, happy to take a suggestion on how to improve it! |
mlir/lib/Bindings/Python/IRModules.cpp | ||
---|---|---|
922 | I also don't quite understand why casting None to a PyAttribute requires handling this other exception here, while above for the cast to std::string it does not... (maybe something about std::string itself...) |
mlir/lib/Bindings/Python/IRModules.cpp | ||
---|---|---|
912 | This and the py::reference_cast_error are deeper than I have gone. If you see PybindUtils.h, you'll see that I punted back to catching std::exception and just tightly scoping the body because I had trouble with the corners. | |
922 | I've never hit this before but probably because I usually explicitly check for none(). | |
939 | This is the version that I improved, believe it or not. There were prior iterations that were more convoluted with respect to checking the failure conditions in a way that wouldn't leak. But agreed. I have a feeling that this method may turn into a performance hotspot and need reworking anyway, so might make sense to save any major uplift to be based on some measurements. There are just a lot of mismatched types and forms that need to be bridged: not sure there is going to be a really elegant way to do it. | |
mlir/test/Bindings/Python/ir_operation.py | ||
562 | Can you make sure these are ValueError (not Exception -- ValueError is most commonly associated with this kind of mismatch)? You may need to throw them as std::invalid_argument for that to be the case. |
mlir/test/Bindings/Python/ir_operation.py | ||
---|---|---|
562 | I can, but PyBind issue a RuntimeError for cast conversion: https://github.com/pybind/pybind11/blob/master/include/pybind11/detail/common.h#L724 Can you confirm we should stick with ValueError? |
mlir/test/Bindings/Python/ir_operation.py | ||
---|---|---|
562 | That's annoying/inconsistent with typical usage, but better to be internally self consistent I suppose. Leaving it as is sgtm. |
This and the py::reference_cast_error are deeper than I have gone. If you see PybindUtils.h, you'll see that I punted back to catching std::exception and just tightly scoping the body because I had trouble with the corners.