Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Error using Parsec: "transformProgram: Simplify-SuperSimplify after Boxy WorkWrap" #45

Open
master-q opened this Issue Sep 10, 2013 · 9 comments

Comments

Projects
None yet
2 participants
Owner

master-q commented Sep 10, 2013

Error using Parsec: "transformProgram: Simplify-SuperSimplify after Boxy WorkWrap"

$ ajhc -pparsec RssTest.hs
ajhc -pparsec RssTest.hs
ajhc 0.8.0.9 (26656dc5399d5ea92d63165396d1ef561b3dc01e)
Finding Dependencies...
Using Ho Cache: '/home/kiwamu/.ajhc/cache'
Main                    [RssTest.hs]
Typechecking...
[1 of 1] Main             (.............................................)
Compiling...
[1 of 1] Main             <..................................................>
Collected Compilation...
-- TypeAnalyzeMethods
-- BoxifyProgram
-- Boxy WorkWrap
Stack:
transformProgram: Simplify-SuperSimplify after Boxy WorkWrap
ajhc: E.TypeCheck.getType: (EPi x14863645::Jhc.Prim.IO.State_ Jhc.Prim.IO.RealWorld::*::# (EAp Jhc@.Box.*::* (EVar x14863645::Jhc.Prim.IO.State_ Jhc.Prim.IO.RealWorld::*::#)),#,Jhc@.Box.*::*)
$ ghc RssTest.hs
Linking RssTest ...
$ curl -s http://www.reddit.com/r/haskell/.rss | ./RssTest
Right ["For my 17th birthday, my best friend got me &quot;The most obscure programming book I could find&quot; as a joke. I know what language I am learning next!","My first Haskell program - FNIStash - a utility for Torchlight 2 using threepenny for the GUI","Hackage 2 now available for beta testing -- switchover in a few weeks","Cabal version lockdown: reliable builds for application developers","Proposal: New syntax for Haskell (Cucumber Haskell, .chs)"]
--- File: RssTest.hs
import Control.Monad
import Text.ParserCombinators.Parsec

rssTag = do
  manyTill anyChar $ try atomTag
  replicateM 5 itemTag -- <= Error occured!!!

atomTag = do string "<atom"
             many (noneOf ">")
             string ">"

itemTag = do string "<item>"
             t <- titleTag
             skipTag "link"
             skipTag "guid"
             skipTag "pubDate"
             skipTag "description"
             string "</item>"
             return t

titleTag = do string "<title>"
              t <- many (noneOf "<>")
              string "</title>"
              return t

skipTag t = do string ('<':t)
               many (noneOf "<")
               string $ "</" ++ t ++ ">"

main :: IO ()
main = do
  c <- getContents
  print $ parse rssTag "" c
Owner

master-q commented Sep 10, 2013

The error says "I can't find # => * function in the Rules".
http://ajhc.metasepi.org/manual.html#ajhc-core-type-system

Is it Haskell code BUG? Or type check code's?

Owner

master-q commented Sep 10, 2013

WoW! The Bug isn't duplicated with following patch.
I think it's caused by "simplifyProgram" function's optimization...

diff --git a/src/E/Main.hs b/src/E/Main.hs
index ab10971..150369b 100644
--- a/src/E/Main.hs
+++ b/src/E/Main.hs
@@ -497,8 +497,8 @@ compileWholeProgram prog = do
         transformCategory = "Boxy WorkWrap",
         transformDumpProgress = dump FD.Progress,
         transformOperation = evaluate . workWrapProgram } prog
-    prog <- simplifyProgram SS.emptySimplifyOpts { SS.so_finalPhase = True }
-        "SuperSimplify after Boxy WorkWrap" verbose prog
+--    prog <- simplifyProgram SS.emptySimplifyOpts { SS.so_finalPhase = True }
+--        "SuperSimplify after Boxy WorkWrap" verbose prog
     prog <- return $ runIdentity $ programMapBodies (return . cleanupE) prog

     wdump FD.CoreBeforelift $ dumpCore "before-lift" prog
Owner

master-q commented Sep 10, 2013

Also it's not duplicated with -fno-global-optimize option without above patch.

Owner

master-q commented Sep 10, 2013

Got minimum code to duplicate the BUG.

-- File: RssTestMin.hs
import Text.ParserCombinators.Parsec

rssTag :: Parser [String]
rssTag = count 5 titleTag -- <= Error occured!!!

titleTag :: Parser String
titleTag = string "<title>"

main :: IO ()
main = do
  c <- getContents
  print $ parse rssTag "" c
$ ajhc -pparsec RssTestMin.hs
ajhc -pparsec RssTestMin.hs
ajhc 0.8.0.9 (bb2db48f6c3cc9b00ef25f100630d47e5820bcdd)
Finding Dependencies...
Using Ho Cache: '/home/kiwamu/.ajhc/cache'
Main                    [RssTestMin.hs]
Typechecking...
[1 of 1] Main             (.............................................)
Compiling...
[1 of 1] Main             <..................................................>
Collected Compilation...
-- TypeAnalyzeMethods
-- BoxifyProgram
-- Boxy WorkWrap
Stack:
transformProgram: Simplify-SuperSimplify after Boxy WorkWrap
ajhc: E.TypeCheck.getType: (EPi x108042549::Text.ParserCombinators.Parsec.Prim.State Jhc.Type.Basic.Char::* Jhc.Prim.Prim.()::*::* (EAp Jhc@.Box.*::* (EVar x108042549::Text.ParserCombinators.Parsec.Prim.State Jhc.Type.Basic.Char::* Jhc.Prim.Prim.()::*::*)),*,Jhc@.Box.*::*)
Member

mzp commented Oct 20, 2013

This issues might be same as #53.

Owner

master-q commented Oct 21, 2013

John said...

 John:  does the parsec bug do anything different when you run with the '-flint' option?
 me:  Not yet.
Try it and report you.
 John:  hm.. okay. I'll try to take a look too.
 me:  flint is ignore type check?
 John:  no, flint is type check everywhere. between every pass.
 me:  Oh. great!!!
 John:  usually finds bugs nearer to their root cause.
closer.
 me:  Ah. But slow to compile? #flint
 John:  yup.
much slower.
 me:  Make sense.
Good option.
 Sent at 2:02 PM on Monday
 John:  sometimes it finds bugs I didn't  know about though masking the bug I'm trying to find.... not sure whether that's a good or bad thing...
Member

mzp commented Oct 22, 2013

I ran with -flint option, but no result is generated.

mzp@haskell ret:1 $ ajhc  -flint -p parsec Main.hs                                                            [~/tmp/parsec]
ajhc -flint -p parsec Main.hs
ajhc 0.8.0.9 (0e19f347196f9d8dfabc60b9f65dc2b3557885e3)
Finding Dependencies...
Using Ho Cache: '/home/mzp/.ajhc/cache'
Main                    [Main.hs] <~/.ajhc/cache/ohlhvuurrttvl88jgqbn88hhsh.ho>
Fresh: <~/.ajhc/cache/ohlhvuurrttvl88jgqbn88hhsh.ho>
Typechecking...
Compiling...
Collected Compilation...
-- TypeAnalyzeMethods
-- BoxifyProgram
-- Boxy WorkWrap
Stack:
transformProgram: Simplify-SuperSimplify after Boxy WorkWrap
ajhc: E.TypeCheck.getType: (EPi x6486751::Jhc.Prim.IO.State_ Jhc.Prim.IO.RealWorld::*::# (EAp Jhc@.Box.*::* (EVar x6486751::Jhc.Prim.IO.State_ Jhc.Prim.IO.RealWorld::*::#)),#,Jhc@.Box.*::*)
Owner

master-q commented Feb 5, 2014

I got runtime error, also.

To see the error, apply the following patch to Ajhc.

diff --git a/src/E/Main.hs b/src/E/Main.hs
index ab10971..150369b 100644
--- a/src/E/Main.hs
+++ b/src/E/Main.hs
@@ -497,8 +497,8 @@ compileWholeProgram prog = do
         transformCategory = "Boxy WorkWrap",
         transformDumpProgress = dump FD.Progress,
         transformOperation = evaluate . workWrapProgram } prog
-    prog <- simplifyProgram SS.emptySimplifyOpts { SS.so_finalPhase = True }
-        "SuperSimplify after Boxy WorkWrap" verbose prog
+--    prog <- simplifyProgram SS.emptySimplifyOpts { SS.so_finalPhase = True }
+--        "SuperSimplify after Boxy WorkWrap" verbose prog
     prog <- return $ runIdentity $ programMapBodies (return . cleanupE) prog

     wdump FD.CoreBeforelift $ dumpCore "before-lift" prog

Then compile and run the test code.

$ cat Test.hs
import Control.Monad.Trans.Class
import Control.Monad.Trans.Error

f1 :: ErrorT String IO Int
f1 = do
  lift $ print "call f1" -- <= Error occured!!!
  return 1

main :: IO ()
main = do
  r <- runErrorT f1
  print r
$ ajhc -fdebug -p transformers --tdir=tdir Test.hs
$ gdb hs.out
(gdb) run 
Starting program: /home/kiwamu/tmp/hs.out
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

tdir/rts/rts_support.c:1142: case fell off

Program received signal SIGABRT, Aborted.
0x00007ffff77661d5 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  0x00007ffff77661d5 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff7769388 in __GI_abort () at abort.c:90
#2  0x00000000004010a6 in jhc_case_fell_off (n=1142) at tdir/rts/rts_support.c:54
#3  0x0000000000404cc0 in bapply__14617 (gc=0x7ffff7530090, arena=0x60f020, v17=0x7ffff7430078) at tdir/main_code.c:1142
#4  0x0000000000405305 in fInstance$__iJhc_Monad_$rre_$ontrol_Monad_Trans_Error_ErrorT (gc=0x7ffff7530058, arena=0x60f020, 
    v372770881=0xf0002, v119285244=0x120002, v1542334015=0x90002, v135370992=0xd0002) at tdir/main_code.c:1216
#5  0x0000000000405e3a in fJhc_Monad_$rred3 (gc=0x7ffff7530038, arena=0x60f020, v29077244=0x90002, v110207572=0xd0002, v565706783=0xf0002, 
    v567672863=0x120002) at tdir/main_code.c:1356
#6  0x0000000000404ada in bapply__14617 (gc=0x7ffff7530018, arena=0x60f020, v17=0x7ffff742f028) at tdir/main_code.c:1106
#7  0x000000000040989d in ftheMain (gc=0x7ffff7530010, arena=0x60f020) at tdir/main_code.c:2160
#8  0x000000000040433b in b__main (gc=0x7ffff7530010, arena=0x60f020) at tdir/main_code.c:996
#9  0x0000000000404301 in _amain () at tdir/main_code.c:989
#10 0x000000000040130f in main (argc=1, argv=0x7fffffffe0c8) at tdir/rts/jhc_rts.c:172
(gdb) up
#1  0x00007ffff7769388 in __GI_abort () at abort.c:90
90      abort.c: No such file or directory.
(gdb) up
#2  0x00000000004010a6 in jhc_case_fell_off (n=1142) at tdir/rts/rts_support.c:54
54              abort();
(gdb) up
#3  0x0000000000404cc0 in bapply__14617 (gc=0x7ffff7530090, arena=0x60f020, v17=0x7ffff7430078) at tdir/main_code.c:1142
1142            default: jhc_case_fell_off(__LINE__);
(gdb) l
1137                break;
1138            case P1__theMain$d4:
1139                {   return ftheMain$d4(gc,arena);
1140                }
1141                break;
1142            default: jhc_case_fell_off(__LINE__);
1143            }
1144    }
1145
1146    static wptr_t A_STD A_MALLOC
Owner

master-q commented Feb 5, 2014

Try to compile without using cache and hl files. But catch error... orz

$ tree Control Data *.hs
Control
|-- Applicative.hs
|-- Arrow.hs
|-- Category.hs
`-- Monad
    |-- IO
    |   `-- Class.hs
    `-- Trans
        |-- Class.hs
        |-- Cont.hs
        |-- Error.hs
        |-- Identity.hs
        |-- List.hs
        |-- Maybe.hs
        |-- RWS
        |   |-- Lazy.hs
        |   `-- Strict.hs
        |-- RWS.hs
        |-- Reader.hs
        |-- State
        |   |-- Lazy.hs
        |   `-- Strict.hs
        |-- State.hs
        |-- Writer
        |   |-- Lazy.hs
        |   `-- Strict.hs
        `-- Writer.hs
Data
`-- Functor
    |-- Compose.hs
    |-- Constant.hs
    |-- Identity.hs
    `-- Product.hs
Test.hs [error opening dir]

7 directories, 24 files
$ ajhc --ignore-cache -fdebug --tdir=tdir Test.hs
-- snip --
Stack:
transformProgram: Simplify-SuperSimplify after Boxy WorkWrap
ajhc: E.TypeCheck.getType: (EPi x14767373::Jhc.Prim.IO.State_ Jhc.Prim.IO.RealWorld::*::# (EAp Jhc@.Box.*::* (EVar x14767373::Jhc.Prim.IO.Sta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment