@@ -2113,7 +2113,7 @@ implemented include the following:
2113
2113
2114
2114
* MIR specifications that use overrides (i.e., the ` [MIRSpec] ` argument to
2115
2115
` mir_verify ` must always be the empty list at present)
2116
- * The ability to construct MIR ` struct ` or ` enum ` values in specifications
2116
+ * The ability to construct MIR ` enum ` values in specifications
2117
2117
* The ability to specify the layout of slice values
2118
2118
2119
2119
The ` String ` supplied as an argument to ` mir_verify ` is expected to be a
@@ -2229,6 +2229,7 @@ Java types are built up using the following functions:
2229
2229
2230
2230
MIR types are built up using the following functions:
2231
2231
2232
+ * ` mir_adt : MIRAdt -> MIRType `
2232
2233
* ` mir_array : Int -> MIRType -> MIRType `
2233
2234
* ` mir_bool : MIRType `
2234
2235
* ` mir_char : MIRType `
@@ -2627,9 +2628,81 @@ construct compound values:
2627
2628
* ` mir_array_value : MIRType -> [MIRValue] -> MIRValue ` constructs an array
2628
2629
of the given type whose elements consist of the given values. Supplying the
2629
2630
element type is necessary to support length-0 arrays.
2631
+ * ` mir_struct_value : MIRAdt -> [MIRValue] -> MIRValue ` construct a struct
2632
+ with the given list of values as elements. The ` MIRAdt ` argument determines
2633
+ what struct type to create.
2634
+
2635
+ See the "Finding MIR alegraic data types" section for more information on how
2636
+ to compute a ` MIRAdt ` value to pass to ` mir_struct_value ` .
2630
2637
* ` mir_tuple_value : [MIRValue] -> MIRValue ` construct a tuple with the given
2631
2638
list of values as elements.
2632
2639
2640
+ ### Finding MIR alegraic data types
2641
+
2642
+ We collectively refer to MIR ` struct ` s and ` enum ` s together as _ algebraic data
2643
+ types_ , or ADTs for short. ADTs have identifiers to tell them apart, and a
2644
+ single ADT declaration can give rise to multiple identifiers depending on how
2645
+ the declaration is used. For example:
2646
+
2647
+ ~~~~ .rs
2648
+ pub struct S <A , B > {
2649
+ pub x : A ,
2650
+ pub y : B ,
2651
+ }
2652
+
2653
+ pub fn f () -> S <u8 , u16 > {
2654
+ S {
2655
+ x : 1 ,
2656
+ y : 2 ,
2657
+ }
2658
+ }
2659
+
2660
+ pub fn g () -> S <u32 , u64 > {
2661
+ S {
2662
+ x : 3 ,
2663
+ y : 4 ,
2664
+ }
2665
+ }
2666
+ ~~~~
2667
+
2668
+ This program as a single ` struct ` declaration ` S ` , which is used in the
2669
+ functions ` f ` and ` g ` . Note that ` S ` 's declaration is _ polymorphic_ , as it uses
2670
+ type parameters, but the uses of ` S ` in ` f ` and ` g ` are _ monomorphic_ , as ` S ` 's
2671
+ type parameters are fully instantiated. Each unique, monomorphic instantiation
2672
+ of an ADT gives rise to its own identifier. In the example above, this might
2673
+ mean that the following identifiers are created when this code is compiled with
2674
+ ` mir-json ` :
2675
+
2676
+ * ` S<u8, u16> ` gives rise to ` example/abcd123::S::_adt456 `
2677
+ * ` S<u32, u64> ` gives rise to ` example/abcd123::S::_adt789 `
2678
+
2679
+ The suffix ` _adt<number> ` is autogenerated by ` mir-json ` and is typically
2680
+ difficult for humans to guess. For this reason, we offer a command to look up
2681
+ an ADT more easily:
2682
+
2683
+ * ` mir_find_adt : MIRModule -> String -> [MIRType] -> MIRAdt ` consults the
2684
+ given ` MIRModule ` to find an algebraic data type (` MIRAdt ` ). It uses the given
2685
+ ` String ` as an identifier and the given MIRTypes as the types to instantiate
2686
+ the type parameters of the ADT. If such a ` MIRAdt ` cannot be found in the
2687
+ ` MIRModule ` , this will raise an error.
2688
+
2689
+ Note that the ` String ` argument to ` mir_find_adt ` does not need to include the
2690
+ ` _adt<num> ` suffix, as ` mir_find_adt ` will discover this for you. The ` String `
2691
+ is expected to adhere to the identifier conventions described in the "Running a
2692
+ MIR-based verification" section. For instance, the following two lines will
2693
+ look up ` S<u8, u16> ` and ` S<u32, u64> ` from the example above as ` MIRAdt ` s:
2694
+
2695
+ ~~~~
2696
+ m <- mir_load_module "example.linked-mir.json";
2697
+
2698
+ s_8_16 <- mir_find_adt m "example::S" [mir_u8, mir_u16];
2699
+ s_32_64 <- mir_find_adt m "example::S" [mir_u32, mir_u64];
2700
+ ~~~~
2701
+
2702
+ The ` mir_adt ` command (for constructing a struct type) and ` mir_struct_value `
2703
+ (for constructing a struct value) commands in turn take a ` MIRAdt ` as an
2704
+ argument.
2705
+
2633
2706
### Bitfields
2634
2707
2635
2708
SAW has experimental support for specifying ` struct ` s with bitfields, such as
0 commit comments