Stream: wit-bindgen

Topic: ✔ Where do func params names come from


view this post on Zulip Scott Waye (Sep 20 2023 at 13:52):

Hi, can I ask for a bit of help with a problem I have with the parameter name for a function. The problem is that I am generating this code:

    internal static void A(string p0)
    {
        var result = x;
        IntPtr interopString = InteropString.FromString(result, out int length);
        AInterop.wasmImportA(interopString.ToInt32(), length);

Where what I want is
internal static void A(string p0)
{
var result = p0;

I.e. `p0`, not `x`.  The `x` comes from the `GetArg` instruction:
[image.png](/user_uploads/15107/fF4EE_QccOFok-SJwbuXhxPq/image.png)
And my question is where does the `x` come from and what might I have done wrong so that it doesn't match

let sig = self.resolve.wasm_signature(AbiVariant::GuestImport, func);

and `sig.params` ?

Thanks

view this post on Zulip Scott Waye (Sep 20 2023 at 13:54):

image.png

view this post on Zulip Lann Martin (Sep 20 2023 at 13:55):

Param names should be available from func.params (https://docs.rs/wit-parser/0.11.1/wit_parser/type.Params.html)

view this post on Zulip Lann Martin (Sep 20 2023 at 13:56):

sig is a core wasm func signature; core func params don't have names

view this post on Zulip Scott Waye (Sep 20 2023 at 13:57):

So

impl Bindgen for FunctionBindgen<'_, '_> {
    type Operand = String;

    fn emit(
        &mut self,
        _resolve: &Resolve,
        inst: &Instruction<'_>,
        operands: &mut Vec<String>,
        results: &mut Vec<String>,
    ) {
        match inst {
            Instruction::GetArg { nth } => results.push(self.params[*nth].clone()),

Is correct?

view this post on Zulip Lann Martin (Sep 20 2023 at 13:58):

I am not that familiar with bindgen; is nth referring to the component signature or the core signature?

view this post on Zulip Lann Martin (Sep 20 2023 at 13:59):

One component param could be lowered into multiple core params

view this post on Zulip Scott Waye (Sep 20 2023 at 14:01):

Right, what I'm after is the core params

view this post on Zulip Scott Waye (Sep 20 2023 at 14:04):

Interesting that core params don't have names, I wonder where "x" comes from

view this post on Zulip Lann Martin (Sep 20 2023 at 14:04):

Core params don't inherently have names. I see wasmtime bindgen for example just uses argN

view this post on Zulip Scott Waye (Sep 20 2023 at 14:19):

Thanks, I'll have a look at the rust to see how it works

view this post on Zulip Scott Waye (Sep 20 2023 at 16:59):

Problem between keyboard and chair :-)

view this post on Zulip Notification Bot (Sep 20 2023 at 16:59):

Scott Waye has marked this topic as resolved.


Last updated: Nov 22 2024 at 17:03 UTC