rems-project / sail

Sail architecture definition language
Other
591 stars 101 forks source link

Clickable error/warning messages? #117

Open arichardson opened 3 years ago

arichardson commented 3 years ago

Many IDEs allow for clickable links if you format error messages similar to common GCC/Clang C compiler output:

For example, in PyCharm, if I get an error/warning when compiling the simulator code, I get something like:

sail-riscv/c_emulator/riscv_sim.c:755:11: error: implicit declaration of function 'zrvfi_halt_exec_packet' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
          zrvfi_halt_exec_packet(UNIT);

If I click on the file path, my IDE will open the file at that line.

However, a sail error such as

Type error:
[sail-riscv/model/riscv_mem.sail]:147:4-35
147 |    rvfi_mem_data->rvfi_mem_wmask() = 0xFF;

Does not result in a clickable link. It should work if the message is changed to use: sail-riscv/model/riscv_mem.sail:147:4-35:

arichardson commented 3 years ago

Similarly warning messages such as

Warning: Possible incomplete pattern match at
Most general matched pattern is AT_CAP_ERR_

Warning: Possible incomplete pattern match at [sail-riscv/model/riscv_pmp_regs.sail]:76:7-12
76 |  then match n {
   |       ^---^
   | 
Most general matched pattern is 0

would be clickable if they were reported as

<unknown>:0:0: Warning: Possible incomplete pattern match
Most general matched pattern is AT_CAP_ERR_

sail-riscv/model/riscv_pmp_regs.sail]:76:7-12: Warning: Possible incomplete pattern match
76 |  then match n {
   |       ^---^
   | 
Most general matched pattern is 0
SamB commented 2 years ago

This would also be useful for Emacs; check Emacs' compile library/command for details, but of course it supports GCC-style error messages -- it turns out that this style is actually laid out in the GNU Coding Standards: https://www.gnu.org/prep/standards/standards.html#Errors.

(I mean how else are the GNU Emacs developers going to check the errors in their C code when compiling on GNU/Linux -- even the other compiler uses GCC-style messsages: https://clang.llvm.org/docs/UsersManual.html#cl-diag-formatting.)

Alasdair commented 2 years ago

Thanks for bumping this issue, this looks like a fairly straightforward change. Should just be a case of changing some format strings in src/error_format.ml. I will put it on my todo list for the next Sail release.

My only question is there any guidance for nesting errors formatted in this way, so that the inner locations will also be clickable? For example:

Type error:
[duplicate_binding.sail]:6:10-11
6 |  let (x, x) = (true, false);
  |          ^
  | Duplicate binding for x in pattern
  | 
  | Caused by [duplicate_binding.sail]:6:7-8
  | 6 |  let (x, x) = (true, false);
  |   |       ^
  |   | Previous binding of x here
  |