77
88from pyk .kast .inner import KApply , KSequence , KSort , KVariable , Subst , build_cons
99from pyk .kast .manip import free_vars , split_config_from
10- from pyk .kast .prelude .collections import list_empty , list_of
10+ from pyk .kast .prelude .collections import list_empty , list_of , map_of
1111from pyk .kast .prelude .kint import eqInt , intToken , leInt
1212from pyk .kast .prelude .ml import mlEqualsTrue
1313from pyk .kast .prelude .utils import token
1919 BoolValue ,
2020 DynamicSize ,
2121 IntValue ,
22- Local ,
2322 Metadata ,
24- Place ,
2523 PtrLocalValue ,
2624 RangeValue ,
2725 RefValue ,
26+ SlotPlace ,
2827 StaticSize ,
2928)
3029
@@ -192,12 +191,16 @@ def init_subst() -> dict[str, KInner]:
192191 k_cell ,
193192 )
194193
194+ slot_ids = [token (i ) for i in range (len (localvars ))]
195195 subst = Subst (
196196 {
197197 ** init_subst (),
198198 ** {
199199 'K_CELL' : k_cell ,
200- 'LOCALS_CELL' : list_of (localvars ),
200+ 'OWNEDSLOTS_CELL' : list_of (slot_ids ),
201+ 'SLOTSTORE_CELL' : map_of (zip (slot_ids , localvars , strict = True )),
202+ 'NEXTSLOT_CELL' : token (len (slot_ids )),
203+ 'GENERATEDCOUNTER_CELL' : token (len (slot_ids )),
201204 },
202205 }
203206 )
@@ -215,11 +218,15 @@ def _make_symbolic_call_config(
215218 types : Mapping [Ty , TypeMetadata ],
216219) -> tuple [KInner , list [KInner ]]:
217220 locals , constraints = _symbolic_locals (fn_data .args , types )
221+ slot_ids = [token (i ) for i in range (len (locals ))]
218222 subst = Subst (
219223 {
220224 'K_CELL' : fn_data .call_terminator ,
221225 'STACK_CELL' : list_empty (), # FIXME see #560, problems matching a symbolic stack
222- 'LOCALS_CELL' : list_of (locals ),
226+ 'OWNEDSLOTS_CELL' : list_of (slot_ids ),
227+ 'SLOTSTORE_CELL' : map_of (zip (slot_ids , locals , strict = True )),
228+ 'NEXTSLOT_CELL' : token (len (slot_ids )),
229+ 'GENERATEDCOUNTER_CELL' : token (len (slot_ids )),
223230 },
224231 )
225232 empty_config = definition .empty_config (KSort ('GeneratedTopCell' ))
@@ -373,7 +380,11 @@ def _symbolic_value(self, ty: Ty, mutable: bool) -> tuple[KInner, Iterable[KInne
373380 mlEqualsTrue (leInt (variant_var , token (max_variant ))),
374381 ]
375382 args = self ._fresh_var ('ENUM_ARGS' )
376- return KApply ('Value::Aggregate' , (KApply ('variantIdx' , (variant_var ,)), args )), idx_range , None
383+ return (
384+ KApply ('Value::Aggregate' , (KApply ('variantIdx' , (variant_var ,)), args )),
385+ idx_range + [mlEqualsTrue (KApply ('allValues' , (args ,)))],
386+ None ,
387+ )
377388
378389 case StructT (_, _, fields ):
379390 field_vars : list [KInner ] = []
@@ -390,14 +401,18 @@ def _symbolic_value(self, ty: Ty, mutable: bool) -> tuple[KInner, Iterable[KInne
390401
391402 case UnionT ():
392403 args = self ._fresh_var ('ARG_UNION' )
393- return KApply ('Value::Aggregate' , (KApply ('variantIdx' , (token (0 ),)), args )), [], None
404+ return (
405+ KApply ('Value::Aggregate' , (KApply ('variantIdx' , (token (0 ),)), args )),
406+ [mlEqualsTrue (KApply ('allValues' , (args ,)))],
407+ None ,
408+ )
394409
395410 case ArrayT (_, None ):
396411 elems = self ._fresh_var ('ARG_ARRAY' )
397412 l = self ._fresh_var ('ARG_ARRAY_LEN' )
398413 return (
399414 KApply ('Value::Range' , (elems ,)),
400- [mlEqualsTrue (eqInt (KApply ('sizeList' , (elems ,)), l ))],
415+ [mlEqualsTrue (eqInt (KApply ('sizeList' , (elems ,)), l )), mlEqualsTrue ( KApply ( 'allValues' , ( elems ,))) ],
401416 KApply (
402417 'Metadata' ,
403418 (
@@ -450,8 +465,7 @@ def _symbolic_value(self, ty: Ty, mutable: bool) -> tuple[KInner, Iterable[KInne
450465 KApply (
451466 'Value::Reference' ,
452467 (
453- token (0 ), # Stack OFFSET field
454- KApply ('place' , (KApply ('local' , (token (ref ),)), KApply ('ProjectionElems::empty' , ()))),
468+ KApply ('SlotPlace' , (token (ref ), KApply ('ProjectionElems::empty' , ()))),
455469 KApply ('Mutability::Mut' , ()) if mutable else KApply ('Mutability::Not' , ()),
456470 metadata if metadata is not None else no_metadata ,
457471 ),
@@ -468,8 +482,7 @@ def _symbolic_value(self, ty: Ty, mutable: bool) -> tuple[KInner, Iterable[KInne
468482 KApply (
469483 'Value::PtrLocal' ,
470484 (
471- token (0 ),
472- KApply ('place' , (KApply ('local' , (token (ref ),)), KApply ('ProjectionElems::empty' , ()))),
485+ KApply ('SlotPlace' , (token (ref ), KApply ('ProjectionElems::empty' , ()))),
473486 KApply ('Mutability::Mut' , ()) if mutable else KApply ('Mutability::Not' , ()),
474487 metadata if metadata is not None else no_metadata ,
475488 ),
@@ -652,15 +665,13 @@ def _random_ptr_value(self, mut: bool, type_info: PtrT | RefT) -> PtrLocalValue
652665 match type_info :
653666 case PtrT ():
654667 return PtrLocalValue (
655- stack_depth = 0 ,
656- place = Place (local = Local (ref )),
668+ place = SlotPlace (slot = ref ),
657669 mut = mut ,
658670 metadata = metadata ,
659671 )
660672 case RefT ():
661673 return RefValue (
662- stack_depth = 0 ,
663- place = Place (local = Local (ref )),
674+ place = SlotPlace (slot = ref ),
664675 mut = mut ,
665676 metadata = metadata ,
666677 )
0 commit comments