Skip to content

Commit

Permalink
Add missing context rule
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg committed Oct 9, 2024
1 parent 379d081 commit 3b41f7f
Show file tree
Hide file tree
Showing 5 changed files with 244 additions and 203 deletions.
31 changes: 18 additions & 13 deletions spectec/spec/wasm-3.0/8-reduction.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ rule Eval_expr:
;; Instructions
;;

;; Context

rule Step/ctxt-instrs:
z; val* instr* instr_1* ~> z'; val* instr'* instr_1*
-- Step: z; instr* ~> z'; instr'*
-- if val* =/= eps \/ instr_1* =/= eps

rule Step/ctxt-label:
z; (LABEL_ n `{instr_0*} instr*) ~> z'; (LABEL_ n `{instr_0*} instr'*)
-- Step: z; instr* ~> z'; instr'*

rule Step/ctxt-frame:
s; f; (FRAME_ n `{f'} instr*) ~> s'; f; (FRAME_ n `{f'} instr'*)
-- Step: s; f'; instr* ~> s'; f'; instr'*


;; Polymorphic instructions

rule Step_pure/unreachable:
Expand Down Expand Up @@ -228,7 +244,7 @@ rule Step/throw:
rule Step_read/throw_ref-null:
z; (REF.NULL ht) THROW_REF ~> TRAP

rule Step_read/throw_ref-vals:
rule Step_read/throw_ref-instrs:
z; val* (REF.EXN_ADDR a) THROW_REF instr* ~> (REF.EXN_ADDR a) THROW_REF
-- if val* =/= eps \/ instr* =/= eps

Expand Down Expand Up @@ -272,7 +288,7 @@ rule Step_pure/handler-vals:

;; Traps

rule Step_pure/trap-vals:
rule Step_pure/trap-instrs:
val* TRAP instr* ~> TRAP
-- if val* =/= eps \/ instr* =/= eps

Expand All @@ -283,17 +299,6 @@ rule Step_pure/trap-frame:
(FRAME_ n `{f} TRAP) ~> TRAP


;; Context

rule Step/ctxt-label:
z; (LABEL_ n `{instr_0*} instr*) ~> z'; (LABEL_ n `{instr_0*} instr'*)
-- Step: z; instr* ~> z'; instr'*

rule Step/ctxt-frame:
s; f; (FRAME_ n `{f'} instr*) ~> s'; f; (FRAME_ n `{f'} instr'*)
-- Step: s; f'; instr* ~> s'; f'; instr'*


;; Numeric instructions

rule Step_pure/unop-val:
Expand Down
76 changes: 41 additions & 35 deletions spectec/test-frontend/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -5671,7 +5671,7 @@ relation Step_pure: `%~>%`(instr*, instr*)
`%~>%`([`HANDLER_%{%}%`_instr(n, catch*{catch <- `catch*`}, (val : val <: instr)*{val <- `val*`})], (val : val <: instr)*{val <- `val*`})

;; 8-reduction.watsup
rule `trap-vals`{`val*` : val*, `instr*` : instr*}:
rule `trap-instrs`{`val*` : val*, `instr*` : instr*}:
`%~>%`((val : val <: instr)*{val <- `val*`} ++ [TRAP_instr] ++ instr*{instr <- `instr*`}, [TRAP_instr])
-- if ((val*{val <- `val*`} =/= []) \/ (instr*{instr <- `instr*`} =/= []))

Expand Down Expand Up @@ -6038,7 +6038,7 @@ relation Step_read: `%~>%`(config, instr*)
`%~>%`(`%;%`_config(z, [REF.NULL_instr(ht) THROW_REF_instr]), [TRAP_instr])

;; 8-reduction.watsup
rule `throw_ref-vals`{z : state, `val*` : val*, a : addr, `instr*` : instr*}:
rule `throw_ref-instrs`{z : state, `val*` : val*, a : addr, `instr*` : instr*}:
`%~>%`(`%;%`_config(z, (val : val <: instr)*{val <- `val*`} ++ [REF.EXN_ADDR_instr(a)] ++ [THROW_REF_instr] ++ instr*{instr <- `instr*`}), [REF.EXN_ADDR_instr(a) THROW_REF_instr])
-- if ((val*{val <- `val*`} =/= []) \/ (instr*{instr <- `instr*`} =/= []))

Expand Down Expand Up @@ -6522,142 +6522,148 @@ relation Step: `%~>%`(config, config)
`%~>%`(`%;%`_config(z, instr*{instr <- `instr*`}), `%;%`_config(z, instr'*{instr' <- `instr'*`}))
-- Step_read: `%~>%`(`%;%`_config(z, instr*{instr <- `instr*`}), instr'*{instr' <- `instr'*`})

;; 8-reduction.watsup:221.1-226.49
rule throw{z : state, `val*` : val*, n : n, x : idx, exn : exninst, a : addr, `t*` : valtype*}:
`%~>%`(`%;%`_config(z, (val : val <: instr)^n{val <- `val*`} ++ [THROW_instr(x)]), `%;%`_config($add_exninst(z, [exn]), [REF.EXN_ADDR_instr(a) THROW_REF_instr]))
-- Expand: `%~~%`($tag(z, x).TYPE_taginst, FUNC_comptype(`%->%`_functype(`%`_resulttype(t^n{t <- `t*`}), `%`_resulttype([]))))
-- if (a = |$exninst(z)|)
-- if (exn = {TAG $tagaddr(z)[x!`%`_idx.0], FIELDS val^n{val <- `val*`}})
;; 8-reduction.watsup:42.1-45.41
rule `ctxt-instrs`{z : state, `val*` : val*, `instr*` : instr*, `instr_1*` : instr*, z' : state, `instr'*` : instr*}:
`%~>%`(`%;%`_config(z, (val : val <: instr)*{val <- `val*`} ++ instr*{instr <- `instr*`} ++ instr_1*{instr_1 <- `instr_1*`}), `%;%`_config(z', (val : val <: instr)*{val <- `val*`} ++ instr'*{instr' <- `instr'*`} ++ instr_1*{instr_1 <- `instr_1*`}))
-- Step: `%~>%`(`%;%`_config(z, instr*{instr <- `instr*`}), `%;%`_config(z', instr'*{instr' <- `instr'*`}))
-- if ((val*{val <- `val*`} =/= []) \/ (instr_1*{instr_1 <- `instr_1*`} =/= []))

;; 8-reduction.watsup:288.1-290.36
;; 8-reduction.watsup:47.1-49.36
rule `ctxt-label`{z : state, n : n, `instr_0*` : instr*, `instr*` : instr*, z' : state, `instr'*` : instr*}:
`%~>%`(`%;%`_config(z, [`LABEL_%{%}%`_instr(n, instr_0*{instr_0 <- `instr_0*`}, instr*{instr <- `instr*`})]), `%;%`_config(z', [`LABEL_%{%}%`_instr(n, instr_0*{instr_0 <- `instr_0*`}, instr'*{instr' <- `instr'*`})]))
-- Step: `%~>%`(`%;%`_config(z, instr*{instr <- `instr*`}), `%;%`_config(z', instr'*{instr' <- `instr'*`}))

;; 8-reduction.watsup:292.1-294.44
;; 8-reduction.watsup:51.1-53.44
rule `ctxt-frame`{s : store, f : frame, n : n, f' : frame, `instr*` : instr*, s' : store, `instr'*` : instr*}:
`%~>%`(`%;%`_config(`%;%`_state(s, f), [`FRAME_%{%}%`_instr(n, f', instr*{instr <- `instr*`})]), `%;%`_config(`%;%`_state(s', f), [`FRAME_%{%}%`_instr(n, f', instr'*{instr' <- `instr'*`})]))
-- Step: `%~>%`(`%;%`_config(`%;%`_state(s, f'), instr*{instr <- `instr*`}), `%;%`_config(`%;%`_state(s', f'), instr'*{instr' <- `instr'*`}))

;; 8-reduction.watsup:412.1-416.65
;; 8-reduction.watsup:237.1-242.49
rule throw{z : state, `val*` : val*, n : n, x : idx, exn : exninst, a : addr, `t*` : valtype*}:
`%~>%`(`%;%`_config(z, (val : val <: instr)^n{val <- `val*`} ++ [THROW_instr(x)]), `%;%`_config($add_exninst(z, [exn]), [REF.EXN_ADDR_instr(a) THROW_REF_instr]))
-- Expand: `%~~%`($tag(z, x).TYPE_taginst, FUNC_comptype(`%->%`_functype(`%`_resulttype(t^n{t <- `t*`}), `%`_resulttype([]))))
-- if (a = |$exninst(z)|)
-- if (exn = {TAG $tagaddr(z)[x!`%`_idx.0], FIELDS val^n{val <- `val*`}})

;; 8-reduction.watsup:417.1-421.65
rule struct.new{z : state, `val*` : val*, n : n, x : idx, si : structinst, a : addr, `mut*` : mut*, `zt*` : storagetype*}:
`%~>%`(`%;%`_config(z, (val : val <: instr)^n{val <- `val*`} ++ [STRUCT.NEW_instr(x)]), `%;%`_config($add_structinst(z, [si]), [REF.STRUCT_ADDR_instr(a)]))
-- Expand: `%~~%`($type(z, x), STRUCT_comptype(`%`_structtype(`%%`_fieldtype(mut, zt)^n{mut <- `mut*`, zt <- `zt*`})))
-- if (a = |$structinst(z)|)
-- if (si = {TYPE $type(z, x), FIELDS $packfield_(zt, val)^n{val <- `val*`, zt <- `zt*`}})

;; 8-reduction.watsup:432.1-433.53
;; 8-reduction.watsup:437.1-438.53
rule `struct.set-null`{z : state, ht : heaptype, val : val, x : idx, i : nat}:
`%~>%`(`%;%`_config(z, [REF.NULL_instr(ht) (val : val <: instr) STRUCT.SET_instr(x, `%`_u32(i))]), `%;%`_config(z, [TRAP_instr]))

;; 8-reduction.watsup:435.1-437.45
;; 8-reduction.watsup:440.1-442.45
rule `struct.set-struct`{z : state, a : addr, val : val, x : idx, i : nat, `zt*` : storagetype*, `mut*` : mut*}:
`%~>%`(`%;%`_config(z, [REF.STRUCT_ADDR_instr(a) (val : val <: instr) STRUCT.SET_instr(x, `%`_u32(i))]), `%;%`_config($with_struct(z, a, i, $packfield_(zt*{zt <- `zt*`}[i], val)), []))
-- Expand: `%~~%`($type(z, x), STRUCT_comptype(`%`_structtype(`%%`_fieldtype(mut, zt)*{mut <- `mut*`, zt <- `zt*`})))

;; 8-reduction.watsup:450.1-455.65
;; 8-reduction.watsup:455.1-460.65
rule array.new_fixed{z : state, `val*` : val*, n : n, x : idx, ai : arrayinst, a : addr, mut : mut, zt : storagetype}:
`%~>%`(`%;%`_config(z, (val : val <: instr)^n{val <- `val*`} ++ [ARRAY.NEW_FIXED_instr(x, `%`_u32(n))]), `%;%`_config($add_arrayinst(z, [ai]), [REF.ARRAY_ADDR_instr(a)]))
-- Expand: `%~~%`($type(z, x), ARRAY_comptype(`%%`_arraytype(mut, zt)))
-- if ((a = |$arrayinst(z)|) /\ (ai = {TYPE $type(z, x), FIELDS $packfield_(zt, val)^n{val <- `val*`}}))

;; 8-reduction.watsup:495.1-496.64
;; 8-reduction.watsup:500.1-501.64
rule `array.set-null`{z : state, ht : heaptype, i : nat, val : val, x : idx}:
`%~>%`(`%;%`_config(z, [REF.NULL_instr(ht) CONST_instr(I32_numtype, `%`_num_(i)) (val : val <: instr) ARRAY.SET_instr(x)]), `%;%`_config(z, [TRAP_instr]))

;; 8-reduction.watsup:498.1-500.39
;; 8-reduction.watsup:503.1-505.39
rule `array.set-oob`{z : state, a : addr, i : nat, val : val, x : idx}:
`%~>%`(`%;%`_config(z, [REF.ARRAY_ADDR_instr(a) CONST_instr(I32_numtype, `%`_num_(i)) (val : val <: instr) ARRAY.SET_instr(x)]), `%;%`_config(z, [TRAP_instr]))
-- if (i >= |$arrayinst(z)[a].FIELDS_arrayinst|)

;; 8-reduction.watsup:502.1-505.43
;; 8-reduction.watsup:507.1-510.43
rule `array.set-array`{z : state, a : addr, i : nat, val : val, x : idx, zt : storagetype, mut : mut}:
`%~>%`(`%;%`_config(z, [REF.ARRAY_ADDR_instr(a) CONST_instr(I32_numtype, `%`_num_(i)) (val : val <: instr) ARRAY.SET_instr(x)]), `%;%`_config($with_array(z, a, i, $packfield_(zt, val)), []))
-- Expand: `%~~%`($type(z, x), ARRAY_comptype(`%%`_arraytype(mut, zt)))

;; 8-reduction.watsup:823.1-824.56
;; 8-reduction.watsup:828.1-829.56
rule local.set{z : state, val : val, x : idx}:
`%~>%`(`%;%`_config(z, [(val : val <: instr) LOCAL.SET_instr(x)]), `%;%`_config($with_local(z, x, val), []))

;; 8-reduction.watsup:836.1-837.58
;; 8-reduction.watsup:841.1-842.58
rule global.set{z : state, val : val, x : idx}:
`%~>%`(`%;%`_config(z, [(val : val <: instr) GLOBAL.SET_instr(x)]), `%;%`_config($with_global(z, x, val), []))

;; 8-reduction.watsup:850.1-852.33
;; 8-reduction.watsup:855.1-857.33
rule `table.set-oob`{z : state, i : nat, ref : ref, x : idx}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) (ref : ref <: instr) TABLE.SET_instr(x)]), `%;%`_config(z, [TRAP_instr]))
-- if (i >= |$table(z, x).REFS_tableinst|)

;; 8-reduction.watsup:854.1-856.32
;; 8-reduction.watsup:859.1-861.32
rule `table.set-val`{z : state, i : nat, ref : ref, x : idx}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) (ref : ref <: instr) TABLE.SET_instr(x)]), `%;%`_config($with_table(z, x, i, ref), []))
-- if (i < |$table(z, x).REFS_tableinst|)

;; 8-reduction.watsup:864.1-867.46
;; 8-reduction.watsup:869.1-872.46
rule `table.grow-succeed`{z : state, ref : ref, n : n, x : idx, ti : tableinst}:
`%~>%`(`%;%`_config(z, [(ref : ref <: instr) CONST_instr(I32_numtype, `%`_num_(n)) TABLE.GROW_instr(x)]), `%;%`_config($with_tableinst(z, x, ti), [CONST_instr(I32_numtype, `%`_num_(|$table(z, x).REFS_tableinst|))]))
-- if (ti = $growtable($table(z, x), n, ref))

;; 8-reduction.watsup:869.1-870.81
;; 8-reduction.watsup:874.1-875.81
rule `table.grow-fail`{z : state, ref : ref, n : n, x : idx}:
`%~>%`(`%;%`_config(z, [(ref : ref <: instr) CONST_instr(I32_numtype, `%`_num_(n)) TABLE.GROW_instr(x)]), `%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_($invsigned_(32, - (1 : nat <: int))))]))

;; 8-reduction.watsup:930.1-931.51
;; 8-reduction.watsup:935.1-936.51
rule elem.drop{z : state, x : idx}:
`%~>%`(`%;%`_config(z, [ELEM.DROP_instr(x)]), `%;%`_config($with_elem(z, x, []), []))

;; 8-reduction.watsup:1014.1-1017.60
;; 8-reduction.watsup:1019.1-1022.60
rule `store-num-oob`{z : state, i : nat, nt : numtype, c : num_(nt), x : idx, ao : memarg}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) CONST_instr(nt, c) STORE_instr(nt, ?(), x, ao)]), `%;%`_config(z, [TRAP_instr]))
-- if (((i + ao.OFFSET_memarg!`%`_u32.0) + ($size(nt) / 8)) > |$mem(z, x).BYTES_meminst|)

;; 8-reduction.watsup:1019.1-1023.29
;; 8-reduction.watsup:1024.1-1028.29
rule `store-num-val`{z : state, i : nat, nt : numtype, c : num_(nt), x : idx, ao : memarg, `b*` : byte*}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) CONST_instr(nt, c) STORE_instr(nt, ?(), x, ao)]), `%;%`_config($with_mem(z, x, (i + ao.OFFSET_memarg!`%`_u32.0), ($size(nt) / 8), b*{b <- `b*`}), []))
-- if (b*{b <- `b*`} = $nbytes_(nt, c))

;; 8-reduction.watsup:1025.1-1028.52
;; 8-reduction.watsup:1030.1-1033.52
rule `store-pack-oob`{z : state, i : nat, Inn : Inn, c : num_((Inn : Inn <: numtype)), nt : numtype, n : n, x : idx, ao : memarg}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) CONST_instr((Inn : Inn <: numtype), c) STORE_instr(nt, ?(`%`_sz(n)), x, ao)]), `%;%`_config(z, [TRAP_instr]))
-- if (((i + ao.OFFSET_memarg!`%`_u32.0) + (n / 8)) > |$mem(z, x).BYTES_meminst|)

;; 8-reduction.watsup:1030.1-1034.52
;; 8-reduction.watsup:1035.1-1039.52
rule `store-pack-val`{z : state, i : nat, Inn : Inn, c : num_((Inn : Inn <: numtype)), nt : numtype, n : n, x : idx, ao : memarg, `b*` : byte*}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) CONST_instr((Inn : Inn <: numtype), c) STORE_instr(nt, ?(`%`_sz(n)), x, ao)]), `%;%`_config($with_mem(z, x, (i + ao.OFFSET_memarg!`%`_u32.0), (n / 8), b*{b <- `b*`}), []))
-- if (b*{b <- `b*`} = $ibytes_(n, $wrap__($size((Inn : Inn <: numtype)), n, c)))

;; 8-reduction.watsup:1036.1-1038.63
;; 8-reduction.watsup:1041.1-1043.63
rule `vstore-oob`{z : state, i : nat, c : vec_(V128_Vnn), x : idx, ao : memarg}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) VCONST_instr(V128_vectype, c) VSTORE_instr(V128_vectype, x, ao)]), `%;%`_config(z, [TRAP_instr]))
-- if (((i + ao.OFFSET_memarg!`%`_u32.0) + ($vsize(V128_vectype) / 8)) > |$mem(z, x).BYTES_meminst|)

;; 8-reduction.watsup:1040.1-1042.31
;; 8-reduction.watsup:1045.1-1047.31
rule `vstore-val`{z : state, i : nat, c : vec_(V128_Vnn), x : idx, ao : memarg, `b*` : byte*}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) VCONST_instr(V128_vectype, c) VSTORE_instr(V128_vectype, x, ao)]), `%;%`_config($with_mem(z, x, (i + ao.OFFSET_memarg!`%`_u32.0), ($vsize(V128_vectype) / 8), b*{b <- `b*`}), []))
-- if (b*{b <- `b*`} = $vbytes_(V128_vectype, c))

;; 8-reduction.watsup:1045.1-1047.50
;; 8-reduction.watsup:1050.1-1052.50
rule `vstore_lane-oob`{z : state, i : nat, c : vec_(V128_Vnn), N : N, x : idx, ao : memarg, j : nat}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) VCONST_instr(V128_vectype, c) VSTORE_LANE_instr(V128_vectype, `%`_sz(N), x, ao, `%`_laneidx(j))]), `%;%`_config(z, [TRAP_instr]))
-- if (((i + ao.OFFSET_memarg!`%`_u32.0) + N) > |$mem(z, x).BYTES_meminst|)

;; 8-reduction.watsup:1049.1-1053.49
;; 8-reduction.watsup:1054.1-1058.49
rule `vstore_lane-val`{z : state, i : nat, c : vec_(V128_Vnn), N : N, x : idx, ao : memarg, j : nat, `b*` : byte*, Jnn : Jnn, M : M}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(i)) VCONST_instr(V128_vectype, c) VSTORE_LANE_instr(V128_vectype, `%`_sz(N), x, ao, `%`_laneidx(j))]), `%;%`_config($with_mem(z, x, (i + ao.OFFSET_memarg!`%`_u32.0), (N / 8), b*{b <- `b*`}), []))
-- if (N = $lsize((Jnn : Jnn <: lanetype)))
-- if (M = (128 / N))
-- if (b*{b <- `b*`} = $ibytes_(N, `%`_iN($lanes_(`%X%`_shape((Jnn : Jnn <: lanetype), `%`_dim(M)), c)[j]!`%`_lane_.0)))

;; 8-reduction.watsup:1061.1-1064.37
;; 8-reduction.watsup:1066.1-1069.37
rule `memory.grow-succeed`{z : state, n : n, x : idx, mi : meminst}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(n)) MEMORY.GROW_instr(x)]), `%;%`_config($with_meminst(z, x, mi), [CONST_instr(I32_numtype, `%`_num_((|$mem(z, x).BYTES_meminst| / (64 * $Ki))))]))
-- if (mi = $growmem($mem(z, x), n))

;; 8-reduction.watsup:1066.1-1067.78
;; 8-reduction.watsup:1071.1-1072.78
rule `memory.grow-fail`{z : state, n : n, x : idx}:
`%~>%`(`%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_(n)) MEMORY.GROW_instr(x)]), `%;%`_config(z, [CONST_instr(I32_numtype, `%`_num_($invsigned_(32, - (1 : nat <: int))))]))

;; 8-reduction.watsup:1127.1-1128.51
;; 8-reduction.watsup:1132.1-1133.51
rule data.drop{z : state, x : idx}:
`%~>%`(`%;%`_config(z, [DATA.DROP_instr(x)]), `%;%`_config($with_data(z, x, []), []))
}
Expand Down
Loading

0 comments on commit 3b41f7f

Please sign in to comment.