Skip to content

Commit 6f65b2c

Browse files
committed
feat(rt): implement pointer cast address allocation
1 parent b97ec0f commit 6f65b2c

130 files changed

Lines changed: 1297 additions & 246 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ requires "./value.md"
1919
module KMIR-CONFIGURATION
2020
imports INT-SYNTAX
2121
imports BOOL-SYNTAX
22+
imports MAP
23+
imports SET
2224
imports RT-VALUE-SYNTAX
2325
2426
syntax RetVal ::= return( Value )
@@ -47,6 +49,10 @@ module KMIR-CONFIGURATION
4749
</currentFrame>
4850
// remaining call stack (without top frame)
4951
<stack> .List </stack>
52+
// address allocation model for pointer-to-integer casts
53+
<addressMap> .Map </addressMap>
54+
<nextAddress> 4096 </nextAddress>
55+
<exposedSet> .Set </exposedSet>
5056
</kmir>
5157
```
5258

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

Lines changed: 356 additions & 2 deletions
Large diffs are not rendered by default.

kmir/src/kmir/testing/fixtures.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,53 @@ def _normalize_symbol_hashes(text: str) -> str:
3131
return text
3232

3333

34+
def _normalize_optional_show_diagnostics(text: str) -> str:
35+
"""Drop diagnostics that are present only on some environments/backends."""
36+
return re.sub(r'(?m)^ >> message: .*\n?', '', text)
37+
38+
39+
def _normalize_step_counts(text: str) -> str:
40+
"""Normalize unstable proof step counts in human-facing snapshots."""
41+
text = re.sub(r'\(\d+ steps\)', '(<steps> steps)', text)
42+
text = re.sub(r'steps \d+', 'steps <steps>', text)
43+
return text
44+
45+
46+
def _normalize_trailing_newlines(text: str) -> str:
47+
"""Ignore EOF newline count drift in snapshot comparisons."""
48+
return text.rstrip('\n')
49+
50+
3451
def assert_or_update_show_output(
35-
actual_text: str, expected_file: Path, *, update: bool, path_replacements: dict[str, str] | None = None
52+
actual_text: str,
53+
expected_file: Path,
54+
*,
55+
update: bool,
56+
path_replacements: dict[str, str] | None = None,
57+
normalize_optional_diagnostics: bool = False,
58+
normalize_steps: bool = False,
3659
) -> None:
3760
if path_replacements:
3861
for old, new in path_replacements.items():
3962
actual_text = actual_text.replace(old, new)
4063
# Normalize rustc symbol hash suffixes that can drift across builds/environments.
4164
actual_text = _normalize_symbol_hashes(actual_text)
65+
if normalize_optional_diagnostics:
66+
actual_text = _normalize_optional_show_diagnostics(actual_text)
67+
if normalize_steps:
68+
actual_text = _normalize_step_counts(actual_text)
69+
actual_text = _normalize_trailing_newlines(actual_text)
4270
if update:
4371
expected_file.write_text(actual_text)
4472
else:
4573
assert expected_file.is_file()
4674
expected_text = expected_file.read_text()
4775
expected_text = _normalize_symbol_hashes(expected_text)
76+
if normalize_optional_diagnostics:
77+
expected_text = _normalize_optional_show_diagnostics(expected_text)
78+
if normalize_steps:
79+
expected_text = _normalize_step_counts(expected_text)
80+
expected_text = _normalize_trailing_newlines(expected_text)
4881
if actual_text != expected_text:
4982
diff = '\n'.join(
5083
unified_diff(

kmir/src/tests/integration/data/exec-smir/allocs/array_const_compare.state

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
ty ( -1 )
1010
</currentFunc>
1111
<currentFrame>
12+
<frameId>
13+
0
14+
</frameId>
1215
<currentBody>
1316
ListItem ( basicBlock (... statements: statement (... kind: statementKindAssign (... place: place (... local: local ( 2 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandConstant ( constOperand (... span: span ( 271 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: provenanceMapEntry (... offset: 0 , allocId: allocId ( 0 ) ) .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 25 ) , id: mirConstId ( 35 ) ) ) ) ) ) , span: span ( 271 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 3 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandConstant ( constOperand (... span: span ( 272 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: provenanceMapEntry (... offset: 0 , allocId: allocId ( 1 ) ) .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 25 ) , id: mirConstId ( 36 ) ) ) ) ) ) , span: span ( 272 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 1 ) , projection: .ProjectionElems ) , rvalue: rvalueAggregate ( aggregateKindTuple , operandMove ( place (... local: local ( 2 ) , projection: .ProjectionElems ) ) operandMove ( place (... local: local ( 3 ) , projection: .ProjectionElems ) ) .Operands ) ) , span: span ( 273 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 4 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandCopy ( place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 25 ) ) .ProjectionElems ) ) ) ) , span: span ( 274 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 5 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandCopy ( place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 1 ) , ty ( 25 ) ) .ProjectionElems ) ) ) ) , span: span ( 275 ) ) .Statements , terminator: terminator (... kind: terminatorKindCall (... func: operandConstant ( constOperand (... span: span ( 270 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindZeroSized , ty: ty ( 79 ) , id: mirConstId ( 34 ) ) ) ) , args: operandCopy ( place (... local: local ( 4 ) , projection: .ProjectionElems ) ) operandCopy ( place (... local: local ( 5 ) , projection: .ProjectionElems ) ) .Operands , destination: place (... local: local ( 6 ) , projection: .ProjectionElems ) , target: someBasicBlockIdx ( basicBlockIdx ( 1 ) ) , unwind: unwindActionContinue ) , span: span ( 270 ) ) ) )
1417
ListItem ( basicBlock (... statements: .Statements , terminator: terminator (... kind: terminatorKindSwitchInt (... discr: operandMove ( place (... local: local ( 6 ) , projection: .ProjectionElems ) ) , targets: switchTargets (... branches: branch ( 0 , basicBlockIdx ( 3 ) ) .Branches , otherwise: basicBlockIdx ( 2 ) ) ) , span: span ( 270 ) ) ) )
@@ -47,6 +50,15 @@
4750
</locals>
4851
</currentFrame>
4952
<stack>
50-
ListItem ( StackFrame ( ty ( -1 ) , place (... local: local ( -1 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionUnreachable , .List ) )
53+
ListItem ( StackFrame ( 0 , ty ( -1 ) , place (... local: local ( -1 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionUnreachable , .List ) )
5154
</stack>
55+
<addressMap>
56+
.Map
57+
</addressMap>
58+
<nextAddress>
59+
4096
60+
</nextAddress>
61+
<exposedSet>
62+
.Set
63+
</exposedSet>
5264
</kmir>

kmir/src/tests/integration/data/exec-smir/allocs/array_nest_compare.state

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
ty ( -1 )
1010
</currentFunc>
1111
<currentFrame>
12+
<frameId>
13+
0
14+
</frameId>
1215
<currentBody>
1316
ListItem ( basicBlock (... statements: statement (... kind: statementKindAssign (... place: place (... local: local ( 2 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandConstant ( constOperand (... span: span ( 249 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: provenanceMapEntry (... offset: 0 , allocId: allocId ( 0 ) ) .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 28 ) , id: mirConstId ( 36 ) ) ) ) ) ) , span: span ( 249 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 3 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandConstant ( constOperand (... span: span ( 250 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: provenanceMapEntry (... offset: 0 , allocId: allocId ( 1 ) ) .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 28 ) , id: mirConstId ( 37 ) ) ) ) ) ) , span: span ( 250 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 1 ) , projection: .ProjectionElems ) , rvalue: rvalueAggregate ( aggregateKindTuple , operandMove ( place (... local: local ( 2 ) , projection: .ProjectionElems ) ) operandMove ( place (... local: local ( 3 ) , projection: .ProjectionElems ) ) .Operands ) ) , span: span ( 251 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 4 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandCopy ( place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 28 ) ) .ProjectionElems ) ) ) ) , span: span ( 252 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 5 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandCopy ( place (... local: local ( 1 ) , projection: projectionElemField ( fieldIdx ( 1 ) , ty ( 28 ) ) .ProjectionElems ) ) ) ) , span: span ( 253 ) ) .Statements , terminator: terminator (... kind: terminatorKindCall (... func: operandConstant ( constOperand (... span: span ( 248 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindZeroSized , ty: ty ( 100 ) , id: mirConstId ( 35 ) ) ) ) , args: operandCopy ( place (... local: local ( 4 ) , projection: .ProjectionElems ) ) operandCopy ( place (... local: local ( 5 ) , projection: .ProjectionElems ) ) .Operands , destination: place (... local: local ( 6 ) , projection: .ProjectionElems ) , target: someBasicBlockIdx ( basicBlockIdx ( 1 ) ) , unwind: unwindActionContinue ) , span: span ( 248 ) ) ) )
1417
ListItem ( basicBlock (... statements: .Statements , terminator: terminator (... kind: terminatorKindSwitchInt (... discr: operandMove ( place (... local: local ( 6 ) , projection: .ProjectionElems ) ) , targets: switchTargets (... branches: branch ( 0 , basicBlockIdx ( 3 ) ) .Branches , otherwise: basicBlockIdx ( 2 ) ) ) , span: span ( 248 ) ) ) )
@@ -63,6 +66,15 @@
6366
</locals>
6467
</currentFrame>
6568
<stack>
66-
ListItem ( StackFrame ( ty ( -1 ) , place (... local: local ( -1 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionUnreachable , .List ) )
69+
ListItem ( StackFrame ( 0 , ty ( -1 ) , place (... local: local ( -1 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionUnreachable , .List ) )
6770
</stack>
71+
<addressMap>
72+
.Map
73+
</addressMap>
74+
<nextAddress>
75+
4096
76+
</nextAddress>
77+
<exposedSet>
78+
.Set
79+
</exposedSet>
6880
</kmir>

kmir/src/tests/integration/data/exec-smir/allocs/enum-two-refs-fail.state

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
ty ( 85 )
1010
</currentFunc>
1111
<currentFrame>
12+
<frameId>
13+
1
14+
</frameId>
1215
<currentBody>
1316
ListItem ( basicBlock (... statements: statement (... kind: statementKindAssign (... place: place (... local: local ( 3 ) , projection: .ProjectionElems ) , rvalue: rvalueAggregate ( aggregateKindTuple , operandCopy ( place (... local: local ( 1 ) , projection: .ProjectionElems ) ) operandCopy ( place (... local: local ( 2 ) , projection: .ProjectionElems ) ) .Operands ) ) , span: span ( 146 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 13 ) , projection: .ProjectionElems ) , rvalue: rvalueCopyForDeref ( place (... local: local ( 3 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 25 ) ) .ProjectionElems ) ) ) , span: span ( 145 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 4 ) , projection: .ProjectionElems ) , rvalue: rvalueRef ( region (... kind: regionKindReErased ) , borrowKindShared , place (... local: local ( 13 ) , projection: projectionElemDeref projectionElemDowncast ( variantIdx ( 0 ) ) projectionElemField ( fieldIdx ( 0 ) , ty ( 37 ) ) .ProjectionElems ) ) ) , span: span ( 145 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 14 ) , projection: .ProjectionElems ) , rvalue: rvalueCopyForDeref ( place (... local: local ( 3 ) , projection: projectionElemField ( fieldIdx ( 0 ) , ty ( 25 ) ) .ProjectionElems ) ) ) , span: span ( 147 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 5 ) , projection: .ProjectionElems ) , rvalue: rvalueRef ( region (... kind: regionKindReErased ) , borrowKindShared , place (... local: local ( 14 ) , projection: projectionElemDeref projectionElemDowncast ( variantIdx ( 0 ) ) projectionElemField ( fieldIdx ( 1 ) , ty ( 45 ) ) .ProjectionElems ) ) ) , span: span ( 147 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 15 ) , projection: .ProjectionElems ) , rvalue: rvalueCopyForDeref ( place (... local: local ( 3 ) , projection: projectionElemField ( fieldIdx ( 1 ) , ty ( 25 ) ) .ProjectionElems ) ) ) , span: span ( 145 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 6 ) , projection: .ProjectionElems ) , rvalue: rvalueRef ( region (... kind: regionKindReErased ) , borrowKindShared , place (... local: local ( 15 ) , projection: projectionElemDeref projectionElemDowncast ( variantIdx ( 0 ) ) projectionElemField ( fieldIdx ( 0 ) , ty ( 37 ) ) .ProjectionElems ) ) ) , span: span ( 145 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 16 ) , projection: .ProjectionElems ) , rvalue: rvalueCopyForDeref ( place (... local: local ( 3 ) , projection: projectionElemField ( fieldIdx ( 1 ) , ty ( 25 ) ) .ProjectionElems ) ) ) , span: span ( 147 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 7 ) , projection: .ProjectionElems ) , rvalue: rvalueRef ( region (... kind: regionKindReErased ) , borrowKindShared , place (... local: local ( 16 ) , projection: projectionElemDeref projectionElemDowncast ( variantIdx ( 0 ) ) projectionElemField ( fieldIdx ( 1 ) , ty ( 45 ) ) .ProjectionElems ) ) ) , span: span ( 147 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 9 ) , projection: .ProjectionElems ) , rvalue: rvalueRef ( region (... kind: regionKindReErased ) , borrowKindShared , place (... local: local ( 4 ) , projection: .ProjectionElems ) ) ) , span: span ( 145 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 10 ) , projection: .ProjectionElems ) , rvalue: rvalueRef ( region (... kind: regionKindReErased ) , borrowKindShared , place (... local: local ( 6 ) , projection: .ProjectionElems ) ) ) , span: span ( 145 ) ) .Statements , terminator: terminator (... kind: terminatorKindCall (... func: operandConstant ( constOperand (... span: span ( 145 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindZeroSized , ty: ty ( 93 ) , id: mirConstId ( 47 ) ) ) ) , args: operandMove ( place (... local: local ( 9 ) , projection: .ProjectionElems ) ) operandMove ( place (... local: local ( 10 ) , projection: .ProjectionElems ) ) .Operands , destination: place (... local: local ( 8 ) , projection: .ProjectionElems ) , target: someBasicBlockIdx ( basicBlockIdx ( 1 ) ) , unwind: unwindActionContinue ) , span: span ( 145 ) ) ) )
1417
ListItem ( basicBlock (... statements: .Statements , terminator: terminator (... kind: terminatorKindSwitchInt (... discr: operandMove ( place (... local: local ( 8 ) , projection: .ProjectionElems ) ) , targets: switchTargets (... branches: branch ( 0 , basicBlockIdx ( 3 ) ) .Branches , otherwise: basicBlockIdx ( 2 ) ) ) , span: span ( 145 ) ) ) )
@@ -50,7 +53,7 @@
5053
</locals>
5154
</currentFrame>
5255
<stack>
53-
ListItem ( StackFrame ( ty ( -1 ) , place (... local: local ( 0 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionContinue , ListItem ( newLocal ( ty ( 1 ) , mutabilityMut ) )
56+
ListItem ( StackFrame ( 0 , ty ( -1 ) , place (... local: local ( 0 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionContinue , ListItem ( newLocal ( ty ( 1 ) , mutabilityMut ) )
5457
ListItem ( typedValue ( Aggregate ( variantIdx ( 0 ) , ListItem ( thunk ( #decodeConstant ( constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: provenanceMapEntry (... offset: 0 , allocId: allocId ( 1 ) ) .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty ( 25 ) , typeInfoRefType ( ty ( 109 ) ) ) ) )
5558
ListItem ( thunk ( #decodeConstant ( constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: provenanceMapEntry (... offset: 0 , allocId: allocId ( 2 ) ) .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty ( 25 ) , typeInfoRefType ( ty ( 109 ) ) ) ) ) ) , ty ( 91 ) , mutabilityMut ) )
5659
ListItem ( typedValue ( Moved , ty ( 25 ) , mutabilityMut ) )
@@ -73,6 +76,15 @@
7376
ListItem ( newLocal ( ty ( 1 ) , mutabilityNot ) )
7477
ListItem ( newLocal ( ty ( 68 ) , mutabilityMut ) )
7578
ListItem ( newLocal ( ty ( 69 ) , mutabilityNot ) ) ) )
76-
ListItem ( StackFrame ( ty ( -1 ) , place (... local: local ( -1 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionUnreachable , .List ) )
79+
ListItem ( StackFrame ( 0 , ty ( -1 ) , place (... local: local ( -1 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionUnreachable , .List ) )
7780
</stack>
81+
<addressMap>
82+
.Map
83+
</addressMap>
84+
<nextAddress>
85+
4096
86+
</nextAddress>
87+
<exposedSet>
88+
.Set
89+
</exposedSet>
7890
</kmir>

0 commit comments

Comments
 (0)