Execution of byte-code with recompile in-between breaks normal execution flow (e. g. disregards "return" or "break" commands).
PoC:
set i [interp create]
$i eval {proc _recompile_ {} {rename set __set; rename __set set}}
$i eval {puts A; puts B; return; puts C}
$i eval {puts A; _recompile_; puts B; return; puts C}
The last eval does not return before puts C.
35c83160d6closes [fa6bf38d07]: integrate bug-fa6bf38d07-v2 check-in2019-08-27 18:27:05a03e05de6efixes [fa6bf38d07]: command invocation (NRE callback to TEBCResume) caused by execution of recompiled TEBC (on epoch bump) check-in2019-08-27 15:00:44f7ece56ca2added tests covering bug [fa6bf38d07] check-in2019-08-27 12:03:51
This is also not slave (interp-command) related issue, same with in main-interp within tclsh (compiled Tcl_RecordAndEval):
Just strange, the issue is not reproducible at all with
proc _recompile_ {} {rename set __set; rename __set set}
puts A; _recompile_; puts B; return; puts C
if 1 {puts A; _recompile_; puts B; return; puts C}
set i 0; while {[incr i] < 10} {puts A; _recompile_; puts B; return; puts C}
eval, namespace eval/inscope ::, or if invoked like a proc.
It looks like the issue is not restricted to "returnImm" instruction.
Trying to check command "break" issued with:
As assumed it seems to be NRE (because 8.5 was not affected), so possibly [c718302fcab3892c] causes that (so ISC peephole, e. g. NRE-related switch to direct invocation, is implemented not correct, or it got broken later with some further commits).
% set i 0; while {[incr i] < 10} { puts A; _recompile_; puts B; break; puts C }
A
B
invoked "break" outside of a loop"
A piece of the puzzle is the special handling of exceptional return codes when (interp->numLevels == 0). The restarted evaluation of a recompile is probably not recreating the same value of that field as the first pass.
Sure, just I think it is rather an after effect (looks like a continuation with direct execution, resp. GetSrcInfoForPc() starts retriving from wrong current command)...
So for some reason in case of a while-loop (without a break), bumping of epoch causes "direct" execution starting from incr i, not by puts B.
So it is called firstly after whole single iteration (while-body) is processed.
Also debugging of other cases shows strange continuation points in instStartCmdFailed.
There is possibly a related issue [723a2f4ac3]
Should be fixed now in branch bug-fa6bf38d07.
After small review I provided another variant as bug-fa6bf38d07-v2, with a simplification (used the same "fixed" (and faster) code for INST_EVAL_STK).