Subtyping¶
Subtyping defines when a value of one type may be used when a value of another type is expected.
TODO: This is not complete, pending further discussion, especially in re the special treatment that may or may not be required or specialized value types.
Value types¶
Reflexivity¶
Any value type is a subtype of itself
Numeric types¶
\(\href{../valid/types.html#syntax-evaltype}{\mathsf{s8}}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s16}}\), \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s32}}\), and \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s64}}\).
\(\href{../valid/types.html#syntax-evaltype}{\mathsf{s16}}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s32}}\) and \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s64}}\).
\(\href{../valid/types.html#syntax-evaltype}{\mathsf{s32}}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s64}}\).
\(\href{../valid/types.html#syntax-evaltype}{\mathsf{u8}}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathsf{u16}}\), \(\href{../valid/types.html#syntax-evaltype}{\mathsf{u32}}\), \(\href{../valid/types.html#syntax-evaltype}{\mathsf{u64}}\), \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s16}}\), \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s32}}\), and \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s64}}\).
\(\href{../valid/types.html#syntax-evaltype}{\mathsf{u16}}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathsf{u32}}\), \(\href{../valid/types.html#syntax-evaltype}{\mathsf{u64}}\), \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s32}}\), and \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s64}}\).
\(\href{../valid/types.html#syntax-evaltype}{\mathsf{u32}}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathsf{u64}}\) and \(\href{../valid/types.html#syntax-evaltype}{\mathsf{s64}}\).
\(\href{../valid/types.html#syntax-evaltype}{\mathsf{float32}}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathsf{float64}}\).
Records¶
A type \(\href{../valid/types.html#syntax-evaltype2}{\mathsf{record}}~\overline{{\href{../valid/types.html#syntax-erecordfield}{\mathit{record\_field}_e}}_i}\) is a subtype of a type \(\href{../valid/types.html#syntax-evaltype2}{\mathsf{record}}~\overline{{\href{../valid/types.html#syntax-erecordfield}{\mathit{record\_field}_e}'}_j}\) if, for each named field of the latter type, a field with the same name is present in the former, and the type of the field in the former is a subtype of the type of the field in the latter.
Todo: We may need to move despecialization later because of subtyping?
Variants¶
A type \(\href{../valid/types.html#syntax-evaltype2}{\mathsf{variant}}~\overline{{\href{../valid/types.html#syntax-evariantcase}{\mathit{variant\_case}_e}}_i}\) is a subtype of a type \(\href{../valid/types.html#syntax-evaltype2}{\mathsf{variant}}~\overline{{\href{../valid/types.html#syntax-evariantcase}{\mathit{variant\_case}_e}'}_j}\) if, or each named case of the former type, either:
A case of the same name exists in the latter type, such that the type of the field in the former is a subtype of the type of the field in the latter; or
No case of the same name exists in the latter type, and the case in the former contains a \(\href{../valid/types.html#syntax-evariantcase}{\mathsf{refines}}\).
Lists¶
A type \(\href{../valid/types.html#syntax-evaltype}{\mathsf{list}}~\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}\) is a subtype of a type \(\href{../valid/types.html#syntax-evaltype}{\mathsf{list}}~\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'\) if \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'\)
Result types¶
A result type of the form \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}\) is a subtype of a result type of te form \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'\) if \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'\).
\[\frac{ \href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e} \preccurlyeq \href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}' }{ \href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e} \preccurlyeq \href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}' }\]A result type of the form \(\overline{\{ \href{../valid/types.html#syntax-eresulttype}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}_i, \href{../valid/types.html#syntax-eresulttype}{\mathsf{type}}~{\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}}_i \}}\) is a subtype of a result type of the form \(\overline{\{ \href{../valid/types.html#syntax-eresulttype}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}'_j, \href{../valid/types.html#syntax-eresulttype}{\mathsf{type}}~{\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'}_j \}}\) when:
For each \(\href{../syntax/values.html#syntax-name}{\mathit{name}}'_j\), there is some \(i\) such that \(\href{../syntax/values.html#syntax-name}{\mathit{name}}'_j = \href{../syntax/values.html#syntax-name}{\mathit{name}}_i\) and \({\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}}_i \preccurlyeq {\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}}'_j\).
\[\frac{ \forall j, \exists i, \href{../syntax/values.html#syntax-name}{\mathit{name}}_i = \href{../syntax/values.html#syntax-name}{\mathit{name}}'_j \land {\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}}_i \preccurlyeq {\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}}'_j }{ \overline{\{ \href{../valid/types.html#syntax-eresulttype}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}_i, \href{../valid/types.html#syntax-eresulttype}{\mathsf{type}}~{\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}}_i \}} \preccurlyeq \overline{\{ \href{../valid/types.html#syntax-eresulttype}{\mathsf{name}}~\href{../syntax/values.html#syntax-name}{\mathit{name}}'_j, \href{../valid/types.html#syntax-eresulttype}{\mathsf{type}}~{\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'}_j \}} }\]
Function types¶
A function type \({\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}}_1 \to {\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}}_2\) is a subtype of a function \({\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}'}_1 \to {\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}'}_2\) if \({\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}'}_1 \preccurlyeq {\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}}_1\) and \({\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}}_2 \preccurlyeq {\href{../valid/types.html#syntax-eresulttype}{\mathit{resulttype}_e}'}_2\).
Type bound¶
\(\href{../valid/types.html#syntax-etypebound}{\mathsf{eq}}~\href{../valid/types.html#syntax-edeftype}{\mathit{deftype}_e}\)¶
A type bound \(\href{../valid/types.html#syntax-etypebound}{\mathsf{eq}}~\href{../valid/types.html#syntax-edeftype}{\mathit{deftype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-etypebound}{\mathsf{eq}}~\href{../valid/types.html#syntax-edeftype}{\mathit{deftype}_e}'\) if \(\href{../valid/types.html#syntax-edeftype}{\mathit{deftype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-edeftype}{\mathit{deftype}_e}'\).
Extern descriptors¶
\(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{core\_module}}~\href{../valid/types.html#syntax-ecoremoduletype}{\mathit{core{:}moduletype}_e}\)¶
A extern descriptor \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{core\_module}}~\href{../valid/types.html#syntax-ecoremoduletype}{\mathit{core{:}moduletype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{core\_module}}~\href{../valid/types.html#syntax-ecoremoduletype}{\mathit{core{:}moduletype}_e}'\) if \(\href{../valid/types.html#syntax-ecoremoduletype}{\mathit{core{:}moduletype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-ecoremoduletype}{\mathit{core{:}moduletype}_e}'\).
\(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{func}}~\href{../valid/types.html#syntax-efunctype}{\mathit{functype}_e}\)¶
An extern descriptor \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{func}}~\href{../valid/types.html#syntax-efunctype}{\mathit{functype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{func}}~\href{../valid/types.html#syntax-efunctype}{\mathit{functype}_e}'\) if \(\href{../valid/types.html#syntax-efunctype}{\mathit{functype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-efunctype}{\mathit{functype}_e}'\).
\(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{value}}~\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}\)¶
An extern descriptor \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{value}}~\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{value}}~\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'\) if \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-evaltype}{\mathit{valtype}_e}'\).
\(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{type}}~\href{../valid/types.html#syntax-etypebound}{\mathit{typebound}_e}\)¶
An extern descriptor \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{type}}~\href{../valid/types.html#syntax-etypebound}{\mathit{typebound}_e}\) is a subtype of \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{type}}~\href{../valid/types.html#syntax-etypebound}{\mathit{typebound}_e}'\) if \(\href{../valid/types.html#syntax-etypebound}{\mathit{typebound}_e}\) is a subtype of \(\href{../valid/types.html#syntax-etypebound}{\mathit{typebound}_e}'\).
\(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{instance}}~\href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}\)¶
An extern descriptor \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{instance}}~\href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{instance}}~\href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}'\) if \(\href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}'\).
\(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{component}}~\href{../valid/types.html#syntax-ecomponenttype}{\mathit{componenttype}_e}\)¶
An extern descriptor \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{component}}~\href{../valid/types.html#syntax-ecomponenttype}{\mathit{componenttype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-eexterndesc}{\mathsf{component}}~\href{../valid/types.html#syntax-ecomponenttype}{\mathit{componenttype}_e}'\) if \(\href{../valid/types.html#syntax-ecomponenttype}{\mathit{componenttype}_e}\) is a subtype of \(\href{../valid/types.html#syntax-ecomponenttype}{\mathit{componenttype}_e}'\).
Instance types¶
An instance type \(\overline{{\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}}_i}\) is a subtype of an instance type \(\overline{{\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}'}_j}\) if:
For each \(j\), there exists some \(i\) such that \({\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}}_i.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{name}} = {\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}'}_j.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{name}}\) and \({\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}}_i.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{desc}} \preccurlyeq {\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}'}_j.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{desc}}\).
Component types¶
A component type \(\overline{{\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}}_i} \to \href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}\) is a subtype of a \(\overline{{\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}'}_j} \to \href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}'\) if:
For each \(i\), there exists some \(j\), such that \({\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}'}_j.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{name}} = {\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}}_i.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{name}}\) and \({\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}'}_j.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{desc}} \preccurlyeq {\href{../valid/types.html#syntax-eexportdecl}{\mathit{externdecl}_e}}_i.\href{../valid/types.html#syntax-eexportdecl}{\mathsf{desc}}\); and
\(\href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e} \preccurlyeq \href{../valid/types.html#syntax-einstancetype}{\mathit{instancetype}_e}'\)