[commit: ghc] wip/spj-temp: Fix TcUnify.tc_sub_type_ds (ebbb8cf)

git at git.haskell.org git at git.haskell.org
Thu Sep 29 08:37:12 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/spj-temp
Link       : http://ghc.haskell.org/trac/ghc/changeset/ebbb8cffc6f65ce3b37041e619ffc9309d815451/ghc

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

commit ebbb8cffc6f65ce3b37041e619ffc9309d815451
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Sun Sep 25 15:50:18 2016 +0100

    Fix TcUnify.tc_sub_type_ds
    
    This patch fixes Trac #12616. There were two separate bugs
    
    1.  For some reason, in TcDeriv we switched on
        -XImpredicativeTypes locally, for the code generated by a
        'deriving' clause.  But GHC really doesn't support
        impredicative types, so this is a deeply bogus thing to
        do.  And it interacted with (2) to cause the failure.
    
        So I've just removed the local flag setting.  Let's see if
        anything breaks.  (If it does, a non-solution is to
        restore the flag!)
    
    2.  In TcUnify.tc_sub_type_ds we were going to some trouble to
        support co- and contra-variance even for impredicative
        types.  Because of (1) that allowed a unification variable
        to be unified with a polytype (probably wrongly) and that
        caused later trouble, in the constraint solver where
        -XImpredicativeTypes was not on.  In effect,
        -XImpredicativeTypes can't be switched on locally.
    
    So this patch just deletes code to fix the bug.  I think we
    should probably nuke -XImpredicativeTypes altogether.


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

ebbb8cffc6f65ce3b37041e619ffc9309d815451
 compiler/typecheck/TcDeriv.hs |  3 +--
 compiler/typecheck/TcUnify.hs | 28 +++++++---------------------
 2 files changed, 8 insertions(+), 23 deletions(-)

diff --git a/compiler/typecheck/TcDeriv.hs b/compiler/typecheck/TcDeriv.hs
index 0b5f073..342e0c0 100644
--- a/compiler/typecheck/TcDeriv.hs
+++ b/compiler/typecheck/TcDeriv.hs
@@ -2272,8 +2272,7 @@ genInst spec@(DS { ds_tvs = tvs, ds_tc = rep_tycon
                         { ib_binds      = gen_Newtype_binds loc clas tvs tys rhs_ty
                         , ib_tyvars     = map Var.varName tvs   -- Scope over bindings
                         , ib_pragmas    = []
-                        , ib_extensions = [ LangExt.ImpredicativeTypes
-                                          , LangExt.RankNTypes ]
+                        , ib_extensions = [ LangExt.RankNTypes ]
                         , ib_derived    = True } }
                 , emptyBag
                 , Just $ getName $ head $ tyConDataCons rep_tycon ) }
diff --git a/compiler/typecheck/TcUnify.hs b/compiler/typecheck/TcUnify.hs
index b564f9f..b8c7640 100644
--- a/compiler/typecheck/TcUnify.hs
+++ b/compiler/typecheck/TcUnify.hs
@@ -721,27 +721,13 @@ tc_sub_type_ds eq_orig inst_orig ctxt ty_actual ty_expected
                     ; tc_sub_type_ds eq_orig inst_orig ctxt ty_a' ty_e }
                Unfilled _   -> unify }
 
-
-    go ty_a (TyVarTy tv_e)
-      = do { dflags <- getDynFlags
-           ; tclvl  <- getTcLevel
-           ; lookup_res <- lookupTcTyVar tv_e
-           ; case lookup_res of
-               Filled ty_e' ->
-                 do { traceTc "tcSubTypeDS_NC_O following filled exp meta-tyvar:"
-                        (ppr tv_e <+> text "-->" <+> ppr ty_e')
-                    ; tc_sub_tc_type eq_orig inst_orig ctxt ty_a ty_e' }
-               Unfilled details
-                 |  canUnifyWithPolyType dflags details
-                    && isTouchableMetaTyVar tclvl tv_e  -- don't want skolems here
-                 -> unify
-
-     -- We've avoided instantiating ty_actual just in case ty_expected is
-     -- polymorphic. But we've now assiduously determined that it is *not*
-     -- polymorphic. So instantiate away. This is needed for e.g. test
-     -- typecheck/should_compile/T4284.
-                 |  otherwise
-                 -> inst_and_unify }
+    -- Historical note (Sept 16): there was a case here for
+    --    go ty_a (TyVarTy alpha)
+    -- which, in the impredicative case unified  alpha := ty_a
+    -- where th_a is a polytype.  Not only is this probably bogus (we
+    -- simply do not have decent story for imprdicative types), but it
+    -- caused Trac #12616 because (also bizarrely) 'deriving' code had
+    -- -XImpredicativeTypes on.  I deleted the entire case.
     
     go (FunTy act_arg act_res) (FunTy exp_arg exp_res)
       | not (isPredTy act_arg)



More information about the ghc-commits mailing list