@@ -308,21 +308,33 @@ The call stack is not necessarily empty at this point so it is left untouched.
308308` Call ` is calling another function, setting up its stack frame and
309309where the returned result should go.
310310
311-
312311``` k
313- // Intrinsic function call - execute directly without state switching
314- rule [termCallIntrinsic]: <k> #execTerminator(terminator(terminatorKindCall(FUNC, ARGS, DEST, TARGET, _UNWIND), _SPAN)) ~> _
315- =>
316- #execIntrinsic(lookupFunction(#tyOfCall(FUNC)), ARGS, DEST) ~> #continueAt(TARGET)
312+ syntax KItem ::= #execTerminatorCall(fty: Ty, func: MonoItemKind, args: Operands, destination: Place, target: MaybeBasicBlockIdx, unwind: UnwindAction)
313+
314+ rule <k> #execTerminator(terminator(terminatorKindCall(operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, Ty, _))), ARGS, DEST, TARGET, UNWIND), _SPAN))
315+ => #execTerminatorCall(Ty, lookupFunction(Ty), ARGS, DEST, TARGET, UNWIND)
316+ ...
317317 </k>
318- requires isIntrinsicFunction(lookupFunction(#tyOfCall(FUNC)))
318+
319+ rule <k> #execTerminator(terminator(terminatorKindCall(operandMove(place(local(I), .ProjectionElems)), ARGS, DEST, TARGET, UNWIND), _SPAN))
320+ => #execTerminatorCall(tyOfLocal(getLocal(LOCALS, I)), lookupFunction(tyOfLocal(getLocal(LOCALS, I))), ARGS, DEST, TARGET, UNWIND)
321+ ...
322+ </k>
323+ <locals> LOCALS </locals>
324+
325+ // Intrinsic function call - execute directly without state switching
326+ rule [termCallIntrinsic]:
327+ <k> #execTerminatorCall(_, FUNC, ARGS, DEST, TARGET, _UNWIND) ~> _
328+ => #execIntrinsic(FUNC, ARGS, DEST) ~> #continueAt(TARGET)
329+ </k>
330+ requires isIntrinsicFunction(FUNC)
319331
320332 // Regular function call - full state switching and stack setup
321- rule [termCallFunction]: <k> #execTerminator(terminator(terminatorKindCall(FUNC, ARGS, DEST, TARGET, UNWIND), _SPAN)) ~> _
322- =>
323- #setUpCalleeData(lookupFunction(#tyOfCall( FUNC)) , ARGS)
333+ rule [termCallFunction]:
334+ <k> #execTerminatorCall(FTY, FUNC, ARGS, DEST, TARGET, UNWIND) ~> _
335+ => #setUpCalleeData(FUNC, ARGS)
324336 </k>
325- <currentFunc> CALLER => #tyOfCall(FUNC) </currentFunc>
337+ <currentFunc> CALLER => FTY </currentFunc>
326338 <currentFrame>
327339 <currentBody> _ </currentBody>
328340 <caller> OLDCALLER => CALLER </caller>
@@ -332,7 +344,7 @@ where the returned result should go.
332344 <locals> LOCALS </locals>
333345 </currentFrame>
334346 <stack> STACK => ListItem(StackFrame(OLDCALLER, OLDDEST, OLDTARGET, OLDUNWIND, LOCALS)) STACK </stack>
335- requires notBool isIntrinsicFunction(lookupFunction(#tyOfCall( FUNC)) )
347+ requires notBool isIntrinsicFunction(FUNC)
336348
337349 syntax Bool ::= isIntrinsicFunction(MonoItemKind) [function]
338350 rule isIntrinsicFunction(IntrinsicFunction(_)) => true
@@ -341,11 +353,6 @@ where the returned result should go.
341353 syntax KItem ::= #continueAt(MaybeBasicBlockIdx)
342354 rule <k> #continueAt(someBasicBlockIdx(TARGET)) => #execBlockIdx(TARGET) ... </k>
343355 rule <k> #continueAt(noBasicBlockIdx) => .K ... </k>
344-
345- syntax Ty ::= #tyOfCall( Operand ) [function, total]
346-
347- rule #tyOfCall(operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, Ty, _)))) => Ty
348- rule #tyOfCall(_) => ty(-1) [owise] // copy, move, non-zero size: not supported
349356```
350357
351358The 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.
@@ -415,7 +422,8 @@ An operand may be a `Reference` (the only way a function could access another fu
415422 andBool isTypedValue(CALLERLOCALS[I])
416423 [preserves-definedness] // valid list indexing checked
417424
418- rule <k> #setArgFromStack(IDX, operandMove(place(local(I), .ProjectionElems)))
425+ // TODO: This is not safe, need to add more checks to this.
426+ rule <k> #setArgFromStack(IDX, operandMove(place(local(I), _)))
419427 =>
420428 #setLocalValue(place(local(IDX), .ProjectionElems), #incrementRef(getValue(CALLERLOCALS, I)))
421429 ...
0 commit comments