Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update array.copy semantics to handle packed types #416

Merged
merged 5 commits into from
Sep 9, 2023
Merged

Conversation

tlively
Copy link
Member

@tlively tlively commented Aug 24, 2023

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
Copy link
Member Author

tlively commented Aug 24, 2023

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 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
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
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
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!

@@ -1120,61 +1120,75 @@ Reference Instructions
:math:`\ARRAYCOPY~x~y`
......................

.. 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
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.


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
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 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
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


a. Let :math:`\X{get}` be the instruction :math:`\ARRAYGET~y`.
6. Pop the value :math:`n` from the stack.
Copy link
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.

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
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.


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
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.

\begin{array}{lll}
\getfield(\valtype) &=& \ARRAYGET \\
\getfield(\packedtype) &=& \ARRAYGETU \\
\end{array}
Copy link
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
Copy link
Member Author

tlively commented Sep 9, 2023

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

Copy link
Member

@rossberg rossberg left a comment

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
4 checks passed
@rossberg rossberg deleted the array-copy-getu branch September 9, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants