Open rmn30 opened 1 year ago
Also the function I introduced that calls internal_error
:
/*!
* Raise an internal error reporting that width w is invalid for access kind, k,
* and current xlen. The file name and line number should be passed in as the
* first two arguments using the __FILE__ and __LINE__ built-in macros.
* This is mainly used to supress Sail warnings about incomplete matches and
* should be unreachable. See https://github.com/riscv/sail-riscv/issues/194
* and https://github.com/riscv/sail-riscv/pull/197 .
*/
val report_invalid_width : forall ('a : Type). (string, int, word_width, string) -> 'a effect {escape}
function report_invalid_width(f , l, w, k) -> 'a = {
internal_error(f, l, "Invalid width, " ^ size_mnemonic(w) ^ ", for " ^ k ^
" with xlen=" ^ string_of_int(sizeof(xlen)));
}
I guess it probably has something to do with the return type. Do you mean to use throw
right after an assert(false)
though? The throw will never actually occur.
default Order dec
$include <prelude.sail>
infixr 5 ^^
overload operator ^^ = {concat_str}
union exception = {
Error_internal_error : unit
}
val internal_error : forall ('a : Type). (string, int, string) -> 'a
function internal_error(file, line, s) = {
assert (false, file ^^ ":" ^^ dec_str(line) ^^ ": " ^^ s);
throw Error_internal_error()
}
val internal_error_caller : forall ('a : Type). (string, int, string) -> 'a
function internal_error_caller(f , l, k) -> 'a = {
internal_error(f, l, k);
}
val main : unit -> unit
function main() = {
internal_error_caller(__FILE__, __LINE__, "message 1");
internal_error(__FILE__, __LINE__, "message 2");
}
Should be a fairly minimal example
What it's doing is it does one round of monomorphisation, specialising internal_error and internal_error_caller, then it does a second round because the call to internal_error within internal_error_caller can now be monomorphised within the body of the specialised internal_error_caller producing the duplicate definition.
Thanks! Re. the throw at the end of internal_error
I think it is required to get it to type check as otherwise Sail is not aware that it never returns? Perhaps it should be rewritten to just throw Internal_Error(string).
I can confirm it now compiles!
If this is needed for the RISC-V spec would it make sense to do a 0.15.1 point release?
It is blocking the merge of the above PR so yes please. There are also some fixes to SMT I'd like to have in a release :-)
If this is needed for the RISC-V spec would it make sense to do a 0.15.1 point release?
FYI https://github.com/rems-project/sail/commit/444132c18fff5a3cde45c8a8642f1ed8e923fbdb causes lots of warnings in the RISC-V model. I'm not sure how to fix those so it would be good to check that they are indeed valid warnings before releasing the fix.
I made that warning one that only prints at most once so it prints less often. I think most of the issues in the RISC-V spec are valid warnings though. I fixed an issue with spurious warnings for mappings, but the definitions in https://github.com/riscv/sail-riscv/blob/master/model/prelude_mapping.sail are in the wrong order to do what I think is intended so the warnings for those are valid.
I will see about making a pull request to fix that file
When attempting to compile the current version of this PR: https://github.com/riscv/sail-riscv/pull/197 I get an error when compiling the C file generated by Sail:
I've not been able to reproduce in a smaller example yet. I suspect it is something to do with the interesting type of
internal_error
: