summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2016-09-25 15:50:18 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2016-09-27 17:17:27 +0100
commitebbb8cffc6f65ce3b37041e619ffc9309d815451 (patch)
treed0e11ca0c3c5d80d3d8d811d058e1a36496f862d
parentedec5b33b5fc5bebce936decbadbe9df2b7d8074 (diff)
downloadhaskell-ebbb8cffc6f65ce3b37041e619ffc9309d815451.tar.gz
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.
-rw-r--r--compiler/typecheck/TcDeriv.hs3
-rw-r--r--compiler/typecheck/TcUnify.hs30
2 files changed, 9 insertions, 24 deletions
diff --git a/compiler/typecheck/TcDeriv.hs b/compiler/typecheck/TcDeriv.hs
index 0b5f07301a..342e0c08a1 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 b564f9fd9a..b8c7640223 100644
--- a/compiler/typecheck/TcUnify.hs
+++ b/compiler/typecheck/TcUnify.hs
@@ -721,28 +721,14 @@ 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)
, not (isPredTy exp_arg)