gprolog icon indicating copy to clipboard operation
gprolog copied to clipboard

Resource error cannot be caught

Open UWN opened this issue 1 year ago • 3 comments

(I tried to celebrate the safe, conforming implementation of integers, but meanwhile ran against memory limits)

| ?- length(_,I),N is 2^2^I, catch(length(L,N),Err,true).

I = 0
L = [_, _]
N = 2 ? ;

I = 1
L = [_, _, _, _]
N = 4 ? ;

I = 2
L = [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]
N = 16 ? ;

I = 3
L = [_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _]
N = 256 ? ;

I = 4
L = _ % omitted
N = 65536 ? ;

Fatal Error: global stack overflow (size: 100000 Kb, reached: 99997 Kb, environment variable used: GLOBALSZ)

Expected:

I = 5
N = 4294967296
Err = error(resource_error(...),...)

The error handling mechanism is designed to catch such errors as well. Strictly speaking, an implementation does not have to handle such cases, but it does help a lot.

UWN avatar Jul 08 '23 17:07 UWN

I know, but it was a design choice: don't lose time to check stack overflow by software while the hadware (MMU+virtual memory) can do it for free. Unfortunately, it is then very difficult to continue/resume the execution after such hard error detection. Some cases could be (maybe) handled but I never find a stable and general solution working on every plateform.

didoudiaz avatar Jul 08 '23 18:07 didoudiaz

But on the other hand you permit interrupts which should be similarly difficult to handle...

UWN avatar Jul 08 '23 18:07 UWN

Just out of curiosity: How do you know that an overflow happened (and not a real bug)? In above case, it seems you do know that the heap overflowed. But if you just rely on the MMU, you cannot be sure, can you?

UWN avatar Aug 30 '23 15:08 UWN