Skip to content

Commit d131a7d

Browse files
Added nullaryOpAlignOf for primitives (#578)
`nullaryOpAlignOf` for primitives: - Returns correct values for `u{8,16,32,64,128}`, `i{8,16,32,64,128}`, `bool`, `char`, `floats`; - Assumes `usize` and `isize` are `64bit`; - Hardcoded return size of `64bit` since `isize` and `usize` assume `64bit` currently; We already have tests that trigger this however they are going to require `thunk` to be implemented to get past the casts. Also I feel alignment should be platform specific, so I added a FIXME because I believe this values are essentially assumptions. Or am I misunderstanding? --------- Co-authored-by: devops <[email protected]>
1 parent 30021dd commit d131a7d

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

kmir/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "kmir"
7-
version = "0.3.154"
7+
version = "0.3.155"
88
description = ""
99
requires-python = "~=3.10"
1010
dependencies = [

kmir/src/kmir/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from typing import Final
22

3-
VERSION: Final = '0.3.154'
3+
VERSION: Final = '0.3.155'

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

+16
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,22 @@ One important use case of `UbChecks` is to determine overflows in unchecked arit
13051305
`nullOpAlignOf`
13061306
`nullOpOffsetOf(VariantAndFieldIndices)`
13071307

1308+
```k
1309+
// FIXME: 64 is hardcoded since usize not supported
1310+
rule <k> rvalueNullaryOp(nullOpAlignOf, TY)
1311+
=>
1312+
typedValue(
1313+
Integer(#alignOf({TYPEMAP[TY]}:>TypeInfo), 64, false),
1314+
TyUnknown,
1315+
mutabilityNot
1316+
)
1317+
...
1318+
</k>
1319+
<types> TYPEMAP </types>
1320+
requires TY in_keys(TYPEMAP)
1321+
andBool isTypeInfo(TYPEMAP[TY])
1322+
```
1323+
13081324
#### Other operations
13091325

13101326
`binOpOffset`

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

+25
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,31 @@ This truncation function is instrumental in the implementation of Integer arithm
150150
[preserves-definedness] // positive shift, divisor non-zero
151151
```
152152

153+
## Alignment of Primitives
154+
155+
```k
156+
// FIXME: Alignment is platform specific
157+
syntax Int ::= #alignOf( TypeInfo ) [function]
158+
rule #alignOf( typeInfoPrimitiveType(primTypeBool) ) => 1
159+
rule #alignOf( typeInfoPrimitiveType(primTypeChar) ) => 4
160+
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyIsize)) ) => 8 // FIXME: Hard coded since usize not implemented
161+
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI8)) ) => 1
162+
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI16)) ) => 2
163+
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI32)) ) => 4
164+
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI64)) ) => 8
165+
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI128)) ) => 16
166+
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyUsize)) ) => 8 // FIXME: Hard coded since usize not implemented
167+
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU8)) ) => 1
168+
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU16)) ) => 2
169+
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU32)) ) => 4
170+
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU64)) ) => 8
171+
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU128)) ) => 16
172+
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF16)) ) => 2
173+
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF32)) ) => 4
174+
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF64)) ) => 8
175+
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF128)) ) => 16
176+
```
177+
153178
```k
154179
endmodule
155180
```

kmir/uv.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.154
1+
0.3.155

0 commit comments

Comments
 (0)