Stream: beginners

Topic: roc__mainForHost_1_exposed_generic


view this post on Zulip Luke Boswell (Nov 09 2023 at 22:34):

How do you know what the exposed function signature will be for e.g. mainForHost : Str -> Str? I have been having a hard time trying to make a very basic platform using zig than the platform switching example which is just mainForHost : Str. Is there a way to generate the LLVM for example which might provide a clue as to the expected signature?

view this post on Zulip Luke Boswell (Nov 09 2023 at 22:35):

For reference I have been trying to get https://github.com/lukewilliamboswell/roc-serverless working.. but even without the wasm part I'm not confident I have the signature correct

view this post on Zulip Luke Boswell (Nov 09 2023 at 22:39):

Would it be possible fore something like roc glue to generate this signature in future?

view this post on Zulip Brendan Hansknecht (Nov 09 2023 at 22:55):

--debug

view this post on Zulip Brendan Hansknecht (Nov 09 2023 at 22:55):

That will get you the llvm ir

view this post on Zulip Luke Boswell (Nov 09 2023 at 22:55):

I think I answered part of my question above. Build it using a debug version of the compiler and I get a .bc file

view this post on Zulip Brendan Hansknecht (Nov 09 2023 at 22:56):

And yeah, all of this can be generated by roc glue.

view this post on Zulip Brendan Hansknecht (Nov 09 2023 at 22:56):

The roc webserver that Richard is working on in rust had these functions generated (though currently with a bug)

view this post on Zulip Brendan Hansknecht (Nov 09 2023 at 22:57):

Also, debug should get you a .ll file

view this post on Zulip Luke Boswell (Nov 09 2023 at 22:59):

'I could not find the debugir tool on the PATH do you have to build that from source? Is there a distribution for macos?

view this post on Zulip Brendan Hansknecht (Nov 09 2023 at 22:59):

You actually don't need it. The .ll file should exist now.

view this post on Zulip Luke Boswell (Nov 09 2023 at 23:03):

This will help me investigate further

view this post on Zulip Luke Boswell (Nov 09 2023 at 23:30):

The glue from Richard's webserver generates identically to what I expect, two pointers return and argument of RocStr.

The llvm though gives, which looks like it takes a single pointer.

define void @roc__mainForHost_1_exposed_generic(ptr %0) {
entry:
  %call = call fastcc {} @_mainForHost_f03bf86f79d121cbfd774dec4a65912e99f5f17c33852bbc45e81916e62b53b()
  store {} %call, ptr %0, align 1
  ret void
}

The issue I have is that zig is generating different wasm type signature from roc I think. How is this possible?

$ roc build --target=wasm32 examples/echo.roc
🔨 Rebuilding platform...
LLD Link... warning(link): unexpected LLD stderr:
wasm-ld: warning: function signature mismatch: roc__mainForHost_1_exposed_generic
>>> defined as (i32, i32) -> void in lto.tmp
>>> defined as (i32) -> void in /Users/luke/.cache/zig/o/21804a4778e09cb059cc1335d2b95b55/roc_appxhNgOx.o

0 errors and 0 warnings found in 420 ms while successfully building:

    examples/echo.wasm

I suspect there is some kind of optimization going on maybe?

view this post on Zulip Luke Boswell (Nov 09 2023 at 23:37):

I figured it out!! :tada: I had to change the platform from mainForHost = main to mainForHost = \str -> main str and then it works. I have no idea why.

view this post on Zulip Ayaz Hafiz (Nov 09 2023 at 23:51):

sorry, just saw this. it's because of lambda sets :upside_down:

view this post on Zulip Ayaz Hafiz (Nov 09 2023 at 23:51):

I think there's an issue to make it so that's automatically suggested in these cases

view this post on Zulip Brendan Hansknecht (Nov 09 2023 at 23:52):

Can we automatically just wrap/add that on the compiler side so users don't have to?

view this post on Zulip Ayaz Hafiz (Nov 10 2023 at 00:14):

in theory, yes


Last updated: Jul 06 2025 at 12:14 UTC