Skip to content

[spec] specify host functions in spectec#2210

Open
zilinc wants to merge 1 commit into
WebAssembly:mainfrom
zilinc:zilinc/hostfunc
Open

[spec] specify host functions in spectec#2210
zilinc wants to merge 1 commit into
WebAssembly:mainfrom
zilinc:zilinc/hostfunc

Conversation

@zilinc

@zilinc zilinc commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

It breaks the prose backend.
The official spec still needs to splice the relevant additions from spectec.

@zilinc

zilinc commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@rossberg We talked about upstreaming this part, and here we go. It should be a good starting point, but there're still TODOs.

@rossberg rossberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it not work to use pattern matching here, like in the hand-written version?

@zilinc zilinc Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. In that case leave it as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}} \\

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly. Or more precisely, the show hint for $funcinst removes the call parens..

@zilinc zilinc force-pushed the zilinc/hostfunc branch from 2e45c1b to 58e434e Compare July 15, 2026 10:00
@rossberg

Copy link
Copy Markdown
Member

Quick reminder: please never, ever force-push to a PR branch, since that breaks half of GitHub's review work flow. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants