1 -----------------------------------------------------------------------------
3 -- GHCi Interactive debugging commands
5 -- Pepe Iborra (supported by Google SoC) 2006
7 -----------------------------------------------------------------------------
9 module DebuggerTys (instantiateTyVarsToUnknown) where
21 ----------------------------------------------------------------------------
22 -- | Replace all the tyvars in a Term with the opaque type GHC.Base.Unknown
23 ----------------------------------------------------------------------------
24 instantiateTyVarsToUnknown :: HscEnv -> Type -> IO Type
25 instantiateTyVarsToUnknown hsc_env ty
26 -- We have a GADT, so just fix its tyvars
27 | Just (tycon, args) <- splitTyConApp_maybe ty
30 = mapM fixTyVars args >>= return . mkTyConApp tycon
31 -- We have a regular TyCon, so map recursively to its args
32 | Just (tycon, args) <- splitTyConApp_maybe ty
34 = do unknownTyVar <- unknownTV
35 args' <- mapM (instantiateTyVarsToUnknown hsc_env) args
36 return$ mkTyConApp tycon args'
37 -- we have a tyvar of kind *
38 | Just tyvar <- getTyVar_maybe ty
39 , ([],_) <- splitKindFunTys (tyVarKind tyvar)
41 -- we have a higher kind tyvar, so insert an unknown of the appropriate kind
42 | Just tyvar <- getTyVar_maybe ty
43 , (args,_) <- splitKindFunTys (tyVarKind tyvar)
44 = liftM mkTyConTy $ unknownTC !! length args
46 | otherwise = return ty
49 Just (ATyCon unknown_tc) <- tcRnLookupName hsc_env unknownTyConName
50 return$ mkTyConTy unknown_tc
51 unknownTC = [undefined, unknownTC1, unknownTC2, unknownTC3]
53 Just (ATyCon unknown_tc) <- tcRnLookupName hsc_env unknown1TyConName
56 Just (ATyCon unknown_tc) <- tcRnLookupName hsc_env unknown2TyConName
59 Just (ATyCon unknown_tc) <- tcRnLookupName hsc_env unknown3TyConName
61 -- isGADT ty | pprTrace' "isGADT" (ppr ty <> colon <> ppr(isGadtSyntaxTyCon ty)) False = undefined
62 isGADT tc | Just dcs <- tyConDataCons_maybe tc = any (not . null . dataConEqSpec) dcs
65 | Just (tycon, args) <- splitTyConApp_maybe ty
66 = mapM fixTyVars args >>= return . mkTyConApp tycon
67 -- Fix the tyvar so that the interactive environment doesn't choke on it TODO
68 | Just tv <- getTyVar_maybe ty = return ty --TODO
69 | otherwise = return ty