diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2020-07-09 22:22:34 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-18 07:26:43 -0400 |
commit | bcb177dd00c91d825e00ed228bce6cfeb7684bf7 (patch) | |
tree | 78094377d9f81531b39fbdaaa82bff600ac3b958 /compiler/GHC/Tc/Gen/Expr.hs | |
parent | e6cf27dfded59fe42bd6be323573c0d576e6204a (diff) | |
download | haskell-bcb177dd00c91d825e00ed228bce6cfeb7684bf7.tar.gz |
Allow multiple case branches to have a higher rank type
As #18412 points out, it should be OK for multiple case alternatives
to have a higher rank type, provided they are all the same.
This patch implements that change. It sweeps away
GHC.Tc.Gen.Match.tauifyMultipleBranches, and friends, replacing it
with an enhanced version of fillInferResult.
The basic change to fillInferResult is to permit the case in which
another case alternative has already filled in the result; and in
that case simply unify. It's very simple actually.
See the new Note [fillInferResult] in TcMType
Other refactoring:
- Move all the InferResult code to one place, in GHC.Tc.Utils.TcMType
(previously some of it was in Unify)
- Move tcInstType and friends from TcMType to Instantiate, where it
more properly belongs. (TCMType was getting very long.)
Diffstat (limited to 'compiler/GHC/Tc/Gen/Expr.hs')
-rw-r--r-- | compiler/GHC/Tc/Gen/Expr.hs | 11 |
1 files changed, 1 insertions, 10 deletions
diff --git a/compiler/GHC/Tc/Gen/Expr.hs b/compiler/GHC/Tc/Gen/Expr.hs index d5ecbcbe45..e8954914e3 100644 --- a/compiler/GHC/Tc/Gen/Expr.hs +++ b/compiler/GHC/Tc/Gen/Expr.hs @@ -599,22 +599,13 @@ tcExpr (HsCase x scrut matches) res_ty tcExpr (HsIf x pred b1 b2) res_ty = do { pred' <- tcLExpr pred (mkCheckExpType boolTy) - ; res_ty <- tauifyExpType res_ty - -- Just like Note [Case branches must never infer a non-tau type] - -- in GHC.Tc.Gen.Match (See #10619) ; (u1,b1') <- tcCollectingUsage $ tcLExpr b1 res_ty ; (u2,b2') <- tcCollectingUsage $ tcLExpr b2 res_ty ; tcEmitBindingUsage (supUE u1 u2) ; return (HsIf x pred' b1' b2') } tcExpr (HsMultiIf _ alts) res_ty - = do { res_ty <- if isSingleton alts - then return res_ty - else tauifyExpType res_ty - -- Just like GHC.Tc.Gen.Match - -- Note [Case branches must never infer a non-tau type] - - ; alts' <- mapM (wrapLocM $ tcGRHS match_ctxt res_ty) alts + = do { alts' <- mapM (wrapLocM $ tcGRHS match_ctxt res_ty) alts ; res_ty <- readExpType res_ty ; return (HsMultiIf res_ty alts') } where match_ctxt = MC { mc_what = IfAlt, mc_body = tcBody } |