[spec] specify host functions in spectec#2210
Conversation
|
@rossberg We talked about upstreaming this part, and here we go. It should be a good starting point, but there're still TODOs. |
rossberg
left a comment
There was a problem hiding this comment.
Thanks, this looks good so far.
|
|
||
| def $lift_result(result) : instr* hint(show %) | ||
| def $lift_result(_VALS val*) = val* | ||
| def $lift_result(`(REF.EXN_ADDR a) THROW_REF) = (REF.EXN_ADDR a) THROW_REF |
There was a problem hiding this comment.
Note that the representation of exception results changes in #2189.
| rule Step/call_ref-hostfunc-res: | ||
| s; f; val^n (REF.FUNC_ADDR a) (CALL_REF yy) ~> s'; f; $lift_result(result) | ||
| ---- | ||
| -- if $funcinst((s; f))[a] = fi |
There was a problem hiding this comment.
Does it not work to use pattern matching here, like in the hand-written version?
There was a problem hiding this comment.
I think the reason was that there's a MODULE field in the record as well, so it has to appear in the pattern. But otherwise I don't see any problems. I can do it if it's preferred.
There was a problem hiding this comment.
Ah, right. In that case leave it as is.
There was a problem hiding this comment.
I was wondering why I needed the parens around (s; f) in the $funcinst call. Maybe the reason is in the latex generation:
-\mbox{if}~ (s ; f){.}\mathsf{funcs}{}[a] = {\mathit{fi}} \\
+\mbox{if}~ s ; f{.}\mathsf{funcs}{}[a] = {\mathit{fi}} \\
There was a problem hiding this comment.
Yes, exactly. Or more precisely, the show hint for $funcinst removes the call parens..
|
Quick reminder: please never, ever force-push to a PR branch, since that breaks half of GitHub's review work flow. ;) |
|
We don't necessarily need prose for these (since they are mostly interesting as part of a formalisation). But of course, the pipeline shouldn't break over them. |
https://github.com/f52985/spec/tree/hostfunc In this branch, I implemented a fix that allows function calls—or, more generally, any expression whose type is a list of instructions—on the right-hand side of a reduction rule. It also seems to work correctly with the interpreter backend. Please check if this works, and let me know if something goes wrong. |
Thanks heaps Dongjun. I'll give it a go and let you know. |
|
@f52985 Thanks agian. The pipeline now works without errors. The prose merges the cases in a somewhat unexpected way, but since we are not using the prose for any of the rules here, it should be fine. |
|
@rossberg This should be ready. The new rules look almost identical as before. I edited the doc a bit to reflect some meta-variable changes, and also tried to fix the manual prose for the normal function call case. |
rossberg
left a comment
There was a problem hiding this comment.
Ah, it wasn't necessary to change the prose for the normal function case, since that's gone anyway with #2189.
But while you're converting the host function section to SpecTec, would you mind including the inline math as well? For example, :math:`(s, \val^n)` becomes ${:(s, val^n)}.
rossberg
left a comment
There was a problem hiding this comment.
Thanks! Two minor oversights, I believe.
| which means that it adheres to suitable pre- and post-conditions: | ||
| under a :ref:`valid store <valid-store>` :math:`S`, and given arguments :math:`\val^n` matching the ascribed parameter types :math:`t_1^n`, | ||
| executing the host function must yield a non-empty set of possible outcomes each of which is either divergence or consists of a valid store :math:`S'` that is an :ref:`extension <extend-store>` of :math:`S` and a result matching the ascribed return types :math:`t_2^m`. | ||
| under a :ref:`valid store <valid-store>` ${:s}, and given arguments ${:\val^n} matching the ascribed parameter types ${:t_1^n}, |
There was a problem hiding this comment.
| under a :ref:`valid store <valid-store>` ${:s}, and given arguments ${:\val^n} matching the ascribed parameter types ${:t_1^n}, | |
| under a :ref:`valid store <valid-store>` ${:s}, and given arguments ${:val^n} matching the ascribed parameter types ${:t_1^n}, |
| Here, :math:`\X{hf}(S; \val^n)` denotes the implementation-defined execution of host function :math:`\X{hf}` in current store :math:`S` with arguments :math:`\val^n`. | ||
| It yields a set of possible outcomes, where each element is either a pair of a modified store :math:`S'` and a :ref:`result <syntax-result>` | ||
| or the special value :math:`\bot` indicating divergence. | ||
| Here, ${:$hostcall(_HOSTFUNC hf, s, val^n)} denotes the implementation-defined execution of host function ${:_HOSTFUNC hf} in current store ${:s} with arguments ${:val^n}. |
There was a problem hiding this comment.
| Here, ${:$hostcall(_HOSTFUNC hf, s, val^n)} denotes the implementation-defined execution of host function ${:_HOSTFUNC hf} in current store ${:s} with arguments ${:val^n}. | |
| Here, ${:$hostcall(_HOSTFUNC hf, s, val^n)} denotes the implementation-defined execution of host function ${:hf} in current store ${:s} with arguments ${:val^n}. |
There was a problem hiding this comment.
Thanks for spotting them. The other one was an oversight; this one was intentional, but the intention was not quite correct.
It breaks the prose backend.
The official spec still needs to splice the relevant additions from spectec.