Skip to content

Commit 7f25f8d

Browse files
committed
Merge remote-tracking branch 'origin/master' into release
2 parents c526d74 + 3d763c0 commit 7f25f8d

Some content is hidden

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

49 files changed

+7916
-4269
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ update-exec-smir:
132132

133133
# Update checked-in smir.json files (using stable-mir-json dependency and jq)
134134
# file paths for spans in the the updated smir are truncated to known infixes
135+
# Compiles run-smir-random files as libraries, others as binaries
135136
.PHONY: update-smir-json
136137
update-smir-json: TARGETS = $(shell git ls-files | grep -e ".*\.smir\.json$$" | grep -v -e pinocchio)
137138
update-smir-json: SMIR = cargo -q -Z unstable-options -C deps/stable-mir-json run --
@@ -140,7 +141,11 @@ update-smir-json: stable-mir-json
140141
dir=$$(realpath $$(dirname $$file)); \
141142
rust=$$dir/$$(basename $${file%.smir.json}.rs); \
142143
[ -f "$$rust" ] || (echo "Source file $$rust missing."; exit 1); \
143-
${SMIR} -Zno-codegen --out-dir $$dir $$rust; \
144+
if echo "$$file" | grep -q "run-smir-random"; then \
145+
${SMIR} --crate-type=lib --out-dir $$dir $$rust; \
146+
else \
147+
${SMIR} -Zno-codegen --out-dir $$dir $$rust; \
148+
fi; \
144149
jq '.spans[].[1].[0] |= sub("/.*lib/rustlib"; "rustlib") | .spans[].[1].[0] |= sub("/.*/integration/data"; "data")' $$file > $$file.tmp; \
145150
mv $$file.tmp $$file; \
146151
done

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ will not create an `Aggregate` instead of a `Union` `Value`.
9393
```k
9494
syntax Bool ::= #isUnionType ( TypeInfo ) [function, total]
9595
// --------------------------------------------------------
96-
rule #isUnionType(typeInfoUnionType(_NAME, _ADTDEF) ) => true
97-
rule #isUnionType(_) => false [owise]
96+
rule #isUnionType(typeInfoUnionType(_NAME, _ADTDEF, _FIELDS, _LAYOUT) ) => true
97+
rule #isUnionType(_) => false [owise]
9898
```
9999

100100
## Determining types of places with projection
@@ -254,9 +254,12 @@ This information is either hard-wired for primitive types (numbers, first and fo
254254
rule #sizeOf(typeInfoTupleType(_, noLayoutShape)) => 0
255255
rule #alignOf(typeInfoTupleType(_, someLayoutShape(layoutShape(_, _, _, align(BYTES),_)))) => BYTES
256256
rule #alignOf(typeInfoTupleType(_, noLayoutShape)) => 1
257-
// size of union types: FIXME use layout (currently not in K AST)
258-
// rule #sizeOf(typeInfoUnionType(_, _)) => FIXME
259-
// rule #alignOf(typeInfoUnionType(_, _)) => FIXME
257+
// union
258+
rule #sizeOf(typeInfoUnionType(_, _, _, someLayoutShape(layoutShape(_, _, _, _, machineSize( BITS ))))) => BITS /Int 8 [preserves-definedness]
259+
rule #sizeOf(typeInfoUnionType(_, _, _, someLayoutShape(layoutShape(_, _, _, _, machineSize(mirInt(BITS)))))) => BITS /Int 8 [preserves-definedness]
260+
rule #sizeOf(typeInfoUnionType(_, _, _, noLayoutShape)) => 0
261+
rule #alignOf(typeInfoUnionType(_, _, _, someLayoutShape(layoutShape(_, _, _, align(BYTES),_)))) => BYTES
262+
rule #alignOf(typeInfoUnionType(_, _, _, noLayoutShape)) => 1
260263
// arrays with known length have the alignment of the element type, and a size multiplying element count and element size
261264
rule #sizeOf(typeInfoArrayType(ELEM_TY, someTyConst(tyConst(KIND, _)))) => #sizeOf(lookupTy(ELEM_TY)) *Int readTyConstInt(KIND)
262265
rule #sizeOf(typeInfoArrayType( _ , noTyConst )) => 0

kmir/src/kmir/kdist/mir-semantics/ty.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@ syntax ExistentialPredicateBinders ::= List {ExistentialPredicateBinder, ""}
270270
, adtDef: AdtDef
271271
, fields: Tys
272272
, layout: MaybeLayoutShape) [symbol(TypeInfo::StructType) , group(mir-enum---name--adt-def--fields--layout)]
273-
| typeInfoUnionType(MIRString, AdtDef) [symbol(TypeInfo::UnionType) , group(mir-enum---name--adt-def)]
273+
| typeInfoUnionType(
274+
name: MIRString
275+
, adtDef: AdtDef
276+
, fields: Tys
277+
, layout: MaybeLayoutShape) [symbol(TypeInfo::UnionType) , group(mir-enum---name--adt-def--fields--layout)]
274278
| typeInfoArrayType(Ty, MaybeTyConst) [symbol(TypeInfo::ArrayType) , group(mir-enum---elem-type--size)]
275279
| typeInfoPtrType(Ty) [symbol(TypeInfo::PtrType) , group(mir-enum---pointee-type)]
276280
| typeInfoRefType(Ty) [symbol(TypeInfo::RefType) , group(mir-enum---pointee-type)]
@@ -299,7 +303,7 @@ syntax ExistentialPredicateBinders ::= List {ExistentialPredicateBinder, ""}
299303
| "noLayoutShape" [group(mir-option)]
300304
301305
syntax FieldsShape ::= "fieldsShapePrimitive" [group(mir-enum), symbol(FieldsShape::Primitive)]
302-
| fieldsShapeUnion(/* TODO */) [group(mir-enum), symbol(FieldsShape::Union)]
306+
| fieldsShapeUnion(MIRInt) [group(mir-enum), symbol(FieldsShape::Union)]
303307
| fieldsShapeArray(/* TODO */) [group(mir-enum), symbol(FieldsShape::Array)]
304308
| fieldsShapeArbitrary(FieldsShapeArbitrary) [group(mir-enum), symbol(FieldsShape::Arbitrary)]
305309

kmir/src/kmir/linker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def apply_offset_type_info(typeinfo: dict, offset: int) -> dict:
235235
typeinfo['StructType']['fields'] = [x + offset for x in typeinfo['StructType']['fields']]
236236
typeinfo['StructType']['adt_def'] += offset
237237
elif 'UnionType' in typeinfo:
238+
typeinfo['UnionType']['fields'] = [x + offset for x in typeinfo['UnionType']['fields']]
238239
typeinfo['UnionType']['adt_def'] += offset
239240
elif 'ArrayType' in typeinfo:
240241
typeinfo['ArrayType']['elem_type'] += offset

kmir/src/kmir/ty.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def from_raw(data: Any) -> FieldsShape:
218218
match data:
219219
case 'Primitive':
220220
return PrimitiveFields()
221+
case {'Union': count}:
222+
return UnionFields(count=count)
221223
case {
222224
'Arbitrary': {
223225
'offsets': offsets,
@@ -234,6 +236,11 @@ def from_raw(data: Any) -> FieldsShape:
234236
class PrimitiveFields(FieldsShape): ...
235237

236238

239+
@dataclass
240+
class UnionFields(FieldsShape):
241+
count: int
242+
243+
237244
@dataclass
238245
class ArbitraryFields(FieldsShape):
239246
offsets: list[MachineSize]
@@ -525,6 +532,8 @@ def nbytes(self, types: Mapping[Ty, TypeMetadata]) -> int:
525532
class UnionT(TypeMetadata):
526533
name: str
527534
adt_def: int
535+
fields: list[Ty]
536+
layout: LayoutShape | None
528537

529538
@staticmethod
530539
def from_raw(data: Any) -> UnionT:
@@ -533,11 +542,15 @@ def from_raw(data: Any) -> UnionT:
533542
'UnionType': {
534543
'name': name,
535544
'adt_def': adt_def,
545+
'fields': fields,
546+
'layout': layout,
536547
}
537548
}:
538549
return UnionT(
539550
name=name,
540551
adt_def=adt_def,
552+
fields=list(fields),
553+
layout=LayoutShape.from_raw(layout) if layout is not None else None,
541554
)
542555
case _:
543556
raise _cannot_parse_as('UnionT', data)

0 commit comments

Comments
 (0)