X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fghci%2FRtClosureInspect.hs;h=e7c85c922545d697f8751e722fbb74650726034a;hb=940524aec90652b5ef81789c9a453c57c0e42cc9;hp=9db0a189ca43ef991b3885e88ccd3b4c920cbfd7;hpb=f3e5a3add2e8b5f878be96d7b04ef52e3c39a211;p=ghc-hetmet.git diff --git a/compiler/ghci/RtClosureInspect.hs b/compiler/ghci/RtClosureInspect.hs index 9db0a18..e7c85c9 100644 --- a/compiler/ghci/RtClosureInspect.hs +++ b/compiler/ghci/RtClosureInspect.hs @@ -22,6 +22,8 @@ module RtClosureInspect( isFullyEvaluated, isPointed, isFullyEvaluatedTerm, + mapTermType, + termTyVars -- unsafeDeepSeq, ) where @@ -284,6 +286,18 @@ idTermFoldM = TermFold { fSuspension = (((return.).).). Suspension } +mapTermType f = foldTerm idTermFold { + fTerm = \ty dc hval tt -> Term (f ty) dc hval tt, + fSuspension = \ct mb_ty hval n -> + Suspension ct (fmap f mb_ty) hval n } + +termTyVars = foldTerm TermFold { + fTerm = \ty _ _ tt -> + tyVarsOfType ty `plusVarEnv` concatVarEnv tt, + fSuspension = \_ mb_ty _ _ -> + maybe emptyVarEnv tyVarsOfType mb_ty, + fPrim = \ _ _ -> emptyVarEnv } + where concatVarEnv = foldr plusVarEnv emptyVarEnv ---------------------------------- -- Pretty printing of terms ---------------------------------- @@ -374,7 +388,7 @@ type TR a = TcM a runTR :: HscEnv -> TR Term -> IO Term runTR hsc_env c = do - mb_term <- initTcPrintErrors hsc_env iNTERACTIVE (c >>= zonkTerm) + mb_term <- initTcPrintErrors hsc_env iNTERACTIVE c case mb_term of Nothing -> panic "Can't unify" Just term -> return term @@ -472,44 +486,17 @@ instScheme ty | (tvs, rho) <- tcSplitForAllTys ty = liftTcM$ do return (ty', zipTopTvSubst tvs' (mkTyVarTys tvs)) cvObtainTerm :: HscEnv -> Bool -> Maybe Type -> HValue -> IO Term -cvObtainTerm hsc_env force mb_ty a = do - -- Obtain the term and tidy the type before returning it - term <- cvObtainTerm1 hsc_env force mb_ty a - let term' = tidyTypes term - return term' - where allvars = nub . foldTerm TermFold { - fTerm = \ty _ _ tt -> - varEnvElts(tyVarsOfType ty) ++ concat tt, - fSuspension = \_ mb_ty _ _ -> - maybe [] (varEnvElts . tyVarsOfType) mb_ty, - fPrim = \ _ _ -> [] } - tidyTypes term = let - go = foldTerm idTermFold { - fTerm = \ty dc hval tt -> - Term (tidy ty) dc hval tt, - fSuspension = \ct mb_ty hval n -> - Suspension ct (fmap tidy mb_ty) hval n } - tidy ty = tidyType (emptyTidyOccEnv, tidyVarEnv) ty - tidyVarEnv = mkVarEnv$ - [ (v, alpha_tv `setTyVarUnique` varUnique v) - | (alpha_tv,v) <- zip alphaTyVars (allvars term)] - in go term - -cvObtainTerm1 :: HscEnv -> Bool -> Maybe Type -> HValue -> IO Term -cvObtainTerm1 hsc_env force mb_ty hval = runTR hsc_env $ do +cvObtainTerm hsc_env force mb_ty hval = runTR hsc_env $ do tv <- liftM mkTyVarTy (newVar argTypeKind) case mb_ty of - Nothing -> go tv tv hval - Just ty | isMonomorphic ty -> go ty ty hval + Nothing -> go tv tv hval >>= zonkTerm + Just ty | isMonomorphic ty -> go ty ty hval >>= zonkTerm Just ty -> do (ty',rev_subst) <- instScheme (sigmaType ty) addConstraint tv ty' - term <- go tv tv hval + term <- go tv tv hval >>= zonkTerm --restore original Tyvars - return$ flip foldTerm term idTermFold { - fTerm = \ty dc hval tt -> Term (substTy rev_subst ty) dc hval tt, - fSuspension = \ct mb_ty hval n -> - Suspension ct (substTy rev_subst `fmap` mb_ty) hval n} + return$ mapTermType (substTy rev_subst) term where go tv ty a = do let monomorphic = not(isTyVarTy tv) -- This is a convention. The ancestor tests for