Commit 184a569c authored by Simon Peyton Jones's avatar Simon Peyton Jones

Clean up TcHsSyn.zonkEnv

Triggered by Trac #15552, I'd been looking at ZonkEnv in TcHsSyn.

This patch does some minor refactoring

* Make ZonkEnv into a record with named fields, and use them.
  (I'm planning to add a new field, for TyCons, so this prepares
  the way.)

* Replace UnboundTyVarZonker (a higer order function) with the
  simpler and more self-descriptive ZonkFlexi data type, below.
 It's just much more perspicuous and direct, and (I suspect)
 a tiny bit faster too -- no unknown function calls.

data ZonkFlexi   -- See Note [Un-unified unification variables]
  = DefaultFlexi    -- Default unbound unificaiton variables to Any
  | SkolemiseFlexi  -- Skolemise unbound unification variables
                    -- See Note [Zonking the LHS of a RULE]
  | RuntimeUnkFlexi -- Used in the GHCi debugger

There was one knock-on effect in the GHCi debugger -- the
RuntimeUnkFlexi case.  Somehow previously, these RuntimeUnk
variables were sometimes getting SystemNames (and hence
printed as 'a0', 'a1', etc) and sometimes not (and hence
printed as 'a', 'b' etc).  I'm not sure precisely why, but
the new behaviour seems more uniform, so I just accepted the
(small) renaming wibbles in some ghci.debugger tests.

I had a quick look at perf: any changes are tiny.
parent 14d88380
......@@ -39,7 +39,7 @@ import Var
import TcRnMonad
import TcType
import TcMType
import TcHsSyn ( zonkTcTypeToType, mkEmptyZonkEnv )
import TcHsSyn ( zonkTcTypeToType, mkEmptyZonkEnv, ZonkFlexi( RuntimeUnkFlexi ) )
import TcUnify
import TcEnv
......@@ -1257,17 +1257,8 @@ zonkTerm = foldTermM (TermFoldM
zonkRttiType :: TcType -> TcM Type
-- Zonk the type, replacing any unbound Meta tyvars
-- by skolems, safely out of Meta-tyvar-land
zonkRttiType = zonkTcTypeToType (mkEmptyZonkEnv zonk_unbound_meta)
where
zonk_unbound_meta tv
= ASSERT( isTcTyVar tv )
do { tv' <- skolemiseRuntimeUnk tv
-- This is where RuntimeUnks are born:
-- otherwise-unconstrained unification variables are
-- turned into RuntimeUnks as they leave the
-- typechecker's monad
; return (mkTyVarTy tv') }
-- by RuntimeUnk skolems, safely out of Meta-tyvar-land
zonkRttiType = zonkTcTypeToType (mkEmptyZonkEnv RuntimeUnkFlexi)
--------------------------------------------------------------------------------
-- Restore Class predicates out of a representation type
......
This diff is collapsed.
......@@ -24,7 +24,7 @@ module TcMType (
cloneMetaTyVar,
newFmvTyVar, newFskTyVar,
readMetaTyVar, writeMetaTyVar,
readMetaTyVar, writeMetaTyVar, writeMetaTyVarRef,
newMetaDetails, isFilledMetaTyVar, isUnfilledMetaTyVar,
--------------------------------
......@@ -63,8 +63,7 @@ module TcMType (
-- Zonking and tidying
zonkTidyTcType, zonkTidyTcTypes, zonkTidyOrigin,
tidyEvVar, tidyCt, tidySkolemInfo,
skolemiseRuntimeUnk,
zonkTcTyVar, zonkTcTyVars,
zonkTcTyVar, zonkTcTyVars,
zonkTcTyVarToTyVar, zonkTyVarTyVarPairs,
zonkTyCoVarsAndFV, zonkTcTypeAndFV,
zonkTyCoVarsAndFVList,
......@@ -1140,21 +1139,12 @@ defaultTyVar default_kind tv
where
(_, kv') = tidyOpenTyCoVar emptyTidyEnv kv
skolemiseRuntimeUnk :: TcTyVar -> TcM TyVar
skolemiseRuntimeUnk tv
= skolemise_tv tv RuntimeUnk
skolemiseUnboundMetaTyVar :: TcTyVar -> TcM TyVar
skolemiseUnboundMetaTyVar tv
= skolemise_tv tv (SkolemTv (metaTyVarTcLevel tv) False)
skolemise_tv :: TcTyVar -> TcTyVarDetails -> TcM TyVar
-- We have a Meta tyvar with a ref-cell inside it
-- Skolemise it, so that
-- we are totally out of Meta-tyvar-land
-- We create a skolem TyVar, not a regular TyVar
-- Skolemise it, so that we are totally out of Meta-tyvar-land
-- We create a skolem TcTyVar, not a regular TyVar
-- See Note [Zonking to Skolem]
skolemise_tv tv details
skolemiseUnboundMetaTyVar tv
= ASSERT2( isMetaTyVar tv, ppr tv )
do { when debugIsOn (check_empty tv)
; span <- getSrcSpanM -- Get the location from "here"
......@@ -1173,6 +1163,7 @@ skolemise_tv tv details
; return final_tv }
where
details = SkolemTv (metaTyVarTcLevel tv) False
check_empty tv -- [Sept 04] Check for non-empty.
= when debugIsOn $ -- See note [Silly Type Synonym]
do { cts <- readMetaTyVar tv
......
t = O (_t1::a)
t = O (_t1::a0)
t :: Opaque = O _
_t1 :: a = _
_t1 :: a0 = _
()
t = O ((_t2::a1) : (_t3::[a1]))
t = O ((_t2::a0) : (_t3::[a0]))
t :: Opaque = O (_ : _)
_t1 :: [a] = _ : _
it :: () = ()
_t3 :: [a1] = _
_t2 :: a1 = _
_t3 :: [a0] = _
_t2 :: a0 = _
()
t = O (Just [1,1] : (_t4::[Maybe [Integer]]))
()
......
t = O (_t1::a)
t = O (_t1::a0)
()
t = O ((_t2::a1) : (_t3::[a1]))
t = O ((_t2::a0) : (_t3::[a0]))
()
t = O ((_t4::a2) : (_t5::a2) : (_t6::[a2]))
t = O ((_t4::a1) : (_t5::a1) : (_t6::[a1]))
()
t = O ((_t7::Maybe [Integer]) : Just [2,2] :
(_t8::[Maybe [Integer]]))
......
t = O (_t1::a)
_t1 :: a
t = O (_t1::a0)
_t1 :: a0
()
t = O ((_t2::a1) : (_t3::[a1]))
t = O ((_t2::a0) : (_t3::[a0]))
()
t = O (Just [1,1] : (_t4::[Maybe [Integer]]))
_t4 :: [Maybe [Integer]]
o = O (_t1::a)
o = O (_t1::a0)
()
o = O ((_t2::a1) : (_t3::[a1]))
o = O ((_t2::a0) : (_t3::[a0]))
()
3
o = O [0,(_t4::Integer),(_t5::Integer),(_t6::Integer)]
o = O (_t1::a)
o = O (_t1::a0)
()
_t1 :: SafeList Integer NonEmpty
o = O (Cons 3 (_t4::SafeList Integer y))
o = O (Cons 3 (_t4::SafeList Integer y0))
()
o = O (Cons 3 (Cons 6 (_t9::SafeList Integer y)))
o = O (Cons 3 (Cons 6 (_t9::SafeList Integer y0)))
a = O (_t1::a)
a = O (_t1::a0)
b = O (_t2::a1)
()
_t1 = 'a'
......
o = O (_t1::a)
o = O (_t1::a0)
()
_t1 :: SafeList Bool NonEmpty
o = O (One False (_t4::SafeList Bool Empty))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment