Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

The meaning of providing a constant for a mutable global import #9

Open
lars-t-hansen opened this issue Apr 9, 2018 · 4 comments
Open
Assignees

Comments

@lars-t-hansen
Copy link
Collaborator

Suppose a module is this:

(module (import "m" "g" (global (mut i32))))

and we try to instantiate it with the import object {m: {g: 42}}. Is this allowed or not?

Firefox currently allows it and there seems to be no difficulty in allowing it generally, but I think the spec is vague here. The current spec text to cover this seems to be (document/js-api/index.bs line 335):

        1. If |externtype| is of the form [=𝗀𝗅𝗈𝖻𝖺𝗅=] |globaltype|,
            1. If |globaltype| [=Type=](|v|) is [=Number=],
                1. If |globaltype| is [=𝗂𝟨𝟦=], throw a {{LinkError}} exception.
                1. Let |value| be [=ToWebAssemblyValue=](|v|, |globaltype|.<em>[=global type|valtype=]</em>)
                1. Let |store| be the current agent's [=associated store=].
                1. Let (|store|, |globaladdr|) be [=alloc_global=](|store|, |globaltype|, |value|).
                1. Set the current agent's [=associated store=] to |store|.

A globaltype can't be just a JS type I think, it needs to carry a mutability specifier. One could argue that since this is a number value the implicit mutability specifier is const, but need it be so?

@lars-t-hansen
Copy link
Collaborator Author

FWIW the original proposal text did allow a number to be imported into a mutable global: https://github.com/WebAssembly/mutable-global/blob/master/proposals/mutable-global/Overview.md#webassemblyinstance-constructor

@binji
Copy link
Member

binji commented Apr 9, 2018

One could argue that since this is a number value the implicit mutability specifier is const, but need it be so?

It makes the most sense to me for it to be immutable. What is the benefit of allowing an imported Number to be mutable?

@binji binji self-assigned this Apr 9, 2018
@rossberg
Copy link
Member

rossberg commented Apr 9, 2018

Allowing an implicit coercion from Number to mutable Global does not seem desirable.

I think the occurrence of |globaltype| in the second line of the snippet is just a typo?

@lars-t-hansen
Copy link
Collaborator Author

I agree that it makes most sense for it to be immutable (and we can always open it up later), I just wanted to make sure the decision was made explicitly. The spec text needs to synthesize the const part of the globaltype here explicitly.

@rossberg, yes I was confused by that |globaltype|, couldn't tell if it was magic spec syntax or what.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants