slang
slang copied to clipboard
Heterogeneous flag hiding errors
Currently, the -heterogeneous flag attempts to write the bytecode blob of a program to to C++ (if possible). However, if compilation fails, the error produced is the internal error:
(0): error 99999: Slang compilation aborted due to an exception of class Slang::InternalError: unexpected: No blob to emit
This error message should probably be made more descriptive, and at least give an indication of what the compilation error is.
I suspect the big fix would be to not diagnose an internal compiler error in that case. Diagnosing an internal error triggers logic in the compiler that tries to exit as quickly as possible (kind of like a kernel panic), while an "ordinary" error would just append to the list of diagnostics and keep going. In the non-internal error case, all the preceding error messages would still show up in the output.
I suspect there are two main options here:
-
We could try to ensure that all the kernels that would be embedded in the output C++ code are generated before we go to generate C++ output, and then have logic to bail out of compilation if any of them produced an error. This option might be tricky given that we don't currently control the relative order of the targets, and thus can't easily guarantee that DXBC output gets written before CPU C++.
-
We could simply write defensive code in the C++ output case, byt replacing the internal error with an ordinary error message that says more or less the same thing ("No generated code was found for kernel X in format Y; this may be because of another compilation error") and then make sure that we conditionalize the logic that required the blob so that it produces some kind of valid workaround code when the blob isn't present.
Sounds good; I think option (2) makes sense to me, I'll start working on implementing that. It should be straightforward to just output the same C++ code without the blob (which obviously won't compile), but an error at the end of the output should make that clear.