Skip to content
Closed
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
40 changes: 20 additions & 20 deletions kmir/src/kmir/kdist/mir-semantics/rt/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ This eliminates any `Deref` projections from the place, and also resolves `Index

rule <k> rvalueRef(_REGION, KIND, place(local(I), PROJS))
=> #traverseProjection(toLocal(I), getValue(LOCALS, I), PROJS, .Contexts)
~> #forRef(#mutabilityOf(KIND), metadata(#metadataSize(tyOfLocal({LOCALS[I]}:>TypedLocal), PROJS), 0, noMetadataSize)) // TODO: Sus on this rule
~> #forRef(#mutabilityOf(KIND), metadata(#metadataSize(tyOfLocal({LOCALS[I]}:>TypedLocal), PROJS), 0, noMetadataSize)) // TODO: only 1st size component is used
...
</k>
<locals> LOCALS </locals>
Expand All @@ -1260,8 +1260,8 @@ This eliminates any `Deref` projections from the place, and also resolves `Index
syntax KItem ::= #forRef( Mutability , Metadata )

// once traversal is finished, reconstruct the last projections and the reference offset/local, and possibly read the size
rule <k> #traverseProjection(DEST, VAL:Value, .ProjectionElems, CTXTS) ~> #forRef(MUT, metadata(SIZE, OFFSET, ORIGIN_SIZE))
=> #mkRef(DEST, #projectionsFor(CTXTS), MUT, metadata(#maybeDynamicSize(SIZE, VAL), OFFSET, ORIGIN_SIZE) )
rule <k> #traverseProjection(DEST, VAL:Value, .ProjectionElems, CTXTS) ~> #forRef(MUT, metadata(SIZE, OFFSET, _))
=> #mkRef(DEST, #projectionsFor(CTXTS), MUT, metadata(#maybeDynamicSize(SIZE, VAL), OFFSET, #maybeDynamicSize(SIZE, VAL)))
...
</k>

Expand Down Expand Up @@ -1308,7 +1308,7 @@ The operation typically creates a pointer with empty metadata.
rule <k> rvalueAddressOf(MUT, place(local(I), PROJS))
=>
#traverseProjection(toLocal(I), getValue(LOCALS, I), PROJS, .Contexts)
~> #forPtr(MUT, metadata(#metadataSize(tyOfLocal({LOCALS[I]}:>TypedLocal), PROJS), 0, noMetadataSize)) // TODO These initial values might get overwrote
~> #forPtr(MUT, metadata(#metadataSize(tyOfLocal({LOCALS[I]}:>TypedLocal), PROJS), 0, noMetadataSize)) // TODO only 1st component is used
// we should use #alignOf to emulate the address
...
</k>
Expand All @@ -1318,8 +1318,8 @@ The operation typically creates a pointer with empty metadata.
[preserves-definedness] // valid list indexing checked, #metadataSize should only use static information

// once traversal is finished, reconstruct the last projections and the reference offset/local, and possibly read the size
rule <k> #traverseProjection(DEST, VAL:Value, .ProjectionElems, CTXTS) ~> #forPtr(MUT, metadata(SIZE, OFFSET, ORIGIN_SIZE))
=> #mkPtr(DEST, #projectionsFor(CTXTS), MUT, metadata(#maybeDynamicSize(SIZE, VAL), OFFSET, ORIGIN_SIZE))
rule <k> #traverseProjection(DEST, VAL:Value, .ProjectionElems, CTXTS) ~> #forPtr(MUT, metadata(SIZE, OFFSET, _ORIGIN_SIZE))
=> #mkPtr(DEST, #projectionsFor(CTXTS), MUT, metadata(#maybeDynamicSize(SIZE, VAL), OFFSET, #maybeDynamicSize(SIZE, VAL)))
...
</k>

Expand Down Expand Up @@ -1453,11 +1453,11 @@ The pointer's metadata needs to be adapted to the new type.
syntax Metadata ::= #convertMetadata ( Metadata , TypeInfo ) [function, total]
```

Pointers to slices can be converted to pointers to single elements, _losing_ their metadata.
Pointers to slices can be converted to pointers to single elements, _losing_ their metadata (original size is remembered).
```k
rule #convertMetadata( metadata(SIZE, OFFSET, _) , typeInfoRefType(POINTEE_TY) ) => metadata(noMetadataSize, OFFSET, SIZE)
rule #convertMetadata( metadata(_, OFFSET, SIZE) , typeInfoRefType(POINTEE_TY) ) => metadata(noMetadataSize, OFFSET, SIZE)
requires #metadataSize(POINTEE_TY) ==K noMetadataSize [priority(60)]
rule #convertMetadata( metadata(SIZE, OFFSET, _) , typeInfoPtrType(POINTEE_TY) ) => metadata(noMetadataSize, OFFSET, SIZE)
rule #convertMetadata( metadata(_, OFFSET, SIZE) , typeInfoPtrType(POINTEE_TY) ) => metadata(noMetadataSize, OFFSET, SIZE)
requires #metadataSize(POINTEE_TY) ==K noMetadataSize [priority(60)]
```

Expand All @@ -1468,16 +1468,16 @@ the original allocation size must be checked to be sufficient.

```k
// no metadata to begin with, fill it in from target type (NB dynamicSize(1) if dynamic)
rule #convertMetadata( metadata(noMetadataSize, OFFSET, _) , typeInfoRefType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, noMetadataSize)
rule #convertMetadata( metadata(noMetadataSize, OFFSET, _) , typeInfoPtrType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, noMetadataSize)
rule #convertMetadata( metadata(noMetadataSize, OFFSET, ORIG) , typeInfoRefType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIG)
rule #convertMetadata( metadata(noMetadataSize, OFFSET, ORIG) , typeInfoPtrType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIG)
```

Conversion from an array to a slice pointer requires adding metadata (`dynamicSize`) with the previously-static length.
```k
// convert static length to dynamic length
rule #convertMetadata(metadata(staticSize(SIZE), OFFSET, _), typeInfoRefType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, staticSize(SIZE))
rule #convertMetadata(metadata(staticSize(SIZE), OFFSET, ORIG), typeInfoRefType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, ORIG)
requires #metadataSize(POINTEE_TY) ==K dynamicSize(1)
rule #convertMetadata(metadata(staticSize(SIZE), OFFSET, _), typeInfoPtrType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, staticSize(SIZE))
rule #convertMetadata(metadata(staticSize(SIZE), OFFSET, ORIG), typeInfoPtrType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, ORIG)
requires #metadataSize(POINTEE_TY) ==K dynamicSize(1)
```

Expand All @@ -1487,29 +1487,29 @@ It may however be illegal to _dereference_ (i.e., access) the created pointer, d
**TODO** we can mark cases of insufficient original length as "InvalidCast" in the future, similar to the above future work.

```k
rule #convertMetadata(metadata(staticSize(_) #as ORIGIN_SIZE, OFFSET, _), typeInfoRefType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
rule #convertMetadata(metadata(staticSize(_), OFFSET, ORIGIN_SIZE), typeInfoRefType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
requires #metadataSize(POINTEE_TY) =/=K dynamicSize(1)
rule #convertMetadata(metadata(staticSize(_) #as ORIGIN_SIZE, OFFSET, _), typeInfoPtrType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
rule #convertMetadata(metadata(staticSize(_), OFFSET, ORIGIN_SIZE), typeInfoPtrType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
requires #metadataSize(POINTEE_TY) =/=K dynamicSize(1)

rule #convertMetadata(metadata(dynamicSize(_) #as ORIGIN_SIZE, OFFSET, _), typeInfoRefType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
rule #convertMetadata(metadata(dynamicSize(_), OFFSET, ORIGIN_SIZE), typeInfoRefType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
requires #metadataSize(POINTEE_TY) =/=K dynamicSize(1)
rule #convertMetadata(metadata(dynamicSize(_) #as ORIGIN_SIZE, OFFSET, _), typeInfoPtrType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
rule #convertMetadata(metadata(dynamicSize(_), OFFSET, ORIGIN_SIZE), typeInfoPtrType(POINTEE_TY)) => metadata(#metadataSize(POINTEE_TY), OFFSET, ORIGIN_SIZE)
requires #metadataSize(POINTEE_TY) =/=K dynamicSize(1)
```

For a cast bwetween two pointer types with `dynamicSize` metadata (unlikely to occur), the dynamic size value is retained.

```k
rule #convertMetadata(metadata(dynamicSize(SIZE), OFFSET, _), typeInfoRefType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, dynamicSize(SIZE))
rule #convertMetadata(metadata(dynamicSize(SIZE), OFFSET, ORIG), typeInfoRefType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, ORIG)
requires #metadataSize(POINTEE_TY) ==K dynamicSize(1)
rule #convertMetadata(metadata(dynamicSize(SIZE), OFFSET, _), typeInfoPtrType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, dynamicSize(SIZE))
rule #convertMetadata(metadata(dynamicSize(SIZE), OFFSET, ORIG), typeInfoPtrType(POINTEE_TY)) => metadata(dynamicSize(SIZE), OFFSET, ORIG)
requires #metadataSize(POINTEE_TY) ==K dynamicSize(1)
```

```k
// non-pointer and non-ref target type (should not happen!)
rule #convertMetadata( metadata(SIZE, OFFSET, _) , _OTHER_INFO ) => metadata(noMetadataSize, OFFSET, SIZE) [priority(100)]
rule #convertMetadata( metadata(_, OFFSET, ORIG) , _OTHER_INFO ) => metadata(noMetadataSize, OFFSET, ORIG) [priority(100)]
```

`PointerCoercion` may achieve a simmilar effect, or deal with function and closure pointers, depending on the coercion type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
ListItem ( AllocRef ( allocId ( 10 ) , .ProjectionElems , metadata ( noMetadataSize , 0 , noMetadataSize ) ) ) ) , ty ( 118 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 25 ) , mutabilityMut ) )
ListItem ( typedValue ( Aggregate ( variantIdx ( 0 ) , .List ) , ty ( 119 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 28 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , noMetadataSize ) ) , ty ( 33 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 28 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , staticSize ( 3 ) ) ) , ty ( 33 ) , mutabilityNot ) )
ListItem ( typedValue ( Moved , ty ( 25 ) , mutabilityMut ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 31 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 25 ) , mutabilityNot ) )
ListItem ( typedValue ( AllocRef ( allocId ( 10 ) , .ProjectionElems , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 25 ) , mutabilityNot ) )
Expand All @@ -96,10 +96,10 @@
ListItem ( typedValue ( Aggregate ( variantIdx ( 0 ) , ListItem ( Reference ( 0 , place (... local: local ( 43 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) )
ListItem ( Reference ( 0 , place (... local: local ( 46 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) ) ) , ty ( 118 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 25 ) , mutabilityMut ) )
ListItem ( typedValue ( Aggregate ( variantIdx ( 1 ) , ListItem ( Reference ( 0 , place (... local: local ( 40 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , noMetadataSize ) ) ) ) , ty ( 119 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 40 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , noMetadataSize ) ) , ty ( 33 ) , mutabilityNot ) )
ListItem ( typedValue ( Aggregate ( variantIdx ( 1 ) , ListItem ( Reference ( 0 , place (... local: local ( 40 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , staticSize ( 3 ) ) ) ) ) , ty ( 119 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 40 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , staticSize ( 3 ) ) ) , ty ( 33 ) , mutabilityNot ) )
ListItem ( typedValue ( Moved , ty ( 25 ) , mutabilityMut ) )
ListItem ( typedValue ( Aggregate ( variantIdx ( 1 ) , ListItem ( Reference ( 0 , place (... local: local ( 40 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , noMetadataSize ) ) ) ) , ty ( 119 ) , mutabilityNot ) )
ListItem ( typedValue ( Aggregate ( variantIdx ( 1 ) , ListItem ( Reference ( 0 , place (... local: local ( 40 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 3 ) , 0 , staticSize ( 3 ) ) ) ) ) , ty ( 119 ) , mutabilityNot ) )
ListItem ( typedValue ( Moved , ty ( 33 ) , mutabilityMut ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 43 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 25 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 46 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 25 ) , mutabilityNot ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
ListItem ( Integer ( 30 , 8 , false ) )
ListItem ( Integer ( 31 , 8 , false ) ) ) ) ) , ty ( 30 ) , mutabilityNot ) )
ListItem ( typedValue ( Integer ( 32 , 64 , false ) , ty ( 26 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 31 ) ) .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 32 ) , 0 , noMetadataSize ) ) , ty ( 27 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 31 ) ) .ProjectionElems ) , mutabilityNot , metadata ( staticSize ( 32 ) , 0 , staticSize ( 32 ) ) ) , ty ( 27 ) , mutabilityNot ) )
ListItem ( typedValue ( Integer ( 32 , 64 , false ) , ty ( 26 ) , mutabilityNot ) )
</locals>
</currentFrame>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
ListItem ( typedValue ( Range ( ListItem ( Integer ( 11 , 32 , true ) )
ListItem ( Integer ( 22 , 32 , true ) )
ListItem ( Integer ( 33 , 32 , true ) ) ) , ty ( 53 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , noMetadataSize ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , noMetadataSize ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , dynamicSize ( 2 ) ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , dynamicSize ( 2 ) ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Moved , ty ( 39 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 11 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 4 ) , mutabilityMut ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
ListItem ( Integer ( 22 , 16 , false ) )
ListItem ( Integer ( 33 , 16 , false ) ) ) ) ) , ty ( 55 ) , mutabilityNot ) )
ListItem ( typedValue ( Moved , ty ( 52 ) , mutabilityMut ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 52 ) ) PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , noMetadataSize ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 52 ) ) PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , noMetadataSize ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 52 ) ) PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , dynamicSize ( 2 ) ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 52 ) ) PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityNot , metadata ( dynamicSize ( 2 ) , 0 , dynamicSize ( 2 ) ) ) , ty ( 10 ) , mutabilityNot ) )
ListItem ( typedValue ( Moved , ty ( 39 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 11 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 4 ) , mutabilityMut ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
ListItem ( Integer ( 44 , 16 , false ) )
ListItem ( Integer ( 33 , 16 , false ) ) ) ) ) , ty ( 50 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 47 ) , mutabilityMut ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 47 ) ) PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityMut , metadata ( dynamicSize ( 2 ) , 0 , noMetadataSize ) ) , ty ( 11 ) , mutabilityMut ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 47 ) ) PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityMut , metadata ( dynamicSize ( 2 ) , 0 , dynamicSize ( 2 ) ) ) , ty ( 11 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 40 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 12 ) , mutabilityMut ) )
ListItem ( typedValue ( Integer ( 0 , 64 , false ) , ty ( 3 ) , mutabilityNot ) )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
ListItem ( typedValue ( Range ( ListItem ( Integer ( 11 , 32 , true ) )
ListItem ( Integer ( 44 , 32 , true ) )
ListItem ( Integer ( 33 , 32 , true ) ) ) , ty ( 48 ) , mutabilityMut ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityMut , metadata ( dynamicSize ( 2 ) , 0 , noMetadataSize ) ) , ty ( 11 ) , mutabilityMut ) )
ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: PointerOffset ( 1 , 3 ) .ProjectionElems ) , mutabilityMut , metadata ( dynamicSize ( 2 ) , 0 , dynamicSize ( 2 ) ) ) , ty ( 11 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 40 ) , mutabilityMut ) )
ListItem ( typedValue ( Moved , ty ( 12 ) , mutabilityMut ) )
ListItem ( typedValue ( Integer ( 0 , 64 , false ) , ty ( 3 ) , mutabilityNot ) )
Expand Down
Loading