Skip to content

Commit 3a3fbe5

Browse files
authored
Merge pull request #2563 from GaloisInc/mir-vec-of
MIR: Add `mir_vec_of` command
2 parents 29a7ced + 9ee1d1d commit 3a3fbe5

File tree

14 files changed

+301
-18
lines changed

14 files changed

+301
-18
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ support compositional verification using techniques similar to SAW.
8787
* Add new SAWScript MIR commands `mir_elem_value` and `mir_elem_ref` for
8888
indexing into arrays and references to arrays.
8989

90+
* Add a new SAWScript MIR command `mir_vec_of` for creating Rust `Vec` values in
91+
specifications.
92+
9093
* Support writing MIR specifications involving raw pointers. This is done with
9194
the new SAWScript commands `mir_raw_ptr_const`, `mir_raw_ptr_mut`,
9295
`mir_alloc_raw_ptr_const`, and `mir_alloc_raw_ptr_mut`, which are similar to

cryptol-saw-core/src/CryptolSAWCore/CryptolEnv.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module CryptolSAWCore.CryptolEnv
2323
, bindType
2424
, bindInteger
2525
, parseTypedTerm
26+
, pExprToTypedTerm
2627
, parseDecls
2728
, parseSchema
2829
, declareName
@@ -645,11 +646,17 @@ parseTypedTerm ::
645646
(?fileReader :: FilePath -> IO ByteString) =>
646647
SharedContext -> CryptolEnv -> InputText -> IO TypedTerm
647648
parseTypedTerm sc env input = do
648-
let modEnv = eModuleEnv env
649-
650649
-- Parse
651650
pexpr <- ioParseExpr input
652651

652+
pExprToTypedTerm sc env pexpr
653+
654+
pExprToTypedTerm ::
655+
(?fileReader :: FilePath -> IO ByteString) =>
656+
SharedContext -> CryptolEnv -> P.Expr P.PName -> IO TypedTerm
657+
pExprToTypedTerm sc env pexpr = do
658+
let modEnv = eModuleEnv env
659+
653660
((expr, schema), modEnv') <- liftModuleM modEnv $ do
654661

655662
-- Eliminate patterns
2 Bytes
Binary file not shown.
-61 Bytes
Binary file not shown.

doc/pdfs/saw-user-manual.pdf

2.26 KB
Binary file not shown.

doc/saw-user-manual/specification-based-verification.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ Note that we are passing _references_ of arrays to `mir_slice_value` and
11381138
`mir_slice_range_value`. It would be an error to pass a bare array to these
11391139
functions, so the following specification would be invalid:
11401140

1141-
:::
1141+
:::{code-block} sawscript
11421142
let f_fail_spec_ = do {
11431143
let arr = mir_term {{ [1, 2, 3, 4, 5] : [5][32] }};
11441144

@@ -1264,6 +1264,29 @@ On the other hand, SAW will allow you define a slice of the form
12641264
the responsibility of the SAW user to ensure that `mir_str_slice_range` indices
12651265
align with character boundaries.
12661266

1267+
### MIR `Vec`s
1268+
1269+
[`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html) is a commonly used
1270+
data type in the Rust standard library. `Vec` values can be created from array
1271+
values in MIR specifications with the following command:
1272+
1273+
- `mir_vec_of : String -> MIRType -> MIRValue -> MIRSetup MIRValue`
1274+
1275+
The `String` argument is used as a prefix for naming the internal symbolic
1276+
variables created as part of the `Vec` struct (think of it just as a name you
1277+
give to the `Vec` variable). The `MIRType` argument is the element type of the
1278+
`Vec`. The `MIRValue` argument is the contents of the `Vec`, which must be a MIR
1279+
array value whose element type matches the `MIRType` argument. Note that this
1280+
could either be created with `mir_array_value` or obtained from a `Term` like a
1281+
fresh variable or a Cryptol sequence expression.
1282+
1283+
`Vec` is just a regular struct and not a special language construct, so
1284+
technically you could write specifications for `Vec`s just using the primitive
1285+
MIR specification commands (in fact, this is what `mir_vec_of` does internally).
1286+
However, you would need to explicitly specify all the internal details and
1287+
invariants of `Vec`, and that can get quite messy. Therefore, this command
1288+
exists for convenience reasons.
1289+
12671290
### Finding MIR algebraic data types
12681291

12691292
We collectively refer to MIR `struct`s and `enum`s together as _algebraic data

doc/scripts/epoch.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
# - the devel version can then be bumped to the current day if needed
2525
#
2626

27-
# BSD/Linux: date +%s -d "07/23/2025 00:00:00 GMT"
28-
# OSX: date -j -f "%m/%d/%Y %H:%M:%S %Z" "7/23/2025 00:00:00 GMT" +%s
29-
SOURCE_DATE_EPOCH=1753228800
27+
# BSD/Linux: date +%s -d "08/22/2025 00:00:00 GMT"
28+
# OSX: date -j -f "%m/%d/%Y %H:%M:%S %Z" "8/22/2025 00:00:00 GMT" +%s
29+
SOURCE_DATE_EPOCH=1755820800

intTests/test2032/test.linked-mir.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
versions
22
rustc 1.86.0-nightly (9cd60bd2c 2025-02-15)
3-
mir-json ae8c20d96b874ee977b5fba0f02059d6593943a8 from 2025-08-06
3+
mir-json mtime: Aug 21 23:14:39 2025
4+
mir-json version from cargo: mir-json v0.1.0
5+
probable mir-json commit: 753fe4b97b59035adc204aa426a3ae44b44822b9 from Mon Aug 18 12:31:05 2025 and/or Mon Aug 18 12:31:05 2025
6+
versions-notes
7+
Generated by update-from.sh version 1

0 commit comments

Comments
 (0)