Skip to content

Commit 370164c

Browse files
authored
Update feature/ptoken with master (#849)
- #811 - #847 - #846 - #840 - #839
2 parents 678423e + 596829b commit 370164c

25 files changed

+573
-211
lines changed

deps/k_release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.1.301
1+
7.1.304

deps/pyproject-build-systems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dbfc0483b5952c6b86e36f8b3afeb9dde30ea4b5
1+
795a980d25301e5133eca37adae37283ec3c8e66

deps/uv2nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b6ed0901aec29583532abe65117b18d86a49b617
1+
c8cf711802cb00b2e05d5c54d3486fce7bfc8f7c

deps/uv_release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.9.2
1+
0.9.9

flake.lock

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
inputs.flake-utils.follows = "flake-utils";
1313
};
1414

15-
k-framework.url = "github:runtimeverification/k/v7.1.301";
15+
k-framework.url = "github:runtimeverification/k/v7.1.304";
1616
k-framework = {
1717
inputs.flake-utils.follows = "flake-utils";
1818
inputs.nixpkgs.follows = "nixpkgs";
1919
};
2020

21-
uv2nix.url = "github:pyproject-nix/uv2nix/b6ed0901aec29583532abe65117b18d86a49b617";
21+
uv2nix.url = "github:pyproject-nix/uv2nix/c8cf711802cb00b2e05d5c54d3486fce7bfc8f7c";
2222
# uv2nix requires a newer version of nixpkgs
2323
# therefore, we pin uv2nix specifically to a newer version of nixpkgs
2424
# until we replaced our stale version of nixpkgs with an upstream one as well
@@ -27,7 +27,7 @@
2727
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
2828
uv2nix.inputs.nixpkgs.follows = "nixpkgs-unstable";
2929
# uv2nix.inputs.nixpkgs.follows = "nixpkgs";
30-
pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/dbfc0483b5952c6b86e36f8b3afeb9dde30ea4b5";
30+
pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/795a980d25301e5133eca37adae37283ec3c8e66";
3131
pyproject-build-systems = {
3232
inputs.nixpkgs.follows = "uv2nix/nixpkgs";
3333
inputs.uv2nix.follows = "uv2nix";

kmir/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version = "0.3.181"
88
description = ""
99
requires-python = ">=3.10"
1010
dependencies = [
11-
"kframework==v7.1.301",
11+
"kframework==v7.1.304",
1212
"rust-demangler==1.0",
1313
]
1414

kmir/src/kmir/kdist/mir-semantics/rt/data.md

Lines changed: 110 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,15 +1265,78 @@ the `Value` sort.
12651265
Conversion is especially possible for the case of _Slices_ (of dynamic length) and _Arrays_ (of static length),
12661266
which have the same representation `Value::Range`.
12671267

1268+
When the cast crosses transparent wrappers (newtypes that just forward field `0` e.g. `struct Wrapper<T>(T)`), the pointer's
1269+
`Place` must be realigned. `#alignTransparentPlace` rewrites the projection list until the source and target
1270+
expose the same inner value:
1271+
- if the source unwraps more than the target, append an explicit `field(0)` so the target still sees that field;
1272+
- if the target unwraps more, strip any redundant tail projections with `#popTransparentTailTo`, leaving the
1273+
canonical prefix shared by both sides.
1274+
12681275
```k
12691276
rule <k> #cast(PtrLocal(OFFSET, PLACE, MUT, META), castKindPtrToPtr, TY_SOURCE, TY_TARGET)
12701277
=>
1271-
PtrLocal(OFFSET, PLACE, MUT, #convertMetadata(META, lookupTy(TY_TARGET)))
1278+
PtrLocal(
1279+
OFFSET,
1280+
#alignTransparentPlace(
1281+
PLACE,
1282+
#lookupMaybeTy(pointeeTy(lookupTy(TY_SOURCE))),
1283+
#lookupMaybeTy(pointeeTy(lookupTy(TY_TARGET)))
1284+
),
1285+
MUT,
1286+
#convertMetadata(META, lookupTy(TY_TARGET))
1287+
)
12721288
...
12731289
</k>
12741290
requires #typesCompatible(lookupTy(TY_SOURCE), lookupTy(TY_TARGET))
12751291
[preserves-definedness] // valid map lookups checked
12761292
1293+
syntax Place ::= #alignTransparentPlace ( Place , TypeInfo , TypeInfo ) [function, total]
1294+
syntax ProjectionElems ::= #popTransparentTailTo ( ProjectionElems , TypeInfo ) [function, total]
1295+
1296+
rule #alignTransparentPlace(place(LOCAL, PROJS), typeInfoStructType(_, _, FIELD_TY .Tys, LAYOUT) #as SOURCE, TARGET)
1297+
=> #alignTransparentPlace(
1298+
place(
1299+
LOCAL,
1300+
appendP(PROJS, projectionElemField(fieldIdx(0), FIELD_TY) .ProjectionElems)
1301+
),
1302+
lookupTy(FIELD_TY),
1303+
TARGET
1304+
)
1305+
requires #transparentDepth(SOURCE) >Int #transparentDepth(TARGET)
1306+
andBool #zeroFieldOffset(LAYOUT)
1307+
1308+
rule #alignTransparentPlace(
1309+
place(LOCAL, PROJS),
1310+
SOURCE,
1311+
typeInfoStructType(_, _, FIELD_TY .Tys, LAYOUT) #as TARGET
1312+
)
1313+
=> #alignTransparentPlace(
1314+
place(LOCAL, #popTransparentTailTo(PROJS, lookupTy(FIELD_TY))),
1315+
SOURCE,
1316+
lookupTy(FIELD_TY)
1317+
)
1318+
requires #transparentDepth(SOURCE) <Int #transparentDepth(TARGET)
1319+
andBool #zeroFieldOffset(LAYOUT)
1320+
andBool PROJS =/=K #popTransparentTailTo(PROJS, lookupTy(FIELD_TY))
1321+
1322+
rule #alignTransparentPlace(PLACE, _, _) => PLACE [owise]
1323+
1324+
rule #popTransparentTailTo(
1325+
projectionElemField(fieldIdx(0), FIELD_TY) .ProjectionElems,
1326+
TARGET
1327+
)
1328+
=> .ProjectionElems
1329+
requires lookupTy(FIELD_TY) ==K TARGET
1330+
1331+
rule #popTransparentTailTo(
1332+
X:ProjectionElem REST:ProjectionElems,
1333+
TARGET
1334+
)
1335+
=> X #popTransparentTailTo(REST, TARGET)
1336+
requires REST =/=K .ProjectionElems
1337+
1338+
rule #popTransparentTailTo(PROJS, _) => PROJS [owise]
1339+
12771340
syntax Metadata ::= #convertMetadata ( Metadata , TypeInfo ) [function, total]
12781341
// -------------------------------------------------------------------------------------
12791342
```
@@ -1497,23 +1560,58 @@ Casting an integer to a `[u8; N]` array materialises its little-endian bytes.
14971560
rule #staticArrayLenBits(_OTHER) => 0 [owise]
14981561
```
14991562

1500-
Another specialisation is getting the discriminant of `enum`s without fields after converting some integer data to it
1501-
(see `#discriminant` and `rvalueDiscriminant`).
1502-
If none of the `enum` variants has any fields, the `Transmute` of a number to the `enum` data is necessarily just the discriminant itself., and can be returned as the integer value afgter adjusting to the byte length of the discriminant:
1563+
A transmutation from an integer to an enum is wellformed if:
1564+
- The bit width of the incoming integer is the same as the discriminant type of the enum
1565+
(e.g. `u8 -> i8` fine, `u8 -> u16` not fine) - this is guaranteed by the compiler;
1566+
- The incoming integer has a bit pattern that matches a discriminant of the enum
1567+
(e.g. `255_u8` and `-1_i8` fine iff `0b1111_1111` is a discriminant of the enum);
15031568

1504-
```k
1505-
rule <k> #discriminant(
1506-
thunk(#cast (Integer(DATA, _, false), castKindTransmute, _, TY)),
1507-
TY
1508-
) => Integer(DATA, 0, false) // HACK: bit width 0 means "flexible"
1509-
...
1510-
</k>
1511-
requires #isEnumWithoutFields(lookupTy(TY))
1569+
Note that discriminants are stored as `u128` in the type data even if they are signed
1570+
or unsigned at the source level. This means that our approach to soundly transmute an
1571+
integer into a enum is to treat the incoming integer as unsigned (converting if signed),
1572+
and check if the value is in the discriminants. If yes, find the corresponding variant
1573+
index; if not, return `#UBErrorInvalidDiscriminantsInEnumCast`.
15121574

1575+
```k
15131576
syntax Bool ::= #isEnumWithoutFields ( TypeInfo ) [function, total]
15141577
// ----------------------------------------------------------------
15151578
rule #isEnumWithoutFields(typeInfoEnumType(_, _, _, FIELDSS, _)) => #noFields(FIELDSS)
15161579
rule #isEnumWithoutFields(_OTHER) => false [owise]
1580+
1581+
// TODO: Connect this with MirError
1582+
syntax Evaulation ::= "#UBErrorInvalidDiscriminantsInEnumCast"
1583+
rule <k>
1584+
#cast( Integer ( VAL , WIDTH , _SIGNED ) , castKindTransmute , _TY_FROM , TY_TO ) ~> _REST
1585+
=>
1586+
#UBErrorInvalidDiscriminantsInEnumCast
1587+
</k>
1588+
requires #isEnumWithoutFields(lookupTy(TY_TO))
1589+
andBool notBool #validDiscriminant( truncate(VAL, WIDTH, Unsigned) , lookupTy(TY_TO) )
1590+
1591+
rule <k>
1592+
#cast( Integer ( VAL , WIDTH , _SIGNED ) , castKindTransmute , _TY_FROM , TY_TO )
1593+
=>
1594+
Aggregate( #findVariantIdxFromTy( truncate(VAL, WIDTH, Unsigned), lookupTy(TY_TO) ) , .List )
1595+
...
1596+
</k>
1597+
requires #isEnumWithoutFields(lookupTy(TY_TO))
1598+
andBool #validDiscriminant( truncate(VAL, WIDTH, Unsigned) , lookupTy(TY_TO))
1599+
1600+
syntax VariantIdx ::= #findVariantIdxFromTy ( Int , TypeInfo ) [function, total]
1601+
//------------------------------------------------------------------------------
1602+
rule #findVariantIdxFromTy( VAL , typeInfoEnumType(_, _, DISCRIMINANTS, _, _) ) => #findVariantIdx( VAL, DISCRIMINANTS)
1603+
rule #findVariantIdxFromTy( _ , _ ) => err("NotAnEnum") [owise]
1604+
1605+
syntax Bool ::= #validDiscriminant ( Int , TypeInfo ) [function, total]
1606+
// ----------------------------------------------------------------------------
1607+
rule #validDiscriminant( VAL , typeInfoEnumType(_, _, DISCRIMINANTS, _, _) ) => #validDiscriminantAux( VAL , DISCRIMINANTS )
1608+
rule #validDiscriminant( _ , _ ) => false [owise]
1609+
1610+
syntax Bool ::= #validDiscriminantAux ( Int , Discriminants ) [function, total]
1611+
// ----------------------------------------------------------------------------
1612+
rule #validDiscriminantAux( VAL, discriminant(mirInt(DISCRIMINANT)) REST ) => VAL ==Int DISCRIMINANT orBool #validDiscriminantAux( VAL, REST )
1613+
rule #validDiscriminantAux( VAL, discriminant( DISCRIMINANT ) REST ) => VAL ==Int DISCRIMINANT orBool #validDiscriminantAux( VAL, REST )
1614+
rule #validDiscriminantAux( _VAL, .Discriminants ) => false
15171615
```
15181616

15191617

kmir/src/kmir/kdist/mir-semantics/rt/decoding.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,6 @@ syntax Int ::= #msBytes ( MachineSize ) [function, total]
111111
rule #msBytes(machineSize(mirInt(NBITS))) => NBITS /Int 8 [preserves-definedness]
112112
rule #msBytes(machineSize(NBITS)) => NBITS /Int 8 [owise, preserves-definedness]
113113
114-
// Extract field offsets from the struct layout when available (Arbitrary only).
115-
syntax MachineSizes ::= #layoutOffsets ( MaybeLayoutShape ) [function, total]
116-
rule #layoutOffsets(someLayoutShape(layoutShape(fieldsShapeArbitrary(mk(OFFSETS)), _, _, _, _))) => OFFSETS
117-
rule #layoutOffsets(noLayoutShape) => .MachineSizes
118-
rule #layoutOffsets(_) => .MachineSizes [owise]
119-
120114
// Minimum number of input bytes required to decode all fields by the chosen offsets.
121115
// Uses builtin maxInt to compute max(offset + size). The lists of types and
122116
// offsets must have the same length; if not, this function returns -1 to signal

0 commit comments

Comments
 (0)