Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Update array.copy semantics to handle packed types#416

Merged
rossberg merged 5 commits into
mainfrom
array-copy-getu
Sep 9, 2023
Merged

Update array.copy semantics to handle packed types#416
rossberg merged 5 commits into
mainfrom
array-copy-getu

Conversation

@tlively

@tlively tlively commented Aug 24, 2023

Copy link
Copy Markdown
Member

Previously the array.copy semantics were defined in terms of executing array.get
on the source array, which is not correct if the source array contains a packed
type. Update the semantics prose and formalism to choose between array.get and
array.get_u depending on whether the array contents are packed. The interpreter
does not need updating because it already handled the difference correctly.

Previously the array.copy semantics were defined in terms of executing array.get
on the source array, which is not correct if the source array contains a packed
type. Update the semantics prose and formalism to choose between array.get and
array.get_u depending on whether the array contents are packed. The interpreter
does not need updating because it already handled the difference correctly.
@tlively tlively requested a review from rossberg August 24, 2023 19:18
@tlively

tlively commented Aug 24, 2023

Copy link
Copy Markdown
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@tlively tlively mentioned this pull request Aug 24, 2023
53 tasks
Comment thread document/core/exec/instructions.rst Outdated
Comment on lines +1272 to +1273
\land & (\X{get} = \ARRAYGET~y \vee \X{get} = \ARRAYGETU~y) \\
\land & (F.\AMODULE.\MITYPES[x] = \TARRAY~\mut~\packedtype \Longleftrightarrow \X{get} = \ARRAYGETU~y))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of a better way to express this? Is there a better symbol to use for bidirectional implication than \Longleftrightarrow?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The symbol would be correct. But I would suggest to factor out the choice of get into an auxiliary function which does a case distinction on the storage type, i.e., something like

getfield(valtype) = array.get
getfield(packedtype) = array.get_u

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've written this up now. PTAL!

Comment thread document/core/exec/instructions.rst Outdated
......................

.. todo:: Handle packed fields correctly via array.get_u instead of array.get
1. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`defined type <syntax-deftype>` :math:`F.\AMODULE.\MITYPES[y]` exists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`defined type <syntax-deftype>` :math:`F.\AMODULE.\MITYPES[y]` exists.
1. Assert: due to :ref:`validation <valid-array.copy>`, the :ref:`defined type <syntax-deftype>` :math:`F.\AMODULE.\MITYPES[y]` exists.

Comment thread document/core/exec/instructions.rst Outdated
2. Let :math:`\deftype` be the :ref:`defined type <syntax-deftype>` :math:`F.\AMODULE.\MITYPES[y]`.

2. Pop the value :math:`n` from the stack.
3. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`expansion <aux-expand-deftype>` of :math:`\deftype` is an :ref:`array type <syntax-arraytype>`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`expansion <aux-expand-deftype>` of :math:`\deftype` is an :ref:`array type <syntax-arraytype>`.
3. Assert: due to :ref:`validation <valid-array.copy>`, the :ref:`expansion <aux-expand-deftype>` of :math:`\deftype` is an :ref:`array type <syntax-arraytype>`.

Comment thread document/core/exec/instructions.rst Outdated
Comment on lines +1272 to +1273
\land & (\X{get} = \ARRAYGET~y \vee \X{get} = \ARRAYGETU~y) \\
\land & (F.\AMODULE.\MITYPES[x] = \TARRAY~\mut~\packedtype \Longleftrightarrow \X{get} = \ARRAYGETU~y))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The symbol would be correct. But I would suggest to factor out the choice of get into an auxiliary function which does a case distinction on the storage type, i.e., something like

getfield(valtype) = array.get
getfield(packedtype) = array.get_u

Comment thread document/core/exec/instructions.rst Outdated
5. Assert: due to :ref:`validation <valid-array.copy>`, a :ref:`value <syntax-val>` of :ref:`type <syntax-valtype>` :math:`\I32` is on the top of the stack.

a. Let :math:`\X{get}` be the instruction :math:`\ARRAYGET~y`.
6. Pop the value :math:`n` from the stack.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
6. Pop the value :math:`n` from the stack.
6. Pop the value :math:`\I32.\CONST~n` from the stack.

Comment thread document/core/exec/instructions.rst Outdated
8. Pop the value :math:`n` from the stack.

9. Assert: due to :ref:`validation <valid-array.copy>`, a :ref:`value <syntax-val>` of :ref:`type <syntax-valtype>` :math:`\I32` is on the top of the stack.
8. Pop the value :math:`s` from the stack.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
8. Pop the value :math:`s` from the stack.
8. Pop the value :math:`\I32.\CONST~s` from the stack.

Comment thread document/core/exec/instructions.rst Outdated
11. Assert: due to :ref:`validation <valid-array.copy>`, a :ref:`value <syntax-val>` of :ref:`type <syntax-valtype>` :math:`\I32` is on the top of the stack.

13. Assert: due to :ref:`validation <valid-array.copy>`, a :ref:`value <syntax-val>` of :ref:`type <syntax-valtype>` :math:`\I32` is on the top of the stack.
12. Pop the value :math:`d` from the stack.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
12. Pop the value :math:`d` from the stack.
12. Pop the value :math:`(\I32.\CONST~d)` from the stack.

Comment thread document/core/syntax/instructions.rst Outdated
\begin{array}{lll}
\getfield(\valtype) &=& \ARRAYGET \\
\getfield(\packedtype) &=& \ARRAYGETU \\
\end{array}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this next to the rules (as a "where:" sort of thing), since it is local helper for that specific rule only.

@tlively

tlively commented Sep 9, 2023

Copy link
Copy Markdown
Member Author

Comments addressed. I also updated the formatting of the side conditions now that they are shorter.

@rossberg rossberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@rossberg rossberg merged commit d6a2c16 into main Sep 9, 2023
@rossberg rossberg deleted the array-copy-getu branch September 9, 2023 16:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants