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

mir_array_value #1925

Merged
merged 3 commits into from
Sep 2, 2023
Merged

mir_array_value #1925

merged 3 commits into from
Sep 2, 2023

Conversation

RyanGlScott
Copy link
Contributor

@RyanGlScott RyanGlScott commented Aug 30, 2023

This adds support for a mir_array_value function in the MIR backend, which allows constructing array SetupValues. This largely behaves like llvm_array_values in the LLVM backend, but with the following differences:

  • Unlike in the LLVM backend, MIR arrays can have length 0. To account for this possibility, mir_array_value has a MIRType argument to ensure that SAW can always infer the type of the array, even if there are no element values from which to infer the type.

    Similarly, the SAW remote API's array() function now has an optional element_type kwarg that can be used to specify the element type in the event that there are no element values.

  • Because only the MIR backend makes use of the element type, this is encoded in the XSetupArray extension field.

This checks off one box in #1859.

Comment on lines +311 to +325
-- match arrays point-wise
(MIRVal (ArrayShape _ _ elemShp) xs, Mir.TyArray y _len, MS.SetupArray _elemTy zs)
| Mir.MirVector_Vector xs' <- xs
, V.length xs' == length zs ->
sequence_
[ matchArg opts sc cc cs prepost md (MIRVal elemShp x) y z
| (x, z) <- zip (V.toList xs') zs ]

| Mir.MirVector_PartialVector xs' <- xs
, V.length xs' == length zs ->
do xs'' <- liftIO $
traverse (readMaybeType sym "vector element" (shapeType elemShp)) xs'
sequence_
[ matchArg opts sc cc cs prepost md (MIRVal elemShp x) y z
| (x, z) <- zip (V.toList xs'') zs ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is how SAW matches array arguments in specifications. Note that MirVector_Array (for symbolic, SMT-based arrays) aren't supported.

Comment on lines +123 to +124
MS.SetupArray elemTy vs ->
pure $ Mir.TyArray elemTy (length vs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is where the type of mir_array_values are computed.

Comment on lines +2618 to +2629
In the experimental MIR verification implementation, the following functions
construct compound values:

* `mir_array_value : MIRType -> [SetupValue] -> SetupValue` constructs an array
of the given type whose elements consist of the given values. Supplying the
element type is necessary to support length-0 arrays.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Documentation

Copy link
Contributor

@bboston7 bboston7 left a comment

Choose a reason for hiding this comment

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

Looks good! I only looked at the most recent commit because the rest seemed covered by #1919. Let me know if that's not true and I'll go back and review some of the other commits.

saw-remote-api/CHANGELOG.md Outdated Show resolved Hide resolved
@RyanGlScott RyanGlScott force-pushed the T1859-mir_array_value branch from f12cdf4 to 9d74cbd Compare September 2, 2023 00:09
@RyanGlScott RyanGlScott marked this pull request as ready for review September 2, 2023 00:09
@RyanGlScott RyanGlScott added the PR: ready to merge Magic flag for pull requests to ask Mergify to merge given an approval and a successful CI run label Sep 2, 2023
This adds support for a `mir_array_value` function in the MIR backend, which
allows constructing array `SetupValue`s. This largely behaves like
`llvm_array_value`s in the LLVM backend, but with the following differences:

* Unlike in the LLVM backend, MIR arrays can have length 0. To account for this
  possibility, `mir_array_value` has a `MIRType` argument to ensure that SAW
  can always infer the type of the array, even if there are no element values
  from which to infer the type.

  Similarly, the SAW remote API's `array()` function now has an optional
  `element_type` kwarg that can be used to specify the element type in the
  event that there are no element values.
* Because only the MIR backend makes use of the element type, this is encoded
  in the `XSetupArray` extension field.

This checks off one box in #1859.
@RyanGlScott RyanGlScott force-pushed the T1859-mir_array_value branch from 9d74cbd to ca34dbe Compare September 2, 2023 00:48
@mergify mergify bot merged commit 4c0985c into master Sep 2, 2023
@mergify mergify bot deleted the T1859-mir_array_value branch September 2, 2023 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: ready to merge Magic flag for pull requests to ask Mergify to merge given an approval and a successful CI run
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants