[commit: ghc] wip/T8503: Comments with Simon (e329ed5)

git at git.haskell.org git at git.haskell.org
Thu Nov 21 12:51:03 UTC 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/T8503
Link       : http://ghc.haskell.org/trac/ghc/changeset/e329ed56727848774049255875ec24bc39ba4965/ghc

>---------------------------------------------------------------

commit e329ed56727848774049255875ec24bc39ba4965
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Nov 21 12:50:13 2013 +0000

    Comments with Simon


>---------------------------------------------------------------

e329ed56727848774049255875ec24bc39ba4965
 compiler/typecheck/TcInteract.lhs |    3 ++-
 compiler/typecheck/TcRnTypes.lhs  |   42 +++++++++++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/compiler/typecheck/TcInteract.lhs b/compiler/typecheck/TcInteract.lhs
index e4122e8..e559197 100644
--- a/compiler/typecheck/TcInteract.lhs
+++ b/compiler/typecheck/TcInteract.lhs
@@ -1439,8 +1439,9 @@ doTopReact inerts workItem
 --------------------
 doTopReactDict :: InertSet -> CtEvidence -> Class -> [Xi]
                -> CtLoc -> TcS TopInteractResult
+-- Try to use type-class instance declarations to simplify the constraint
 doTopReactDict inerts fl cls xis loc
-  | not (isWanted fl)
+  | not (isWanted fl)   -- Never use instances for Given or Derived constraints
   = try_fundeps_and_return
 
   | Just ev <- lookupSolvedDict inerts pred   -- Cached
diff --git a/compiler/typecheck/TcRnTypes.lhs b/compiler/typecheck/TcRnTypes.lhs
index fd9513e..9f334cc 100644
--- a/compiler/typecheck/TcRnTypes.lhs
+++ b/compiler/typecheck/TcRnTypes.lhs
@@ -1493,18 +1493,44 @@ See the call sites for explanations.
 %*                                                                      *
 %************************************************************************
 
+Note [SubGoalDepth]
+~~~~~~~~~~~~~~~~~~~
 The 'SubGoalCounter' takes care of stopping the constraint solver from looping.
 Because of the different use-cases of regular constaints and type function
 applications, there are two independent counters. Therefore, this datatype is
-abstract.
+abstract. See Note [WorkList]
+
+Each counter starts at zero and increases.
+
+* The "dictionary constraint counter counts the depth of type class
+  instance declarations.  Example:
+     [W] d{7} : Eq [Int]
+  That is d's dictionary-constraint depth is 7.  If we use the instance
+     $dfEqList :: Eq a => Eq [a]
+  to simplify it, we get
+     d{7} = $dfEqList d'{8}
+  where d'{8} : Eq Int, and d' has dictionary-constraint depth 8.
+
+  For civilised (decidable) instance declarations, each increase of
+  depth removes a type constructor from the type, so the depth never
+  gets big; i.e. is bounded by the structural depth of the type.
+
+  The flag -fcontext-stack=n (not very well named!) fixes the maximium
+  level.
+
+* .... function
+
+  The flag -ftype-function-depth=n fixes the maximium level.
+
 
 \begin{code}
 data SubGoalCounter = CountConstraints | CountTyFunApps
 
-data SubGoalDepth = SubGoalDepth !Int !Int deriving (Eq, Ord)
- -- An ever increasing number used to restrict
- -- simplifier iterations. Bounded by -fcontext-stack.
- -- See Note [WorkList]
+data SubGoalDepth  -- See Note [SubGoalDepth]
+   = SubGoalDepth
+         {-# UNPACK #-} !Int      -- Dictionary constraints
+         {-# UNPACK #-} !Int      -- Type function reductions
+  deriving (Eq, Ord)
 
 instance Outputable SubGoalDepth where
  ppr (SubGoalDepth c f) =  angleBrackets $
@@ -1567,15 +1593,13 @@ type will evolve...
 
 \begin{code}
 data CtLoc = CtLoc { ctl_origin :: CtOrigin
-                   , ctl_env ::  TcLclEnv
-                   , ctl_depth :: SubGoalDepth }
+                   , ctl_env    :: TcLclEnv
+                   , ctl_depth  :: !SubGoalDepth }
   -- The TcLclEnv includes particularly
   --    source location:  tcl_loc   :: SrcSpan
   --    context:          tcl_ctxt  :: [ErrCtxt]
   --    binder stack:     tcl_bndrs :: [TcIdBinders]
 
-
-
 mkGivenLoc :: SkolemInfo -> TcLclEnv -> CtLoc
 mkGivenLoc skol_info env = CtLoc { ctl_origin = GivenOrigin skol_info
                                  , ctl_env = env



More information about the ghc-commits mailing list