[Git][ghc/ghc][wip/T18300] Add Note [Do not always instantiate eagerly in types]
Richard Eisenberg
gitlab at gitlab.haskell.org
Tue Jun 16 16:57:45 UTC 2020
Richard Eisenberg pushed to branch wip/T18300 at Glasgow Haskell Compiler / GHC
Commits:
43681909 by Richard Eisenberg at 2020-06-16T17:56:55+01:00
Add Note [Do not always instantiate eagerly in types]
- - - - -
1 changed file:
- compiler/GHC/Tc/Gen/HsType.hs
Changes:
=====================================
compiler/GHC/Tc/Gen/HsType.hs
=====================================
@@ -640,10 +640,12 @@ tcInferLHsTypeKind lhs_ty@(L loc hs_ty)
setSrcSpan loc $ -- Cover the tcInstInvisibleTyBinders
do { (res_ty, res_kind) <- tc_infer_hs_type (mkMode TypeLevel) hs_ty
; tcInstInvisibleTyBinders res_ty res_kind }
+ -- See Note [Do not always instantiate eagerly in types]
-- Used to check the argument of GHCi :kind
-- Allow and report wildcards, e.g. :kind T _
-- Do not saturate family applications: see Note [Dealing with :kind]
+-- Does not instantiate eagerly; See Note [Do not always instantiate eagerly in types]
tcInferLHsTypeUnsaturated :: LHsType GhcRn -> TcM (TcType, TcKind)
tcInferLHsTypeUnsaturated hs_ty
= addTypeCtxt hs_ty $
@@ -677,6 +679,19 @@ to switch off saturation.
So tcInferLHsTypeUnsaturated does a little special case for top level
applications. Actually the common case is a bare variable, as above.
+Note [Do not always instantiate eagerly in types]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Terms are eagerly instantiated. This means that if you say
+
+ x = id
+
+then `id` gets instantiated to have type alpha -> alpha. The variable
+alpha is then unconstrained and regeneralized. But we cannot do this
+in types, as we have no type-level lambda. So, when we are sure
+that we will not want to regeneralize later -- because we are done
+checking a type, for example -- we can instantiate. But we do not
+instantiate at variables, nor do we in tcInferLHsTypeUnsaturated,
+which is used by :kind in GHCi.
************************************************************************
* *
@@ -1705,6 +1720,7 @@ tc_lhs_pred mode pred = tc_lhs_type mode pred constraintKind
tcTyVar :: TcTyMode -> Name -> TcM (TcType, TcKind)
-- See Note [Type checking recursive type and class declarations]
-- in GHC.Tc.TyCl
+-- This does not instantiate. See Note [Do not always instantiate eagerly in types]
tcTyVar mode name -- Could be a tyvar, a tycon, or a datacon
= do { traceTc "lk1" (ppr name)
; thing <- tcLookup name
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/436819094bc1422044fd36c42384b1b1f977ae7d
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/436819094bc1422044fd36c42384b1b1f977ae7d
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200616/03704087/attachment-0001.html>
More information about the ghc-commits
mailing list