Skip to content

Commit

Permalink
Remove use of comma operator
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg committed Jul 9, 2024
1 parent d5905db commit fbcdf97
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 71 deletions.
11 changes: 0 additions & 11 deletions document/core/valid/conventions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,6 @@ More concretely, contexts are defined as :ref:`records <notation-record>` ${:C}

$${syntax: context}

.. _notation-extend:

In addition to field access written ${:C.FIELD}, the following notation is adopted for manipulating contexts:

* ${:C, FIELD A*} denotes the same context as ${:C} but with the elements ${:A*} prepended to its ${:FIELD} component sequence.

.. note::
:ref:`Indexing notation <notation-index>` like ${resulttype: C.LABELS[i]} is used to look up indices in their respective :ref:`index space <syntax-index>` in the context.
Context extension notation ${:C, FIELD A} is primarily used to locally extend *relative* index spaces, such as :ref:`label indices <syntax-labelidx>`.
Accordingly, the notation is defined to append at the *front* of the respective sequence, introducing a new relative index ${:0} and shifting the existing ones.


.. index:: ! type closure
.. _type-closure:
Expand Down
6 changes: 3 additions & 3 deletions document/core/valid/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ Control Instructions
$${rule: Instr_ok/block}

.. note::
The :ref:`notation <notation-extend>` ${context: C, LABELS (t*)} inserts the new label type at index ${:0}, shifting all others.
The :ref:`notation <notation-concat>` ${context: {LABELS (t*)} ++ C} inserts the new label type at index ${:0}, shifting all others.


.. _valid-loop:
Expand All @@ -1414,7 +1414,7 @@ $${rule: Instr_ok/block}
$${rule: Instr_ok/loop}

.. note::
The :ref:`notation <notation-extend>` ${context: C, LABELS (t*)} inserts the new label type at index ${:0}, shifting all others.
The :ref:`notation <notation-concat>` ${context: {LABELS (t*)} ++ C} inserts the new label type at index ${:0}, shifting all others.


.. _valid-if:
Expand All @@ -1437,7 +1437,7 @@ $${rule: Instr_ok/loop}
$${rule: Instr_ok/if}

.. note::
The :ref:`notation <notation-extend>` ${context: C, LABELS (t*)} inserts the new label type at index ${:0}, shifting all others.
The :ref:`notation <notation-concat>` ${context: {LABELS (t*)} ++ C} inserts the new label type at index ${:0}, shifting all others.


.. _valid-br:
Expand Down
10 changes: 5 additions & 5 deletions spectec/spec/wasm-1.0/6-typing.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ rule Instr_ok/select:

rule Instr_ok/block:
C |- BLOCK t? instr* : eps -> t?
-- Instrs_ok: C, LABELS (t?) |- instr* : eps -> t?
-- Instrs_ok: {LABELS (t?)} ++ C |- instr* : eps -> t?

rule Instr_ok/loop:
C |- LOOP t? instr* : eps -> t?
-- Instrs_ok: C, LABELS (eps) |- instr* : eps -> eps
-- Instrs_ok: {LABELS (eps)} ++ C |- instr* : eps -> eps

rule Instr_ok/if:
C |- IF t? instr_1* ELSE instr_2* : I32 -> t?
-- Instrs_ok: C, LABELS (t?) |- instr_1* : eps -> t?
-- Instrs_ok: C, LABELS (t?) |- instr_2* : eps -> t?
-- Instrs_ok: {LABELS (t?)} ++ C |- instr_1* : eps -> t?
-- Instrs_ok: {LABELS (t?)} ++ C |- instr_2* : eps -> t?


;; Branch instructions
Expand Down Expand Up @@ -333,7 +333,7 @@ rule Type_ok:
rule Func_ok:
C |- FUNC x (LOCAL t)* expr : t_1* -> t_2?
-- if C.TYPES[x] = t_1* -> t_2?
-- Expr_ok: C, LOCALS t_1* t*, LABELS (t_2?), RETURN (t_2?) |- expr : t_2?
-- Expr_ok: C ++ {LOCALS t_1* t*, LABELS (t_2?), RETURN (t_2?)} |- expr : t_2?

rule Global_ok:
C |- GLOBAL gt expr : gt
Expand Down
10 changes: 5 additions & 5 deletions spectec/spec/wasm-2.0/6-typing.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,18 @@ rule Blocktype_ok/typeidx:
rule Instr_ok/block:
C |- BLOCK bt instr* : t_1* -> t_2*
-- Blocktype_ok: C |- bt : t_1* -> t_2*
-- Instrs_ok: C, LABELS (t_2*) |- instr* : t_1* -> t_2*
-- Instrs_ok: {LABELS (t_2*)} ++ C |- instr* : t_1* -> t_2*

rule Instr_ok/loop:
C |- LOOP bt instr* : t_1* -> t_2*
-- Blocktype_ok: C |- bt : t_1* -> t_2*
-- Instrs_ok: C, LABELS (t_1*) |- instr* : t_1* -> t_2*
-- Instrs_ok: {LABELS (t_1*)} ++ C |- instr* : t_1* -> t_2*

rule Instr_ok/if:
C |- IF bt instr_1* ELSE instr_2* : t_1* I32 -> t_2*
-- Blocktype_ok: C |- bt : t_1* -> t_2*
-- Instrs_ok: C, LABELS (t_2*) |- instr_1* : t_1* -> t_2*
-- Instrs_ok: C, LABELS (t_2*) |- instr_2* : t_1* -> t_2*
-- Instrs_ok: {LABELS (t_2*)} ++ C |- instr_1* : t_1* -> t_2*
-- Instrs_ok: {LABELS (t_2*)} ++ C |- instr_2* : t_1* -> t_2*


;; Branch instructions
Expand Down Expand Up @@ -554,7 +554,7 @@ rule Type_ok:
rule Func_ok:
C |- FUNC x (LOCAL t)* expr : t_1* -> t_2*
-- if C.TYPES[x] = t_1* -> t_2*
-- Expr_ok: C, LOCALS t_1* t*, LABELS (t_2*), RETURN (t_2*) |- expr : t_2*
-- Expr_ok: C ++ {LOCALS t_1* t*, LABELS (t_2*), RETURN (t_2*)} |- expr : t_2*

rule Global_ok:
C |- GLOBAL gt expr : gt
Expand Down
10 changes: 5 additions & 5 deletions spectec/spec/wasm-3.0/6-typing.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -598,18 +598,18 @@ rule Blocktype_ok/typeidx:
rule Instr_ok/block:
C |- BLOCK bt instr* : t_1* -> t_2*
-- Blocktype_ok: C |- bt : t_1* -> t_2*
-- Instrs_ok: C, LABELS (t_2*) |- instr* : t_1* ->_(x*) t_2*
-- Instrs_ok: {LABELS (t_2*)} ++ C |- instr* : t_1* ->_(x*) t_2*

rule Instr_ok/loop:
C |- LOOP bt instr* : t_1* -> t_2*
-- Blocktype_ok: C |- bt : t_1* -> t_2*
-- Instrs_ok: C, LABELS (t_1*) |- instr* : t_1* ->_(x*) t_2*
-- Instrs_ok: {LABELS (t_1*)} ++ C |- instr* : t_1* ->_(x*) t_2*

rule Instr_ok/if:
C |- IF bt instr_1* ELSE instr_2* : t_1* I32 -> t_2*
-- Blocktype_ok: C |- bt : t_1* -> t_2*
-- Instrs_ok: C, LABELS (t_2*) |- instr_1* : t_1* ->_(x_1*) t_2*
-- Instrs_ok: C, LABELS (t_2*) |- instr_2* : t_1* ->_(x_2*) t_2*
-- Instrs_ok: {LABELS (t_2*)} ++ C |- instr_1* : t_1* ->_(x_1*) t_2*
-- Instrs_ok: {LABELS (t_2*)} ++ C |- instr_2* : t_1* ->_(x_2*) t_2*


;; Branch instructions
Expand Down Expand Up @@ -1205,7 +1205,7 @@ rule Func_ok:
C |- FUNC x local* expr : C.TYPES[x]
-- Expand: C.TYPES[x] ~~ FUNC (t_1* -> t_2*)
-- (Local_ok: C |- local : lct)*
-- Expr_ok: C, LOCALS (SET t_1)* lct*, LABELS (t_2*), RETURN (t_2*) |- expr : t_2*
-- Expr_ok: C ++ {LOCALS (SET t_1)* lct*, LABELS (t_2*), RETURN (t_2*)} |- expr : t_2*

rule Global_ok:
C |- GLOBAL globaltype expr : globaltype
Expand Down
2 changes: 1 addition & 1 deletion spectec/spec/wasm-3.0/C-conventions.watsup
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ rule NotationTypingInstrScheme/global.get:
rule NotationTypingInstrScheme/block:
C |- BLOCK blocktype instr* : t_1* -> t_2*
-- Blocktype_ok: C |- blocktype : t_1* -> t_2*
-- NotationTypingInstrScheme: C, LABELS (t_2*) |- instr* : t_1* -> t_2*
-- NotationTypingInstrScheme: {LABELS (t_2*)} ++ C |- instr* : t_1* -> t_2*


;; Execution notation
Expand Down
2 changes: 1 addition & 1 deletion spectec/src/el/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ and exp' =
| ExtE of exp * path * exp (* exp `[` path `=..` exp `]` *)
| StrE of expfield nl_list (* `{` list(expfield, `,`) `}` *)
| DotE of exp * atom (* exp `.` atom *)
| CommaE of exp * exp (* exp `,` exp *)
| CommaE of exp * exp (* exp `,` exp *) (* TODO(3, rossberg): Remove? *)
| CatE of exp * exp (* exp `++` exp *)
| MemE of exp * exp (* exp `<-` exp *)
| LenE of exp (* `|` exp `|` *)
Expand Down
10 changes: 5 additions & 5 deletions spectec/test-frontend/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -4070,19 +4070,19 @@ relation Instr_ok: `%|-%:%`(context, instr, instrtype)
-- Valtype_sub: `%|-%<:%`(C, t, t')
-- if ((t' = (numtype : numtype <: valtype)) \/ (t' = (vectype : vectype <: valtype)))

;; 6-typing.watsup:598.1-601.63
;; 6-typing.watsup:598.1-601.67
rule block{C : context, bt : blocktype, instr* : instr*, t_1* : valtype*, t_2* : valtype*, x* : idx*}:
`%|-%:%`(C, BLOCK_instr(bt, instr*{instr : instr}), `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), [], `%`_resulttype(t_2*{t_2 : valtype})))
-- Blocktype_ok: `%|-%:%`(C, bt, `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), [], `%`_resulttype(t_2*{t_2 : valtype})))
-- Instrs_ok: `%|-%:%`({TYPES [], RECS [], FUNCS [], GLOBALS [], TABLES [], MEMS [], ELEMS [], DATAS [], LOCALS [], LABELS [`%`_resulttype(t_2*{t_2 : valtype})], RETURN ?(), REFS []} ++ C, instr*{instr : instr}, `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), x*{x : localidx}, `%`_resulttype(t_2*{t_2 : valtype})))

;; 6-typing.watsup:603.1-606.63
;; 6-typing.watsup:603.1-606.67
rule loop{C : context, bt : blocktype, instr* : instr*, t_1* : valtype*, t_2* : valtype*, x* : idx*}:
`%|-%:%`(C, LOOP_instr(bt, instr*{instr : instr}), `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), [], `%`_resulttype(t_2*{t_2 : valtype})))
-- Blocktype_ok: `%|-%:%`(C, bt, `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), [], `%`_resulttype(t_2*{t_2 : valtype})))
-- Instrs_ok: `%|-%:%`({TYPES [], RECS [], FUNCS [], GLOBALS [], TABLES [], MEMS [], ELEMS [], DATAS [], LOCALS [], LABELS [`%`_resulttype(t_1*{t_1 : valtype})], RETURN ?(), REFS []} ++ C, instr*{instr : instr}, `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), x*{x : localidx}, `%`_resulttype(t_2*{t_2 : valtype})))

;; 6-typing.watsup:608.1-612.67
;; 6-typing.watsup:608.1-612.71
rule if{C : context, bt : blocktype, instr_1* : instr*, instr_2* : instr*, t_1* : valtype*, t_2* : valtype*, x_1* : idx*, x_2* : idx*}:
`%|-%:%`(C, `IF%%ELSE%`_instr(bt, instr_1*{instr_1 : instr}, instr_2*{instr_2 : instr}), `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype} :: [I32_valtype]), [], `%`_resulttype(t_2*{t_2 : valtype})))
-- Blocktype_ok: `%|-%:%`(C, bt, `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), [], `%`_resulttype(t_2*{t_2 : valtype})))
Expand Down Expand Up @@ -4754,7 +4754,7 @@ relation Func_ok: `%|-%:%`(context, func, deftype)
`%|-%:%`(C, FUNC_func(x, local*{local : local}, expr), C.TYPES_context[x!`%`_idx.0])
-- Expand: `%~~%`(C.TYPES_context[x!`%`_idx.0], FUNC_comptype(`%->%`_functype(`%`_resulttype(t_1*{t_1 : valtype}), `%`_resulttype(t_2*{t_2 : valtype}))))
-- (Local_ok: `%|-%:%`(C, local, lct))*{lct : localtype, local : local}
-- Expr_ok: `%|-%:%`({TYPES [], RECS [], FUNCS [], GLOBALS [], TABLES [], MEMS [], ELEMS [], DATAS [], LOCALS [], LABELS [], RETURN ?(`%`_resulttype(t_2*{t_2 : valtype})), REFS []} ++ {TYPES [], RECS [], FUNCS [], GLOBALS [], TABLES [], MEMS [], ELEMS [], DATAS [], LOCALS [], LABELS [`%`_resulttype(t_2*{t_2 : valtype})], RETURN ?(), REFS []} ++ {TYPES [], RECS [], FUNCS [], GLOBALS [], TABLES [], MEMS [], ELEMS [], DATAS [], LOCALS `%%`_localtype(SET_init, t_1)*{t_1 : valtype} :: lct*{lct : localtype}, LABELS [], RETURN ?(), REFS []} ++ C, expr, `%`_resulttype(t_2*{t_2 : valtype}))
-- Expr_ok: `%|-%:%`(C ++ {TYPES [], RECS [], FUNCS [], GLOBALS [], TABLES [], MEMS [], ELEMS [], DATAS [], LOCALS `%%`_localtype(SET_init, t_1)*{t_1 : valtype} :: lct*{lct : localtype}, LABELS [`%`_resulttype(t_2*{t_2 : valtype})], RETURN ?(`%`_resulttype(t_2*{t_2 : valtype})), REFS []}, expr, `%`_resulttype(t_2*{t_2 : valtype}))

;; 6-typing.watsup
relation Global_ok: `%|-%:%`(context, global, globaltype)
Expand Down Expand Up @@ -6369,7 +6369,7 @@ relation NotationTypingInstrScheme: `%|-%:%`(context, instr*, functype)
`%|-%:%`(C, [GLOBAL.GET_instr(x)], `%->%`_functype(`%`_resulttype([]), `%`_resulttype([t])))
-- if (C.GLOBALS_context[x!`%`_idx.0] = `%%`_globaltype(mut, t))

;; C-conventions.watsup:47.1-50.74
;; C-conventions.watsup:47.1-50.78
rule block{C : context, blocktype : blocktype, instr* : instr*, t_1* : valtype*, t_2* : valtype*}:
`%|-%:%`(C, [BLOCK_instr(blocktype, instr*{instr : instr})], `%->%`_functype(`%`_resulttype(t_1*{t_1 : valtype}), `%`_resulttype(t_2*{t_2 : valtype})))
-- Blocktype_ok: `%|-%:%`(C, blocktype, `%->_%%`_instrtype(`%`_resulttype(t_1*{t_1 : valtype}), [], `%`_resulttype(t_2*{t_2 : valtype})))
Expand Down
18 changes: 12 additions & 6 deletions spectec/test-latex/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -5302,7 +5302,8 @@ $$
\frac{
C \vdash {\mathit{bt}} : {t_1^\ast} \rightarrow {t_2^\ast}
\qquad
C, \mathsf{labels}~({t_2^\ast}) \vdash {{\mathit{instr}}^\ast} : {t_1^\ast}~{\rightarrow}_{({x^\ast})}\,{t_2^\ast}
\{ \begin{array}[t]{@{}l@{}}
\mathsf{labels}~({t_2^\ast}) \}\end{array} \oplus C \vdash {{\mathit{instr}}^\ast} : {t_1^\ast}~{\rightarrow}_{({x^\ast})}\,{t_2^\ast}
}{
C \vdash \mathsf{block}~{\mathit{bt}}~{{\mathit{instr}}^\ast} : {t_1^\ast} \rightarrow {t_2^\ast}
} \, {[\textsc{\scriptsize T{-}block}]}
Expand All @@ -5315,7 +5316,8 @@ $$
\frac{
C \vdash {\mathit{bt}} : {t_1^\ast} \rightarrow {t_2^\ast}
\qquad
C, \mathsf{labels}~({t_1^\ast}) \vdash {{\mathit{instr}}^\ast} : {t_1^\ast}~{\rightarrow}_{({x^\ast})}\,{t_2^\ast}
\{ \begin{array}[t]{@{}l@{}}
\mathsf{labels}~({t_1^\ast}) \}\end{array} \oplus C \vdash {{\mathit{instr}}^\ast} : {t_1^\ast}~{\rightarrow}_{({x^\ast})}\,{t_2^\ast}
}{
C \vdash \mathsf{loop}~{\mathit{bt}}~{{\mathit{instr}}^\ast} : {t_1^\ast} \rightarrow {t_2^\ast}
} \, {[\textsc{\scriptsize T{-}loop}]}
Expand All @@ -5328,9 +5330,11 @@ $$
\frac{
C \vdash {\mathit{bt}} : {t_1^\ast} \rightarrow {t_2^\ast}
\qquad
C, \mathsf{labels}~({t_2^\ast}) \vdash {{\mathit{instr}}_1^\ast} : {t_1^\ast}~{\rightarrow}_{({x_1^\ast})}\,{t_2^\ast}
\{ \begin{array}[t]{@{}l@{}}
\mathsf{labels}~({t_2^\ast}) \}\end{array} \oplus C \vdash {{\mathit{instr}}_1^\ast} : {t_1^\ast}~{\rightarrow}_{({x_1^\ast})}\,{t_2^\ast}
\qquad
C, \mathsf{labels}~({t_2^\ast}) \vdash {{\mathit{instr}}_2^\ast} : {t_1^\ast}~{\rightarrow}_{({x_2^\ast})}\,{t_2^\ast}
\{ \begin{array}[t]{@{}l@{}}
\mathsf{labels}~({t_2^\ast}) \}\end{array} \oplus C \vdash {{\mathit{instr}}_2^\ast} : {t_1^\ast}~{\rightarrow}_{({x_2^\ast})}\,{t_2^\ast}
}{
C \vdash \mathsf{if}~{\mathit{bt}}~{{\mathit{instr}}_1^\ast}~\mathsf{else}~{{\mathit{instr}}_2^\ast} : {t_1^\ast}~\mathsf{i{\scriptstyle 32}} \rightarrow {t_2^\ast}
} \, {[\textsc{\scriptsize T{-}if}]}
Expand Down Expand Up @@ -6798,7 +6802,8 @@ C{.}\mathsf{types}{}[x] \approx \mathsf{func}~({t_1^\ast} \rightarrow {t_2^\ast}
\qquad
(C \vdash {\mathit{local}} : {{\mathit{lt}}})^\ast
\qquad
C, \mathsf{locals}~{(\mathsf{set}~t_1)^\ast}~{{{\mathit{lt}}}^\ast}, \mathsf{labels}~({t_2^\ast}), \mathsf{return}~({t_2^\ast}) \vdash {\mathit{expr}} : {t_2^\ast}
C \oplus \{ \begin{array}[t]{@{}l@{}}
\mathsf{locals}~{(\mathsf{set}~t_1)^\ast}~{{{\mathit{lt}}}^\ast},\; \mathsf{labels}~({t_2^\ast}),\; \mathsf{return}~({t_2^\ast}) \}\end{array} \vdash {\mathit{expr}} : {t_2^\ast}
}{
C \vdash \mathsf{func}~x~{{\mathit{local}}^\ast}~{\mathit{expr}} : C{.}\mathsf{types}{}[x]
} \, {[\textsc{\scriptsize T{-}func}]}
Expand Down Expand Up @@ -9705,7 +9710,8 @@ $$
\frac{
C \vdash {\mathit{blocktype}} : {t_1^\ast} \rightarrow {t_2^\ast}
\qquad
C, \mathsf{labels}~({t_2^\ast}) \vdash {{\mathit{instr}}^\ast} : {t_1^\ast} \rightarrow {t_2^\ast}
\{ \begin{array}[t]{@{}l@{}}
\mathsf{labels}~({t_2^\ast}) \}\end{array} \oplus C \vdash {{\mathit{instr}}^\ast} : {t_1^\ast} \rightarrow {t_2^\ast}
}{
C \vdash \mathsf{block}~{\mathit{blocktype}}~{{\mathit{instr}}^\ast} : {t_1^\ast} \rightarrow {t_2^\ast}
} \, {[\textsc{\scriptsize NotationTypingInstrScheme{-}block}]}
Expand Down
Loading

0 comments on commit fbcdf97

Please sign in to comment.