Mercury Bugs - mercury
View Issue Details
0000559mercuryBugpublic2022-05-03 16:122022-08-03 19:41
Reporterjuliensf 
Assigned Tozs 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000559: Stack overflow in hlc.gc Mercury 22.01.1 compiler on Windows
DescriptionThe attached module is derived from a stress test for the Zinc compiler. Compiling this with a Mercury 22.0.1 compiler built in the hlc.gc results in a stack overflow on Windows when reading the module. (The significance of Window is that the stack size is very small, even though IIRC we bump it up a bit.)
(This is not a new problem, Mercury 20.01 also has the same problem.)
Steps To Reproduce
    $ mmc -C zm_hug_flat_case.m
TagsNo tags attached.
Attached Filesgz zm_huge_flat_case.m.gz (96,956) 2022-05-03 16:12
https://bugs.mercurylang.org/file_download.php?file_id=319&type=bug

Notes
(0001194)
zs   
2022-05-03 18:06   
I believe I have diagnosed the problem, though I cannot confirm it,
since I am not set up to program on Windows.

Compiling zm_huge_flat_case.m with a debug grade compiler under mdb,
the command "min_depth 10000" shows very deep mutual recursion in
parse_goal.m between parse_goal, parse_non_call_goal, and parse_goal_semicolon.
Basically, you need three stack frames for each disjunct in that big
disjunction, and the different determinisms (parse_non_call_goal is semidet,
the others are det) prevent both the MLDS and the LLDS code generator
from being able to do tail recursion.

I have an idea for a solution and will try it out tomorrow, but it may
add some overhead. Once I have an implementation ready, I will need you
to run some benchmarks to see whether it adds any overhead for run-of-the-mill,
non-extreme Mercury code, and if so, whether that overhead is significant.
(0001201)
zs   
2022-08-03 19:41   
Last part of the fix committed 2022 may 7.

Issue History
2022-05-03 16:12juliensfNew Issue
2022-05-03 16:12juliensfFile Added: zm_huge_flat_case.m.gz
2022-05-03 18:06zsNote Added: 0001194
2022-05-03 18:07zsAssigned To => zs
2022-05-03 18:07zsStatusnew => assigned
2022-08-03 19:41zsStatusassigned => resolved
2022-08-03 19:41zsResolutionopen => fixed
2022-08-03 19:41zsNote Added: 0001201