-
Notifications
You must be signed in to change notification settings - Fork 200
Log verifier errors #1226
Log verifier errors #1226
Conversation
|
I think https://docs.rs/cranelift-codegen/0.50.0/cranelift_codegen/print_errors/fn.pretty_verifier_error.html should be used instead. Also it would be nice to make the verifier error unwraps in for example cranelift_module give a nice panic message, instead of adding this error logging. This error logging makes verifier errors show up twice when using for example clif-util compile, as it already shows the function annnotated with verifier errors. |
|
@bjorn3, I tried to use |
What issues?
Wherever a |
|
It would also be possible to add a stringified version of the entity to |
|
Making errors more discoverable and easy to understand is a valuable goal. Just trying to understand the use case: is it when there's a verifier error in wasmtime itself? Or are you using the clif-util and sometimes verifier errors aren't displayed? In the former case, wasmtime could use the exposed pretty printers that are in
Are you suggesting to cause panics whenever there are verifier errors? If so, I think we should let this decision to the users of any cranelift module, and not do this by ourselves. Embedders should be able to handle invalid wasm code (for instance) and not crash. |
|
I mean that when somebody already unwraps, it should give a nicer error message by default. |
Yeah, in both cases-- cranelift/cranelift-filetests/src/test_compile.rs Lines 43 to 45 in 8ef665d
This seems to be largely the case as I search around in cranelift but not in wasmtime. In wasmtime the When I mentioned having issues with this before, it is because I tried to make Since holding on to references to |
|
And another thought: do we really need to have lazy errors? What if cranelift/cranelift-codegen/src/result.rs Lines 10 to 17 in d23030f
|
I think this is useful because then we can only provide context once (i.e. printing lines of code around the error location), otherwise we couldn't print two different errors within a single context.
I imagine you mean it's complicated to have wasmtime convert from our error type to its own error type, calling the pretty printing methods btw. Otherwise, it might be worth doing this in wasmtime, wouldn't it?
I have looked at the pretty printing, and it seems it's consuming errors as it prints them, so I wonder if @bjorn3 meant that if a verifier errors vector has been emptied, and we're calling the pretty printers again, then we should panic. If so, I agree it'd be nice to signal it to the caller of the pretty print functions. [edit] Dismiss this last part, the pretty print function takes ownership of the |
|
No. When somebody uses |
|
I think I'm on board with what is suggested:
I can convert this PR to do the first point if we all agree? |
|
I think this sounds great 👍 |
abbc3d3 to
ccc46bd
Compare
ccc46bd to
4515e21
Compare
|
An explanation of these commits:
Finally, the build failures are somewhat surprising: I don't see that I made a mistake in moving over to the new |
4515e21 to
adcaf4c
Compare
Nope 😆. I found it. |
As discussed in bytecodealliance/cranelift#1226, the context of Cranelift errors is lost after exiting the scope containing the Cranelift function. `CodegenError` then only contains something like `inst2: arg 0 (v4) has type i16x8, expected i8x16`, which is rarely enough information for investigating a codegen failure. This change uses Cranelift's `pretty_error` function to improve the error messages wrapped in `CompileError`; `CompileError` has lost the reference to `CodegenError` due to `pretty_error` taking ownership but this seems preferable since no backtrace is attached and losing the pretty-printed context would be worse (if `CodegenError` gains a `Backtrace` or implements `Clone` we can revisit this).
As discussed in bytecodealliance/cranelift#1226, the context of Cranelift errors is lost after exiting the scope containing the Cranelift function. `CodegenError` then only contains something like `inst2: arg 0 (v4) has type i16x8, expected i8x16`, which is rarely enough information for investigating a codegen failure. This change uses Cranelift's `pretty_error` function to improve the error messages wrapped in `CompileError`; `CompileError` has lost the reference to `CodegenError` due to `pretty_error` taking ownership but this seems preferable since no backtrace is attached and losing the pretty-printed context would be worse (if `CodegenError` gains a `Backtrace` or implements `Clone` we can revisit this).
bnjbvr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks!
| } | ||
|
|
||
| /// Diagnose a fatal error, and return `Err`. | ||
| fn fatal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Can the fatal and nonfatal macros be entirely removed now, by replacing other uses in the other files contained in the verifier directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fatal! still has 52 usages, nonfatal! has 4 usages, and report! has 23 usages; I'll create an issue to do that as a separate PR because I think I would like to refactor that stuff on to VerifierErrors: #1248.
Previously, verifier errors looked like `inst42: v2 is not...`; now, when printed, these same errors will have the instruction context: `inst42 (v3 = not v2): v2 is not...`. This should make it easier to troubleshoot verifier errors when the full pretty-printed error string is not available (see `pretty_error`).
adcaf4c to
82a54e5
Compare
inst2: arg 0 (v4) has type i16x8, expected i8x16) is usually not enough to troubleshoot the location of the failure. This change adds logging like the following:The logging level can be controlled with the
RUST_LOGenvironment variable but due toenv_loggerhaving a default log level ofERRORthese messages will always be printed. If we don't want that, we can downgrade these logs toWARNINGso they can optionally be turned on by something likeRUST_LOG=cranelift_codegen=warning.