[Yhc] Running catch on the HughesPJ prettyprinter

Thorkil Naur naur at post11.tele.dk
Mon Jul 23 08:43:57 EDT 2007


Hello Neil (cc Yhc),

I am trying to run your catch on the HughesPJ prettyprinter. The serious 
reason for trying this is that I suspect that some parts of the HughesPJ 
module are actually never used. That is, certain definitions are impossible 
to reach using the exported definitions. And I guess (but I haven't 
progressed far enough to tell) that catch can be used for this, simply by 
modifying some definition that you suspect is never used to head [] or 
perhaps just error "Something" and then see if catch can find a case where 
this error is reported.

Another reason is, of course, the expected entertainment value of such an 
experiment. In the latter, I was not disappointed, as I will now describe in 
some detail:

1. Catch (http://www.cs.york.ac.uk/fp/darcs/catch/catch.htm) requires me to 
use Yhc, so I decided to upgrade my Yhc installation. That didn't work out 
particularly well, as reported separately to yhc at haskell.org. But as a 
workaround, I am simply using the Yhc that gets built by the Yhc buildbot 
slave on my machine regularly. For some reason, this still works, even if I 
am unable to build an entirely fresh Yhc.

2. Trying the catch Risers example, I got this reaction:

> $ catch Risers
> 
Executing: /Users/thorkilnaur/tn/install/catch-0.1/share/catch-0.1/examples/Regress/Risers.hs
> Compiling
> yhc: Could not parse cmd-line options: unrecognized option `-l'
>
>
> catch: Failed to 
compile, /Users/thorkilnaur/tn/install/catch-0.1/share/catch-0.1/examples/Regress/Risers.hs
> $

To correct this:

> src/Prepare/Compile.hs:    res <- system $ "yhc --hide --linkcore \"" ++ 
file ++ "\" " ++ flags

(This is the 
http://hackage.haskell.org/packages/archive/catch/0.1.1/catch-0.1.1.tar.gz 
package that you recommend using). In addition:

> Task: Overlay
> yhc: Could not parse cmd-line options: unrecognized option `-o'
>
> unrecognized option `-r'
>
> unrecognized option `-e'
>
>
> catch: Failed to compile the overlay

was fixed by:

> src/Prepare/Overlay.hs:    res <- system $ "yhc --hide --core \"" ++ prim ++ 
"\""

3. Next on the agenda, we get

> $ catch HughesPJ
> Executing: HughesPJ.hs
> Compiling
> Compiling Text.PrettyPrint.HughesPJ ( HughesPJ.hs )
> -- during after type inference/checking
> Error: Type error type clash between Prelude.Int and Prelude.Bool
> when trying to apply function at 931:26 to its 2nd argument at 
931:31-931:33.
>
> catch: Failed to compile, HughesPJ.hs
> $

This is fixed by changing HughesPJ.hs as follows:

> 931c931
> <         lay1 k _ sl _ | k+sl `seq` False = undefined
> ---
> >         lay1 k _ sl _ | (k+sl) `seq` False = undefined

And this is, of course, rather interesting, since this type error (I cannot 
see it as anything else) is neither detected by Hugs nor GHC. But that is a 
matter for further work some other time.

4. Then I get this problem:

> $ catch HughesPJ
> Executing: HughesPJ.hs
> Compiling
> Compiling Text.PrettyPrint.HughesPJ ( HughesPJ.hs )
> Loading Core for YHC.Internal
> ...
> Loading Core for PreludeAux
> Linking...
> catch: ycr/HughesPJ.yca: openBinaryFile: does not exist (No such file or 
directory)
> 
> $

I have earlier disagreed with yhc as to where it's output files were placed 
and I also reported a bug about this some time back. This seems to be 
related, although I must admit that I have not at the time of writing 
investigated further. The first part of this problem is that bare "yhc 
HughesPJ" seems to place its output .hi and .hbc files in 
"../../Text/PrettyPrint/" and this is, of course, somewhat OK if you are 
already in "$SOMEWHERE/Text/PrettyPrint/". But if you are not, I assure you 
that this is confusing.

So, instead of working with "$SOMEWHERE/HughesPJ.hs", I created 
"$SOMEWHERE/Text/PrettyPrint/HughesPJ.hs" and started working from there. And 
thus, I was able to compile with "yhc HughesPJ" and find the output .hi 
and .hbc files in the same directory as HughesPJ.hs. However, catch HughesPJ 
still couldn't find its ycr/HughesPJ.yca file. Looking around again, I found 
the yhc output, as directed by catch, in 
"$SOMEWHERE/ycr/Text.PrettyPrint.HughesPJ.yca", etc. So because HughesPJ.hs 
has a module name Text.PrettyPrint.HughesPJ, the --hide option of yhc 
performs this massaging of the directory and output file name. And, 
apparently, catch is not able to match yhc in this.

This was fixed by changing HughesPJ.hs as follows:

> 170c170
> < module Text.PrettyPrint.HughesPJ (
> ---
> > module HughesPJ (

5. And then catch starts to run. It is presently here:

> $ catch HughesPJ
> Executing: HughesPJ.hs
> Compiling
> Compiling HughesPJ         ( HughesPJ.hs )
> Loading Core for YHC.Internal
> ...
> Loading Core for PreludeAux
> Linking...
> Transformations
> Task: Overlay
> Task: Firstify
> Warning: Failed in stage Firstify
> Task: LetElim
> Task: OneArg
> Task: UniqueVars
> Task: ShortCtors
> Analysing
> Checking [1/19]: Data.Ratio.% with zero as the second argument, bad person
> Partial: "Data.Ratio.%$142"
> Answer: _
> Checking [2/19]: HughesPJ: Pattern match failure in function at 
799:5-804:51.
> Partial: "HughesPJ.HughesPJ.Prelude.580.get"
> Partial: "HughesPJ.best"

and it's been there for about an hour, working. But I am sure that you have 
also noticed the ominous "Warning: Failed in stage Firstify" which may 
indicate that there is very little chance of getting a useful result anyway. 
So I will probably just interrupt it before long.

I know you are probably busy with other things, so understand that this matter 
is not particularly critical for me. But if you have any comments to this 
situation, I would gladly hear about them.

Thanks and best regards
Thorkil


More information about the Yhc mailing list