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

[crux-mir-comp] struct support for munge #1711

Merged
merged 6 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crux-mir-comp/src/Mir/Cryptol.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ munge sym shp rv = do
W4.justPartExpr sym <$> go shp rv
return $ MirVector_PartialVector pv'
MirVector_Array _ -> error $ "munge: MirVector_Array NYI"
-- TODO: StructShape
go (StructShape _ _ flds) (AnyValue tpr rvs)
| StructRepr ctx <- tpr
, Just Refl <- testEquality (fmapFC fieldShapeType flds) ctx =
AnyValue tpr <$> goFields flds rvs
| otherwise = error $ "munge: StructShape AnyValue with NYI TypeRepr " ++ show tpr
go (TransparentShape _ shp) rv = go shp rv
-- TODO: RefShape
go shp _ = error $ "munge: " ++ show (shapeType shp) ++ " NYI"
Expand Down
3 changes: 3 additions & 0 deletions crux-mir-comp/test/symb_eval/comp/munge_struct.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test munge_struct/3a1fbbbh::munge_struct_equiv_test[0]: ok

[Crux] Overall status: Valid.
20 changes: 20 additions & 0 deletions crux-mir-comp/test/symb_eval/comp/munge_struct.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
extern crate crucible;
use crucible::*;
use crucible::cryptol::munge;

#[derive(Clone)]
struct Point{
x: u32,
y: u32,
}

fn reflect(p: Point) -> Point {
Point{x: p.y, y: p.x}
}

#[crux_test]
fn munge_struct_equiv_test() {
let (x, y) = <(u32, u32)>::symbolic("p");
let p2 = reflect(munge(Point{x, y}));
plredmond marked this conversation as resolved.
Show resolved Hide resolved
crucible_assert!(p2.x == y);
}