kevinlawler / kona

Open-source implementation of the K programming language
ISC License
1.36k stars 138 forks source link

Instability #623

Closed john1761 closed 1 year ago

john1761 commented 2 years ago

There appears to be an instability. As far as I can tell it requires:

This seems to be a regression in that the behaviour was not present in interpreters up until early 2019. I am currently using windows only, I do not know if it exists on other platforms.

Example; bug.k:

s:{+/!x}         / needs to include the '/ over' adverb, any verb will do
test:{s[x]+s[x]} / needs to call the other function at least twice

_k               / version check - appears to regress in 2019
/s[3]            / uncomment this line and the program does not crash.
"before"
test 3
"after"

produces output:

C:\bin\k : k.exe bug.k
kona      \ for help. \\ to exit.

"2021-12-24"
"before"

C:\bin\k :

The 'after' is not displayed and buried in the windows event log is an unhelpful message about a crash.

Oddly, calling the inner function from global scope before it is called from function scope appears to prevent the crash. Presumably it is accidentally tidying a memory issue?

gitonthescene commented 2 years ago

I tested on macOS and I also get the crash with the line commented and not without.

➜  kona git:(master) ✗ ./k bug.k 
kona      \ for help. \\ to exit.

"2021-12-06"
"before"
[1]    72342 segmentation fault  ./k bug.k
➜  kona git:(master) ✗ uname -a
Darwin Macintosh.local 21.1.0 Darwin Kernel Version 21.1.0: Wed Oct 13 17:33:23 PDT 2021; root:xnu-8019.41.5~1/RELEASE_X86_64 x86_64
➜  kona git:(master) ✗ 

Just to make it easier, I've attached the script (with the suffix changed): bug.k.txt

Running git bisect with this file, I got the following:

$ git bisect good; make; ./k bug.k
1f02a068912106f8f1f8cc14e0914aceb911877e is the first bad commit
commit 1f02a068912106f8f1f8cc14e0914aceb911877e
Author: Tom Szczesny <tom@new-host-2.home>
Date:   Wed May 15 16:19:57 2019 -0400

    pass dict by value

 src/kx.c |  2 +-
 src/kx.h |  2 +-
 src/p.c  | 26 +++++++++++++-------------
 src/p.h  |  4 ++--
 src/v.c  |  2 +-
 src/v.h  |  2 +-
 6 files changed, 19 insertions(+), 19 deletions(-)
make: Nothing to be done for `all'.
kona      \ for help. \\ to exit.

  "2021-12-06"
"before"
6
"after"
$
tavmem commented 1 year ago

Got a similar result in Linux on kona

$ ./k bug.k 
kona      \ for help. \\ to exit.

"2022-08-30"
"before"
Segmentation fault (core dumped)
tavmem commented 1 year ago

in k2.8

$ ./k bug.k
K 2.8 2000-10-10 Copyright (C) 1993-2000 Kx Systems
\ for help. \\ to exit.

"2.8"
"before"
6
"after"
tavmem commented 1 year ago

The problem first appears in the commit of Sep 1, 2019 which was made by TomDuCoin to fix issue #521: Recursive call overrides earlier data

In all fairness: the 9/1/19 commit does indeed resolve issue #521 The "instability" appears to be a side effect of the #521 fix.

tavmem commented 1 year ago

This area of the code was then modified further (by me) in the commit of Nov 2, 2019 titled "fix #566 and fix #549: recursions housed in subfunctions" Obviously, the "instability" side effect remained.