-
Notifications
You must be signed in to change notification settings - Fork 4
feat: model interior borrows for refcell #786
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
Changes from 1 commit
8a72058
9f82eec
c2d6862
28cf9d5
93cad6f
fa24d9b
ede664c
55237eb
21f5034
537b584
c525218
f270fe8
c25f259
2093f58
a313ead
1057a44
d3d93ca
8d95126
46e791a
4b3ba64
e319042
96dc111
e4b482c
430dd93
6cb7e3f
e5f30b7
0a78bae
d0c1793
08389d0
2e1aeb1
1b24944
5ca54b5
4683341
a8b3258
f1c3005
d94197b
d45a24a
69a4efd
eb83742
b13b312
d3b81e1
716dc16
3450bc8
1efd5f7
cd57064
0a16989
0b07a30
d57f4f3
541edd4
193bef5
8358db0
3b3ef6a
9cc3eaf
8a77758
8e75511
4f9fcd9
83c924c
54ceab5
00e2df2
55f9281
5c6128e
61c8c69
8cc88c4
82392e7
cca1452
76a081e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ requires "value.md" | |
|
|
||
| module RT-TYPES | ||
| imports BOOL | ||
| imports INT | ||
| imports MAP | ||
| imports K-EQUAL | ||
|
|
||
|
|
@@ -59,6 +60,35 @@ Pointers to arrays/slices are compatible with pointers to the element type | |
|
|
||
| rule #isArrayOf(typeInfoArrayType(TY, _), TY) => true | ||
| rule #isArrayOf( _ , _ ) => false [owise] | ||
|
|
||
| rule #typesCompatible(SRC, OTHER) => true | ||
| requires #zeroSizedType(SRC) orBool #zeroSizedType(OTHER) | ||
|
|
||
| syntax Bool ::= #zeroSizedType ( TypeInfo ) [function, total] | ||
|
|
||
| rule #zeroSizedType(typeInfoTupleType(.Tys)) => true | ||
| rule #zeroSizedType(typeInfoStructType(_, _, .Tys, _)) => true | ||
| rule #zeroSizedType(_) => false [owise] | ||
|
||
|
|
||
| rule #typesCompatible(typeInfoStructType(_, _, FIELD .Tys, LAYOUT), OTHER) | ||
| => #typesCompatible(lookupTy(FIELD), OTHER) | ||
| requires #zeroFieldOffset(LAYOUT) | ||
|
|
||
| rule #typesCompatible(OTHER, typeInfoStructType(_, _, FIELD .Tys, LAYOUT)) | ||
| => #typesCompatible(OTHER, lookupTy(FIELD)) | ||
| requires #zeroFieldOffset(LAYOUT) | ||
|
|
||
| syntax Bool ::= #zeroFieldOffset ( MaybeLayoutShape ) [function, total] | ||
|
|
||
| rule #zeroFieldOffset(LAYOUT) | ||
| => #structOffsets(LAYOUT) ==K .MachineSizes | ||
| orBool #structOffsets(LAYOUT) ==K machineSize(mirInt(0)) .MachineSizes | ||
| orBool #structOffsets(LAYOUT) ==K machineSize(0) .MachineSizes | ||
|
||
|
|
||
| syntax MachineSizes ::= #structOffsets ( MaybeLayoutShape ) [function, total] | ||
|
|
||
| rule #structOffsets(someLayoutShape(layoutShape(fieldsShapeArbitrary(mk(OFFSETS)), _, _, _, _))) => OFFSETS | ||
| rule #structOffsets(_) => .MachineSizes [owise] | ||
| ``` | ||
|
|
||
| ## Determining types of places with projection | ||
|
|
@@ -70,6 +100,24 @@ To make this function total, an optional `MaybeTy` is used. | |
| syntax MaybeTy ::= Ty | ||
| | "TyUnknown" | ||
|
|
||
| syntax MaybeTy ::= #transparentFieldTy ( TypeInfo ) [function, total] | ||
|
|
||
| rule #transparentFieldTy(typeInfoStructType(_, _, FIELD .Tys, LAYOUT)) => FIELD | ||
| requires #zeroFieldOffset(LAYOUT) | ||
| rule #transparentFieldTy(_) => TyUnknown [owise] | ||
|
|
||
| syntax Int ::= #transparentDepth ( TypeInfo ) [function, total] | ||
|
|
||
| rule #transparentDepth(typeInfoStructType(_, _, FIELD .Tys, LAYOUT)) | ||
| => 1 +Int #transparentDepth(lookupTy(FIELD)) | ||
| requires #zeroFieldOffset(LAYOUT) | ||
| rule #transparentDepth(_) => 0 [owise] | ||
|
|
||
| syntax TypeInfo ::= #lookupMaybeTy ( MaybeTy ) [function, total] | ||
|
|
||
| rule #lookupMaybeTy(TY:Ty) => lookupTy(TY) | ||
| rule #lookupMaybeTy(TyUnknown) => typeInfoVoidType | ||
|
|
||
| syntax MaybeTy ::= getTyOf( MaybeTy , ProjectionElems ) [function, total] | ||
| // ----------------------------------------------------------- | ||
| rule getTyOf(TyUnknown, _ ) => TyUnknown | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,49 +1,42 @@ | ||
| <kmir> | ||
| <k> | ||
| #cast ( PtrLocal ( 1 , place (... local: local ( 1 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , castKindPtrToPtr , ty ( 31 ) , ty ( 27 ) ) ~> #freezer#setLocalValue(_,_)_RT-DATA_KItem_Place_Evaluation1_ ( place (... local: local ( 3 ) , projection: .ProjectionElems ) ~> .K ) ~> #execStmts ( statement (... kind: statementKindAssign (... place: place (... local: local ( 4 ) , projection: .ProjectionElems ) , rvalue: rvalueCast ( castKindPtrToPtr , operandCopy ( place (... local: local ( 3 ) , projection: .ProjectionElems ) ) , ty ( 28 ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 5 ) , projection: .ProjectionElems ) , rvalue: rvalueCast ( castKindTransmute , operandCopy ( place (... local: local ( 4 ) , projection: .ProjectionElems ) ) , ty ( 29 ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 6 ) , projection: .ProjectionElems ) , rvalue: rvalueNullaryOp ( nullOpAlignOf , ty ( 25 ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 7 ) , projection: .ProjectionElems ) , rvalue: rvalueBinaryOp ( binOpSub , operandCopy ( place (... local: local ( 6 ) , projection: .ProjectionElems ) ) , operandConstant ( constOperand (... span: span ( 55 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x01\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 29 ) , id: mirConstId ( 9 ) ) ) ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 8 ) , projection: .ProjectionElems ) , rvalue: rvalueBinaryOp ( binOpBitAnd , operandCopy ( place (... local: local ( 5 ) , projection: .ProjectionElems ) ) , operandCopy ( place (... local: local ( 7 ) , projection: .ProjectionElems ) ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 9 ) , projection: .ProjectionElems ) , rvalue: rvalueBinaryOp ( binOpEq , operandCopy ( place (... local: local ( 8 ) , projection: .ProjectionElems ) ) , operandConstant ( constOperand (... span: span ( 55 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 29 ) , id: mirConstId ( 10 ) ) ) ) ) ) , span: span ( 55 ) ) .Statements ) ~> #execTerminator ( terminator (... kind: assert (... cond: operandCopy ( place (... local: local ( 9 ) , projection: .ProjectionElems ) ) , expected: true , msg: assertMessageMisalignedPointerDereference (... required: operandCopy ( place (... local: local ( 6 ) , projection: .ProjectionElems ) ) , found: operandCopy ( place (... local: local ( 5 ) , projection: .ProjectionElems ) ) ) , target: basicBlockIdx ( 1 ) , unwind: unwindActionUnreachable ) , span: span ( 55 ) ) ) ~> .K | ||
| #EndProgram ~> .K | ||
| </k> | ||
| <retVal> | ||
| noReturn | ||
| </retVal> | ||
| <currentFunc> | ||
| ty ( 34 ) | ||
| ty ( -1 ) | ||
| </currentFunc> | ||
| <currentFrame> | ||
| <currentBody> | ||
| ListItem ( basicBlock (... statements: statement (... kind: statementKindAssign (... place: place (... local: local ( 2 ) , projection: .ProjectionElems ) , rvalue: rvalueAddressOf ( mutabilityNot , place (... local: local ( 1 ) , projection: projectionElemDeref .ProjectionElems ) ) ) , span: span ( 56 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 3 ) , projection: .ProjectionElems ) , rvalue: rvalueCast ( castKindPtrToPtr , operandCopy ( place (... local: local ( 2 ) , projection: .ProjectionElems ) ) , ty ( 27 ) ) ) , span: span ( 57 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 4 ) , projection: .ProjectionElems ) , rvalue: rvalueCast ( castKindPtrToPtr , operandCopy ( place (... local: local ( 3 ) , projection: .ProjectionElems ) ) , ty ( 28 ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 5 ) , projection: .ProjectionElems ) , rvalue: rvalueCast ( castKindTransmute , operandCopy ( place (... local: local ( 4 ) , projection: .ProjectionElems ) ) , ty ( 29 ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 6 ) , projection: .ProjectionElems ) , rvalue: rvalueNullaryOp ( nullOpAlignOf , ty ( 25 ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 7 ) , projection: .ProjectionElems ) , rvalue: rvalueBinaryOp ( binOpSub , operandCopy ( place (... local: local ( 6 ) , projection: .ProjectionElems ) ) , operandConstant ( constOperand (... span: span ( 55 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x01\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 29 ) , id: mirConstId ( 9 ) ) ) ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 8 ) , projection: .ProjectionElems ) , rvalue: rvalueBinaryOp ( binOpBitAnd , operandCopy ( place (... local: local ( 5 ) , projection: .ProjectionElems ) ) , operandCopy ( place (... local: local ( 7 ) , projection: .ProjectionElems ) ) ) ) , span: span ( 55 ) ) statement (... kind: statementKindAssign (... place: place (... local: local ( 9 ) , projection: .ProjectionElems ) , rvalue: rvalueBinaryOp ( binOpEq , operandCopy ( place (... local: local ( 8 ) , projection: .ProjectionElems ) ) , operandConstant ( constOperand (... span: span ( 55 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 29 ) , id: mirConstId ( 10 ) ) ) ) ) ) , span: span ( 55 ) ) .Statements , terminator: terminator (... kind: assert (... cond: operandCopy ( place (... local: local ( 9 ) , projection: .ProjectionElems ) ) , expected: true , msg: assertMessageMisalignedPointerDereference (... required: operandCopy ( place (... local: local ( 6 ) , projection: .ProjectionElems ) ) , found: operandCopy ( place (... local: local ( 5 ) , projection: .ProjectionElems ) ) ) , target: basicBlockIdx ( 1 ) , unwind: unwindActionUnreachable ) , span: span ( 55 ) ) ) ) | ||
| ListItem ( basicBlock (... statements: statement (... kind: statementKindAssign (... place: place (... local: local ( 0 ) , projection: .ProjectionElems ) , rvalue: rvalueUse ( operandCopy ( place (... local: local ( 3 ) , projection: projectionElemDeref .ProjectionElems ) ) ) ) , span: span ( 55 ) ) .Statements , terminator: terminator (... kind: terminatorKindReturn , span: span ( 58 ) ) ) ) | ||
| ListItem ( basicBlock (... statements: .Statements , terminator: terminator (... kind: terminatorKindCall (... func: operandConstant ( constOperand (... span: span ( 64 ) , userTy: someUserTypeAnnotationIndex ( userTypeAnnotationIndex ( 0 ) ) , const: mirConst (... kind: constantKindZeroSized , ty: ty ( 33 ) , id: mirConstId ( 11 ) ) ) ) , args: operandConstant ( constOperand (... span: span ( 65 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b")\x00\x00\x00\x00\x00\x00\x00" , provenance: provenanceMap (... ptrs: .ProvenanceMapEntries ) , align: align ( 8 ) , mutability: mutabilityMut ) ) , ty: ty ( 25 ) , id: mirConstId ( 12 ) ) ) ) .Operands , destination: place (... local: local ( 1 ) , projection: .ProjectionElems ) , target: someBasicBlockIdx ( basicBlockIdx ( 1 ) ) , unwind: unwindActionContinue ) , span: span ( 66 ) ) ) ) | ||
| ListItem ( basicBlock (... statements: statement (... kind: statementKindAssign (... place: place (... local: local ( 3 ) , projection: .ProjectionElems ) , rvalue: rvalueRef ( region (... kind: regionKindReErased ) , borrowKindShared , place (... local: local ( 1 ) , projection: .ProjectionElems ) ) ) , span: span ( 69 ) ) .Statements , terminator: terminator (... kind: terminatorKindCall (... func: operandConstant ( constOperand (... span: span ( 67 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindZeroSized , ty: ty ( 34 ) , id: mirConstId ( 13 ) ) ) ) , args: operandCopy ( place (... local: local ( 3 ) , projection: .ProjectionElems ) ) .Operands , destination: place (... local: local ( 2 ) , projection: .ProjectionElems ) , target: someBasicBlockIdx ( basicBlockIdx ( 2 ) ) , unwind: unwindActionContinue ) , span: span ( 68 ) ) ) ) | ||
| ListItem ( basicBlock (... statements: .Statements , terminator: terminator (... kind: terminatorKindSwitchInt (... discr: operandMove ( place (... local: local ( 2 ) , projection: .ProjectionElems ) ) , targets: switchTargets (... branches: branch ( 41 , basicBlockIdx ( 3 ) ) .Branches , otherwise: basicBlockIdx ( 4 ) ) ) , span: span ( 70 ) ) ) ) | ||
| ListItem ( basicBlock (... statements: .Statements , terminator: terminator (... kind: terminatorKindReturn , span: span ( 71 ) ) ) ) | ||
| ListItem ( basicBlock (... statements: .Statements , terminator: terminator (... kind: terminatorKindCall (... func: operandConstant ( constOperand (... span: span ( 72 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindZeroSized , ty: ty ( 35 ) , id: mirConstId ( 14 ) ) ) ) , args: operandConstant ( constOperand (... span: span ( 32 ) , userTy: noUserTypeAnnotationIndex , const: mirConst (... kind: constantKindAllocated ( allocation (... bytes: b"\x00\x00\x00\x00\x00\x00\x00\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 ( 36 ) , id: mirConstId ( 15 ) ) ) ) .Operands , destination: place (... local: local ( 4 ) , projection: .ProjectionElems ) , target: noBasicBlockIdx , unwind: unwindActionContinue ) , span: span ( 72 ) ) ) ) | ||
| </currentBody> | ||
| <caller> | ||
| ty ( -1 ) | ||
| </caller> | ||
| <dest> | ||
| place (... local: local ( 2 ) , projection: .ProjectionElems ) | ||
| place (... local: local ( 0 ) , projection: .ProjectionElems ) | ||
| </dest> | ||
| <target> | ||
| someBasicBlockIdx ( basicBlockIdx ( 2 ) ) | ||
| noBasicBlockIdx | ||
| </target> | ||
| <unwind> | ||
| unwindActionContinue | ||
| </unwind> | ||
| <locals> | ||
| ListItem ( newLocal ( ty ( 25 ) , mutabilityMut ) ) | ||
| ListItem ( typedValue ( Reference ( 1 , place (... local: local ( 1 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 30 ) , mutabilityNot ) ) | ||
| ListItem ( typedValue ( PtrLocal ( 1 , place (... local: local ( 1 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 31 ) , mutabilityNot ) ) | ||
| ListItem ( newLocal ( ty ( 27 ) , mutabilityNot ) ) | ||
| ListItem ( newLocal ( ty ( 28 ) , mutabilityMut ) ) | ||
| ListItem ( newLocal ( ty ( 29 ) , mutabilityMut ) ) | ||
| ListItem ( newLocal ( ty ( 29 ) , mutabilityMut ) ) | ||
| ListItem ( newLocal ( ty ( 29 ) , mutabilityMut ) ) | ||
| ListItem ( newLocal ( ty ( 29 ) , mutabilityMut ) ) | ||
| ListItem ( newLocal ( ty ( 32 ) , mutabilityMut ) ) | ||
| ListItem ( newLocal ( ty ( 1 ) , mutabilityMut ) ) | ||
| ListItem ( typedValue ( Aggregate ( variantIdx ( 0 ) , ListItem ( Integer ( 41 , 64 , true ) ) ) , ty ( 26 ) , mutabilityNot ) ) | ||
| ListItem ( typedValue ( Moved , ty ( 25 ) , mutabilityMut ) ) | ||
| ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 30 ) , mutabilityNot ) ) | ||
| ListItem ( newLocal ( ty ( 37 ) , mutabilityMut ) ) | ||
| </locals> | ||
| </currentFrame> | ||
| <stack> | ||
| ListItem ( StackFrame ( ty ( -1 ) , place (... local: local ( 0 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionContinue , ListItem ( newLocal ( ty ( 1 ) , mutabilityMut ) ) | ||
| ListItem ( typedValue ( Aggregate ( variantIdx ( 0 ) , ListItem ( Integer ( 41 , 64 , true ) ) ) , ty ( 26 ) , mutabilityNot ) ) | ||
| ListItem ( newLocal ( ty ( 25 ) , mutabilityMut ) ) | ||
| ListItem ( typedValue ( Reference ( 0 , place (... local: local ( 1 ) , projection: .ProjectionElems ) , mutabilityNot , metadata ( noMetadataSize , 0 , noMetadataSize ) ) , ty ( 30 ) , mutabilityNot ) ) | ||
| ListItem ( newLocal ( ty ( 37 ) , mutabilityMut ) ) ) ) | ||
| ListItem ( StackFrame ( ty ( -1 ) , place (... local: local ( -1 ) , projection: .ProjectionElems ) , noBasicBlockIdx , unwindActionUnreachable , .List ) ) | ||
| </stack> | ||
| </kmir> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I guess this means that any cast involving a ZST is valid? This is in a section about points to array slices being compatible, I think this needs to be under a ZST section with an explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed the current semantics writing style and tried to keep changes simple. Do you mean to move these rules to a separate section with more decriptions?