Could not reenable global-stack / No room for exception term

bug
#1

I’m using: SWI-Prolog version 8.1.5-2-gb5fc66177, compiled from source.

There seems to be a problem with how the “out of global stack” situation is handled. Here is what I observe (It is not wrong but maybe suboptimal?)

$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.1.5-2-gb5fc66177)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

    CMake built from "/home/boris/install/swipl-devel/build"

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- length(L, N).
L = [],
N = 0 ;
L = [_5708],
N = 1 ;
L = [_5708, _5714],
N = 2 .

?- length(L, N), N = 0.
L = [],
N = 0 ;
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
ERROR: Out of global-stack.
ERROR: No room for exception term.  Aborting.
Message: $aborted
C-stack trace labeled "printMessage()":
  [0] save_backtrace() at /home/boris/install/swipl-devel/build/../src/os/pl-cstack.c:336 [0x7f7fa754e6cb]
  [1] print_c_backtrace() at /home/boris/install/swipl-devel/build/../src/os/pl-cstack.c:871 [0x7f7fa754e88e]
  [2] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:912 [0x7f7fa74a13aa]
  [3] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [4] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [5] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [6] PL_next_solution() at /home/boris/install/swipl-devel/build/../src/pl-vmi.c:4376 [0x7f7fa748dca6]
  [7] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [8] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [9] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [10] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [11] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [12] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [13] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [14] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [15] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [16] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [17] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [18] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [19] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [20] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [21] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [22] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [23] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [24] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [25] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [26] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [27] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [28] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [29] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [30] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [31] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [32] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [33] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [34] query_loop() at /home/boris/install/swipl-devel/build/../src/pl-pro.c:139 [0x7f7fa74d1b8e]
  [35] prologToplevel() at /home/boris/install/swipl-devel/build/../src/pl-pro.c:467 [0x7f7fa74d23fb]
  [36] PL_toplevel() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4532 [0x7f7fa7485c2d]
  [37] swipl(+0x1075) [0x556d61cfc075]
  [38] __libc_start_main() at ??:? [0x7f7fa7272ce3]
  [39] swipl(+0x10be) [0x556d61cfc0be]
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Message: debug_mode(on)
C-stack trace labeled "printMessage()":
  [0] save_backtrace() at /home/boris/install/swipl-devel/build/../src/os/pl-cstack.c:336 [0x7f7fa754e6cb]
  [1] print_c_backtrace() at /home/boris/install/swipl-devel/build/../src/os/pl-cstack.c:871 [0x7f7fa754e88e]
  [2] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:912 [0x7f7fa74a13aa]
  [3] PL_next_solution() at /home/boris/install/swipl-devel/build/../src/pl-vmi.c:4376 [0x7f7fa748dca6]
  [4] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [5] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [6] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [7] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [8] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [9] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [10] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [11] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [12] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [13] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [14] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [15] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [16] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [17] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [18] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [19] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [20] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [21] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [22] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [23] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [24] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [25] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [26] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [27] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [28] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [29] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [30] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [31] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [32] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [33] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [34] query_loop() at /home/boris/install/swipl-devel/build/../src/pl-pro.c:139 [0x7f7fa74d1b8e]
  [35] prologToplevel() at /home/boris/install/swipl-devel/build/../src/pl-pro.c:467 [0x7f7fa74d23fb]
  [36] PL_toplevel() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4532 [0x7f7fa7485c2d]
  [37] swipl(+0x1075) [0x556d61cfc075]
  [38] __libc_start_main() at ??:? [0x7f7fa7272ce3]
  [39] swipl(+0x10be) [0x556d61cfc0be]
Message: error(resource_error(stack),stack)
C-stack trace labeled "printMessage()":
  [0] save_backtrace() at /home/boris/install/swipl-devel/build/../src/os/pl-cstack.c:336 [0x7f7fa754e6cb]
  [1] print_c_backtrace() at /home/boris/install/swipl-devel/build/../src/os/pl-cstack.c:871 [0x7f7fa754e88e]
  [2] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:912 [0x7f7fa74a13aa]
  [3] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [4] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [5] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [6] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [7] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [8] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [9] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [10] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [11] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [12] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [13] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [14] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [15] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [16] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [17] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [18] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [19] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [20] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [21] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [22] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [23] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [24] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [25] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [26] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [27] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [28] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [29] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [30] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [31] PL_call_predicate() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4092 [0x7f7fa7497828]
  [32] printMessage() at /home/boris/install/swipl-devel/build/../src/pl-error.c:897 [0x7f7fa74a1412]
  [33] PL_put_term__LD() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:2732 [0x7f7fa748dd9a]
  [34] query_loop() at /home/boris/install/swipl-devel/build/../src/pl-pro.c:139 [0x7f7fa74d1b8e]
  [35] prologToplevel() at /home/boris/install/swipl-devel/build/../src/pl-pro.c:467 [0x7f7fa74d23fb]
  [36] PL_toplevel() at /home/boris/install/swipl-devel/build/../src/pl-fli.c:4532 [0x7f7fa7485c2d]
  [37] swipl(+0x1075) [0x556d61cfc075]
  [38] __libc_start_main() at ??:? [0x7f7fa7272ce3]
  [39] swipl(+0x10be) [0x556d61cfc0be]
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
Could not reenable global-stack
% Execution Aborted
?-
#2

Thanks. Note that is only a problem in an interactive session:

9 ?- catch((length(L, N), N = 0, fail), E, true).
E = error(resource_error(stack), stack_overflow{choicepoints:4, depth:38346063, environments:9, globalused:898735, localused:1, stack:[frame(38346063, system:'$length3'(_130, _132, 38346052), []), frame(9, system:'<meta-call>'('<garbage_collected>'), []), frame(8, system:catch((:)/2, _172,  (:)/2), []), frame(7, '$toplevel':toplevel_call('<garbage_collected>'), []), frame(5, '$toplevel':'$execute_goal2'(..., ...), [])], stack_limit:1048576, trailused:3}).

Seems to run out of stack again while trying to print a nice report. I’ll have a look. Today is for more well founded semantics in tabling though :slight_smile: