Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Execution of byte-code with recompile in-between breaks normal execution flow (e. g. disregards "return" or "break" commands).

Closed / Fixedfa6bf38d0728fbc7c7146f798ce0e3e35c70146cCreated 7 years agoUpdated 7 years ago
Descriptionwiki2019-08-26 14:02:29
Execution of byte-code after TEBC recompilation initiated from peephole breaks normal execution flow (e. g. disregards "return" or "break" commands) if some command or proc before would bump compiler epoch (cause recompile of a code in-between).

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.

Referenced by3
sebres Ticket [fa6bf38d07]: 3 changes [History diff]2019-08-26 14:03:31
sebreswiki2019-08-26 14:44:10

This is also not slave (interp-command) related issue, same with in main-interp within tclsh (compiled Tcl_RecordAndEval):

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}
Just strange, the issue is not reproducible at all with eval, namespace eval/inscope ::, or if invoked like a proc.

sebreswiki2019-08-26 15:41:18

It looks like the issue is not restricted to "returnImm" instruction.
Trying to check command "break" issued with:

% set i 0; while {[incr i] < 10} { puts A; _recompile_; puts B; break; puts C }
A
B
invoked "break" outside of a loop"
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).

sebres Ticket [fa6bf38d07]: 4 changes [History diff]2019-08-26 17:01:25
dgpplain2019-08-26 19:58:16
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.
sebreswiki2019-08-27 11:11:20

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.

sebreswiki2019-08-27 12:12:29

There is possibly a related issue [723a2f4ac3]

sebreswiki2019-08-27 15:03:40

Should be fixed now in branch bug-fa6bf38d07.

sebreswiki2019-08-27 15:42:26

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).

sebres Closed ticket [fa6bf38d07]. [History diff]2019-08-28 14:42:08
Log in (anonymous is fine) to add a comment.