Opened 10 years ago

Closed 10 years ago

Last modified 44 years ago

#209 closed bug (Wont Fix)

-O causes unbounded memory use

Reported by: ktakusa Owned by: nobody
Priority: normal Milestone:
Component: Compiler Version: 6.2
Keywords: Cc:
Operating System: Architecture:
Type of failure: Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The attached simple program, when compiled with
-O quickly allocates all the available memory.

But without -O, it only consumes a small amout
of memory.

(The program is deliberately non-terminating;
it is a simplified test case of real program.)

==
Platform: i386 Linux, RH9

% ghc -v -O ptest2.hs 
Glasgow Haskell Compiler, Version 6.2, for Haskell 98,
compiled by GHC version 5.04.3
Using package config file:
/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/package.conf

==================== Packages ====================
Package
   {name = "data",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/data"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSdata"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["haskell98", "lang", "util"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "rts",
    auto = False,
    import_dirs = [],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSrts"],
    extra_libraries = ["m", "gmp", "dl"],
    include_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/include"],
    c_includes = ["Stg.h"],
    package_deps = [],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts =
      ["-u",
       "GHCziBase_Izh_static_info",
       "-u",
       "GHCziBase_Czh_static_info",
       "-u",
       "GHCziFloat_Fzh_static_info",
       "-u",
       "GHCziFloat_Dzh_static_info",
       "-u",
       "GHCziPtr_Ptr_static_info",
       "-u",
       "GHCziWord_Wzh_static_info",
       "-u",
       "GHCziInt_I8zh_static_info",
       "-u",
       "GHCziInt_I16zh_static_info",
       "-u",
       "GHCziInt_I32zh_static_info",
       "-u",
       "GHCziInt_I64zh_static_info",
       "-u",
       "GHCziWord_W8zh_static_info",
       "-u",
       "GHCziWord_W16zh_static_info",
       "-u",
       "GHCziWord_W32zh_static_info",
       "-u",
       "GHCziWord_W64zh_static_info",
       "-u",
       "GHCziStable_StablePtr_static_info",
       "-u",
       "GHCziBase_Izh_con_info",
       "-u",
       "GHCziBase_Czh_con_info",
       "-u",
       "GHCziFloat_Fzh_con_info",
       "-u",
       "GHCziFloat_Dzh_con_info",
       "-u",
       "GHCziPtr_Ptr_con_info",
       "-u",
       "GHCziPtr_FunPtr_con_info",
       "-u",
       "GHCziStable_StablePtr_con_info",
       "-u",
       "GHCziBase_False_closure",
       "-u",
       "GHCziBase_True_closure",
       "-u",
       "GHCziPack_unpackCString_closure",
       "-u",
       "GHCziIOBase_stackOverflow_closure",
       "-u",
       "GHCziIOBase_heapOverflow_closure",
       "-u",
       "GHCziIOBase_NonTermination_closure",
       "-u",
       "GHCziIOBase_BlockedOnDeadMVar_closure",
       "-u",
       "GHCziIOBase_Deadlock_closure",
       "-u",
       "GHCziWeak_runFinalizzerBatch_closure",
       "-u",
       "__stginit_Prelude"],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "base",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSbase"],
    extra_libraries = ["HSbase_cbits"],
    include_dirs = [],
    c_includes = ["HsBase.h"],
    package_deps = ["rts"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "haskell98",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HShaskell98"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "haskell-src",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HShaskell-src"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["base", "haskell98"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "network",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSnetwork"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = ["HsNet.h"],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "parsec",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSparsec"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "QuickCheck",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSQuickCheck"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "readline",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSreadline"],
    extra_libraries = ["readline", "ncurses"],
    include_dirs = [],
    c_includes = ["HsReadline.h"],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "unix",
    auto = True,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/imports"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSunix"],
    extra_libraries = ["HSunix_cbits", "dl"],
    include_dirs = [],
    c_includes = ["HsUnix.h"],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "lang",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/lang"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSlang"],
    extra_libraries = ["HSlang_cbits"],
    include_dirs = [],
    c_includes = ["HsLang.h"],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "concurrent",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/concurrent"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSconcurrent"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["base"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "posix",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/posix"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSposix"],
    extra_libraries = ["HSposix_cbits", "dl"],
    include_dirs = [],
    c_includes = ["HsPosix.h"],
    package_deps = ["lang", "unix"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "util",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/util"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSutil"],
    extra_libraries = ["HSutil_cbits"],
    include_dirs = [],
    c_includes = ["HsUtil.h"],
    package_deps =
      ["lang", "concurrent", "QuickCheck", "readline",
"posix"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "text",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/text"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HStext"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["lang", "parsec"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "net",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/net"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HSnet"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["network"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}
Package
   {name = "hssource",
    auto = False,
    import_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2/hslibs-imports/hssource"],
    source_dirs = [],
    library_dirs =
     
["/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2"],
    hs_libraries = ["HShssource"],
    extra_libraries = [],
    include_dirs = [],
    c_includes = [],
    package_deps = ["haskell-src"],
    extra_ghc_opts = [],
    extra_cc_opts = [],
    extra_ld_opts = [],
    framework_dirs = [],
    extra_frameworks = []}


Hsc static flags: -static
*** Checking old interface for Main:
compilation IS NOT required
*** Touching object file
touch ptest2.o
*** Linker
gcc -v -o a.out -DDONT_WANT_WIN32_DLL_SUPPORT ptest2.o
-L/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2
-lHShaskell98 -lHSbase -lHSbase_cbits -lHSrts -lm -lgmp
-ldl -u GHCziBase_Izh_static_info -u
GHCziBase_Czh_static_info -u GHCziFloat_Fzh_static_info
-u GHCziFloat_Dzh_static_info -u
GHCziPtr_Ptr_static_info -u GHCziWord_Wzh_static_info
-u GHCziInt_I8zh_static_info -u
GHCziInt_I16zh_static_info -u
GHCziInt_I32zh_static_info -u
GHCziInt_I64zh_static_info -u
GHCziWord_W8zh_static_info -u
GHCziWord_W16zh_static_info -u
GHCziWord_W32zh_static_info -u
GHCziWord_W64zh_static_info -u
GHCziStable_StablePtr_static_info -u
GHCziBase_Izh_con_info -u GHCziBase_Czh_con_info -u
GHCziFloat_Fzh_con_info -u GHCziFloat_Dzh_con_info -u
GHCziPtr_Ptr_con_info -u GHCziPtr_FunPtr_con_info -u
GHCziStable_StablePtr_con_info -u
GHCziBase_False_closure -u GHCziBase_True_closure -u
GHCziPack_unpackCString_closure -u
GHCziIOBase_stackOverflow_closure -u
GHCziIOBase_heapOverflow_closure -u
GHCziIOBase_NonTermination_closure -u
GHCziIOBase_BlockedOnDeadMVar_closure -u
GHCziIOBase_Deadlock_closure -u
GHCziWeak_runFinalizzerBatch_closure -u __stginit_Prelude
Reading specs from
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix
--disable-checking --with-system-zlib
--enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
 /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/collect2
--eh-frame-hdr -m elf_i386 -dynamic-linker
/lib/ld-linux.so.2 -o a.out -u
GHCziBase_Izh_static_info -u GHCziBase_Czh_static_info
-u GHCziFloat_Fzh_static_info -u
GHCziFloat_Dzh_static_info -u GHCziPtr_Ptr_static_info
-u GHCziWord_Wzh_static_info -u
GHCziInt_I8zh_static_info -u GHCziInt_I16zh_static_info
-u GHCziInt_I32zh_static_info -u
GHCziInt_I64zh_static_info -u
GHCziWord_W8zh_static_info -u
GHCziWord_W16zh_static_info -u
GHCziWord_W32zh_static_info -u
GHCziWord_W64zh_static_info -u
GHCziStable_StablePtr_static_info -u
GHCziBase_Izh_con_info -u GHCziBase_Czh_con_info -u
GHCziFloat_Fzh_con_info -u GHCziFloat_Dzh_con_info -u
GHCziPtr_Ptr_con_info -u GHCziPtr_FunPtr_con_info -u
GHCziStable_StablePtr_con_info -u
GHCziBase_False_closure -u GHCziBase_True_closure -u
GHCziPack_unpackCString_closure -u
GHCziIOBase_stackOverflow_closure -u
GHCziIOBase_heapOverflow_closure -u
GHCziIOBase_NonTermination_closure -u
GHCziIOBase_BlockedOnDeadMVar_closure -u
GHCziIOBase_Deadlock_closure -u
GHCziWeak_runFinalizzerBatch_closure -u
__stginit_Prelude
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crti.o
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtbegin.o
-L/afs/sipb/project/ghc/arch/i386_rh9-2004-01-20/lib/ghc-6.2
-L/usr/lib/gcc-lib/i386-redhat-linux/3.2.2
-L/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../..
ptest2.o -lHShaskell98 -lHSbase -lHSbase_cbits -lHSrts
-lm -lgmp -ldl -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/crtend.o
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crtn.o
*** Deleting temp files
Deleting: /tmp/ghc27620.hc
Warning: deleting non-existent /tmp/ghc27620.hc

Attachments (1)

ptest2.2.hs (273 bytes) - added by ktakusa 10 years ago.

Download all attachments as: .zip

Change History (4)

Changed 10 years ago by ktakusa

comment:1 Changed 10 years ago by simonmar

Logged In: YES 
user_id=48280

You have cleverly constructed an example in which full-
laziness turns out to be a really bad idea.  The infinite list 
gets floated to the top level, and never gets garbage 
collected because the program pretends to need it again.

I thought we had a flag called -fno-full-laziness which was 
specifically for cases like this, but I can't find it now.  I guess 
we should add it.  In the meantime, the only workaround is 
not to compile with -O.

If you'd like to make a case for not doing full-laziness by 
default, please direct it to glasgow-haskell-
users@haskell.org.  Thank you. :-)

comment:2 Changed 10 years ago by simonpj

Logged In: YES 
user_id=50165

It's not easy to see how to fix this "properly", but I've added 
a -fno-full-laziness flag so you can get around it.

comment:3 Changed 10 years ago by simonpj

  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.