Tidy up RuntimeUnkSkols a bit more
authorsimonpj@microsoft.com <unknown>
Thu, 21 Oct 2010 10:06:40 +0000 (10:06 +0000)
committersimonpj@microsoft.com <unknown>
Thu, 21 Oct 2010 10:06:40 +0000 (10:06 +0000)
compiler/ghci/RtClosureInspect.hs
compiler/typecheck/TcErrors.lhs
compiler/typecheck/TcType.lhs

index b281695..5d74dc9 100644 (file)
@@ -571,17 +571,24 @@ liftTcM = id
 newVar :: Kind -> TR TcType
 newVar = liftTcM . newFlexiTyVarTy
 
 newVar :: Kind -> TR TcType
 newVar = liftTcM . newFlexiTyVarTy
 
-type RttiInstantiation = [(TyVar, TcTyVar)]
-   -- Assoicates the debugger-world type variables (which are skolems)
-   -- to typechecker-world meta type variables (which are mutable,
-   -- and may be refined)
+type RttiInstantiation = [(TcTyVar, TyVar)]
+   -- Associates the typechecker-world meta type variables 
+   -- (which are mutable and may be refined), to their 
+   -- debugger-world RuntimeUnkSkol counterparts.
+   -- If the TcTyVar has not been refined by the runtime type
+   -- elaboration, then we want to turn it back into the
+   -- original RuntimeUnkSkol
 
 -- | Returns the instantiated type scheme ty', and the 
 
 -- | Returns the instantiated type scheme ty', and the 
---   mapping from old to new (instantiated) type variables
+--   mapping from new (instantiated) -to- old (skolem) type variables
+--   We want this mapping just for old RuntimeUnkSkols, to avoid
+--   gratuitously changing their unique on every trip
 instScheme :: QuantifiedType -> TR (TcType, RttiInstantiation)
 instScheme (tvs, ty) 
   = liftTcM $ do { (tvs', _, subst) <- tcInstTyVars tvs
 instScheme :: QuantifiedType -> TR (TcType, RttiInstantiation)
 instScheme (tvs, ty) 
   = liftTcM $ do { (tvs', _, subst) <- tcInstTyVars tvs
-                 ; return (substTy subst ty, tvs `zip` tvs') }
+                 ; let rtti_inst = [(tv',tv) | (tv',tv) <- tvs' `zip` tvs
+                                             , isRuntimeUnkSkol tv]
+                 ; return (substTy subst ty, rtti_inst) }
 
 applyRevSubst :: RttiInstantiation -> TR ()
 -- Apply the *reverse* substitution in-place to any un-filled-in
 
 applyRevSubst :: RttiInstantiation -> TR ()
 -- Apply the *reverse* substitution in-place to any un-filled-in
@@ -589,7 +596,7 @@ applyRevSubst :: RttiInstantiation -> TR ()
 -- unless it has been refined by new information from the heap
 applyRevSubst pairs = liftTcM (mapM_ do_pair pairs)
   where
 -- unless it has been refined by new information from the heap
 applyRevSubst pairs = liftTcM (mapM_ do_pair pairs)
   where
-    do_pair (rtti_tv, tc_tv)
+    do_pair (tc_tv, rtti_tv)
       = do { tc_ty <- zonkTcTyVar tc_tv
            ; case tcGetTyVar_maybe tc_ty of
                Just tv | isMetaTyVar tv -> writeMetaTyVar tv (mkTyVarTy rtti_tv)
       = do { tc_ty <- zonkTcTyVar tc_tv
            ; case tcGetTyVar_maybe tc_ty of
                Just tv | isMetaTyVar tv -> writeMetaTyVar tv (mkTyVarTy rtti_tv)
@@ -1131,6 +1138,10 @@ zonkRttiType = zonkType (mkZonkTcTyVar zonk_unbound_meta)
     zonk_unbound_meta tv 
       = ASSERT( isTcTyVar tv )
         do { tv' <- skolemiseUnboundMetaTyVar RuntimeUnkSkol tv
     zonk_unbound_meta tv 
       = ASSERT( isTcTyVar tv )
         do { tv' <- skolemiseUnboundMetaTyVar RuntimeUnkSkol tv
+            -- This is where RuntimeUnkSkols are born: 
+            -- otherwise-unconstrained unification variables are
+            -- turned into RuntimeUnkSkols as they leave the
+            -- typechecker's monad
            ; return (mkTyVarTy tv') }
 
 --------------------------------------------------------------------------------
            ; return (mkTyVarTy tv') }
 
 --------------------------------------------------------------------------------
index c8f624f..28fc91b 100644 (file)
@@ -640,17 +640,8 @@ warnDefaulting wanteds default_ty
 Note [Runtime skolems]
 ~~~~~~~~~~~~~~~~~~~~~~
 We want to give a reasonably helpful error message for ambiguity
 Note [Runtime skolems]
 ~~~~~~~~~~~~~~~~~~~~~~
 We want to give a reasonably helpful error message for ambiguity
-arising from *runtime* skolems in the debugger.  Mostly these
-are created by in RtClosureInspec.zonkRTTIType.  However at a 
-breakpoint we return Ids from the CoreExpr, whose types may have
-free type variables bound by some enclosing 'forall'.  These are
-UnkSkols, created ty TcType.zonkQuantifiedTyVar.  
-
-These UnkSkols should never show up as ambiguous type variables in
-normal typechecking, so we hackily emit the debugger-related message
-both for RuntimeUnkSkols and UnkSkols. Hence the two cases in
-TcType.isRuntimeUnkSkol. Yuk. The rest of the debugger is such
-a mess that I don't feel motivated to clean up this bit.
+arising from *runtime* skolems in the debugger.  These
+are created by in RtClosureInspect.zonkRTTIType.  
 
 
 %************************************************************************
 
 
 %************************************************************************
index 7410092..47bb554 100644 (file)
@@ -673,14 +673,10 @@ isIndirect _            = False
 
 isRuntimeUnkSkol :: TyVar -> Bool
 -- Called only in TcErrors; see Note [Runtime skolems] there
 
 isRuntimeUnkSkol :: TyVar -> Bool
 -- Called only in TcErrors; see Note [Runtime skolems] there
-isRuntimeUnkSkol x 
-  | isTcTyVar x
-  , SkolemTv info <- tcTyVarDetails x 
-  = case info of 
-       UnkSkol -> True
-       RuntimeUnkSkol -> True
-       _ -> False
-  | otherwise = False
+isRuntimeUnkSkol x | isTcTyVar x
+                  , SkolemTv RuntimeUnkSkol <- tcTyVarDetails x 
+                  = True
+                  | otherwise = False
 
 isUnkSkol :: TyVar -> Bool
 isUnkSkol x | isTcTyVar x
 
 isUnkSkol :: TyVar -> Bool
 isUnkSkol x | isTcTyVar x