summaryrefslogtreecommitdiff
path: root/compiler/typecheck/TcType.hs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2020-01-16 16:10:01 +0000
committerBen Gamari <ben@smart-cactus.org>2020-02-06 11:55:41 -0500
commit5541b87c498cdd320e9a18d2134e571d713536e1 (patch)
treefe009afbc27d2aeefd4f1a804f4b9d7cd75b8bf9 /compiler/typecheck/TcType.hs
parent9ca5c88e6370c2cafed6b63fe217f70e87d7fcea (diff)
downloadhaskell-5541b87c498cdd320e9a18d2134e571d713536e1.tar.gz
Use foldTyCo for exactTyCoVarsOfType
This entailed * Adding a tcf_view field to TyCoFolder * Moving exactTyCoVarsOtType to TcType. It properly belongs there, since only the typechecker calls this function. But it also means that we can "see" and inline tcView. Metric Decrease: T14683
Diffstat (limited to 'compiler/typecheck/TcType.hs')
-rw-r--r--compiler/typecheck/TcType.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler/typecheck/TcType.hs b/compiler/typecheck/TcType.hs
index 9faa4bb44e..4cec96a847 100644
--- a/compiler/typecheck/TcType.hs
+++ b/compiler/typecheck/TcType.hs
@@ -898,6 +898,42 @@ would re-occur and we end up with an infinite loop in which each kicks
out the other (#14363).
-}
+{- *********************************************************************
+* *
+ The "exact" free variables of a type
+* *
+********************************************************************* -}
+
+{- Note [Silly type synonym]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Consider
+ type T a = Int
+What are the free tyvars of (T x)? Empty, of course!
+
+exactTyCoVarsOfType is used by the type checker to figure out exactly
+which type variables are mentioned in a type. It only matters
+occasionally -- see the calls to exactTyCoVarsOfType.
+
+We place this function here in TcType, note in TyCoFVs,
+because we want to "see" tcView (efficiency issue only).
+-}
+
+exactTyCoVarsOfType :: Type -> TyCoVarSet
+exactTyCoVarsOfTypes :: [Type] -> TyCoVarSet
+-- Find the free type variables (of any kind)
+-- but *expand* type synonyms. See Note [Silly type synonym] above.
+
+exactTyCoVarsOfType ty = runTyCoVars (exact_ty ty)
+exactTyCoVarsOfTypes tys = runTyCoVars (exact_tys tys)
+
+exact_ty :: Type -> Endo TyCoVarSet
+exact_tys :: [Type] -> Endo TyCoVarSet
+(exact_ty, exact_tys, _, _) = foldTyCo exactTcvFolder emptyVarSet
+
+exactTcvFolder :: TyCoFolder TyCoVarSet (Endo TyCoVarSet)
+exactTcvFolder = deepTcvFolder { tcf_view = tcView }
+ -- This is the key line
+
{-
************************************************************************
* *