I'm trying to play around with GHC's memo function,
but am encountering segmentation faults whenever 
I try to get a heap profile of a simple program 
that uses memo, as indicated in the following 
transcript: 

  [fturbak@lefkas test]$ GHCMemoCyclist 2 10 
  01
  [fturbak@lefkas test]$ GHCMemoCyclist 2 100
  01
  [fturbak@lefkas test]$ GHCMemoCyclist 2 10 +RTS -hC
  01
  Segmentation fault
  [fturbak@lefkas test]$ GHCMemoCyclist 2 100 +RTS -hC
  Segmentation fault

Below are:

(1) The contents of my program file GHCMemoCyclist.hs
(2) The contents of my Makefile
(3) A transcript of ghc-4.08 compling GHCMemoCyclist.hs 
    with the -v flag on. 

Please let me know if you have any insight into this
problem. The experiments I'm working on are part of 
an ICFP paper that I'm working on with Joe Wells that
must be submitted this coming Thursday (March 15). 

Thanks for any help you can provide!

- lyn -


-------------------------------------------------------------------------------
-- (1) Contents of GHCMemoCyclist.hs

-- GHC supports a memo library. Here is a simple experiment
-- using the memo function in this library. According to 
-- the documentation, memo probably won't memoize well 
-- here since the arguments to the memoized function are integers. 

module Main where

import Memo -- GHC's memo library 
import Numeric 
import System
import IO

main = do [arg1, arg2] <- getArgs
          m <- stringToInt arg1
          n <- stringToInt arg2
          cyclist m n

-- stringToInt :: String -> I0 Int
stringToInt str = 
  case readDec str of
    [(n,"")] -> return n
    _ -> do putStr ("Improper number rep " ++ str)
            return 0

cyclist m n = 
  do putStr (show (cycl!!n))
     putStrLn (show (cycl!!(n+1)))
  where 
    cycl = inflistMemo inc 0
    inc x = mod (x+1) m

inflistMemo f = memo (\ x -> x : (inflistMemo f (f x)))

-------------------------------------------------------------------------------
-- (2) Contents of Makefile

# Note: I am using ghc-4.08 and gcc version 2.95 for these tests. 
HC      = /home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/bin/ghc-4.08 
-lHSutil_p -lHSlang_p -lHSconcurrent_p
HC_OPTS = -v -O 
-i.:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/ghc/lib/std:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/concurrent:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/lang
 -prof -auto-all

SRCS = GHCMemoCyclist.hs

.SUFFIXES : .o .hs .hi .lhs .hc .s

# Standard suffix rules
.o.hi:
        @:
.lhs.o:
        $(HC) -c $< $(HC_OPTS)

.hs.o:
        $(HC) -c $< $(HC_OPTS)

depend:
        $(HC) -M $(HC_OPTS) $(SRCS)

# Other 

GHCMemoCyclist: GHCMemoCyclist.o 
        $(HC) $(HC_OPTS) -o GHCMemoCyclist GHCMemoCyclist.o 

GHCMemoCyclist-1K: GHCMemoCyclist
        GHCMemoCyclist 2 1000 +RTS -hC 
        mv GHCMemoCyclist.hp GHCMemoCyclist-1K.hp 
        hp2ps GHCMemoCyclist-1K.hp 
        gv -seascape GHCMemoCyclist-1K.ps & 

# DO NOT DELETE: Beginning of Haskell dependencies
GHCMemoCyclist.o : GHCMemoCyclist.hs
GHCMemoCyclist.o : 
/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util/Memo.hi
# DO NOT DELETE: End of Haskell dependencies

-------------------------------------------------------------------------------
-- (3) Transcript of making GHCMemoCyclist

make GHCMemoCyclist
make: *** Warning: File `GHCMemoCyclist.hs' has modification time in the future 
(984350690 > 984350667)
/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/bin/ghc-4.08 -lHSutil_p 
-lHSlang_p -lHSconcurrent_p -c GHCMemoCyclist.hs -O 
-i.:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/ghc/lib/std:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/concurrent:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/lang
 -prof -auto-all
/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/bin/ghc-4.08 -lHSutil_p 
-lHSlang_p -lHSconcurrent_p -O 
-i.:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/ghc/lib/std:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/concurrent:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/lang
 -prof -auto-all -o GHCMemoCyclist GHCMemoCyclist.o 
make: *** Warning:  Clock skew detected.  Your build may be incomplete.
[fturbak@lefkas test]$ GHCMemoCyclist 2 10
01
[fturbak@lefkas test]$ GHCMemoCyclist 2 100
01
[fturbak@lefkas test]$ GHCMemoCyclist 2 10 +RTS -hC
01
Segmentation fault
[fturbak@lefkas test]$ !ma
make GHCMemoCyclist
make: `GHCMemoCyclist' is up to date.
[fturbak@lefkas test]$ !ma
make GHCMemoCyclist
make: *** Warning: File `Makefile' has modification time in the future (984350762 > 
984350743)
make: `GHCMemoCyclist' is up to date.
make: *** Warning:  Clock skew detected.  Your build may be incomplete.
[fturbak@lefkas test]$ GHCMemoCyclist 2 10 
01
[fturbak@lefkas test]$ GHCMemoCyclist 2 100
01
[fturbak@lefkas test]$ GHCMemoCyclist 2 10 +RTS -hC
01
Segmentation fault
[fturbak@lefkas test]$ GHCMemoCyclist 2 100 +RTS -hC
Segmentation fault
[fturbak@lefkas test]$ !ma
make GHCMemoCyclist
make: `GHCMemoCyclist' is up to date.
[fturbak@lefkas test]$ touch GHCMemoCyclist.hs
[fturbak@lefkas test]$ !ma
make GHCMemoCyclist
/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/bin/ghc-4.08 -lHSutil_p 
-lHSlang_p -lHSconcurrent_p -c GHCMemoCyclist.hs -v -O 
-i.:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/ghc/lib/std:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/concurrent:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/lang
 -prof -auto-all
The Glorious Glasgow Haskell Compilation System, version 4.08

Effective command line: -lHSutil_p -lHSlang_p -lHSconcurrent_p -c -v -O 
-i.:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/ghc/lib/std:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/concurrent:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/lang
 -prof -auto-all

Ineffective C pre-processor:
        echo '{-# LINE 1 "GHCMemoCyclist.hs" -}' > /tmp/ghc22706.cpp && cat 
GHCMemoCyclist.hs >> /tmp/ghc22706.cpp

real    0m0.002s
user    0m0.000s
sys     0m0.000s
ghc-4.08:compile:Interface file GHCMemoCyclist.hi doesn't exist
ghc-4.08:recompile:Input file GHCMemoCyclist.hs newer than GHCMemoCyclist.o

Haskell compiler:
        /home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib/hsc 
/tmp/ghc22706.cpp  -fauto-sccs-on-all-toplevs -fscc-profiling -ffoldr-build-on 
-fdo-eta-reduction -fdo-lambda-eta-expansion -fcase-of-case -fcase-merge -flet-to-case 
-fpedantic-bottoms -fsimplify [ -finline-phase0 -fno-rules -fno-case-of-case 
-fmax-simplifier-iterations2 ] -fspecialise -ffloat-outwards -ffloat-inwards 
-fsimplify [ -finline-phase1 -fmax-simplifier-iterations4 ]  -fsimplify [ 
-finline-phase2 -fmax-simplifier-iterations2 ] -fsimplify [ 
-fmax-simplifier-iterations2 ] -fstrictness -fcpr-analyse -fworker-wrapper -fsimplify 
[ -fmax-simplifier-iterations4 ] -ffloat-outwards -fcse -ffloat-inwards -fsimplify [ 
-fmax-simplifier-iterations4 ] -fmassage-stg-for-profiling  -flet-no-escape 
-fwarn-overlapping-patterns -fwarn-missing-methods -fwarn-missing-fields 
-fwarn-deprecations -fwarn-duplicate-exports -fhi-version=408 -static 
"-himap=.%.hi:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/ghc/lib/st!
d%.hi:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util%.hi:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/concurrent%.hi:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/lang%.hi:.%.hi:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib/imports/std%.p_hi"
 "-himap-sep=:"    -v -hifile=/tmp/ghc22706.hi -olang=C -ofile=/tmp/ghc22706.hc 
-F=/tmp/ghc22706_stb.c -FH=/tmp/ghc22706_stb.h +RTS -H6000000 -K1000000
Glasgow Haskell Compiler, version 4.08, for Haskell 98, compiled by GHC version 4.08

real    0m8.587s
user    0m3.780s
sys     0m0.140s

Pin on Haskell consistency info:
        echo 'static char ghc_hsc_ID[] = "@(#)hsc GHCMemoCyclist.hs     40.0,_p,";' >> 
/tmp/ghc22706.hc

real    0m0.001s
user    0m0.000s
sys     0m0.000s
*** New hi file follows...
__interface "Main" Main  where
__export Main main;
import Concurrent 1 !;
import IO 1;
import Int 1 !;
import Memo 1;
import Numeric 1;
import PrelFloat 1 !;
import Prelude 1;
import System 1;
import Word 1 !;
zdwmain :: PrelGHC.Statezh PrelGHC.RealWorld -> (# PrelGHC.Statezh PrelGHC.RealWorld, 
PrelBase.Z0T #) {-## __A 0 ##-} ;
main :: PrelIOBase.IO PrelBase.Z0T {-## __A 0 __S P __P zdwmain ##-} ;


ghc-4.08: module version unchanged at 3

Replace .hi file, if changed:
        cmp -s Main.hi /tmp/ghc22706.hi-new || ( rm -f Main.hi && cp 
/tmp/ghc22706.hi-new Main.hi )

real    0m0.117s
user    0m0.000s
sys     0m0.000s

C compiler:
        gcc -v  -DDONT_WANT_WIN32_DLL_SUPPORT -S -Wimplicit -DPROFILING -O 
-DSTOLEN_X86_REGS=4 -fomit-frame-pointer -fno-defer-pop  -I. 
-I/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib/includes ghc22706.c > 
/tmp/ghc22706.ccout 2>&1 && ( if [ ghc22706.s != /tmp/ghc22706_o.s ] ; then mv 
ghc22706.s /tmp/ghc22706_o.s ; else exit 0 ; fi )

real    0m4.385s
user    0m1.440s
sys     0m0.120s
Reading specs from /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/cpp -lang-c -v -I. 
-I/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib/includes -D__GNUC__=2 
-D__GNUC_MINOR__=95 -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ 
-D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__OPTIMIZE__ -Wimplicit 
-Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 
-D__i686__ -D__pentiumpro -D__pentiumpro__ -DDONT_WANT_WIN32_DLL_SUPPORT -DPROFILING 
-DSTOLEN_X86_REGS=4 ghc22706.c /tmp/ccg4METL.i
GNU CPP version 2.95 19990728 (release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 .
 /home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib/includes
 /usr/gnu/include
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/../../../../i686-pc-linux-gnu/include
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/../../../../include/g++-3
End of omitted list.
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/cc1 /tmp/ccg4METL.i -quiet -dumpbase 
ghc22706.c -O -Wimplicit -version -fomit-frame-pointer -fno-defer-pop -o ghc22706.s
GNU C version 2.95 19990728 (release) (i686-pc-linux-gnu) compiled by GNU C version 
pgcc-2.91.66 19990314 (egcs-1.1.2 release).

Unix assembler:
        gcc -o GHCMemoCyclist.o -c  -I. 
-I/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib/includes /tmp/ghc22706.s
0.04user 0.01system 0:00.71elapsed 7%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (282major+136minor)pagefaults 0swaps

rm -f /tmp/ghc22706*
/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/bin/ghc-4.08 -lHSutil_p 
-lHSlang_p -lHSconcurrent_p -v -O 
-i.:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/ghc/lib/std:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/util:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/concurrent:/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/hslibs/lang
 -prof -auto-all -o GHCMemoCyclist GHCMemoCyclist.o 
The Glorious Glasgow Haskell Compilation System, version 4.08

Linker:
        gcc -v -u PrelMain_mainIO_closure -u PrelBase_Izh_static_info -u 
PrelBase_Czh_static_info -u PrelFloat_Fzh_static_info -u PrelFloat_Dzh_static_info -u 
PrelAddr_Azh_static_info -u PrelAddr_Wzh_static_info -u PrelAddr_I64zh_static_info -u 
PrelAddr_W64zh_static_info -u PrelStable_StablePtr_static_info -u 
PrelBase_Izh_con_info -u PrelBase_Czh_con_info -u PrelFloat_Fzh_con_info -u 
PrelFloat_Dzh_con_info -u PrelAddr_Azh_con_info -u PrelAddr_Wzh_con_info -u 
PrelAddr_I64zh_con_info -u PrelAddr_W64zh_con_info -u PrelStable_StablePtr_con_info -u 
PrelBase_False_closure -u PrelBase_True_closure -u PrelPack_unpackCString_closure -u 
PrelException_stackOverflow_closure -u PrelException_heapOverflow_closure -u 
PrelException_NonTermination_closure -u PrelException_PutFullMVar_closure -u 
PrelException_BlockedOnDeadMVar_closure -u __init_Prelude -u __init_PrelMain -o 
GHCMemoCyclist GHCMemoCyclist.o 
-L/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib -lHSutil_p -lHSlang_p 
-lHSconcurre!
nt_p -lHSstd_p -lHSstd_cbits -lHSrts_p -lgmp -lm
Reading specs from /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/specs
gcc version 2.95 19990728 (release)
 /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/collect2 -m elf_i386 -dynamic-linker 
/lib/ld-linux.so.2 -o GHCMemoCyclist -u PrelMain_mainIO_closure -u 
PrelBase_Izh_static_info -u PrelBase_Czh_static_info -u PrelFloat_Fzh_static_info -u 
PrelFloat_Dzh_static_info -u PrelAddr_Azh_static_info -u PrelAddr_Wzh_static_info -u 
PrelAddr_I64zh_static_info -u PrelAddr_W64zh_static_info -u 
PrelStable_StablePtr_static_info -u PrelBase_Izh_con_info -u PrelBase_Czh_con_info -u 
PrelFloat_Fzh_con_info -u PrelFloat_Dzh_con_info -u PrelAddr_Azh_con_info -u 
PrelAddr_Wzh_con_info -u PrelAddr_I64zh_con_info -u PrelAddr_W64zh_con_info -u 
PrelStable_StablePtr_con_info -u PrelBase_False_closure -u PrelBase_True_closure -u 
PrelPack_unpackCString_closure -u PrelException_stackOverflow_closure -u 
PrelException_heapOverflow_closure -u PrelException_NonTermination_closure -u 
PrelException_PutFullMVar_closure -u PrelException_BlockedOnDeadMVar_closure -u 
__init_Prelude -u __init_PrelMain /usr/lib/crt1.o /usr/!
lib/crti.o /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/crtbegin.o 
-L/home/lumberjacks/deforest/ghc-4.08/fptools-newgcc-build/lib 
-L/usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95 -L/usr/gnu/lib GHCMemoCyclist.o 
-lHSutil_p -lHSlang_p -lHSconcurrent_p -lHSstd_p -lHSstd_cbits -lHSrts_p -lgmp -lm 
-lgcc -lc -lgcc /usr/gnu/lib/gcc-lib/i686-pc-linux-gnu/2.95/crtend.o /usr/lib/crtn.o
0.67user 0.70system 0:04.72elapsed 29%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (393major+1244minor)pagefaults 0swaps

rm -f /tmp/ghc22726*






_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to