Kill unnecessary varSetElemsWellScoped in deriveTyData
authorBartosz Nitka <niteria@gmail.com>
Wed, 20 Apr 2016 15:54:10 +0000 (08:54 -0700)
committerBartosz Nitka <niteria@gmail.com>
Wed, 20 Apr 2016 15:55:35 +0000 (08:55 -0700)
varSetElemsWellScoped introduces unnecessary non-determinism and it's possible
to do the same thing deterministically for the same price.

Test Plan: ./validate

Reviewers: austin, simonmar, bgamari, simonpj

Reviewed By: simonpj

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2124

GHC Trac Issues: #4012

compiler/typecheck/TcDeriv.hs

index f46fc46..4f45e41 100644 (file)
@@ -63,6 +63,7 @@ import Outputable
 import FastString
 import Bag
 import Pair
+import FV (runFVList, unionFV, someVars)
 import qualified GHC.LanguageExtensions as LangExt
 
 import Control.Monad
@@ -644,9 +645,11 @@ deriveTyData tvs tc tc_args deriv_pred
               mb_match        = tcUnifyTy inst_ty_kind cls_arg_kind
               Just kind_subst = mb_match
 
-              all_tkvs        = varSetElemsWellScoped $
-                                mkVarSet deriv_tvs `unionVarSet`
-                                tyCoVarsOfTypes tc_args_to_keep
+              all_tkvs        = toposortTyVars $
+                                runFVList $ unionFV
+                                  (tyCoVarsOfTypesAcc tc_args_to_keep)
+                                  (someVars deriv_tvs)
+
               unmapped_tkvs   = filter (`notElemTCvSubst` kind_subst) all_tkvs
               (subst, tkvs)   = mapAccumL substTyVarBndr
                                           kind_subst unmapped_tkvs