Closed Timmmm closed 5 months ago
I think the problem is that the if-then-else typing rule is probably inferring to something like {4, 8}
and losing the connection with the 'v
type variable.
I was thinking now I have if-then-else on types I can make that rule a bit more precise.
Aha, that's definitely it! If I explicitly raise let 'pte_width = if 'v == 32 then 4 else 8
to the type level by putting it in a function then it works:
...
val pte_width_bytes : forall 'v, 'v in {32, 39, 48, 57} . (int('v)) -> int(if 'v == 32 then 4 else 8)
function pte_width_bytes(sv_width) = if 'v == 32 then 4 else 8
...
let 'pte_width = pte_width_bytes(sv_width);
write_pte(pte_width, pte)
...
Is there a way to explicitly type annotate it too? Something like this?
let 'pte_width : {if 'v == 32 then 4 else 8} = if 'v == 32 then 4 else 8;
(I don't think I really want to use that here but I was just wondering.)
Should be fixed by: https://github.com/rems-project/sail/pull/553
You could do let 'pte_width : int(if 'v = 32 then 4 else 8) = ...
I think.
Ah works perfectly now, thanks!
This code:
Gives this error:
Which if you expand
'pte_width
is sayingwhich seems quite simple to me, unless I've missed something! Any idea why this isn't working? I couldn't figure out a way around it.