Validation¶
Conventions¶
Contexts¶
The context is enriched with an additional flag on label types:
Existing typing rules are adjusted as follows:
All rules that extend the context with new labels use an absent \(\href{../valid/conventions.html#context}{\mathsf{catch}}\) flag.
All rules that inspect the context for a label ignore the presence of a \(\href{../valid/conventions.html#context}{\mathsf{catch}}\) flag.
Note
This flag is used to distinguish labels bound by catch clauses, which can be targeted by \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{rethrow}}\).
Instructions¶
Control Instructions¶
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast~(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch}}~x~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast)^\ast~(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_all}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_3^\ast)^?~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{end}}\)¶
The block type must be valid as some function type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Let \(C'\) be the same context as \(C\), but with the label type \([t_2^\ast]\) prepended to the \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) vector.
Under context \(C'\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_1^\ast\) must be valid with type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Let \(C''\) be the same context as \(C\), but with the label type \(\href{../valid/conventions.html#context}{\mathsf{catch}}~[t_2^\ast]\) prepended to the \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) vector.
For every \(x_i\) and \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_{2i}^\ast\) in \((\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch}}~x~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_2^\ast)^\ast\):
The tag \(C.\href{../valid/conventions.html#context}{\mathsf{tags}}[x_i]\) must be defined in the context \(C\).
Let \([t_{3i}^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_{4i}^\ast]\) be the tag type \(C.\href{../valid/conventions.html#context}{\mathsf{tags}}[x_i]\).
The result type \([t_{4i}^\ast]\) must be empty.
Under context \(C''\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_{2i}^\ast\) must be valid with type \([t_{3i}^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
If \((\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{catch\_all}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_3^\ast)^?\) is not empty, then:
Under context \(C''\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}_3^\ast\) must be valid with type \([] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Then the compound instruction is valid with type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Note
The notation \(C,\href{../valid/conventions.html#context}{\mathsf{labels}}\,(\href{../valid/conventions.html#context}{\mathsf{catch}}~[t^\ast])\) inserts the new label type at index \(0\), shifting all others.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{try}}~\href{../syntax/instructions.html#syntax-blocktype}{\mathit{blocktype}}~\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast~\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{delegate}}~l\)¶
The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.
The block type must be valid as some function type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Let \(C'\) be the same context as \(C\), but with the result type \([t_2^\ast]\) prepended to the \(\href{../valid/conventions.html#context}{\mathsf{labels}}\) vector.
Under context \(C'\), the instruction sequence \(\href{../syntax/instructions.html#syntax-instr}{\mathit{instr}}^\ast\) must be valid with type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Then the compound instruction is valid with type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\).
Note
The label index space in the context \(C\) contains the most recent label first, so that \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) performs a relative lookup as expected.
\(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{rethrow}}~l\)¶
The label \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\) must be defined in the context.
Let \((\href{../valid/conventions.html#context}{\mathsf{catch}}^?~[t^\ast])\) be the label type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).
The \(\href{../valid/conventions.html#context}{\mathsf{catch}}\) must be present in the label type \(C.\href{../valid/conventions.html#context}{\mathsf{labels}}[l]\).
Then the instruction is valid with type \([t_1^\ast] \href{../syntax/types.html#syntax-functype}{\rightarrow} [t_2^\ast]\), for any sequences of value types \(t_1^\ast\) and \(t_2^\ast\).
Note
The \(\href{../syntax/instructions.html#syntax-instr-control}{\mathsf{rethrow}}\) instruction is stack-polymorphic.