Using "default:" in the switch statemements that handle all our
merger ops has become a bit cumbersome since it is easy to overlook
parts of the code that need to handle ops specifically. By enforcing
full switch statements without "default:", we get a compiler warning
when cases are overlooked.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I like this change a lot, since default cases are too fragile when there are so many cases to consider.
I do wonder though if it might be time to start refactoring the Kind enum to better handle the natural groupings of things. In particular I'm thinking it should be treated like a "bit enum" rather than an "int enum" (e.g., so that the I/F/C/etc suffix is encoded into, say, the low-order bits, whether something is leaf/unary/binary is encoded in the high-order bits, and then the op itself in the middle bits). Of course that should be done in a separate CL
mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp | ||
---|---|---|
1101–1102 | Why is the template keyword needed here when we don't need it for any of the other .cast<T>() method calls? |
mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp | ||
---|---|---|
1101–1102 | Good question, I am not sure how this was introduced, but we can do without. I removed all occurrences in the code. |
Agreed. A bit more "horizontal" encoding of type will simplify the long switch statements a bit, and get an intuitive way of getting the type from an op. But yeah, seems follow up CL.
Removing the default: on the switch in isSingleCondition broke the Windows bot, but unfortunately it was down so there was no timely notification. Sorry about that!
https://lab.llvm.org/buildbot/#/builders/13/builds/21881
FAILED: tools/mlir/lib/Dialect/SparseTensor/Utils/CMakeFiles/obj.MLIRSparseTensorUtils.dir/Merger.cpp.obj C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe ... /Fotools\mlir\lib\Dialect\SparseTensor\Utils\CMakeFiles\obj.MLIRSparseTensorUtils.dir\Merger.cpp.obj /Fdtools\mlir\lib\Dialect\SparseTensor\Utils\CMakeFiles\obj.MLIRSparseTensorUtils.dir\ /FS -c C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Utils\Merger.cpp C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Utils\Merger.cpp(380) : error C2220: the following warning is treated as an error C:\buildbot\mlir-x64-windows-ninja\llvm-project\mlir\lib\Dialect\SparseTensor\Utils\Merger.cpp(380) : warning C4715: 'mlir::sparse_tensor::Merger::isSingleCondition': not all control paths return a value
Why is the template keyword needed here when we don't need it for any of the other .cast<T>() method calls?