Skip to content

Commit 2097ccf

Browse files
committed
introduce a new sort to describe abs place
1 parent 571cf15 commit 2097ccf

File tree

1 file changed

+30
-38
lines changed

1 file changed

+30
-38
lines changed

kmir/src/kmir/kdist/mir-semantics/symbolic/spl-token.md

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ module KMIR-SPL-TOKEN
8989
## Helper syntax
9090

9191
```k
92-
syntax Value ::= SPLRefCell ( Value , Value ) // Reference to the buffer, value in the cell
92+
syntax AbsPlace ::= AbsPlace ( Int , Place )
93+
94+
syntax AbsPlace ::= #adjustAbsPlace ( AbsPlace , Int ) [function, total]
95+
rule #adjustAbsPlace(AbsPlace(DEPTH, PLACE), OFFSET) => AbsPlace(DEPTH +Int OFFSET, PLACE)
96+
97+
syntax Value ::= SPLRefCell ( AbsPlace , Value ) // Place of the buffer, value in the cell
9398
| SPLDataBuffer ( Value )
94-
| SPLDataBorrow ( Value , Value ) // Reference to the buffer, borrowed value
95-
| SPLDataBorrowMut ( Value , Value )
99+
| SPLDataBorrow ( AbsPlace , Value ) // Place of the buffer, borrowed value
100+
| SPLDataBorrowMut ( AbsPlace , Value )
96101
| SPLPubkeyRef ( Value )
97102
```
98103

@@ -175,9 +180,9 @@ module KMIR-SPL-TOKEN
175180
rule #isSPLRentGetFunc("solana_sysvar::rent::<impl Sysvar for solana_rent::Rent>::get") => true
176181
177182
// Adjust references when moving across stack frames
178-
rule #adjustRef(SPLRefCell(PLACE, VAL), OFFSET) => SPLRefCell(#adjustRef(PLACE, OFFSET), #adjustRef(VAL, OFFSET))
179-
rule #adjustRef(SPLDataBorrow(PLACE, VAL), OFFSET) => SPLDataBorrow(#adjustRef(PLACE, OFFSET), #adjustRef(VAL, OFFSET))
180-
rule #adjustRef(SPLDataBorrowMut(PLACE, VAL), OFFSET) => SPLDataBorrowMut(#adjustRef(PLACE, OFFSET), #adjustRef(VAL, OFFSET))
183+
rule #adjustRef(SPLRefCell(PLACE, VAL), OFFSET) => SPLRefCell(#adjustAbsPlace(PLACE, OFFSET), #adjustRef(VAL, OFFSET))
184+
rule #adjustRef(SPLDataBorrow(PLACE, VAL), OFFSET) => SPLDataBorrow(#adjustAbsPlace(PLACE, OFFSET), #adjustRef(VAL, OFFSET))
185+
rule #adjustRef(SPLDataBorrowMut(PLACE, VAL), OFFSET) => SPLDataBorrowMut(#adjustAbsPlace(PLACE, OFFSET), #adjustRef(VAL, OFFSET))
181186
rule #adjustRef(SPLDataBuffer(VAL), OFFSET) => SPLDataBuffer(#adjustRef(VAL, OFFSET))
182187
rule #adjustRef(SPLPubkeyRef(VAL), OFFSET) => SPLPubkeyRef(#adjustRef(VAL, OFFSET))
183188
```
@@ -297,28 +302,24 @@ module KMIR-SPL-TOKEN
297302
ListItem(SPLPubkeyRef(Aggregate(variantIdx(0), ListItem(Range(?SplAccountKey:List))))) // pub key: &'a Pubkey
298303
ListItem(
299304
SPLRefCell(
300-
Reference(
305+
AbsPlace(
301306
0,
302307
place(
303308
LOCAL,
304309
appendP(PROJS, projectionElemDeref projectionElemField(fieldIdx(1), #hack()) .ProjectionElems)
305-
),
306-
mutabilityNot,
307-
metadata(noMetadataSize, 0, noMetadataSize)
310+
)
308311
),
309312
Integer(?SplLamports:Int, 64, false)
310313
)
311314
) // lamports: Rc<RefCell<&'a mut u64>>
312315
ListItem( // data: Rc<RefCell<&'a mut [u8]>>
313316
SPLRefCell(
314-
Reference(
317+
AbsPlace(
315318
0,
316319
place(
317320
LOCAL,
318321
appendP(PROJS, projectionElemDeref projectionElemField(fieldIdx(2), #hack()) .ProjectionElems)
319-
),
320-
mutabilityNot,
321-
metadata(noMetadataSize, 0, noMetadataSize)
322+
)
322323
),
323324
SPLDataBuffer( // data: Rc<RefCell<&'a mut [u8]>>, Aggregate is for &account.data
324325
Aggregate(variantIdx(0),
@@ -371,28 +372,24 @@ module KMIR-SPL-TOKEN
371372
ListItem(SPLPubkeyRef(Aggregate(variantIdx(0), ListItem(Range(?SplMintAccountKey:List))))) // pub key: &'a Pubkey
372373
ListItem(
373374
SPLRefCell(
374-
Reference(
375+
AbsPlace(
375376
0,
376377
place(
377378
LOCAL,
378379
appendP(PROJS, projectionElemDeref projectionElemField(fieldIdx(1), #hack()) .ProjectionElems)
379-
),
380-
mutabilityNot,
381-
metadata(noMetadataSize, 0, noMetadataSize)
380+
)
382381
),
383382
Integer(?SplMintLamports:Int, 64, false)
384383
)
385384
)
386385
ListItem(
387386
SPLRefCell(
388-
Reference(
387+
AbsPlace(
389388
0,
390389
place(
391390
LOCAL,
392391
appendP(PROJS, projectionElemDeref projectionElemField(fieldIdx(2), #hack()) .ProjectionElems)
393-
),
394-
mutabilityNot,
395-
metadata(noMetadataSize, 0, noMetadataSize)
392+
)
396393
),
397394
SPLDataBuffer(
398395
Aggregate(variantIdx(0),
@@ -437,28 +434,24 @@ module KMIR-SPL-TOKEN
437434
ListItem(SPLPubkeyRef(Aggregate(variantIdx(0), ListItem(Range(?SplRentAccountKey:List))))) // pub key: &'a Pubkey
438435
ListItem(
439436
SPLRefCell(
440-
Reference(
437+
AbsPlace(
441438
0,
442439
place(
443440
LOCAL,
444441
appendP(PROJS, projectionElemDeref projectionElemField(fieldIdx(1), #hack()) .ProjectionElems)
445-
),
446-
mutabilityNot,
447-
metadata(noMetadataSize, 0, noMetadataSize)
442+
)
448443
),
449444
Integer(?SplRentLamports:Int, 64, false)
450445
)
451446
) // lamports: Rc<RefCell<&'a mut u64>>
452447
ListItem( // data: Rc<RefCell<&'a mut [u8]>>
453448
SPLRefCell(
454-
Reference(
449+
AbsPlace(
455450
0,
456451
place(
457452
LOCAL,
458453
appendP(PROJS, projectionElemDeref projectionElemField(fieldIdx(2), #hack()) .ProjectionElems)
459-
),
460-
mutabilityNot,
461-
metadata(noMetadataSize, 0, noMetadataSize)
454+
)
462455
),
463456
SPLDataBuffer(
464457
Aggregate(variantIdx(0),
@@ -507,7 +500,7 @@ expose the wrapped payload directly.
507500
syntax KItem ::= #finishSPLRcDeref ( Evaluation , Place , MaybeBasicBlockIdx ) [seqstrict(1)]
508501
| #resolveSPLRcRef ( Value , Place , MaybeBasicBlockIdx )
509502
| #finishResolvedSPLRc ( Place , MaybeBasicBlockIdx )
510-
| #writeThroughRef ( Value , Value )
503+
| #writeThroughAbsPlace ( AbsPlace , Value )
511504
512505
rule <k> #finishSPLRcDeref(Reference(OFFSET, PLACE, MUT, META), DEST, TARGET)
513506
=> #resolveSPLRcRef(Reference(OFFSET, PLACE, MUT, META), DEST, TARGET)
@@ -555,15 +548,15 @@ expose the wrapped payload directly.
555548
</k>
556549
557550
// Cross-frame write helper for SPL ref cells
558-
rule <k> #writeThroughRef(Reference(0, place(local(I), PROJS), _, _), VAL)
551+
rule <k> #writeThroughAbsPlace(AbsPlace(0, place(local(I), PROJS)), VAL)
559552
=> #forceSetPlaceValue(place(local(I), PROJS), VAL)
560553
...
561554
</k>
562555
<locals> LOCALS </locals>
563556
requires 0 <=Int I andBool I <Int size(LOCALS)
564557
andBool isTypedLocal(LOCALS[I])
565558
566-
rule <k> #writeThroughRef(Reference(OFFSET, place(local(I), PROJS), _, _), VAL)
559+
rule <k> #writeThroughAbsPlace(AbsPlace(OFFSET, place(local(I), PROJS)), VAL)
567560
=> #traverseProjection(
568561
toStack(OFFSET, local(I)),
569562
#localFromFrame({STACK[OFFSET -Int 1]}:>StackFrame, local(I), OFFSET),
@@ -608,7 +601,7 @@ expose the wrapped payload directly.
608601

609602
```k
610603
// Step 1
611-
syntax Context ::= CtxSPLRefCell ( Value )
604+
syntax Context ::= CtxSPLRefCell ( AbsPlace )
612605
rule <k> #traverseProjection(
613606
DEST,
614607
SPLRefCell(PLACE, VAL),
@@ -628,7 +621,7 @@ expose the wrapped payload directly.
628621
rule #projectionsFor(CtxSPLRefCell(_) CTXS, PROJS) => #projectionsFor(CTXS, projectionElemDeref PROJS)
629622
630623
// Step 2
631-
syntax Context ::= CtxSPLDataBorrow ( Value )
624+
syntax Context ::= CtxSPLDataBorrow ( AbsPlace )
632625
rule <k> #traverseProjection(
633626
DEST,
634627
SPLDataBorrow(PLACE, VAL),
@@ -647,7 +640,7 @@ expose the wrapped payload directly.
647640
rule #buildUpdate(VAL, CtxSPLDataBorrow(PLACE) CTXS) => #buildUpdate(SPLDataBorrow(PLACE, SPLDataBuffer(VAL)), CTXS)
648641
rule #projectionsFor(CtxSPLDataBorrow(_) CTXS, PROJS) => #projectionsFor(CTXS, projectionElemDeref PROJS)
649642
650-
syntax Context ::= CtxSPLDataBorrowMut ( Value )
643+
syntax Context ::= CtxSPLDataBorrowMut ( AbsPlace )
651644
rule <k> #traverseProjection(
652645
DEST,
653646
SPLDataBorrowMut(PLACE, VAL),
@@ -830,14 +823,13 @@ expose the wrapped payload directly.
830823
syntax KItem ::= #mkSPLAccountPack ( Evaluation , Evaluation , Place ) [seqstrict(1,2)]
831824
832825
rule <k> #mkSPLAccountPack(ACCOUNT, SPLDataBorrowMut(PLACE, SPLDataBuffer(_)), DEST)
833-
=> #writeThroughRef(
826+
=> #writeThroughAbsPlace(
834827
PLACE,
835828
SPLRefCell(PLACE, SPLDataBuffer(ACCOUNT))
836829
)
837830
~> #setLocalValue(DEST, Aggregate(variantIdx(0), ListItem(Aggregate(variantIdx(0), .List))))
838831
...
839832
</k>
840-
requires isRef(PLACE)
841833
```
842834

843835
```{.k .symbolic}

0 commit comments

Comments
 (0)