Hat bug report: hat-stack fails on simple example

Attached is a very simple example program: main calls f, which calls g, which calls h, which calls error. I tried building this with hat ("hmake -hat Foo"), running it ("./Foo") and then using hat-stack ("hat-stack Foo"). But hat-stack reported no useful information. The only output was as follows: | Program terminated with error: | {in h} | Virtual stack trace: source file/line/col | _|_ no source reference | _|_ no source reference ... the same line above, repeated another 62 times ... | _|_ no source reference | _|_ no source reference I also tried using hat-trail, but I couldn't get any useful information out of that either. I am using the latest CVS version of hat with ghc 6.2. Also, hat-trail failed to properly restore the tty state after ":q". -- Fergus J. Henderson | "I have always known that the pursuit Galois Connections, Inc. | of excellence is a lethal habit" Phone: +1 503 626 6616 | -- the last words of T. S. Garp.

Fergus Henderson
I tried building this with hat ("hmake -hat Foo"), running it ("./Foo") and then using hat-stack ("hat-stack Foo"). But hat-stack reported no useful information.
hat-stack is kind of obsolete. At least, it has had no maintenance in a long time, partly because it is written in C rather than Haskell, but mainly because hat-trail can do everything hat-stack can, but better. Perhaps one day we will rewrite hat-stack in Haskell as a cut-down version of hat-trail. However, in this instance, I suspect you got no useful information from hat-stack for exactly the same reason you had trouble with hat-trail (see below).
I also tried using hat-trail, but I couldn't get any useful information out of that either.
The reason for this is that your program exclusively uses CAFs (constants). A CAF does not have a parent recorded in the trace, essentially because the CAF could be called many times, and we have no mechanism for recording multiple parents of the constant. Nevertheless, hat-trail tells me that the message "in h" came from: <- {?} <- error "in h" <- h which is accurate, and only reflects the trivial nature of the program. If you re-cast your program to make f, g, and h into functions, f :: () -> Int f () = g () g () = h () h () = error "in h" main = do { putStrLn "in main"; print (f ()) } you will see a better result: <- {?} <- error "in h" <- h () <- g () <- f () <- main and each of those expressions has an associated source position that you can view with the :source command (for usage), or :Source (for definition).
Also, hat-trail failed to properly restore the tty state after ":q".
This has been reported by several people, but I can't reproduce it on my gnome-terminal. What terminal emulation are you using? Can you tell me the results of 'stty' on a normal terminal window, and also on a corrupted window? Or if the latter is not possible, on a corrupted window after you have reset it in the gentlest way you know? Regards, Malcolm

On 30-Jun-2004, Malcolm Wallace
Also, hat-trail failed to properly restore the tty state after ":q".
This has been reported by several people, but I can't reproduce it on my gnome-terminal. What terminal emulation are you using?
I am using "Konsole" (specifically, Konsole 1.3.2 with KDE 3.2.2). But the same problem also happens if I use "xterm".
Can you tell me the results of 'stty' on a normal terminal window,
bash$ stty speed 38400 baud; line = 0; bash$ stty -a speed 38400 baud; rows 45; columns 112; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -ixon -ixoff -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke
and also on a corrupted window?
bash$

Fergus Henderson
Also, hat-trail failed to properly restore the tty state after ":q".
I am using "Konsole" (specifically, Konsole 1.3.2 with KDE 3.2.2). But the same problem also happens if I use "xterm".
Aha! Terminal resetting works fine with all of the following: xterm, konsole, gnome-terminal, provided you are using ghc-5. But it breaks on all of the above if you use ghc-6. So there is something decidedly odd going on. Here is the relevant code in hat-trail: resetSystem :: State -> IO () resetSystem state = do putStr (enableScrollRegion 1 (height state)) putStr (goto 1 (height state)) System.system ("stty icanon echo") return () which looks fine to me. Indeed, here is a mini-test program that actually works in ghc-6.2.1 without breaking the terminal settings: import System; import Char; import IO main = do hSetBuffering stdin NoBuffering hSetBuffering stdout NoBuffering system ("stty -icanon -echo") getChars system ("stty icanon echo") putStrLn "Done" getChars = do c <- getChar putChar (toUpper c) if c=='q' then return () else getChars I'm inclined to report this as a bug in ghc, even though I don't seem to be able to cut down the problem to a simple test case. Regards, Malcolm

Also, hat-trail failed to properly restore the tty state after ":q".
OK, now I understand what ghc-6 is doing, an easy fix is apparent. It all depends on the order of calling 'stty' and hSetBuffering. This is the wrong order (as in HatTrail.hs):
do system ("stty -icanon -echo") hSetBuffering stdin NoBuffering hSetBuffering stdout NoBuffering
and this is a working order:
do hSetBuffering stdin NoBuffering hSetBuffering stdout NoBuffering system ("stty -icanon -echo")
Regards, Malcolm

I wrote:
Perhaps one day we will rewrite hat-stack in Haskell as a cut-down version of hat-trail.
And realised that today is the day... Well, all the library code for traversing the trace, and for printing trace expressions is already there, so it is just a matter of running a little loop really. So, a new implementation of hat-stack has just been committed to CVS. Regards, Malcolm
participants (2)
-
Fergus Henderson
-
Malcolm Wallace