From 3f205c430218a2a897c5fb6a1e27b7f6647e6fa9 Mon Sep 17 00:00:00 2001 From: simonmar Date: Fri, 21 Jan 2005 16:02:58 +0000 Subject: [PATCH] [project @ 2005-01-21 16:02:47 by simonmar] Don't try to run finalizers at program exit. This turned out to be hard if not impossible to do in general, so now we don't attempt it at all. The Main.main wrapper, previously called runIO and now called runMainIO, flushes stdout and stderr before exiting. This should catch most cases where programs rely on Handles being flushed at program exit, but note that now if you simply drop a Handle in your program, there's no guarantee it'll be flushed on exit. If the punters complain enough, I suppose we could implement a global Handle table and flush them all at exit... I'd rather not do this if possible, though. Better to teach people to close their Handles properly. --- ghc/compiler/prelude/PrelNames.lhs | 6 +++--- ghc/compiler/typecheck/TcRnDriver.lhs | 6 +++--- ghc/rts/RtsStartup.c | 5 ----- ghc/rts/Weak.c | 31 ------------------------------- ghc/rts/Weak.h | 3 +-- 5 files changed, 7 insertions(+), 44 deletions(-) diff --git a/ghc/compiler/prelude/PrelNames.lhs b/ghc/compiler/prelude/PrelNames.lhs index a180e61..2be6f8a 100644 --- a/ghc/compiler/prelude/PrelNames.lhs +++ b/ghc/compiler/prelude/PrelNames.lhs @@ -107,7 +107,7 @@ basicKnownKeyNames ++ typeableClassNames ++ [ -- Type constructors (synonyms especially) ioTyConName, ioDataConName, - runIOName, + runMainIOName, orderingTyConName, rationalTyConName, ratioDataConName, @@ -425,8 +425,8 @@ and it's convenient to write them all down in one place. \begin{code} -rootMainName = varQual rOOT_MAIN FSLIT("main") rootMainKey -runIOName = varQual pREL_TOP_HANDLER FSLIT("runIO") runMainKey +rootMainName = varQual rOOT_MAIN FSLIT("main") rootMainKey +runMainIOName = varQual pREL_TOP_HANDLER FSLIT("runMainIO") runMainKey orderingTyConName = tcQual pREL_BASE FSLIT("Ordering") orderingTyConKey diff --git a/ghc/compiler/typecheck/TcRnDriver.lhs b/ghc/compiler/typecheck/TcRnDriver.lhs index cda838a..58fdf90 100644 --- a/ghc/compiler/typecheck/TcRnDriver.lhs +++ b/ghc/compiler/typecheck/TcRnDriver.lhs @@ -28,7 +28,7 @@ import HsSyn ( HsModule(..), HsExtCore(..), HsGroup(..), LHsDecl, SpliceDecl(.. nlHsApp, nlHsVar, pprLHsBinds ) import RdrHsSyn ( findSplice ) -import PrelNames ( runIOName, rootMainName, mAIN, +import PrelNames ( runMainIOName, rootMainName, mAIN, main_RDR_Unqual ) import RdrName ( RdrName, mkRdrUnqual, emptyGlobalRdrEnv, plusGlobalRdrEnv ) @@ -668,8 +668,8 @@ check_main ghci_mode tcg_env main_mod main_fn Nothing -> do { complain_no_main ; return tcg_env } ; Just main_name -> do - { let { rhs = nlHsApp (nlHsVar runIOName) (nlHsVar main_name) } - -- :Main.main :: IO () = runIO main + { let { rhs = nlHsApp (nlHsVar runMainIOName) (nlHsVar main_name) } + -- :Main.main :: IO () = runMainIO main ; (main_expr, ty) <- setSrcSpan (srcLocSpan (getSrcLoc main_name)) $ tcInferRho rhs diff --git a/ghc/rts/RtsStartup.c b/ghc/rts/RtsStartup.c index 3b6f050..69ae227 100644 --- a/ghc/rts/RtsStartup.c +++ b/ghc/rts/RtsStartup.c @@ -360,11 +360,6 @@ hs_exit(void) /* start timing the shutdown */ stat_startExit(); -#if !defined(GRAN) - /* Finalize any remaining weak pointers */ - finalizeWeakPointersNow(); -#endif - /* stop all running tasks */ exitScheduler(); diff --git a/ghc/rts/Weak.c b/ghc/rts/Weak.c index 787c9e4..c6c0e43 100644 --- a/ghc/rts/Weak.c +++ b/ghc/rts/Weak.c @@ -21,37 +21,6 @@ StgWeak *weak_ptr_list; /* - * finalizeWeakPointersNow() is called just before the system is shut - * down. It runs the finalizer for each weak pointer still in the - * system. - * - * Careful here - rts_evalIO might cause a garbage collection, which - * might change weak_ptr_list. Must re-load weak_ptr_list each time - * around the loop. - */ - -void -finalizeWeakPointersNow(void) -{ - StgWeak *w; - - rts_lock(); - while ((w = weak_ptr_list)) { - weak_ptr_list = w->link; - if (w->header.info != &stg_DEAD_WEAK_info) { - SET_HDR(w, &stg_DEAD_WEAK_info, w->header.prof.ccs); - IF_DEBUG(weak,debugBelch("Finalising weak pointer at %p -> %p\n", w, w->key)); - if (w->finalizer != &stg_NO_FINALIZER_closure) { - rts_evalLazyIO(w->finalizer,NULL); - rts_unlock(); - rts_lock(); - } - } - } - rts_unlock(); -} - -/* * scheduleFinalizers() is called on the list of weak pointers found * to be dead after a garbage collection. It overwrites each object * with DEAD_WEAK, and creates a new thread to run the pending finalizers. diff --git a/ghc/rts/Weak.h b/ghc/rts/Weak.h index 1cdb4d7..29bf356 100644 --- a/ghc/rts/Weak.h +++ b/ghc/rts/Weak.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------------- * - * (c) The GHC Team, 1998-2004 + * (c) The GHC Team, 1998-2005 * * Weak pointers / finalizers * @@ -9,7 +9,6 @@ #ifndef WEAK_H #define WEAK_H -void finalizeWeakPointersNow(void); void scheduleFinalizers(StgWeak *w); void markWeakList(void); -- 1.7.10.4