Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge dependencies #13

Merged
merged 340 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
340 commits
Select commit Hold shift + click to select a range
726d7ec
[spec/interpreter] Rename elem/data.drop; update README; reorder (#75)
rossberg Mar 30, 2019
c3d5cbc
[spec/interpreter/test] Add table bulk instructions missing from bulk…
rossberg Apr 3, 2019
40785ff
Increase the table count limit to 100,000
Apr 4, 2019
fcef8d6
[spec] Use `data.drop` instead of `memory.drop`
binji Apr 5, 2019
d346a8f
[spec] Update instruction index (#81)
binji Apr 5, 2019
e27b4ea
[spec] DataCount section, syntax, and validation (#80)
binji Apr 5, 2019
8bc0aa1
Merge remote-tracking branch 'spec/master' into HEAD
binji Apr 9, 2019
864f382
[spec] Simplify datacount side condition (#83)
rossberg Apr 16, 2019
1b1d70c
Merge remote-tracking branch 'upstream/master'
rossberg Apr 18, 2019
5ad8059
[spec] Adjust soundness appendix
rossberg Apr 18, 2019
a2d5f93
[spec] Adjust invoke
rossberg Apr 18, 2019
8b3fb37
[spec] Fix latex issue
rossberg Apr 18, 2019
dcbc1c5
Merge remote-tracking branch 'upstream/master'
rossberg Apr 19, 2019
02117e4
[spec] Remove Sphinx/Latex workaround
rossberg Apr 19, 2019
4c97261
[spec] Proper binary format for element segments (#82)
binji Apr 19, 2019
05672b0
[test] Disallow table size overflow
rossberg Apr 20, 2019
09dccac
[spec] Correctly account for subtyping in global/table instances (#39)
rossberg Apr 23, 2019
1fec5c1
Update host bindings proposal links
rossberg Apr 25, 2019
b8f6478
Fix links 2
rossberg Apr 25, 2019
d6cd997
[interpreter] Forgot commit
rossberg Apr 30, 2019
16b65a2
[interpreter] Eps
rossberg Apr 30, 2019
29540ac
[spec/interpreter/test] Avoid lubs and glbs (#43)
rossberg May 11, 2019
6eb26a3
Slight simplifications to text format (#84)
rossberg May 13, 2019
08be05a
Init/copy/fill with offsets at the end of the memory or table (#86)
sunfishcode May 13, 2019
e2e3383
Fix merge conflicts introduced w/ PRs #84 and #86 (#87)
binji May 13, 2019
e5cf99f
[spec] Fix oversight in elem typing rule
rossberg May 15, 2019
82c9db1
[spec] Formatting nit
rossberg May 15, 2019
eca021a
[spec] Add memory.fill to exec section (#88)
binji May 16, 2019
4e1a093
[travis] Use a different deploy_key
binji May 21, 2019
822039b
Copy bikeshed fix from spec repo
binji May 21, 2019
0f7f930
[test] JS-compatible module name (#45)
gahaas May 23, 2019
c3289d2
[spec] Add element type to passive element segment (#90)
binji May 23, 2019
88cb638
[spec] Fix title underline in valid/modules.rst
binji May 23, 2019
86c7e35
[spec] Adjust binary format of element segments (#46)
gahaas May 27, 2019
b2d34e0
[test] Use more JS-compatible names (#47)
gahaas May 28, 2019
a976b82
[spec] Runtime format of element and data segments (#91)
binji May 31, 2019
0ee9e67
[spec] Add memory.init and data.drop for exec (#92)
binji Jun 5, 2019
80aea4a
[spec] Use optional data instance, not data address (#93)
binji Jun 8, 2019
983df68
[spec] Add `table.init`, `elem.drop` exec text (#95)
binji Jun 28, 2019
d976981
Update overview for the zero-byte OOB case (#100)
binji Jun 28, 2019
8c6ea22
[spec] Update text for zero-byte OOB case (#101)
binji Jun 28, 2019
d18ec64
[interp] Don't trap on zero-bytes out-of-bounds (#102)
binji Jun 28, 2019
07c57f1
[interp] Remove overlap check from *.copy instr (#103)
binji Jul 6, 2019
aa596e5
Merge pull request #38 from lars-t-hansen/max_tables
binji Jul 7, 2019
600c524
[spec] Add `table.copy` exec text (#105)
gahaas Jul 11, 2019
fd48080
Polish table.init exec spec (#104)
gahaas Jul 11, 2019
820bd12
[spec] Add `memory.copy` exec text (#106)
binji Jul 23, 2019
aadc467
Change element segment encoding (#108)
gahaas Aug 1, 2019
1f0d158
Update some links (#52)
chicoxyzzy Aug 21, 2019
c69a117
New element section encoding in the interpreter (#109)
gahaas Aug 23, 2019
3d87cfa
Adjust element segment encoding to match the bulk-memory proposal (#53)
gahaas Sep 11, 2019
bc81602
[test] Fix the binary.wast test for multi-bytes table indices (#110)
gahaas Sep 12, 2019
d5101bc
[test] Add negative test for ref.func globals (#54)
gahaas Sep 17, 2019
c1a0415
Fix typo in validation of br_table (#56)
eqrion Sep 21, 2019
b1830ae
Adjust immediate memidx order (#118)
rossberg Oct 4, 2019
f47a675
Segment refactoring (#113)
rossberg Oct 7, 2019
df2a55f
[spec] Specify instantiate (#114)
rossberg Oct 7, 2019
8db23a9
[interpreter] Use small-step semantics (#115)
rossberg Oct 7, 2019
b95f821
Polish text format (#119)
rossberg Oct 7, 2019
4f9ae30
Merge remote-tracking branch 'upstream/master'
rossberg Oct 7, 2019
9aef0c5
[interpreter/test] Update table.init semantics as well (#120)
rossberg Oct 7, 2019
074a6fa
Merge remote-tracking branch 'upstream/master'
rossberg Oct 16, 2019
1e05d9b
Fix test expectation (#58)
gahaas Oct 29, 2019
e66f532
Fix call_indirect immediates
rossberg Nov 14, 2019
be7ce1b
[spec] Bounds check bulk-memory before execution (#123)
eqrion Nov 14, 2019
34a7ebe
Fix layout
rossberg Nov 14, 2019
24b0882
Merge remote-tracking branch 'upstream/master'
rossberg Nov 19, 2019
303c942
Merge remote-tracking branch 'upstream/master'
rossberg Nov 20, 2019
b2a5c4f
[interpreter] Simplify zero-len and drop semantics (#126)
rossberg Nov 22, 2019
1e29660
[spec] Adapt OOB behaviour in spec; store typing (#129)
rossberg Nov 23, 2019
b3380e3
Update Overview
rossberg Dec 13, 2019
5556e50
Typo in Overview
rossberg Dec 13, 2019
d4bc208
[spec/interpreter/test] Allow nullref type externally (#66)
rossberg Dec 13, 2019
82be3c0
New segment encoding (#130)
lars-t-hansen Dec 16, 2019
a00705b
Delete mentions of copying order in Overview.md (#134)
aheejin Dec 16, 2019
e383b99
Rebase on bulk proposal (#65)
rossberg Jan 10, 2020
fd804cf
Merge remote-tracking branch 'upstream/master' into rebase-master
rossberg Jan 13, 2020
97dec20
Travis setup; fix references to spec
binji Jan 15, 2020
3e32403
Fix various TODOs (#72)
rossberg Jan 16, 2020
64f9837
[spec/interpreter/test] Declarative element segments (#73)
rossberg Jan 16, 2020
2719ec3
[spec] Fix merge artefact
rossberg Jan 16, 2020
11388e7
Add test ensuring data segment index is unsigned (#136)
binji Jan 28, 2020
22ce5e3
[interpreter] Fix ref asserts (#78)
rossberg Feb 3, 2020
fc990e3
[spec] Fix validation context for globals (#77)
rossberg Feb 3, 2020
404b7e7
[interpreter/test] Fix validation for `elem.drop` (#137)
fitzgen Feb 6, 2020
d258902
[spec/interpreter] Fix missing multi table bulk cases (#80)
rossberg Feb 13, 2020
774dd1d
[spec] Typo
rossberg Feb 19, 2020
a1bfe97
[spec] Fix binary immediate order for table/memory.init (#82)
rossberg Feb 24, 2020
7cfa199
[test] call_indirect with multiple tables (#83)
rossberg Feb 27, 2020
ffdbb6e
Test that drop instructions work w/on memory/table (#140)
binji Feb 28, 2020
0c9a65c
Update proposal
rossberg May 17, 2019
8f034e0
Remove structural subtyping
rossberg May 21, 2019
6fabdde
Eps
rossberg May 21, 2019
43b8b54
Fix some links
May 29, 2019
1a8aa7d
Refactor type algebra to support type imports better
rossberg Jun 26, 2019
24bb644
Local desugaring
rossberg Nov 6, 2019
b736984
Add table initialiser (#10)
rossberg Nov 6, 2019
7cf1a94
Link to the JS type reflection proposal (#12)
Feb 20, 2020
060678f
Change validation error -> malformed in Overview (#143)
binji Mar 23, 2020
d7f0241
Fix {memory,table}.init immediate order (#147)
binji Mar 23, 2020
8c16975
[interpreter] Add ref type and call_ref instruction (#14)
rossberg Mar 23, 2020
2028231
[js-api] Extend with reference types support. (#79)
Ms2ger Mar 24, 2020
1568b35
Generalize test generators for table.copy and table.init to multi-tab…
lars-t-hansen Mar 24, 2020
99ba1f2
Some tweaks; more tests
rossberg Mar 24, 2020
0759a11
[interpreter] ref.as_non_null and br_on_null (#15)
rossberg Mar 24, 2020
9b80f54
[interpreter] Implement let blocks (#16)
rossberg Mar 25, 2020
4753632
[interpreter] Implement func.bind (#17)
rossberg Mar 26, 2020
b4637e9
Merge remote-tracking branch 'upstream/master'
sbc100 Mar 26, 2020
60ff11c
[overview] Fill in binary format (#18)
rossberg Mar 27, 2020
3119a96
Some more tests
rossberg Mar 27, 2020
73fb904
[interpreter] Implement semantic reference types (#19)
rossberg Mar 31, 2020
30002e7
Merge remote-tracking branch 'upstream/master'
rossberg Apr 2, 2020
9f6a39f
Merge fixups
rossberg Apr 2, 2020
c0f30ca
[test] Update JS harnesses to match interpreter harness (#86)
eqrion Apr 3, 2020
e8be8cb
Fixed typing rule
rossberg Apr 22, 2020
4041030
Fix typo
rossberg Apr 27, 2020
551e876
Remove subtyping (#87)
rossberg May 7, 2020
5567def
Merge upstream (#89)
rossberg May 12, 2020
e56ef21
Adjust readme
rossberg May 12, 2020
c8d58c7
Update test/harness/*_index.js for removing subtyping (#88)
eqrion May 12, 2020
b728bbc
[spec/interpreter/test] Relax ref check to whole module (#90)
rossberg May 13, 2020
1bef6a3
Merge remote-tracking branch 'upstream/master'
rossberg May 13, 2020
37e44c9
Update `ref.null` encoding after subtyping change (#149)
binji May 13, 2020
996ef3f
Merge remote-tracking branch 'upstream/master' into HEAD
binji May 13, 2020
dcfc963
Merge remote-tracking branch 'upstream/master' into HEAD
binji May 13, 2020
66d90a7
Test that partially out of bounds segments don't write to a memory/ta…
fitzgen May 13, 2020
cb6be3e
Tweak
rossberg May 14, 2020
d9a0816
Remove debug prints
rossberg May 14, 2020
2d061ff
Merge remote-tracking branch 'upstream/master' into merge
rossberg May 14, 2020
c90e289
Merge remote-tracking branch 'bulk/master' into merge2
rossberg May 14, 2020
458e956
Merge remote-tracking branch 'upstream/master' into merge
rossberg May 14, 2020
4166bdb
Fix type
rossberg May 14, 2020
8b99683
Merge pull request #22 from WebAssembly/merge
rossberg May 14, 2020
0b6f675
Re-add test that fails with a bottom type (#93)
eqrion May 18, 2020
a83b16e
[tests] Delete leftover harness function (#92)
gahaas May 18, 2020
f23154e
[interpreter] Improve error message
rossberg May 19, 2020
63e99ef
Fix syntax
rossberg May 19, 2020
60508dc
Encoding
rossberg May 19, 2020
8dd9a90
[test] Fix JS harness and binary test (#95)
gahaas May 20, 2020
5bc46bb
[js-api] More subtyping removal. (#96)
Ms2ger May 25, 2020
6e11d97
Rename constype to heaptype (#28)
rossberg May 28, 2020
1f008d2
Clarify let is a block; fix bug
rossberg Jun 2, 2020
b4f254b
Add select to Overview
rossberg Jun 5, 2020
17ad993
[overview] Point out generalisation of ref.[is_]null immediate (#30)
rossberg Jun 5, 2020
f18a4eb
Fix off-by-one in spec
rossberg Jun 9, 2020
6c0beae
Remove type annotation on ref.is_null (#100)
rossberg Jun 10, 2020
b583fad
[interpreter] Hot fix
rossberg Jun 10, 2020
7ab5846
[interpreter] Simplify hot fix
rossberg Jun 10, 2020
08f0f5b
Merge remote-tracking branch 'reftype/master'
rossberg Jun 10, 2020
da20676
[interpreter] ARgh
rossberg Jun 10, 2020
46dabe2
Merge remote-tracking branch 'reftype/master'
rossberg Jun 10, 2020
5e2c6ae
Merge fallout
rossberg Jun 10, 2020
a4ef81c
[spec] Sketch algorithm
rossberg Jun 10, 2020
4b6ab3a
Remove type annotations on ref.as_non_null and br_on_null (#31)
rossberg Jun 15, 2020
9df8a3e
Update Overview wrt table.grow
rossberg Jun 17, 2020
401c8eb
Fix links to `table.fill`'s validation and execution in appendix (#103)
fitzgen Jun 22, 2020
a125cbb
Describe the possible extension with function subtyping and exact typ…
rossberg Jun 25, 2020
1e652dd
Add a test for mutating `externref` globals (#104)
fitzgen Jul 16, 2020
c360086
table.fill: Bounds check before mutating the table (#106)
fitzgen Jul 21, 2020
f83fc6c
Simplify heaptype syntax (#34)
rossberg Jul 23, 2020
50e699f
Remove type annotation on ref.is_null in overview
aheejin Aug 26, 2020
4722e6b
Merge remote-tracking branch 'upstream/master' into HEAD
binji Aug 28, 2020
ec4bcea
Update document to use u32 for opcode after prefix (#155)
binji Aug 28, 2020
7708eb4
Merge pull request #108 from aheejin/remove_ref_is_null_type
binji Sep 8, 2020
7ae4890
fix decription of ref.func
turbolent Sep 12, 2020
8f5038e
Merge pull request #109 from turbolent/patch-1
binji Sep 14, 2020
4495265
[test] Uniform failure strings (#117)
q82419 Sep 23, 2020
2ccd487
[spec/interpreter/test] Reintroduce bottom type (#116)
rossberg Sep 30, 2020
736bda2
[test] Fix table index encoding (#154)
gahaas Oct 12, 2020
2799329
[spec] Fix xref
rossberg Oct 14, 2020
28c3a5b
[spec] Fix xref
rossberg Oct 14, 2020
9ad83c3
Fix formatting in 'Table Instructions'. (#119)
Ms2ger Oct 19, 2020
596e5f6
Merge remote-tracking branch 'upstream/master' into merge-upstream
rossberg Oct 29, 2020
244c841
Merge remote-tracking branch 'bulk/master' into merge-upstream2
rossberg Oct 29, 2020
ad009e0
Merge pull request #122 from WebAssembly/merge-upstream2
rossberg Nov 3, 2020
173ea33
Rename "refedtype" to "heaptype" (#124)
wingo Nov 3, 2020
48a7b0d
Fix typo in overview
rossberg Nov 3, 2020
d6046b8
[spec] Fix instantiation to handle ref.func in initializers (#115)
rossberg Nov 4, 2020
008e069
Merge remote-tracking branch 'reftype/master'
rossberg Dec 8, 2020
c19b709
Fix indentation (#126)
chicoxyzzy Jan 14, 2021
7c7bd2a
Fix some js-api bugs. (#128)
Ms2ger Jan 14, 2021
dd92422
[js-api] Explicitly disallow creating Tables with non-reftypes. (#129)
Ms2ger Jan 14, 2021
fc4b17f
Merge remote-tracking branch 'upstream/master' into merge-upstream3
rossberg Jan 20, 2021
cbb4030
Merge upstream (#130)
rossberg Jan 20, 2021
44b626b
[spec] Add missing immediates
rossberg Feb 10, 2021
8546739
Merge upstream (#157)
rossberg Feb 11, 2021
33da5b9
Merge remote-tracking branch 'bulk/master' into merge-bulk
rossberg Feb 11, 2021
1f4297e
Merge upstream bulk instructions proposal (#132)
rossberg Feb 11, 2021
1698322
Merge remote-tracking branch 'upstream/master' into merge-main
rossberg Feb 11, 2021
063d34e
Merge upstream (#133)
rossberg Feb 11, 2021
dd5a6a6
Merge remote-tracking branch 'reftype/master' into merge-reftype
rossberg Feb 15, 2021
e2aaaae
Merge upstream reftypes proposal (#46)
rossberg Feb 15, 2021
b796d0a
Tweak match
rossberg Feb 24, 2021
047470e
Eps
rossberg Feb 24, 2021
431a804
Tweak free
rossberg Feb 24, 2021
42eb75e
Minro refactor of deftype en/decoding
rossberg Feb 24, 2021
64a1ef5
Eps
rossberg Feb 24, 2021
e4dd659
Fix typing
rossberg Feb 25, 2021
1e50317
Forgot a case
rossberg Feb 25, 2021
38a27c8
Pedantic
rossberg Feb 25, 2021
7b631ac
Fix corner case
rossberg Feb 25, 2021
3fa695a
Eps
rossberg Feb 26, 2021
4e539b7
[interpreter] Use unsigned comparison
rossberg Mar 7, 2021
f94b6a2
Makefile tweaks
rossberg Mar 10, 2021
b6614ad
Merge remote-tracking branch 'reftype/master'
rossberg Mar 10, 2021
0b8a376
Merge remote-tracking branch 'upstream/master'
rossberg Mar 11, 2021
b3ff7e8
Merge remote-tracking branch 'reftype/master'
rossberg Mar 11, 2021
3f8b25b
Merge remote-tracking branch 'upstream/master'
rossberg Mar 11, 2021
6be9976
Eps
rossberg Mar 11, 2021
1eb1df6
Merge remote-tracking branch 'upstream/master'
rossberg Mar 11, 2021
3e34cb0
Update front matter
rossberg Mar 11, 2021
4ae98e4
Merge remote-tracking branch 'upstream/master'
rossberg Mar 11, 2021
5c4ff46
Set up Travis
rossberg Mar 11, 2021
9082bcd
Fix revision
rossberg Mar 11, 2021
122e4be
Add a simple test for multiple tables
rossberg Mar 11, 2021
fa36771
Micro-refactoring
rossberg Mar 11, 2021
523f672
Fix typo in example
rossberg Apr 7, 2021
394d0aa
Merge remote-tracking branch 'upstream/master'
rossberg Apr 8, 2021
4c89ec2
[spec] Fix instruction table (#1296)
rossberg Mar 11, 2021
e15137d
Small fixes in build instructions, fix warnings
ngzhian Mar 10, 2021
9c7e637
Upgrade Sphinx to 3.0.0
ngzhian Mar 11, 2021
b63a15a
Upgrade Sphinx to 3.5.2 (#1298)
ngzhian Mar 12, 2021
29c7e0a
[spec] Minor fix to batch file (#1301)
radekdoulik Apr 6, 2021
cdc310b
Remove 'data passive' from bulk-memory examples (#1304)
aheejin Apr 6, 2021
50f1f90
[spec] Add change history appendix (#1306)
rossberg Apr 8, 2021
6951fdb
[spec] Layout improvements (#1307)
rossberg Apr 8, 2021
723702c
[spec] Try to retrigger build
rossberg Apr 8, 2021
cf5f79c
[spec] Move all repo-specifics to conf.py (#1308)
rossberg Apr 8, 2021
b158867
Adjust conf
rossberg Apr 8, 2021
25d26e7
Add br_on_non_null (#48)
rossberg May 19, 2021
43ff65e
Merge branch 'upstream'
rossberg Jun 24, 2021
8a4b3e0
Merge branch 'upstream'
rossberg Jul 24, 2021
887e5de
Simplify func context
rossberg Jul 24, 2021
e8d2909
[spec] Add concrete ref types (#49)
rossberg Aug 6, 2021
02ef8da
Remove outdated statement
rossberg Sep 8, 2021
1a421a0
Minor tweaks to overview
rossberg Sep 15, 2021
b7065d8
[spec] New instructions (#52)
rossberg Sep 17, 2021
c204c78
Fix free
rossberg Oct 20, 2021
9b0e240
Tweak
rossberg Oct 20, 2021
9c0d745
Describe correct tail call behavior across modules
tlively Dec 15, 2021
1a9e868
Merge branch 'upstream' into merge-vec
rossberg Feb 4, 2022
e75f3b2
Merge upstream (#55)
rossberg Feb 4, 2022
d897766
Merge branch 'merge-vec'
rossberg Feb 4, 2022
70ad68b
Merge branch 'funcref' into merge-funcref
rossberg Feb 4, 2022
aa10cd8
Merge pull request #16 from WebAssembly/module-boundaries
rossberg Feb 4, 2022
88ec321
Merge branch 'upstream' into merge-upstream
rossberg Feb 4, 2022
23a6198
Merge pull request #17 from WebAssembly/merge-upstream
rossberg Feb 4, 2022
8d3d2e5
Merge branch 'tailcall' into merge-deps
rossberg Feb 4, 2022
49b9596
Merge branch 'main' into merge-deps
rossberg Feb 4, 2022
acf48b9
Add dependency
rossberg Feb 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[spec/interpreter/test] Avoid lubs and glbs (#43)
  • Loading branch information
rossberg authored May 11, 2019
commit 29540aca3248d2a9158b0681aac53272117e1ab5
148 changes: 69 additions & 79 deletions document/core/appendix/algorithm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,29 @@ Data Structures
~~~~~~~~~~~~~~~

Types are representable as an enumeration.
In addition to the plain types from the WebAssembly validation semantics, an extended notion of operand type includes a bottom type `Unknown` that is used as the type of :ref:`polymorphic <polymorphism>` operands.

A simple subtyping check can be defined on these types.
In addition, corresponding functions computing the join (least upper bound) and meet (greatest lower bound) of two types are used.
Because there is no top type, a join does not exist in all cases.
Similarly, a meet must always be defined on known value types that exclude the auxiliary bottom type `Unknown`,
hence a meet does not exist in all cases either.
A type error is encountered if a join or meet is required when it does not exist.

.. code-block:: pseudo

type val_type = I32 | I64 | F32 | F64 | Anyref | Funcref | Nullref
type opd_type = val_type | Unknown
type val_type = I32 | I64 | F32 | F64 | Anyref | Funcref | Nullref | Bot

func is_num(t : val_type) : bool =
return t = I32 || t = I64 || t = F32 || t = F64 || t = Bot

func is_ref(t : opd_type) : bool =
return t = Anyref || t = Funcref || t = Nullref
func is_ref(t : val_type) : bool =
return t = Anyref || t = Funcref || t = Nullref || t = Bot

func matches(t1 : opd_type, t2 : opd_type) : bool =
return t1 = t2 || t1 = Unknown ||
func matches(t1 : val_type, t2 : val_type) : bool =
return t1 = t2 || t1 = Bot ||
(t1 = Nullref && is_ref(t2)) || (is_ref(t1) && t2 = Anyref)

func join(t1 : opd_type, t2 : opd_type) : opd_type =
if (t1 = t2) return t1
if (matches(t1, t2)) return t2
if (matches(t2, t1)) return t1
error_if(not (is_ref(t1) && is_ref(t2)))
return Anyref

func meet(t1 : val_type, t2 : val_type) : val_type =
if (t1 = t2) return t1
if (matches(t1, t2)) return t1
if (matches(t2, t1)) return t2
error_if(not (is_ref(t1) && is_ref(t2)))
return Nullref

The algorithm uses two separate stacks: the *operand stack* and the *control stack*.
The algorithm uses two separate stacks: the *value stack* and the *control stack*.
The former tracks the :ref:`types <syntax-valtype>` of operand values on the :ref:`stack <stack>`,
the latter surrounding :ref:`structured control instructions <syntax-instr-control>` and their associated :ref:`blocks <syntax-instr-control>`.

.. code-block:: pseudo

type opd_stack = stack(opd_type)
type val_stack = stack(val_type)

type ctrl_stack = stack(ctrl_frame)
type ctrl_frame = {
Expand All @@ -73,7 +54,7 @@ the latter surrounding :ref:`structured control instructions <syntax-instr-contr
unreachable : bool
}

For each value, the operand stack records its :ref:`value type <syntax-valtype>`, or :code:`Unknown` when the type is not known.
For each value, the value stack records its :ref:`value type <syntax-valtype>`.

For each entered block, the control stack records a *control frame* with the type of the associated :ref:`label <syntax-label>` (used to type-check branches), the result type of the block (used to check its result), the height of the operand stack at the start of the block (used to check that operands do not underflow the current block), and a flag recording whether the remainder of the block is unreachable (used to handle :ref:`stack-polymorphic <polymorphism>` typing after branches).

Expand All @@ -85,63 +66,68 @@ For the purpose of presenting the algorithm, the operand and control stacks are

.. code-block:: pseudo

var opds : opd_stack
var vals : val_stack
var ctrls : ctrl_stack

However, these variables are not manipulated directly by the main checking function, but through a set of auxiliary functions:

.. code-block:: pseudo

func push_opd(type : opd_type) =
opds.push(type)
func push_val(type : val_type) =
vals.push(type)

func pop_opd() : opd_type =
if (opds.size() = ctrls[0].height && ctrls[0].unreachable) return Unknown
error_if(opds.size() = ctrls[0].height)
return opds.pop()
func pop_val() : val_type =
if (vals.size() = ctrls[0].height && ctrls[0].unreachable) return Bot
error_if(vals.size() = ctrls[0].height)
return vals.pop()

func pop_opd(expect : val_type) =
let actual = pop_opd()
func pop_val(expect : val_type) : val_type =
let actual = pop_val()
error_if(not matches(actual, expect))
return actual

func push_opds(types : list(val_type)) = foreach (t in types) push_opd(t)
func pop_opds(types : list(val_type)) = foreach (t in reverse(types)) pop_opd(t)
func push_vals(types : list(val_type)) = foreach (t in types) push_val(t)
func pop_vals(types : list(val_type)) : list(val_type) =
var popped := []
foreach (t in reverse(types)) popped.append(pop_val(t))
return popped

Pushing an operand simply pushes the respective type to the operand stack.
Pushing an operand value simply pushes the respective type to the value stack.

Popping an operand checks that the operand stack does not underflow the current block and then removes one type.
But first, a special case is handled where the block contains no known operands, but has been marked as unreachable.
Popping an operand value checks that the value stack does not underflow the current block and then removes one type.
But first, a special case is handled where the block contains no known values, but has been marked as unreachable.
That can occur after an unconditional branch, when the stack is typed :ref:`polymorphically <polymorphism>`.
In that case, an unknown type is returned.
In that case, the :code:`Bot` type is returned, because that is a *principal* choice trivially satisfying all use constraints.

A second function for popping an operand takes an expected (known) type, which the actual operand type is checked against.
The types may differ by subtyping, inlcuding the case where the actual type is unknown.
A second function for popping an operand value takes an expected type, which the actual operand type is checked against.
The types may differ by subtyping, including the case where the actual type is :code:`Bot`, and thereby matches unconditionally.
The function returns the actual type popped from the stack.

Finally, there are accumulative functions for pushing or popping multiple operand types.

.. note::
The notation :code:`stack[i]` is meant to index the stack from the top,
so that :code:`ctrls[0]` accesses the element pushed last.
so that, e.g., :code:`ctrls[0]` accesses the element pushed last.


The control stack is likewise manipulated through auxiliary functions:

.. code-block:: pseudo

func push_ctrl(label : list(val_type), out : list(val_type)) =
 let frame = ctrl_frame(label, out, opds.size(), false)
 let frame = ctrl_frame(label, out, vals.size(), false)
  ctrls.push(frame)

func pop_ctrl() : list(val_type) =
 error_if(ctrls.is_empty())
 let frame = ctrls[0]
  pop_opds(frame.end_types)
  error_if(opds.size() =/= frame.height)
  pop_vals(frame.end_types)
  error_if(vals.size() =/= frame.height)
ctrls.pop()
  return frame.end_types

func unreachable() =
  opds.resize(ctrls[0].height)
  vals.resize(ctrls[0].height)
  ctrls[0].unreachable := true

Pushing a control frame takes the types of the label and result values.
Expand All @@ -152,18 +138,18 @@ It then verifies that the operand stack contains the right types of values expec
Afterwards, it checks that the stack has shrunk back to its initial height.

Finally, the current frame can be marked as unreachable.
In that case, all existing operand types are purged from the operand stack, in order to allow for the :ref:`stack-polymorphism <polymorphism>` logic in :code:`pop_opd` to take effect.
In that case, all existing operand types are purged from the value stack, in order to allow for the :ref:`stack-polymorphism <polymorphism>` logic in :code:`pop_val` to take effect.

.. note::
Even with the unreachable flag set, consecutive operands are still pushed to and popped from the operand stack.
That is necessary to detect invalid :ref:`examples <polymorphism>` like :math:`(\UNREACHABLE~(\I32.\CONST)~\I64.\ADD)`.
However, a polymorphic stack cannot underflow, but instead generates :code:`Unknown` types as needed.
However, a polymorphic stack cannot underflow, but instead generates :code:`Bot` types as needed.


.. index:: opcode

Validation of Opcode Sequences
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Validation of Instruction Sequences
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following function shows the validation of a number of representative instructions that manipulate the stack.
Other instructions are checked in a similar manner.
Expand All @@ -177,18 +163,26 @@ Other instructions are checked in a similar manner.
func validate(opcode) =
switch (opcode)
case (i32.add)
pop_opd(I32)
pop_opd(I32)
push_opd(I32)
pop_val(I32)
pop_val(I32)
push_val(I32)

case (drop)
pop_opd()
pop_val()

case (select)
pop_opd(I32)
let t1 = pop_opd()
let t2 = pop_opd()
push_opd(join(t1, t2))
pop_val(I32)
let t1 = pop_val()
let t2 = pop_val()
error_if(not (is_num(t1) && is_num(t2)))
error_if(t1 =/= t2 && t1 =/= Bot && t2 =/= Bot)
push_val(if (t1 = Bot) t2 else t1)

case (select t)
pop_val(I32)
pop_val(t)
pop_val(t)
push_val(t)

   case (unreachable)
      unreachable()
Expand All @@ -200,39 +194,35 @@ Other instructions are checked in a similar manner.
push_ctrl([], [t*])

case (if t*)
pop_opd(I32)
pop_val(I32)
push_ctrl([t*], [t*])

case (end)
let results = pop_ctrl()
push_opds(results)
push_vals(results)

case (else)
let results = pop_ctrl()
push_ctrl(results, results)

case (br n)
     error_if(ctrls.size() < n)
      pop_opds(ctrls[n].label_types)
      pop_vals(ctrls[n].label_types)
      unreachable()

case (br_if n)
     error_if(ctrls.size() < n)
pop_opd(I32)
      pop_opds(ctrls[n].label_types)
      push_opds(ctrls[n].label_types)
pop_val(I32)
      pop_vals(ctrls[n].label_types)
      push_vals(ctrls[n].label_types)

   case (br_table n* m)
pop_val(I32)
      error_if(ctrls.size() < m)
var ts = ctrls[m].label_types
let arity = ctrls[m].label_types.size()
      foreach (n in n*)
        error_if(ctrls.size() < n)
ts := meet(ts, ctrls[n].label_types)
pop_opd(I32)
      pop_opds(ts)
        error_if(ctrls[n].label_types.size() =/= arity)
push_vals(pop_vals(ctrls[n].label_types))
pop_vals(ctrls[m].label_types)
      unreachable()

.. note::
It is an invariant under the current WebAssembly instruction set that an operand of :code:`Unknown` type is never duplicated on the stack.
This would change if the language were extended with stack operators like :code:`dup`.
Under such an extension, the above algorithm would need to be refined by replacing the :code:`Unknown` type with proper *type variables* to ensure that all uses are consistent.
2 changes: 1 addition & 1 deletion document/core/appendix/index-instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Instruction Binary Opcode Type
(reserved) :math:`\hex{19}`
:math:`\DROP` :math:`\hex{1A}` :math:`[t] \to []` :ref:`validation <valid-drop>` :ref:`execution <exec-drop>`
:math:`\SELECT` :math:`\hex{1B}` :math:`[t~t~\I32] \to [t]` :ref:`validation <valid-select>` :ref:`execution <exec-select>`
(reserved) :math:`\hex{1C}`
:math:`\SELECT~t` :math:`\hex{1C}` :math:`[t~t~\I32] \to [t]` :ref:`validation <valid-select>` :ref:`execution <exec-select>`
(reserved) :math:`\hex{1D}`
(reserved) :math:`\hex{1E}`
(reserved) :math:`\hex{1F}`
Expand Down
5 changes: 3 additions & 2 deletions document/core/binary/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Reference Instructions
Parametric Instructions
~~~~~~~~~~~~~~~~~~~~~~~

:ref:`Parametric instructions <syntax-instr-parametric>` are represented by single byte codes.
:ref:`Parametric instructions <syntax-instr-parametric>` are represented by single byte codes, possibly followed by a type annotation.

.. _binary-drop:
.. _binary-select:
Expand All @@ -101,7 +101,8 @@ Parametric Instructions
\begin{array}{llclll}
\production{instruction} & \Binstr &::=& \dots \\ &&|&
\hex{1A} &\Rightarrow& \DROP \\ &&|&
\hex{1B} &\Rightarrow& \SELECT \\
\hex{1B} &\Rightarrow& \SELECT \\ &&|&
\hex{1C}~~t^\ast{:}\Bvec(\Bvaltype) &\Rightarrow& \SELECT~t^\ast \\
\end{array}


Expand Down
6 changes: 6 additions & 0 deletions document/core/binary/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ Reference Types
\hex{6F} &\Rightarrow& \ANYREF \\
\end{array}

.. note::
The type :math:`\NULLREF` cannot occur in a module.


.. index:: value type, number type, reference type
pair: binary format; value type
Expand All @@ -62,6 +65,9 @@ Value Types
t{:}\Breftype &\Rightarrow& t \\
\end{array}

.. note::
The type :math:`\BOT` cannot occur in a module.


.. index:: result type, value type
pair: binary format; result type
Expand Down
11 changes: 7 additions & 4 deletions document/core/exec/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ Parametric Instructions

.. _exec-select:

:math:`\SELECT`
...............
:math:`\SELECT~(t^\ast)^?`
..........................

1. Assert: due to :ref:`validation <valid-select>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.

Expand All @@ -287,12 +287,15 @@ Parametric Instructions

.. math::
\begin{array}{lcl@{\qquad}l}
\val_1~\val_2~(\I32\K{.}\CONST~c)~\SELECT &\stepto& \val_1
\val_1~\val_2~(\I32\K{.}\CONST~c)~\SELECT~t^? &\stepto& \val_1
& (\iff c \neq 0) \\
\val_1~\val_2~(\I32\K{.}\CONST~c)~\SELECT &\stepto& \val_2
\val_1~\val_2~(\I32\K{.}\CONST~c)~\SELECT~t^? &\stepto& \val_2
& (\iff c = 0) \\
\end{array}

.. note::
In future versions of WebAssembly, |SELECT| may allow more than one value per choice.


.. index:: variable instructions, local index, global index, address, global address, global instance, store, frame, value
pair: execution; instruction
Expand Down
6 changes: 5 additions & 1 deletion document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,16 @@ Instructions in this group can operate on operands of any :ref:`value type <synt
\production{instruction} & \instr &::=&
\dots \\&&|&
\DROP \\&&|&
\SELECT
\SELECT~(\valtype^\ast)^? \\
\end{array}

The |DROP| operator simply throws away a single operand.

The |SELECT| operator selects one of its first two operands based on whether its third operand is zero or not.
It may include a :ref:`value type <syntax-valtype>` determining the type of these operands. If missing, the operands must be of :ref:`numeric type <syntax-numtype>`.

.. note::
In future versions of WebAssembly, the type annotation on |SELECT| may allow for more than a single value being selected at the same time.


.. index:: ! variable instruction, local, global, local index, global index
Expand Down
11 changes: 8 additions & 3 deletions document/core/syntax/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The type |FUNCREF| denotes the infinite union of all references to :ref:`functio

The type |NULLREF| only contains a single value: the :ref:`null <syntax-ref.null>` reference.
It is a :ref:`subtype <match-reftype>` of all other reference types.
By virtue of not being representable in either the :ref:`binary format <binary-reftype>` nor the :ref:`text format <text-reftype>`, the |NULLREF| type cannot be used in a program;
By virtue of being representable in neither the :ref:`binary format <binary-reftype>` nor the :ref:`text format <text-reftype>`, the |NULLREF| type cannot be used in a program;
it only occurs during :ref:`validation <valid>`.

.. note::
Expand All @@ -73,7 +73,7 @@ Reference types are *opaque*, meaning that neither their size nor their bit patt
Values of reference type can be stored in :ref:`tables <syntax-table>`.


.. index:: ! value type, number type, reference type
.. index:: ! value type, number type, reference type, ! bottom type
pair: abstract syntax; value type
pair: value; type
.. _syntax-valtype:
Expand All @@ -82,11 +82,16 @@ Value Types
~~~~~~~~~~~

*Value types* classify the individual values that WebAssembly code can compute with and the values that a variable accepts.
They are either :ref:`number types <syntax-numtype>`, :ref:`reference type <syntax-reftype>`, or the unique *bottom type*, written :math:`\BOT`.

The type :math:`\BOT` is a :ref:`subtype <match-valtype>` of all other types.
By virtue of being representable in neither the :ref:`binary format <binary-valtype>` nor the :ref:`text format <text-valtype>`, it cannot be used in a program;
it only occurs during :ref:`validation <valid>`.

.. math::
\begin{array}{llll}
\production{value type} & \valtype &::=&
\numtype ~|~ \reftype \\
\numtype ~|~ \reftype ~|~ \BOT \\
\end{array}

Conventions
Expand Down
Loading