Skip to content

Commit 058984f

Browse files
authored
Merge pull request #39 from raoxiaojia/2.0
Wasm 2.0 Update
2 parents 1fda06e + a9680f6 commit 058984f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+14297
-17704
lines changed

.github/workflows/main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ name: Test compilation
33
on:
44
push:
55
pull_request:
6+
types:
7+
- opened
8+
- synchronize
9+
- reopened
10+
- ready_for_review
11+
612
workflow_dispatch:
713
inputs:
814

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2019-2023 Martin Bodin, Philippa Gardner, Jean Pichon, Xiaojia Rao, Conrad Watt
3+
Copyright (c) 2019-2024 Martin Bodin, Philippa Gardner, Jean Pichon, Xiaojia Rao, Conrad Watt
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+56-49
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# wasm_coq
2-
WebAssembly (aka Wasm) 1.0 formalisation in Coq, based on the [official formalisation](https://www.w3.org/TR/wasm-core-1/).
3-
Our definitions and proofs initially drew from those given in the [Isabelle mechanisation of Conrad Watt](https://www.isa-afp.org/entries/WebAssembly.html).
2+
A WebAssembly (aka Wasm) formalisation in Coq, based on the [official specification](https://webassembly.github.io/spec/core/).
43

5-
(C) M. Bodin, P. Gardner, J. Pichon, C. Watt, X. Rao 2019-2023 - see LICENSE.txt
4+
(C) M. Bodin, P. Gardner, J. Pichon, C. Watt, X. Rao 2019-2024 - see LICENSE.txt
65

76
The quotes from the WebAssembly standard (starting with `std-doc`) are (C) their respective authors.
87

9-
This work is in progress. While our initial work used the definitions published in PLDI'17, we have now adapted the mechanisation to Wasm 1.0., the specification as ratified by the W3C. A large part of the work has been published at [FM'21](https://link.springer.com/chapter/10.1007/978-3-030-90870-6_4), with more additions to the repository since then.
8+
The current master branch formalises Wasm version 2.0, plus additional subtyping systems from the future funcref/GC extension proposals. A large part of the old Wasm 1.0 formalisation has been published at [FM'21](https://link.springer.com/chapter/10.1007/978-3-030-90870-6_4), with many additions to the repository since then.
109

1110
# Components of the Repository
1211

@@ -22,11 +21,11 @@ This work is in progress. While our initial work used the definitions published
2221
- [x] Soundness results for module instantiation.
2322
- [x] Proof carrying interpreter deriving progress.
2423
- [x] Interpreter with optimised context representations.
24+
- [x] Updates for Wasm 2.0 (except SIMD and new numerics ops) + subtyping systems.
2525

2626
## Unmerged/Future Work
2727
- [ ] Validate WasmRef-Coq (conformance tests).
28-
- [ ] Updates for Wasm 2.0 (except SIMD).
29-
- [ ] Updates for further extension proposals (SIMD, GC, tail calls, etc).
28+
- [ ] Updates for further extension proposals.
3029

3130
# Program Logic
3231

@@ -35,6 +34,7 @@ This is migrated from an older build for the [artefact](https://zenodo.org/recor
3534

3635
# Binary Parser (experimental)
3736
This repository contains some experimental work on a parser for the binary format which is currently unverified.
37+
As the parser forms a part of the extracted interpreter, any error in the parser would result in the interpreter reporting `syntax error` for some valid Wasm binaries. Bug reports are appreciated!
3838

3939
# Usage
4040

@@ -48,10 +48,6 @@ opam repo add coq-released https://coq.inria.fr/opam/released
4848
opam install .
4949
```
5050

51-
## Build Based on Esy
52-
53-
The previous esy-based build is now deprecated; it is moved to esy branch.
54-
5551
## Testing the Installation
5652

5753
The project comes with a small set of tests for the extracted interpreter:
@@ -63,71 +59,82 @@ dune test
6359

6460
A file `wasm_coq_interpreter` will have been generated under `_build/install`.
6561
It takes as argument a list of Wasm files, followed by a function name to run (with the `-r` flag).
66-
For instance, to interpret the function `main` defined in [tests/floatmul.wasm](tests/floatmul.wasm), run:
62+
For instance, to interpret the function `main` defined in [tests/add.wasm](tests/add.wasm), run:
6763
```bash
68-
dune exec -- wasm_coq_interpreter tests/floatmul.wasm -r main
64+
dune exec -- wasm_coq_interpreter tests/add.wasm -r main
6965
```
7066
The interpreter can display intermediate states of the operational semantics:
7167
```bash
72-
dune exec -- wasm_coq_interpreter tests/floatmul.wasm -r main --vi
68+
dune exec -- wasm_coq_interpreter tests/add.wasm -r main --vi
7369
```
7470
would produce:
7571
```bash
76-
parsing OK
72+
parsing OK
7773
instantiation OK
74+
75+
Post-instantiation stage for table and memory initialisers...
76+
step 1:
77+
(empty)
78+
79+
step 2:
80+
Value:
81+
(empty)
82+
success after 2 steps
83+
84+
Instantiation success
7885
interpreting OK
7986
step 0:
8087

81-
invoke 0
88+
Executing configuration:
89+
frame 0
8290
with values (empty)
91+
invoke 0
92+
end frame
8393

8494
step 1:
85-
normal
86-
local 1
87-
with values (empty)
88-
block f32
89-
f32.const 4350553f
90-
f32.const 431c4000
91-
f32.mul
92-
end
93-
end local
95+
frame 0
9496
with values (empty)
95-
and store unchanged
96-
step 2:
97-
normal
98-
local 1
97+
frame 1
9998
with values (empty)
10099
label 1
101100
label_cont
102-
f32.const 4350553f
103-
f32.const 431c4000
104-
f32.mul
101+
i32.const 40
102+
i32.const 2
103+
i32.add
105104
end label
106-
end local
105+
end frame
106+
end frame
107+
108+
step 2:
109+
frame 0
107110
with values (empty)
108-
and store unchanged
109-
step 3:
110-
normal
111-
local 1
111+
frame 1
112112
with values (empty)
113113
label 1
114114
label_cont
115-
f32.const 46fe500f
115+
i32.const 42
116116
end label
117-
end local
117+
end frame
118+
end frame
119+
120+
step 3:
121+
frame 0
118122
with values (empty)
119-
and store unchanged
120-
step 4:
121-
normal
122-
local 1
123+
frame 1
123124
with values (empty)
124-
f32.const 46fe500f
125-
end local
125+
i32.const 42
126+
end frame
127+
end frame
128+
129+
step 4:
130+
frame 0
126131
with values (empty)
127-
and store unchanged
132+
i32.const 42
133+
end frame
134+
128135
step 5:
129-
normal
130-
f32.const 46fe500f
131-
with values (empty)
132-
and store unchanged
136+
Value:
137+
i32.const 42
138+
139+
success after 5 steps
133140
```

changelogs/v2.0.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Release 2.0 + Subtyping
2+
3+
This release for Wasm 2.0 + Subtyping implemented the following changes in the official spec release 2.0:
4+
- Multiple-value blocks;
5+
- Reference types;
6+
- Table instructions;
7+
- Multiple tables;
8+
- Bulk memory and table instructions.
9+
10+
In addition, this release also implemented the subtyping system from the future funcref/GC proposals.
11+
12+
The new sign extension, non-trapping float-to-int conversion, and vector types are added but without any concrete implementation.
13+
14+
## Updated Components:
15+
- [x] Base opsem/typing definitions;
16+
- [x] Preservation theorems;
17+
- [x] Interpreter and progress theorem;
18+
- [x] Instantiation;
19+
- [x] Instantiation soundness theorems;
20+
- [x] Type checker;
21+
- [x] Type checker correctness theorem;
22+
- [x] Binary printer/parser;
23+
- [x] Code pretty printer;
24+
- [x] Subtyping.
25+
26+
# Major Structural Changes
27+
28+
## Values vs Instructions
29+
Due to the introduction of reference values, values are no longer necessarily basic instructions; function references and external references are expressed as administrative instructions due to their direct usage of store addresses instead of module indices. This change has broken some assumptions that many original proofs and definitions based on -- mostly those related to value typing (see below).
30+
Total and partial conversion operations are now provided for conversion between values and their corresponding instructions:
31+
- `v_to_e/e_to_v` for total conversions;
32+
- `e_to_v_opt` for partial operations.
33+
34+
## Value Typing and the Store
35+
Due to the use of store addresses, the new reference values can only be typed given a store. This necessitated the introduction
36+
of a separate `value_typing` relation with respect to a store. In addition, value typing relation now has to be done at the
37+
`e_typing` level (for administrative instructions) as they can no longer be converted to basic instructions and typed using the `const` rule in `be_typing`. New value typing inversion lemmas were added to help reasoning with this change; search for terms involving `value_typing` and `values_typing`.
38+
39+
## Threads
40+
Threads are now properly spelt out as a separate type that constitutes the configuration tuple. The old thread-related definitions (e.g. `s_typing`) are renamed to the names used in the standard (e.g. `thread_typing`).
41+
42+
## Type System and Subtyping
43+
In addition, this release also implements subtyping introduced in the future funcret/GC proposal as a forward-looking move. There is currently no observable effect in Wasm 2.0 except for typing instructions past unconditional branches, as there is no non-trivial subtypings between any of the base value types. There exists a principal type (potentially with some free type parameters) for every value/instruction, which all possible types of it are supertypes of.
44+
The largest impact of this type system change is that, in the future, values can no longer uniquely typed even if it is well typed. This is not the case in Wasm 2.0 yet, but examples can be introduced in future proposals.
45+
The old `weakening` typing rules are replaced by a subtyping rule as a result of this change, which reflects the shift in the future proposals.
46+
47+
# Refactorings and Feature Improvements
48+
49+
## Host Formulation
50+
The parametric host language is now defined using typeclasses.
51+
The main major benefit is the automatic filling of implicit host parameter, instead of needing to redefine all operations involving anything downstream from function instances and stores. The proof context is also greatly simplified since all these redefinitions no longer exist to occupy a major chunk of the buffer window.
52+
53+
## Numerics
54+
- Refactored the old collection of conversion operations *cvtop* to be split up by their individual constructors to better match the spec.
55+
56+
## Name Changes
57+
- Changed the name of some types, instructions, and constructors to better match the official spec.
58+
- Instance indices are now simplified to the base `u32` type without additional constructors.
59+
60+
## Pretty Printer
61+
- Implemented pretty printing for conversion operations.
62+
63+
## Typing
64+
- Massively improved the scope and automation of the typing inversion lemmas.
65+
- Provided a new tactic `resolve_e_typing` that automatically tries to resolve `e_typing` goals, dealing mostly with the operands.
66+
- Provided a separate file for the new subtyping lemmas and tactics.
67+
68+
## Type Checker
69+
- Completely reimplemented the type checker, which should now be slightly more efficient (although this should hardly be observable).
70+
71+
## Miscellaneous
72+
- Introduced many additional excerpts in comments from the official spec for various definitions.
73+
74+
# Bug Fixes
75+
- Fixed a bug where the binary printer incorrectly prints all types of reinterpret conversions to 0xBC.
76+
- Fixed a bug where the binary printer sometimes prints indices via a conversion to nat first.

coq-wasm.opam

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is generated by dune, edit dune-project instead
22
opam-version: "2.0"
3-
version: "0.1"
3+
version: "2.0"
44
synopsis: "Wasm formalisation in Coq"
55
description:
66
"Wasm formalisation in Coq, following the AFP formalisation of Conrad Watt"

dune-project

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
(using coq 0.2)
33
(using mdx 0.2)
44
(name coq-wasm)
5-
(version 0.1)
5+
(version 2.0)
66

77
(generate_opam_files true)
88
(license MIT)

src/convert.ml

-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ let to_triple (a, b, c) = Extract.Pair (Extract.Pair (a, b), c)
4646

4747
let from_string str = Utils.implode str
4848

49-
let string_of_value =
50-
Extract.value_rec_safe
51-
(fun v -> Printf.sprintf "Int32: %s" (from_string (Extract.pp_i32 v)))
52-
(fun v -> Printf.sprintf "Int64: %s" (from_string (Extract.pp_i64 v)))
53-
(fun v -> Printf.sprintf "Float32: %s" (from_string (Extract.pp_f32 v)))
54-
(fun v -> Printf.sprintf "Float64: %s" (from_string (Extract.pp_f64 v)))
55-
5649
let rec to_nat = function
5750
| 0 -> Extract.O
5851
| n when n > 0 -> Extract.S (to_nat (n - 1))

src/convert.mli

-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,4 @@ val from_positive : Extract.positive -> int
5151
(** Convert [Extract.z] to [int]. *)
5252
val from_z : Extract.z -> int
5353

54-
(** Print a Wasm value. *) (* TODO: Removed, now subsumed by [Execute.Interpreter.pp_values]. *)
55-
val string_of_value : Extract.value0 -> string
5654

0 commit comments

Comments
 (0)