Skip to content
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 deps/pyproject-build-systems
Original file line number Diff line number Diff line change
@@ -1 +1 @@
795a980d25301e5133eca37adae37283ec3c8e66
042904167604c681a090c07eb6967b4dd4dae88c
2 changes: 1 addition & 1 deletion deps/stable-mir-json
Submodule stable-mir-json updated 31 files
+38 −2 src/printer.rs
+2 −2 tests/integration/normalise-filter.jq
+99 −194 tests/integration/programs/assert_eq.smir.json.expected
+249 −498 tests/integration/programs/binop.smir.json.expected
+52 −104 tests/integration/programs/char-trivial.smir.json.expected
+62 −124 tests/integration/programs/closure-args.smir.json.expected
+58 −116 tests/integration/programs/closure-no-args.smir.json.expected
+60 −120 tests/integration/programs/const-arithm-simple.smir.json.expected
+65 −130 tests/integration/programs/div.smir.json.expected
+55 −110 tests/integration/programs/double-ref-deref.smir.json.expected
+47 −94 tests/integration/programs/enum.smir.json.expected
+69 −138 tests/integration/programs/fibonacci.smir.json.expected
+70 −140 tests/integration/programs/float.smir.json.expected
+6 −0 tests/integration/programs/fn-ptr-in-arg.rs
+7,489 −0 tests/integration/programs/fn-ptr-in-arg.smir.json.expected
+65 −130 tests/integration/programs/modulo.smir.json.expected
+68 −136 tests/integration/programs/mutual_recursion.smir.json.expected
+56 −112 tests/integration/programs/option-construction.smir.json.expected
+104 −204 tests/integration/programs/param_types.smir.json.expected
+59 −118 tests/integration/programs/primitive-type-bounds.smir.json.expected
+62 −124 tests/integration/programs/recursion-simple-match.smir.json.expected
+62 −124 tests/integration/programs/recursion-simple.smir.json.expected
+53 −106 tests/integration/programs/ref-deref.smir.json.expected
+106 −212 tests/integration/programs/shl_min.smir.json.expected
+122 −246 tests/integration/programs/slice.smir.json.expected
+55 −110 tests/integration/programs/strange-ref-deref.smir.json.expected
+59 −118 tests/integration/programs/struct.smir.json.expected
+75 −150 tests/integration/programs/sum-to-n.smir.json.expected
+73 −146 tests/integration/programs/tuple-eq.smir.json.expected
+55 −110 tests/integration/programs/tuples-simple.smir.json.expected
+86 −172 tests/integration/programs/weirdRefs.smir.json.expected
2 changes: 1 addition & 1 deletion deps/stable-mir-json_release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20a1bbdfc1fb36fb19539d0d4d91f5a437be7de6
626e8fed0470078c4d980b6b5b503a3aceb355ec
2 changes: 1 addition & 1 deletion deps/uv2nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c8cf711802cb00b2e05d5c54d3486fce7bfc8f7c
4cca323a547a1aaa9b94929c4901bed5343eafe8
2 changes: 1 addition & 1 deletion deps/uv_release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.9
0.9.14
36 changes: 18 additions & 18 deletions flake.lock

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

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

flake-utils.url = "github:numtide/flake-utils";

stable-mir-json-flake.url = "github:runtimeverification/stable-mir-json/20a1bbdfc1fb36fb19539d0d4d91f5a437be7de6";
stable-mir-json-flake.url = "github:runtimeverification/stable-mir-json/626e8fed0470078c4d980b6b5b503a3aceb355ec";
stable-mir-json-flake = {
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
Expand All @@ -18,7 +18,7 @@
inputs.nixpkgs.follows = "nixpkgs";
};

uv2nix.url = "github:pyproject-nix/uv2nix/c8cf711802cb00b2e05d5c54d3486fce7bfc8f7c";
uv2nix.url = "github:pyproject-nix/uv2nix/4cca323a547a1aaa9b94929c4901bed5343eafe8";
# uv2nix requires a newer version of nixpkgs
# therefore, we pin uv2nix specifically to a newer version of nixpkgs
# until we replaced our stale version of nixpkgs with an upstream one as well
Expand All @@ -27,7 +27,7 @@
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
uv2nix.inputs.nixpkgs.follows = "nixpkgs-unstable";
# uv2nix.inputs.nixpkgs.follows = "nixpkgs";
pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/795a980d25301e5133eca37adae37283ec3c8e66";
pyproject-build-systems.url = "github:pyproject-nix/build-system-pkgs/042904167604c681a090c07eb6967b4dd4dae88c";
pyproject-build-systems = {
inputs.nixpkgs.follows = "uv2nix/nixpkgs";
inputs.uv2nix.follows = "uv2nix";
Expand Down
42 changes: 25 additions & 17 deletions kmir/src/kmir/kdist/mir-semantics/kmir.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,33 @@ The call stack is not necessarily empty at this point so it is left untouched.
`Call` is calling another function, setting up its stack frame and
where the returned result should go.


```k
// Intrinsic function call - execute directly without state switching
rule [termCallIntrinsic]: <k> #execTerminator(terminator(terminatorKindCall(FUNC, ARGS, DEST, TARGET, _UNWIND), _SPAN)) ~> _
=>
#execIntrinsic(lookupFunction(#tyOfCall(FUNC)), ARGS, DEST) ~> #continueAt(TARGET)
syntax KItem ::= #execTerminatorCall(fty: Ty, func: MonoItemKind, args: Operands, destination: Place, target: MaybeBasicBlockIdx, unwind: UnwindAction)

rule <k> #execTerminator(terminator(terminatorKindCall(operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, Ty, _))), ARGS, DEST, TARGET, UNWIND), _SPAN))
=> #execTerminatorCall(Ty, lookupFunction(Ty), ARGS, DEST, TARGET, UNWIND)
...
</k>
requires isIntrinsicFunction(lookupFunction(#tyOfCall(FUNC)))

rule <k> #execTerminator(terminator(terminatorKindCall(operandMove(place(local(I), .ProjectionElems)), ARGS, DEST, TARGET, UNWIND), _SPAN))
=> #execTerminatorCall(tyOfLocal(getLocal(LOCALS, I)), lookupFunction(tyOfLocal(getLocal(LOCALS, I))), ARGS, DEST, TARGET, UNWIND)
...
</k>
<locals> LOCALS </locals>

// Intrinsic function call - execute directly without state switching
rule [termCallIntrinsic]:
<k> #execTerminatorCall(_, FUNC, ARGS, DEST, TARGET, _UNWIND) ~> _
=> #execIntrinsic(FUNC, ARGS, DEST) ~> #continueAt(TARGET)
</k>
requires isIntrinsicFunction(FUNC)

// Regular function call - full state switching and stack setup
rule [termCallFunction]: <k> #execTerminator(terminator(terminatorKindCall(FUNC, ARGS, DEST, TARGET, UNWIND), _SPAN)) ~> _
=>
#setUpCalleeData(lookupFunction(#tyOfCall(FUNC)), ARGS)
rule [termCallFunction]:
<k> #execTerminatorCall(FTY, FUNC, ARGS, DEST, TARGET, UNWIND) ~> _
=> #setUpCalleeData(FUNC, ARGS)
</k>
<currentFunc> CALLER => #tyOfCall(FUNC) </currentFunc>
<currentFunc> CALLER => FTY </currentFunc>
<currentFrame>
<currentBody> _ </currentBody>
<caller> OLDCALLER => CALLER </caller>
Expand All @@ -332,7 +344,7 @@ where the returned result should go.
<locals> LOCALS </locals>
</currentFrame>
<stack> STACK => ListItem(StackFrame(OLDCALLER, OLDDEST, OLDTARGET, OLDUNWIND, LOCALS)) STACK </stack>
requires notBool isIntrinsicFunction(lookupFunction(#tyOfCall(FUNC)))
requires notBool isIntrinsicFunction(FUNC)

syntax Bool ::= isIntrinsicFunction(MonoItemKind) [function]
rule isIntrinsicFunction(IntrinsicFunction(_)) => true
Expand All @@ -341,11 +353,6 @@ where the returned result should go.
syntax KItem ::= #continueAt(MaybeBasicBlockIdx)
rule <k> #continueAt(someBasicBlockIdx(TARGET)) => #execBlockIdx(TARGET) ... </k>
rule <k> #continueAt(noBasicBlockIdx) => .K ... </k>

syntax Ty ::= #tyOfCall( Operand ) [function, total]

rule #tyOfCall(operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, Ty, _)))) => Ty
rule #tyOfCall(_) => ty(-1) [owise] // copy, move, non-zero size: not supported
```

The local data has to be set up for the call, which requires information about the local variables of a call. This step is separate from the above call stack setup because it needs to retrieve the locals declaration from the body. Arguments to the call are `Operands` which refer to the old locals (`OLDLOCALS` below), and the data is either _copied_ into the new locals using `#setArgs`, or it needs to be _shared_ via references.
Expand Down Expand Up @@ -415,7 +422,8 @@ An operand may be a `Reference` (the only way a function could access another fu
andBool isTypedValue(CALLERLOCALS[I])
[preserves-definedness] // valid list indexing checked

rule <k> #setArgFromStack(IDX, operandMove(place(local(I), .ProjectionElems)))
// TODO: This is not safe, need to add more checks to this.
rule <k> #setArgFromStack(IDX, operandMove(place(local(I), _)))
=>
#setLocalValue(place(local(IDX), .ProjectionElems), #incrementRef(getValue(CALLERLOCALS, I)))
...
Expand Down
11 changes: 11 additions & 0 deletions kmir/src/kmir/kdist/mir-semantics/rt/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ Constant operands are simply decoded according to their type.
requires typeInfoVoidType =/=K lookupTy(TY)
```

Function pointers are zero-sized constants whose `Ty` is a key in the function table instaed of the type table.

```k
rule <k> operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, ty(ID) #as TY, _)))
=> FunPtr(TY)
...
</k>
requires typeInfoVoidType ==K lookupTy(TY) // not a valid type info
andBool lookupFunction(TY) =/=K monoItemFn(symbol("** UNKNOWN FUNCTION **"), defId(ID), noBody ) // valid function Ty
```

### Copying and Moving

When an operand is `Copied` by a read, the original remains valid (see `false` passed to `#readProjection`).
Expand Down
2 changes: 2 additions & 0 deletions kmir/src/kmir/kdist/mir-semantics/rt/value.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ The special `Moved` value represents values that have been used and should not b
[symbol(Value::PtrLocal)]
// pointer to a local TypedValue (on the stack)
// fields are the same as in Reference
| FunPtr ( Ty )
// function pointer, created by operandConstant only. Ty is a key in the function table
| AllocRef ( AllocId , ProjectionElems , Metadata )
[symbol(Value::AllocRef)]
// reference to static allocation, by AllocId, possibly projected, carrying metadata if applicable
Expand Down
Loading