X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Finterpreter%2Fcompiler.c;h=20bc336014454b5f76d1dfcf50d5a3422532493c;hb=9ff75d089614cce1cfa8c88344ace47698258bfa;hp=53f37080c7037843b27e35cdd2e990318dba846d;hpb=ed4f46f41c6293db4536705b4db3024991413f3f;p=ghc-hetmet.git diff --git a/ghc/interpreter/compiler.c b/ghc/interpreter/compiler.c index 53f3708..20bc336 100644 --- a/ghc/interpreter/compiler.c +++ b/ghc/interpreter/compiler.c @@ -11,11 +11,11 @@ * included in the distribution. * * $RCSfile: compiler.c,v $ - * $Revision: 1.23 $ - * $Date: 2000/03/15 23:27:16 $ + * $Revision: 1.28 $ + * $Date: 2000/04/14 15:18:06 $ * ------------------------------------------------------------------------*/ -#include "prelude.h" +#include "hugsbasictypes.h" #include "storage.h" #include "connect.h" #include "errors.h" @@ -847,7 +847,7 @@ List lds; { } case DICTVAR : /* shouldn't really occur */ - assert(0); /* so let's test for it then! ADR */ + //assert(0); /* so let's test for it then! ADR */ case VARIDCELL : case VAROPCELL : return addEqn(pat,expr,lds); @@ -865,10 +865,15 @@ List lds; { /* intentional fall-thru */ case TUPLE : { List ps = getArgs(pat); + /* get rid of leading dictionaries in args */ + if (isName(c) && isCfun(c)) { + Int i = numQualifiers(name(c).type); + for (; i > 0; i--) ps = tl(ps); + } + if (nonNull(ps)) { Cell nv, sel; Int i; - if (isVar(expr) || isName(expr)) nv = expr; else { @@ -1462,15 +1467,6 @@ static List addGlobals( List binds ) return binds; } -typedef void (*sighandler_t)(int); -void eval_ctrlbrk ( int dunnowhat ) -{ - interruptStgRts(); - /* reinstall the signal handler so that further interrupts which - happen before the thread can return to the scheduler, lead back - here rather than invoking the previous break handler. */ - signal(SIGINT, eval_ctrlbrk); -} Void evalExp ( void ) { /* compile and run input expression */ /* ToDo: this name (and other names generated during pattern match?) @@ -1494,47 +1490,82 @@ Void evalExp ( void ) { /* compile and run input expression */ unless doRevertCAFs below is permanently TRUE. */ /* initScheduler(); */ -#ifdef CRUDE_PROFILING + + /* Further comments, JRS 000411. + When control returns to Hugs, you have to be pretty careful about + the state of the heap. In particular, hugs.c may subsequently call + nukeModule() in storage.c, which removes modules from the system. + If a module defines a particular data constructor, the relevant + info table is also free()d. That gives a problem if there are + still closures hanging round in the heap with references to that + info table. + + The solution is to firstly to revert CAFs, and then force a major + collection in between transitions from the mutation, ie actually + running Haskell, and nukeModule. Since major GCs are potentially + expensive, we don't want to do one at every call to nukeModule, + so the flag nukeModule_needs_major_gc is used to signal when one + is needed. + + This all also seems to imply that doRevertCAFs should always + be TRUE. + */ + +# ifdef CRUDE_PROFILING cp_init(); -#endif +# endif { HaskellObj result; /* ignored */ - sighandler_t old_ctrlbrk; SchedulerStatus status; Bool doRevertCAFs = TRUE; /* do not change -- comment above */ - old_ctrlbrk = signal(SIGINT, eval_ctrlbrk); - ASSERT(old_ctrlbrk != SIG_ERR); + HugsBreakAction brkOld = setBreakAction ( HugsRtsInterrupt ); + nukeModule_needs_major_gc = TRUE; status = rts_eval_(closureOfVar(v),10000,&result); - signal(SIGINT,old_ctrlbrk); + setBreakAction ( brkOld ); fflush (stderr); fflush (stdout); switch (status) { case Deadlock: printf("{Deadlock or Blackhole}"); - if (doRevertCAFs) RevertCAFs(); break; case Interrupted: printf("{Interrupted}"); - if (doRevertCAFs) RevertCAFs(); break; case Killed: printf("{Interrupted or Killed}"); - if (doRevertCAFs) RevertCAFs(); break; case Success: - if (doRevertCAFs) RevertCAFs(); break; default: internal("evalExp: Unrecognised SchedulerStatus"); } - deleteAllThreads(); + + /* Begin heap cleanup sequence */ + do { + /* fprintf ( stderr, "finalisation loop START\n" ); */ + finishAllThreads(); + finalizeWeakPointersNow(); + /* fprintf ( stderr, "finalisation loop END %d\n", + howManyThreadsAvail() ); */ + } + while (howManyThreadsAvail() > 0); + + RevertCAFs(); + performMajorGC(); + if (combined && SPT_size != 0) { + FPrintf ( stderr, + "hugs: fatal: stable pointers are not yet allowed in combined mode" ); + internal("evalExp"); + } + /* End heap cleanup sequence */ + fflush(stdout); fflush(stderr); } -#ifdef CRUDE_PROFILING +# ifdef CRUDE_PROFILING cp_show(); -#endif +# endif }