@@ -305,21 +305,33 @@ The call stack is not necessarily empty at this point so it is left untouched.
305305` Call ` is calling another function, setting up its stack frame and
306306where the returned result should go.
307307
308-
309308``` k
310- // Intrinsic function call - execute directly without state switching
311- rule [termCallIntrinsic]: <k> #execTerminator(terminator(terminatorKindCall(FUNC, ARGS, DEST, TARGET, _UNWIND), _SPAN)) ~> _
312- =>
313- #execIntrinsic(lookupFunction(#tyOfCall(FUNC)), ARGS, DEST) ~> #continueAt(TARGET)
309+ syntax KItem ::= #execTerminatorCall(fty: Ty, func: MonoItemKind, args: Operands, destination: Place, target: MaybeBasicBlockIdx, unwind: UnwindAction)
310+
311+ rule <k> #execTerminator(terminator(terminatorKindCall(operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, Ty, _))), ARGS, DEST, TARGET, UNWIND), _SPAN))
312+ => #execTerminatorCall(Ty, lookupFunction(Ty), ARGS, DEST, TARGET, UNWIND)
313+ ...
314314 </k>
315- requires isIntrinsicFunction(lookupFunction(#tyOfCall(FUNC)))
315+
316+ rule <k> #execTerminator(terminator(terminatorKindCall(operandMove(place(local(I), .ProjectionElems)), ARGS, DEST, TARGET, UNWIND), _SPAN))
317+ => #execTerminatorCall(tyOfLocal(getLocal(LOCALS, I)), lookupFunction(tyOfLocal(getLocal(LOCALS, I))), ARGS, DEST, TARGET, UNWIND)
318+ ...
319+ </k>
320+ <locals> LOCALS </locals>
321+
322+ // Intrinsic function call - execute directly without state switching
323+ rule [termCallIntrinsic]:
324+ <k> #execTerminatorCall(_, FUNC, ARGS, DEST, TARGET, _UNWIND) ~> _
325+ => #execIntrinsic(FUNC, ARGS, DEST) ~> #continueAt(TARGET)
326+ </k>
327+ requires isIntrinsicFunction(FUNC)
316328
317329 // Regular function call - full state switching and stack setup
318- rule [termCallFunction]: <k> #execTerminator(terminator(terminatorKindCall(FUNC, ARGS, DEST, TARGET, UNWIND), _SPAN)) ~> _
319- =>
320- #setUpCalleeData(lookupFunction(#tyOfCall( FUNC)) , ARGS)
330+ rule [termCallFunction]:
331+ <k> #execTerminatorCall(FTY, FUNC, ARGS, DEST, TARGET, UNWIND) ~> _
332+ => #setUpCalleeData(FUNC, ARGS)
321333 </k>
322- <currentFunc> CALLER => #tyOfCall(FUNC) </currentFunc>
334+ <currentFunc> CALLER => FTY </currentFunc>
323335 <currentFrame>
324336 <currentBody> _ </currentBody>
325337 <caller> OLDCALLER => CALLER </caller>
@@ -329,7 +341,7 @@ where the returned result should go.
329341 <locals> LOCALS </locals>
330342 </currentFrame>
331343 <stack> STACK => ListItem(StackFrame(OLDCALLER, OLDDEST, OLDTARGET, OLDUNWIND, LOCALS)) STACK </stack>
332- requires notBool isIntrinsicFunction(lookupFunction(#tyOfCall( FUNC)) )
344+ requires notBool isIntrinsicFunction(FUNC)
333345
334346 syntax Bool ::= isIntrinsicFunction(MonoItemKind) [function]
335347 rule isIntrinsicFunction(IntrinsicFunction(_)) => true
@@ -338,11 +350,6 @@ where the returned result should go.
338350 syntax KItem ::= #continueAt(MaybeBasicBlockIdx)
339351 rule <k> #continueAt(someBasicBlockIdx(TARGET)) => #execBlockIdx(TARGET) ... </k>
340352 rule <k> #continueAt(noBasicBlockIdx) => .K ... </k>
341-
342- syntax Ty ::= #tyOfCall( Operand ) [function, total]
343-
344- rule #tyOfCall(operandConstant(constOperand(_, _, mirConst(constantKindZeroSized, Ty, _)))) => Ty
345- rule #tyOfCall(_) => ty(-1) [owise] // copy, move, non-zero size: not supported
346353```
347354
348355The 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.
@@ -412,7 +419,8 @@ An operand may be a `Reference` (the only way a function could access another fu
412419 andBool isTypedValue(CALLERLOCALS[I])
413420 [preserves-definedness] // valid list indexing checked
414421
415- rule <k> #setArgFromStack(IDX, operandMove(place(local(I), .ProjectionElems)))
422+ // TODO: This is not safe, need to add more checks to this.
423+ rule <k> #setArgFromStack(IDX, operandMove(place(local(I), _)))
416424 =>
417425 #setLocalValue(place(local(IDX), .ProjectionElems), #incrementRef(getValue(CALLERLOCALS, I)))
418426 ...
0 commit comments