[commit: ghc] ghc-new-flavor: Make fresh variables when decomposing Givens (ff10612)

Simon Peyton Jones simonpj at microsoft.com
Wed May 9 15:13:21 CEST 2012


Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : ghc-new-flavor

http://hackage.haskell.org/trac/ghc/changeset/ff1061274c6c94ffe7c32f0801879a3619ed99a1

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

commit ff1061274c6c94ffe7c32f0801879a3619ed99a1
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Wed May 9 14:12:59 2012 +0100

    Make fresh variables when decomposing Givens
    
    This turns out to be important becuase we don't have
    a form for superclass selection in TcCoercion (we could
    but we don't).
    
    Se comments with xCtFlavor_cache, the Given case.

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

 compiler/typecheck/TcSMonad.lhs |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/compiler/typecheck/TcSMonad.lhs b/compiler/typecheck/TcSMonad.lhs
index ab42496..7d86d15 100644
--- a/compiler/typecheck/TcSMonad.lhs
+++ b/compiler/typecheck/TcSMonad.lhs
@@ -140,7 +140,7 @@ import UniqFM
 import Maybes ( orElse, catMaybes )
 
 
-import Control.Monad( when )
+import Control.Monad( when, zipWithM )
 import StaticFlags( opt_PprStyle_Debug )
 import Data.IORef
 import TrieMap
@@ -1399,6 +1399,15 @@ setEvBind the_ev t
           | otherwise                                    = False
 #endif
 
+newGivenEvVar :: GivenLoc -> TcPredType -> EvTerm -> TcS CtEvidence
+-- Make a new variable of the given PredType, 
+-- immediately bind it to the given term
+-- and return its CtEvidence
+newGivenEvVar gloc pred rhs
+  = do { new_ev <- wrapTcS $ TcM.newEvVar pred
+       ; setEvBind new_ev rhs
+       ; return (Given { ctev_gloc = gloc, ctev_pred = pred, ctev_evtm = EvId new_ev }) }
+
 newWantedEvVar :: WantedLoc -> TcPredType -> TcS MaybeNew
 newWantedEvVar loc pty
   = do { is <- getTcSInerts
@@ -1471,10 +1480,18 @@ xCtFlavor_cache :: Bool            -- True = if wanted add to the solved bag!
           -> [TcPredType]          -- New predicate types
           -> XEvTerm               -- Instructions about how to manipulate evidence
           -> TcS [CtEvidence]
+
 xCtFlavor_cache _ (Given { ctev_gloc = gl, ctev_evtm = tm }) ptys xev
-  = return [ Given { ctev_gloc = gl, ctev_pred = pred, ctev_evtm = sub_tm } 
-           | (pred, sub_tm) <- zipEqual "xCtFlavor" ptys (ev_decomp xev tm) ]
-    -- ToDo: consider creating new evidence variables for superclasses
+  = ASSERT( equalLength ptys (ev_decomp xev tm) )
+    zipWithM (newGivenEvVar gl) ptys (ev_decomp xev tm)
+    -- For Givens we make new EvVars and bind them immediately. We don't worry
+    -- about caching, but we don't expect complicated calculations among Givens.
+    -- It is important to bind each given:
+    --       class (a~b) => C a b where ....
+    --       f :: C a b => ....
+    -- Then in f's Givens we have g:(C a b) and the superclass sc(g,0):a~b.
+    -- But that superclass selector can't (yet) appear in a coercion
+    -- (see evTermCoercion), so the easy thing is to bind it to an Id
   
 xCtFlavor_cache cache ctev@(Wanted { ctev_wloc = wl, ctev_evar = evar }) ptys xev
   = do { new_evars <- mapM (newWantedEvVar wl) ptys





More information about the Cvs-ghc mailing list