Fix debugger
authorsimonpj@microsoft.com <unknown>
Tue, 19 Oct 2010 15:35:22 +0000 (15:35 +0000)
committersimonpj@microsoft.com <unknown>
Tue, 19 Oct 2010 15:35:22 +0000 (15:35 +0000)
A bit yukky; see Note [Runtime skolems] in TcErrors.
But it works, and the debugger just is yukky in places.

compiler/typecheck/TcErrors.lhs
compiler/typecheck/TcType.lhs

index 572f82c..c8f624f 100644 (file)
@@ -396,7 +396,7 @@ typeExtraInfoMsg env ty
   | Just tv <- tcGetTyVar_maybe ty
   , isTcTyVar tv
   , isSkolemTyVar tv || isSigTyVar tv
-  , not (isUnk tv)
+  , not (isUnkSkol tv)
   , let (env1, tv1) = tidySkolemTyVar env tv
   = (env1, pprSkolTvBinding tv1)
   where
@@ -533,10 +533,11 @@ mkMonomorphismMsg :: ReportErrCtxt -> [TcTyVar] -> TcM (TidyEnv, SDoc)
 -- ASSUMPTION: the Insts are fully zonked
 mkMonomorphismMsg ctxt inst_tvs
   = do { dflags <- getDOpts
-       ; (tidy_env, docs) <- findGlobals ctxt (mkVarSet inst_tvs)
+       ; traceTc "Mono" (vcat (map pprSkolTvBinding inst_tvs))
+        ; (tidy_env, docs) <- findGlobals ctxt (mkVarSet inst_tvs)
        ; return (tidy_env, mk_msg dflags docs) }
   where
-    mk_msg _ _ | any isRuntimeUnk inst_tvs
+    mk_msg _ _ | any isRuntimeUnkSkol inst_tvs  -- See Note [Runtime skolems]
         =  vcat [ptext (sLit "Cannot resolve unknown runtime types:") <+>
                    (pprWithCommas ppr inst_tvs),
                 ptext (sLit "Use :print or :force to determine these types")]
@@ -636,6 +637,22 @@ warnDefaulting wanteds default_ty
     (loc, ppr_wanteds) = pprWithArising wanteds
 \end{code}
 
+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.
+
+
 %************************************************************************
 %*                                                                     *
                  Error from the canonicaliser
index 194deb9..7410092 100644 (file)
@@ -30,7 +30,7 @@ module TcType (
   isImmutableTyVar, isSkolemTyVar, isMetaTyVar,  isMetaTyVarTy,
   isSigTyVar, isExistentialTyVar,  isTyConableTyVar,
   metaTvRef, 
-  isFlexi, isIndirect, isRuntimeUnk, isUnk,
+  isFlexi, isIndirect, isUnkSkol, isRuntimeUnkSkol,
 
   --------------------------------
   -- Builders
@@ -335,6 +335,7 @@ data SkolemInfo
 
   | RuleSkol RuleName  -- The LHS of a RULE
   | GenSkol TcType     -- Bound when doing a subsumption check for ty
+
   | RuntimeUnkSkol      -- a type variable used to represent an unknown
                         -- runtime type (used in the GHCi debugger)
 
@@ -670,15 +671,21 @@ isFlexi _     = False
 isIndirect (Indirect _) = True
 isIndirect _            = False
 
-isRuntimeUnk :: TyVar -> Bool
-isRuntimeUnk x | isTcTyVar x
-               , SkolemTv RuntimeUnkSkol <- tcTyVarDetails x = True
-               | otherwise = False
-
-isUnk :: TyVar -> Bool
-isUnk x | isTcTyVar x
-        , SkolemTv UnkSkol <- tcTyVarDetails x = True
-        | otherwise = False
+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
+
+isUnkSkol :: TyVar -> Bool
+isUnkSkol x | isTcTyVar x
+            , SkolemTv UnkSkol <- tcTyVarDetails x = True
+            | otherwise = False
 \end{code}