Skip to content

Commit

Permalink
Revert import/export mutable global changes
Browse files Browse the repository at this point in the history
Revert "Update docs to allow import/export mut globals (WebAssembly#81)"

This reverts commit 5d2ad6e.

Revert "Support import/export mut globals in interpreter (WebAssembly#80)"

This reverts commit 07a6fb2.
  • Loading branch information
binji committed Feb 2, 2018
1 parent 2bc8b74 commit 00be2e1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 41 deletions.
6 changes: 6 additions & 0 deletions document/core/syntax/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ Each export is identified by a unique :ref:`name <syntax-name>`.
Exportable definitions are :ref:`functions <syntax-func>`, :ref:`tables <syntax-table>`, :ref:`memories <syntax-mem>`, and :ref:`globals <syntax-global>`,
which are referenced through a respective descriptor.

.. note::
In the current version of WebAssembly, only *immutable* globals may be exported.


Conventions
...........
Expand Down Expand Up @@ -357,3 +360,6 @@ Each import is specified by a descriptor with a respective type that a definitio

Every import defines an index in the respective :ref:`index space <syntax-index>`.
In each index space, the indices of imports go before the first index of any definition contained in the module itself.

.. note::
In the current version of WebAssembly, only *immutable* globals may be imported.
14 changes: 10 additions & 4 deletions document/core/valid/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,17 @@ Exports :math:`\export` and export descriptions :math:`\exportdesc` are classifi

* The global :math:`C.\CGLOBALS[x]` must be defined in the context.

* Let :math:`\mut~t` be the :ref:`global type <syntax-globaltype>` :math:`C.\CGLOBALS[x]`.

* The mutability :math:`\mut` must be |MCONST|.

* Then the export description is valid with :ref:`external type <syntax-externtype>` :math:`\ETGLOBAL~C.\CGLOBALS[x]`.

.. math::
\frac{
C.\CGLOBALS[x] = \ETGLOBAL~\globaltype
C.\CGLOBALS[x] = \MCONST~t
}{
C \vdashexportdesc \EDGLOBAL~x : \ETGLOBAL~\globaltype
C \vdashexportdesc \EDGLOBAL~x : \ETGLOBAL~(\MCONST~t)
}
Expand Down Expand Up @@ -410,13 +414,15 @@ Imports :math:`\import` and import descriptions :math:`\importdesc` are classifi

* The global type :math:`\globaltype` must be :ref:`valid <valid-globaltype>`.

* The mutability of :math:`\globaltype` must be |MCONST|.

* Then the import description is valid with type :math:`\ETGLOBAL~\globaltype`.

.. math::
\frac{
\vdashglobaltype \globaltype \ok
\vdashglobaltype \MCONST~t \ok
}{
C \vdashimportdesc \IDGLOBAL~\globaltype : \ETGLOBAL~\globaltype
C \vdashimportdesc \IDGLOBAL~\MCONST~t : \ETGLOBAL~\MCONST~t
}
Expand Down
8 changes: 7 additions & 1 deletion interpreter/valid/valid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ let check_import (im : import) (c : context) : context =
{c with memories = mt :: c.memories}
| GlobalImport gt ->
check_global_type gt idesc.at;
let GlobalType (_, mut) = gt in
require (mut = Immutable) idesc.at
"mutable globals cannot be imported (yet)";
{c with globals = gt :: c.globals}

module NameSet = Set.Make(struct type t = Ast.name let compare = compare end)
Expand All @@ -457,7 +460,10 @@ let check_export (c : context) (set : NameSet.t) (ex : export) : NameSet.t =
| FuncExport x -> ignore (func c x)
| TableExport x -> ignore (table c x)
| MemoryExport x -> ignore (memory c x)
| GlobalExport x -> ignore (global c x)
| GlobalExport x ->
let GlobalType (_, mut) = global c x in
require (mut = Immutable) edesc.at
"mutable globals cannot be exported (yet)"
);
require (not (NameSet.mem name set)) ex.at "duplicate export name";
NameSet.add name set
Expand Down
22 changes: 19 additions & 3 deletions test/core/globals.wast
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,25 @@
"global is immutable"
)

;; mutable globals can be exported
(module (global (mut f32) (f32.const 0)) (export "a" (global 0)))
(module (global (export "a") (mut f32) (f32.const 0)))
(assert_invalid
(module (import "m" "a" (global (mut i32))))
"mutable globals cannot be imported"
)

(assert_invalid
(module (global (import "m" "a") (mut i32)))
"mutable globals cannot be imported"
)

(assert_invalid
(module (global (mut f32) (f32.const 0)) (export "a" (global 0)))
"mutable globals cannot be exported"
)

(assert_invalid
(module (global (export "a") (mut f32) (f32.const 0)))
"mutable globals cannot be exported"
)

(assert_invalid
(module (global f32 (f32.neg (f32.const 0))))
Expand Down
33 changes: 0 additions & 33 deletions test/core/linking.wast
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,16 @@
(module $Mg
(global $glob (export "glob") i32 (i32.const 42))
(func (export "get") (result i32) (get_global $glob))

;; export mutable globals
(global $mut_glob (export "mut_glob") (mut i32) (i32.const 142))
(func (export "get_mut") (result i32) (get_global $mut_glob))
(func (export "set_mut") (param i32) (set_global $mut_glob (get_local 0)))
)
(register "Mg" $Mg)

(module $Ng
(global $x (import "Mg" "glob") i32)
(global $mut_glob (import "Mg" "mut_glob") (mut i32))
(func $f (import "Mg" "get") (result i32))
(func $get_mut (import "Mg" "get_mut") (result i32))
(func $set_mut (import "Mg" "set_mut") (param i32))

(export "Mg.glob" (global $x))
(export "Mg.get" (func $f))
(global $glob (export "glob") i32 (i32.const 43))
(func (export "get") (result i32) (get_global $glob))

(export "Mg.mut_glob" (global $mut_glob))
(export "Mg.get_mut" (func $get_mut))
(export "Mg.set_mut" (func $set_mut))
)

(assert_return (get $Mg "glob") (i32.const 42))
Expand All @@ -71,26 +58,6 @@
(assert_return (invoke $Ng "Mg.get") (i32.const 42))
(assert_return (invoke $Ng "get") (i32.const 43))

(assert_return (get $Mg "mut_glob") (i32.const 142))
(assert_return (get $Ng "Mg.mut_glob") (i32.const 142))
(assert_return (invoke $Mg "get_mut") (i32.const 142))
(assert_return (invoke $Ng "Mg.get_mut") (i32.const 142))

(assert_return (invoke $Mg "set_mut" (i32.const 241)))
(assert_return (get $Mg "mut_glob") (i32.const 241))
(assert_return (get $Ng "Mg.mut_glob") (i32.const 241))
(assert_return (invoke $Mg "get_mut") (i32.const 241))
(assert_return (invoke $Ng "Mg.get_mut") (i32.const 241))


(assert_unlinkable
(module (import "Mg" "mut_glob" (global i32)))
"incompatible import type"
)
(assert_unlinkable
(module (import "Mg" "glob" (global (mut i32))))
"incompatible import type"
)

;; Tables

Expand Down

0 comments on commit 00be2e1

Please sign in to comment.