BTW, thanks very much for Hugs!  It's a wonderful system.

I've been using Hugs with happy-generated parsers (from the version of
happy included with GHC 2.08) in ":set +." mode, and I noticed that it
seemed to pause for quite a while at a certain point in the
compilation.  I decided to see if I could track down what was going
on, and discovered that it was dealing with some very large terms; in
particular, it's running pmcTerm() on some nests of applications of
select(0) which are over 1000 deep.  To demonstrate what was going on,
I made the following patch to compiler.c:

--- compiler.c-ORIG     Mon Oct 13 23:43:31 1997
+++ compiler.c  Mon Oct 13 23:47:13 1997
@@ -923,7 +923,23 @@
 
         case COND     : return ap(COND,pmcTriple(co,sc,snd(e)));
 
-        case AP       : return pmcPair(co,sc,e);
+        case AP       : {
+         if (fun(e) == mkSelect(0)) {
+           int sel_cnt = 0;
+
+           while (whatIs(e) == AP && fun(e) == mkSelect(0)) {
+             e = arg(e);
+             sel_cnt++;
+           }
+
+           if (sel_cnt > 50) {
+             printf("Huge select(0) nest elided: %d terms\n", sel_cnt);
+           }
+
+           return pmcTerm(co,sc,e);
+         }
+         return pmcPair(co,sc,e);
+       }
 
 #if BIGNUMS
         case POSNUM   :

As you can see, this just elides applications of select(0) in
pmcTerm().  When I load my file with this patch in place, I get:

Reading file "ParseMod.hs":
Parsing........................................................................
Dependency analysis............................................................
Type checking..................................................................
Compiling....................Huge select(0) nest elided: 64 terms
Huge select(0) nest elided: 65 terms
[...32 lines deleted...]
Huge select(0) nest elided: 51 terms
..............................Huge select(0) nest elided: 1128 terms
Huge select(0) nest elided: 1129 terms
[...1088 lines deleted...]
Huge select(0) nest elided: 54 terms
....................

I don't know what causes these select(0) nests to be generated, but I
wonder if there's some way to avoid it; or if pmcTerm (or some earlier
stage) should elide them (as in my patch, but without the diagnostic),
so that at least Hugs doesn't have to make copies of these huge terms.
(I'm running with the patch now, with the diagnostic commented out,
and loading my module seems to be significantly faster.  I haven't
done any actual timings though.)

Let me know if you want copies of the relevant source files, or if you
need any more details.

Carl Witty
[EMAIL PROTECTED]

Reply via email to