[commit: ghc] wip/ghc-8.0-det: Kill varSetElems in injImproveEqns (8a6f976)

git at git.haskell.org git at git.haskell.org
Mon Jul 25 14:58:27 UTC 2016


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

On branch  : wip/ghc-8.0-det
Link       : http://ghc.haskell.org/trac/ghc/changeset/8a6f976e93ec10774de03c4778c06dc7a86c29e7/ghc

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

commit 8a6f976e93ec10774de03c4778c06dc7a86c29e7
Author: Bartosz Nitka <niteria at gmail.com>
Date:   Thu Apr 28 05:40:39 2016 -0700

    Kill varSetElems in injImproveEqns
    
    We want to remove varSetElems at the source level because it
    might be a source of nondeterminism. I don't think it introduces
    nondeterminism here, but it's easy to do the same thing
    deterministically for the same price.
    
    instFlexiTcS :: [TKVar] -> TcS (TCvSubst, [TcType])
    instFlexiTcS currently gives the range of the produced substitution
    as the second element of the tuple, but it's not used anywhere
    right now. If it started to be used in the code I'm modifying
    it would cause nondeterminism problems.
    
    Test Plan: ./validate
    
    Reviewers: austin, goldfire, bgamari, simonmar, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D2149
    
    GHC Trac Issues: #4012
    
    (cherry picked from commit 82538f65f48f370764691264c3c71b975fd43e16)


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

8a6f976e93ec10774de03c4778c06dc7a86c29e7
 compiler/typecheck/TcInteract.hs | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/compiler/typecheck/TcInteract.hs b/compiler/typecheck/TcInteract.hs
index 39ad787..ca5d912 100644
--- a/compiler/typecheck/TcInteract.hs
+++ b/compiler/typecheck/TcInteract.hs
@@ -1491,7 +1491,7 @@ improve_top_fun_eqs fam_envs fam_tc args rhs_ty
           -> (a -> [Type])           -- get LHS of an axiom
           -> (a -> Type)             -- get RHS of an axiom
           -> (a -> Maybe CoAxBranch) -- Just => apartness check required
-          -> [( [Type], TCvSubst, TyVarSet, Maybe CoAxBranch )]
+          -> [( [Type], TCvSubst, [TyVar], Maybe CoAxBranch )]
              -- Result:
              -- ( [arguments of a matching axiom]
              -- , RHS-unifying substitution
@@ -1503,15 +1503,20 @@ improve_top_fun_eqs fam_envs fam_tc args rhs_ty
           , let ax_args = axiomLHS axiom
           , let ax_rhs  = axiomRHS axiom
           , Just subst <- [tcUnifyTyWithTFs False ax_rhs rhs_ty]
-          , let tvs           = tyCoVarsOfTypes ax_args
+          , let tvs           = tyCoVarsOfTypesList ax_args
                 notInSubst tv = not (tv `elemVarEnv` getTvSubstEnv subst)
-                unsubstTvs    = filterVarSet (notInSubst <&&> isTyVar) tvs ]
+                unsubstTvs    = filter (notInSubst <&&> isTyVar) tvs ]
 
       injImproveEqns :: [Bool]
-                     -> ([Type], TCvSubst, TyCoVarSet, Maybe CoAxBranch)
+                     -> ([Type], TCvSubst, [TyCoVar], Maybe CoAxBranch)
                      -> TcS [Eqn]
       injImproveEqns inj_args (ax_args, theta, unsubstTvs, cabr) = do
-        (theta', _) <- instFlexiTcS (varSetElems unsubstTvs)
+        (theta', _) <- instFlexiTcS unsubstTvs
+        -- The use of deterministically ordered list for `unsubstTvs`
+        -- is not strictly necessary here, we only use the substitution
+        -- part of the result of instFlexiTcS. If we used the second
+        -- part of the tuple, which is the range of the substitution then
+        -- the order could be important.
         let subst = theta `unionTCvSubst` theta'
         return [ Pair arg (substTyUnchecked subst ax_arg)
                | case cabr of



More information about the ghc-commits mailing list