Skip to content

Added nullaryOpAlignOf for primitives #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2025
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
2 changes: 1 addition & 1 deletion kmir/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "kmir"
version = "0.3.154"
version = "0.3.155"
description = ""
requires-python = "~=3.10"
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion kmir/src/kmir/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from typing import Final

VERSION: Final = '0.3.154'
VERSION: Final = '0.3.155'
16 changes: 16 additions & 0 deletions kmir/src/kmir/kdist/mir-semantics/rt/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,22 @@ One important use case of `UbChecks` is to determine overflows in unchecked arit
`nullOpAlignOf`
`nullOpOffsetOf(VariantAndFieldIndices)`

```k
// FIXME: 64 is hardcoded since usize not supported
rule <k> rvalueNullaryOp(nullOpAlignOf, TY)
=>
typedValue(
Integer(#alignOf({TYPEMAP[TY]}:>TypeInfo), 64, false),
TyUnknown,
mutabilityNot
)
...
</k>
<types> TYPEMAP </types>
requires TY in_keys(TYPEMAP)
andBool isTypeInfo(TYPEMAP[TY])
```

#### Other operations

`binOpOffset`
Expand Down
25 changes: 25 additions & 0 deletions kmir/src/kmir/kdist/mir-semantics/rt/numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ This truncation function is instrumental in the implementation of Integer arithm
[preserves-definedness] // positive shift, divisor non-zero
```

## Alignment of Primitives

```k
// FIXME: Alignment is platform specific
syntax Int ::= #alignOf( TypeInfo ) [function]
rule #alignOf( typeInfoPrimitiveType(primTypeBool) ) => 1
rule #alignOf( typeInfoPrimitiveType(primTypeChar) ) => 4
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyIsize)) ) => 8 // FIXME: Hard coded since usize not implemented
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI8)) ) => 1
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI16)) ) => 2
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI32)) ) => 4
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI64)) ) => 8
rule #alignOf( typeInfoPrimitiveType(primTypeInt(intTyI128)) ) => 16
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyUsize)) ) => 8 // FIXME: Hard coded since usize not implemented
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU8)) ) => 1
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU16)) ) => 2
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU32)) ) => 4
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU64)) ) => 8
rule #alignOf( typeInfoPrimitiveType(primTypeUint(uintTyU128)) ) => 16
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF16)) ) => 2
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF32)) ) => 4
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF64)) ) => 8
rule #alignOf( typeInfoPrimitiveType(primTypeFloat(floatTyF128)) ) => 16
```

```k
endmodule
```
2 changes: 1 addition & 1 deletion kmir/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.154
0.3.155