Skip to content

Commit 8daa165

Browse files
author
Guy Bedford
committed
rework definitions
1 parent aeeba9b commit 8daa165

File tree

3 files changed

+30
-32
lines changed

3 files changed

+30
-32
lines changed

document/core/appendix/embedding.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ Modules
163163

164164
.. math::
165165
\begin{array}{lclll}
166-
\F{module\_extern\_subtype}(\externtype_1, \externtype_2) &=& \TRUE && (\iff \vdashexterntypematch \externtype_1 \matchesexterntype \externtype_2) \\
166+
\F{module\_extern\_subtype}(\externtype_1, \externtype_2) &\iff& \vdashexterntypematch \externtype_1 \matchesexterntype \externtype_2 \\
167167
\end{array}
168168
169169
.. note::
170-
This function encapsulates the external type matching relation defined in the core specification. It allows for checking compatibility of external types when linking modules or validating imports against exports. The current implementation uses the exact matching rules from the core specification, but this function provides a single point for potential future extensions to the type system.
170+
This function encapsulates the external type matching relation defined in the :ref:`Import Subtyping <match>` of the validation section, where the :math:`\vdashexterntypematch \externtype_1 \matchesexterntype \externtype_2` judgment establishes compatibility between external types. This allows for explicit checking of type compatibility when linking modules or validating imports against exports.
171171

172172
.. index:: instantiation, module instance
173173
.. _embed-module-instantiate:
@@ -263,16 +263,20 @@ Modules
263263

264264
4. For each :math:`\export_i` in :math:`\export^\ast` and corresponding :math:`\externtype'_i` in :math:`{\externtype'}^\ast`, do:
265265

266-
a. If :math:`\isdirectexport(\module, \export_i.\EDESC)`, then append the pair :math:`(\export_i.\ENAME, \externtype'_i)` to :math:`\X{result}`.
266+
a. Let :math:`\import_j = \exportimport(\module, \export_i.\EDESC)`.
267+
268+
b. If :math:`\import_j = \epsilon`, then append the pair :math:`(\export_i.\ENAME, \externtype'_i)` to :math:`\X{result}`.
267269

268270
5. Return :math:`\X{result}`.
269271

270272
.. math::
271273
~ \\
272274
\begin{array}{lclll}
273275
\F{module\_direct\_exports}(m) &=& (\X{ex}.\ENAME, \externtype')^\ast \\
274-
&& \qquad (\iff \X{ex} \in m.\MEXPORTS \wedge \externtype' \in {\externtype'}^\ast \wedge {} \vdashmodule m : \externtype^\ast \to {\externtype'}^\ast \\
275-
&& \qquad\quad \wedge \isdirectexport(m, \X{ex}.\EDESC)) \\
276+
&& \qquad (\iff \X{ex}^\ast = m.\MEXPORTS \\
277+
&& \qquad\quad \wedge~\exportimport(m, \X{ex}.\EDESC) = \epsilon \\
278+
&& \qquad\quad \wedge~\vdashmodule m : \externtype^\ast \to {\externtype'}^\ast \\
279+
&& \qquad\quad \wedge~\externtype' = \X{ex}.\EDESC) \\
276280
\end{array}
277281
278282
@@ -292,20 +296,22 @@ Modules
292296

293297
5. For each :math:`\export_i` in :math:`\export^\ast`, do:
294298

295-
a. If :math:`\isindirectexport(\module, \export_i.\EDESC)`, then:
299+
a. Let :math:`\import_j = \exportimport(\module, \export_i.\EDESC)`.
296300

297-
i. Let :math:`\import_j` be the import corresponding to the index in :math:`\export_i.\EDESC`.
301+
b. If :math:`\import_j \neq \epsilon`, then:
298302

299-
ii. Append the triple :math:`(\export_i.\ENAME, \import_j.\IMODULE, \import_j.\INAME)` to :math:`\X{result}`.
303+
i. Append the triple :math:`(\export_i.\ENAME, \import_j.\IMODULE, \import_j.\INAME)` to :math:`\X{result}`.
300304

301305
6. Return :math:`\X{result}`.
302306

303307
.. math::
304308
~ \\
305309
\begin{array}{lclll}
306310
\F{module\_indirect\_exports}(m) &=& (\X{ex}.\ENAME, \X{im}.\IMODULE, \X{im}.\INAME)^\ast \\
307-
&& \qquad (\iff \X{ex} \in m.\MEXPORTS \wedge \X{im} \in m.\MIMPORTS \wedge {} \vdashmodule m : \externtype^\ast \to {\externtype'}^\ast \\
308-
&& \qquad\quad \wedge \isindirectexport(m, \X{ex}.\EDESC) \wedge \X{im} = \importforexport(m, \X{ex}.\EDESC)) \\
311+
&& \qquad (\iff \X{ex}^\ast = m.\MEXPORTS \\
312+
&& \qquad\quad \wedge~\X{im} = \exportimport(m, \X{ex}.\EDESC) \\
313+
&& \qquad\quad \wedge~\X{im} \neq \epsilon \\
314+
&& \qquad\quad \wedge~\vdashmodule m : \externtype^\ast \to {\externtype'}^\ast) \\
309315
\end{array}
310316
311317

document/core/syntax/modules.rst

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -356,32 +356,26 @@ Each export is labeled by a unique :ref:`name <syntax-name>`.
356356
Exportable definitions are :ref:`functions <syntax-func>`, :ref:`tables <syntax-table>`, :ref:`memories <syntax-mem>`, and :ref:`globals <syntax-global>`,
357357
which are referenced through a respective descriptor.
358358

359-
A *direct export* is one where the export references a function, table, memory, or global instance that is defined within the module itself rather than being imported.
359+
A *direct export* is one where the export references a function, table, memory, or global instance that is defined within the module itself rather than being imported.
360360

361361
An *indirect export* (or *re-export*) is one where the export references a function, table, memory, or global that the module imports.
362362

363-
The import corresponding to an export description is given by:
363+
For an export :math:`\export` in module :math:`m`, the export is direct when :math:`\exportimport(m, \export.\EDESC) = \epsilon` and indirect otherwise, where
364+
the import corresponding to an export description is defined by:
364365

365366
.. math::
366-
\begin{array}{lllll}
367-
\production{import for export} & \importforexport(m, \exportdesc) &=&
368-
\begin{cases}
369-
m.\MIMPORTS[\X{idx}] & (\iff \exportdesc = \EDFUNC~\X{idx} \wedge \X{idx} < |\etfuncs(m.\MIMPORTS)|) \\
370-
m.\MIMPORTS[\X{fidx} + \X{idx}] & (\iff \exportdesc = \EDTABLE~\X{idx} \wedge \X{idx} < |\ettables(m.\MIMPORTS)| \\
371-
& \quad \wedge \X{fidx} = |\etfuncs(m.\MIMPORTS)|) \\
372-
m.\MIMPORTS[\X{fidx} + \X{tidx} + \X{idx}] & (\iff \exportdesc = \EDMEM~\X{idx} \wedge \X{idx} < |\etmems(m.\MIMPORTS)| \\
373-
& \quad \wedge \X{fidx} = |\etfuncs(m.\MIMPORTS)| \wedge \X{tidx} = |\ettables(m.\MIMPORTS)|) \\
374-
m.\MIMPORTS[\X{fidx} + \X{tidx} + \X{midx} + \X{idx}] & (\iff \exportdesc = \EDGLOBAL~\X{idx} \wedge \X{idx} < |\etglobals(m.\MIMPORTS)| \\
375-
& \quad \wedge \X{fidx} = |\etfuncs(m.\MIMPORTS)| \wedge \X{tidx} = |\ettables(m.\MIMPORTS)| \\
376-
& \quad \wedge \X{midx} = |\etmems(m.\MIMPORTS)|) \\
377-
\epsilon & (\otherwise) \\
378-
\end{cases} \\
367+
\begin{array}{lclll}
368+
\F{exportimport}(m, \exportdesc) &=& m.\MIMPORTS[i] && (\iff \exportdesc = \EDFUNC~\funcidx \\
369+
&&&& \quad \wedge~\exists~i~\colon \ m.\MIMPORTS[i].\IDESC = \IDFUNC~\typeidx \\
370+
\F{exportimport}(m, \exportdesc) &=& m.\MIMPORTS[i] && (\iff \exportdesc = \EDTABLE~\tableidx \\
371+
&&&& \quad \wedge~\exists~i~\colon \ m.\MIMPORTS[i].\IDESC = \IDTABLE~\tabletype \\
372+
\F{exportimport}(m, \exportdesc) &=& m.\MIMPORTS[i] && (\iff \exportdesc = \EDMEM~\memidx \\
373+
&&&& \quad \wedge~\exists~i~\colon \ m.\MIMPORTS[i].\IDESC = \IDMEM~\memtype \\
374+
\F{exportimport}(m, \exportdesc) &=& m.\MIMPORTS[i] && (\iff \exportdesc = \EDGLOBAL~\globalidx \\
375+
&&&& \quad \wedge~\exists~i~\colon \ m.\MIMPORTS[i].\IDESC = \IDGLOBAL~\globaltype \\
376+
\F{exportimport}(m, \exportdesc) &=& \epsilon && (\otherwise) \\
379377
\end{array}
380378
381-
For embedder convenience, we also define:
382-
383-
* :math:`\isdirectexport(m, \exportdesc) = (\importforexport(m, \exportdesc) = \epsilon)`
384-
* :math:`\isindirectexport(m, \exportdesc) = (\importforexport(m, \exportdesc) \neq \epsilon)`
385379
386380
Conventions
387381
...........

document/core/util/macros.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,7 @@
346346
.. |edtables| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{tables}}
347347
.. |edmems| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{mems}}
348348
.. |edglobals| mathdef:: \xref{syntax/modules}{syntax-exportdesc}{\F{globals}}
349-
.. |importforexport| mathdef:: \xref{syntax/modules}{syntax-export}{\F{import\_for\_export}}
350-
.. |isdirectexport| mathdef:: \xref{syntax/modules}{syntax-export}{\F{is\_direct\_export}}
351-
.. |isindirectexport| mathdef:: \xref{syntax/modules}{syntax-export}{\F{is\_indirect\_export}}
349+
.. |exportimport| mathdef:: \xref{syntax/modules}{syntax-export}{\F{import\_for\_export}}
352350

353351

354352
.. Instructions, terminals

0 commit comments

Comments
 (0)