Opened 11 years ago

Closed 10 years ago

#2797 closed merge (fixed)

ghci stack overflows when ghc does not

Reported by: TristanAllwood Owned by: igloo
Priority: normal Milestone: 6.12.2
Component: GHCi Version: 6.11
Keywords: Cc: fasta
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Happens with today's HEAD and 6.10.1

I appreciate I am playing a little fast and loose by using unsafePerformIO.

module Main where

import System.IO.Unsafe

main :: IO ()
main = do
  bar [] 5000000 `seq` return ()

bar :: [()] -> Int -> Int
bar stk 0 = error $ show stk
bar stk n = stk `seq` bar (push stk) (n-1)

push :: [()] -> [()]
push stk = unsafePerformIO . return $ take 2 (():stk)
$ ~/ghc/ghc/ghc/stage2-inplace/ghc -O0 --make -o GT2 ghciTest2.hs 
[1 of 1] Compiling Main             ( ghciTest2.hs, ghciTest2.o )
Linking GT2.exe ...

t-trallw@MSRC-1326435 ~/ghc/ghc-Stack-Tests
$ ./GT2.exe +RTS -k0.01k -K0.01k
GT2.exe: [(),()]

t-trallw@MSRC-1326435 ~/ghc/ghc-Stack-Tests
$ rm *.o *.exe *.hi ; ~/ghc/ghc/ghc/stage2-inplace/ghc -e 'main' ghciTest2.hs +RTS -K40M
Stack space overflow: current size 40000000 bytes.
Use `+RTS -Ksize' to increase it.

Using -K400M ghci does get there.

Change History (10)

comment:1 Changed 11 years ago by TristanAllwood

Also may be of interest: Compiling with hpc doesn't change the executable behaviour.

$ ~/ghc/ghc/ghc/stage2-inplace/ghc -fhpc -O0 --make -o GT2 
ghciTest2.hs 
[1 of 1] Compiling Main             ( ghciTest2.hs, ghciTest2.o )
Linking GT2.exe ...

t-trallw@MSRC-1326435 ~/ghc/ghc-Stack-Tests
$ ./GT2.exe +RTS -k0.01k -K0.01k
GT2.exe: [(),()]

comment:2 Changed 11 years ago by TristanAllwood

The plot thickens. Interpreting with -fhpc is fine...

$ rm *.o *.exe *.hi ; ~/ghc/ghc/ghc/stage2-inplace/ghc -fhpc -e 'main' ghciTest2.hs      
rm: cannot remove `*.o': No such file or directory
rm: cannot remove `*.exe': No such file or directory
rm: cannot remove `*.hi': No such file or directory
<interactive>: [(),()]

comment:3 Changed 11 years ago by igloo

difficulty: Unknown
Milestone: 6.10.2
Type: bugrun-time performance bug

comment:4 Changed 11 years ago by igloo

In my profiling HEAD, I'm seeing

(gdb) r [...] -e main z.hs +RTS -DS
[Thread debugging using libthread_db enabled]
[New process 4968]
<interactive>: internal error: ASSERTION FAILED: file (null), line 698

    (GHC version 6.11.20090308 for x86_64_unknown_linux)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
[New Thread 139638659299040 (LWP 4968)]

Program received signal SIGABRT, Aborted.
[Switching to Thread 139638659299040 (LWP 4968)]
0x00007f0027811ef5 in raise () from /lib/libc.so.6
(gdb) bt
#0  0x00007f0027811ef5 in raise () from /lib/libc.so.6
#1  0x00007f0027813413 in abort () from /lib/libc.so.6
#2  0x00000000049a1278 in rtsFatalInternalErrorFn (
    s=0x51b3520 "ASSERTION FAILED: file %s, line %u\n", ap=0x7fff30c30cd0)
    at RtsMessages.c:164
#3  0x00000000049a0e3c in barf (
    s=0x51b3520 "ASSERTION FAILED: file %s, line %u\n") at RtsMessages.c:40
#4  0x00000000049a0e96 in _assertFail (filename=0x0, linenum=698)
    at RtsMessages.c:55
#5  0x00000000049c66c6 in stg_ap_pp_info ()
#6  0x0000000000000000 in ?? ()

Looks like this is the assertion in AutoApply_debug_p.cmm here:

        case FUN,
             FUN_1_0,
             FUN_0_1,
             FUN_2_0,
             FUN_1_1,
             FUN_0_2,
             FUN_STATIC: {
            arity = TO_W_(StgFunInfoExtra_arity(%FUN_INFO(info)));
            ASSERT(arity > 0);
            if (arity == 1) {
                R2 = W_[Sp+WDS(1)];
                W_[Sp+WDS(1)] = stg_ap_p_info;
                Sp_adj(1);
                R1 = R1 + 1;
                jump %GET_ENTRY(UNTAG(R1));
            }

comment:5 Changed 10 years ago by igloo

Milestone: 6.10.26.12.1

comment:6 Changed 10 years ago by simonmar

Type of failure: Runtime performance bug

comment:7 Changed 10 years ago by igloo

Milestone: 6.12.16.12.2

comment:8 Changed 10 years ago by fasta

Cc: fasta added

comment:9 Changed 10 years ago by simonmar

Owner: set to igloo
Type: bugmerge

Fixed (sort of):

Thu Jan 28 12:44:54 GMT 2010  Simon Marlow <marlowsd@gmail.com>
  * tweak the totally-bogus arbitrary stack-squeezing heuristic to fix #2797
  In #2797, a program that ran in constant stack space when compiled
  needed linear stack space when interpreted.  It turned out to be
  nothing more than stack-squeezing not happening.  We have a heuristic
  to avoid stack-squeezing when it would be too expensive (shuffling a
  large amount of memory to save a few words), but in some cases even
  expensive stack-squeezing is necessary to avoid linear stack usage.
  One day we should implement stack chunks, which would make this less
  expensive.

comment:10 Changed 10 years ago by igloo

Resolution: fixed
Status: newclosed

Merged

Note: See TracTickets for help on using tickets.