Skip to content
Merged
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
4 changes: 3 additions & 1 deletion kmir/src/kmir/decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,12 @@ def _extract_tag(*, data: bytes, tag_offset: MachineSize, tag: Scalar) -> tuple[
case Initialized(
value=PrimitiveInt(
length=length,
signed=False,
signed=_,
),
valid_range=_,
):
# Stable MIR enum discriminants are represented against the raw tag bits.
# Use unsigned decoding even when the scalar metadata marks the tag as signed.
tag_data = data[tag_offset.in_bytes : tag_offset.in_bytes + length.value]
tag_value = int.from_bytes(tag_data, byteorder='little', signed=False)
return tag_value, length
Expand Down
14 changes: 11 additions & 3 deletions kmir/src/kmir/kdist/mir-semantics/kmir.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,10 @@ Therefore a heuristics is used here:
andBool isTypedValue(LOCALS[TUPLE])
andBool isTupleType(lookupTy(tyOfLocal({LOCALS[TUPLE]}:>TypedLocal)))
andBool isTypedLocal(LOCALS[CLOSURE])
andBool typeInfoVoidType ==K lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal))
// either the closure ref type is missing from type table
andBool (
typeInfoVoidType ==K lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal))
orBool isFunType(lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal)))
)
[priority(40), preserves-definedness]

rule [setupCalleeClosure2]: <k> #setUpCalleeData(
Expand Down Expand Up @@ -581,16 +583,22 @@ Therefore a heuristics is used here:
// or the closure ref type pointee is missing from the type table
andBool isRefType(lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal)))
andBool isTy(pointeeTy(lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal))))
andBool lookupTy({pointeeTy(lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal)))}:>Ty) ==K typeInfoVoidType
andBool (
lookupTy({pointeeTy(lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal)))}:>Ty) ==K typeInfoVoidType
orBool isFunType(lookupTy({pointeeTy(lookupTy(tyOfLocal({LOCALS[CLOSURE]}:>TypedLocal)))}:>Ty))
)
[priority(45), preserves-definedness]

syntax Bool ::= isTupleType ( TypeInfo ) [function, total]
| isRefType ( TypeInfo ) [function, total]
| isFunType ( TypeInfo ) [function, total]
// -------------------------------------------------------
rule isTupleType(typeInfoTupleType(_, _)) => true
rule isTupleType( _ ) => false [owise]
rule isRefType(typeInfoRefType(_)) => true
rule isRefType( _ ) => false [owise]
rule isFunType(typeInfoFunType(_)) => true
rule isFunType( _ ) => false [owise]

syntax KItem ::= #setTupleArgs ( Int , Value )
| #setTupleArgs ( Int , List )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
┌─ 1 (root, init)
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
│ (740 steps)
│ (737 steps)
├─ 3 (terminal)
│ #EndProgram ~> .K
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Aggregate ( variantIdx ( 1 ) , .List )
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"bytes": [
0
],
"types": [],
"typeInfo": {
"EnumType": {
"name": "OrderingLike",
"adt_def": 72,
"discriminants": [
255,
0,
1
],
"fields": [
[],
[],
[]
],
"layout": {
"fields": {
"Arbitrary": {
"offsets": [
{
"num_bits": 0
}
]
}
},
"variants": {
"Multiple": {
"tag": {
"Initialized": {
"value": {
"Int": {
"length": "I8",
"signed": true
}
},
"valid_range": {
"start": 255,
"end": 1
}
}
},
"tag_encoding": "Direct",
"tag_field": 0,
"variants": [
{
"fields": {
"Arbitrary": {
"offsets": []
}
},
"variants": {
"Single": {
"index": 0
}
},
"abi": {
"Aggregate": {
"sized": true
}
},
"abi_align": 1,
"size": {
"num_bits": 8
}
},
{
"fields": {
"Arbitrary": {
"offsets": []
}
},
"variants": {
"Single": {
"index": 1
}
},
"abi": {
"Aggregate": {
"sized": true
}
},
"abi_align": 1,
"size": {
"num_bits": 8
}
},
{
"fields": {
"Arbitrary": {
"offsets": []
}
},
"variants": {
"Single": {
"index": 2
}
},
"abi": {
"Aggregate": {
"sized": true
}
},
"abi_align": 1,
"size": {
"num_bits": 8
}
}
]
}
},
"abi": {
"Scalar": {
"Initialized": {
"value": {
"Int": {
"length": "I8",
"signed": true
}
},
"valid_range": {
"start": 255,
"end": 1
}
}
}
},
"abi_align": 1,
"size": {
"num_bits": 8
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn apply<F: FnOnce(u8, u8) -> u8>(f: F, a: u8, b: u8) -> u8 {
f(a, b)
}

fn main() {
let result = apply(|x, y| x + y, 10, 32);
assert_eq!(result, 42);
}

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions kmir/src/tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
'assume-cheatcode-conflict-fail',
'raw-ptr-cast-fail',
'transmute-u8-to-enum-fail',
'transmute-u8-to-enum-changed-discriminant-signed-fail',
'assert-inhabited-fail',
'iterator-simple',
'unions-fail',
Expand All @@ -63,8 +62,6 @@
'test_offset_from-fail',
'ref-ptr-cast-elem-fail',
'ref-ptr-cast-elem-offset-fail',
'and_then_closure-fail',
'closure_access_struct-fail',
]


Expand Down