summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2017-06-05 11:16:16 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2017-06-05 11:16:16 +0100
commita65dfea535ddf3ca6aa2380ad38cb60cf5c0f1d8 (patch)
tree5073f2314d0526c310ac4741a52ed157d38ee589 /compiler
parent6597f0846904dc5accbe2556badbd29a8a58c28e (diff)
downloadhaskell-a65dfea535ddf3ca6aa2380ad38cb60cf5c0f1d8.tar.gz
Make the MR warning more accurage
Trac #13785 showed that we were emitting monomorphism warnings when we shouldn't. The fix turned out to be simple. In fact test T10935 then turned out to be another example of the over-noisy warning so I changed the test slightly.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/typecheck/TcSimplify.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/compiler/typecheck/TcSimplify.hs b/compiler/typecheck/TcSimplify.hs
index dcb146a3c9..2e49f2adf8 100644
--- a/compiler/typecheck/TcSimplify.hs
+++ b/compiler/typecheck/TcSimplify.hs
@@ -818,16 +818,19 @@ decideMonoTyVars infer_mode name_taus psigs candidates
; gbl_tvs <- tcGetGlobalTyCoVars
; let eq_constraints = filter isEqPred candidates
- constrained_tvs = tyCoVarsOfTypes no_quant
- mono_tvs1 = growThetaTyVars eq_constraints $
- gbl_tvs `unionVarSet` constrained_tvs
+ mono_tvs1 = growThetaTyVars eq_constraints gbl_tvs
+ constrained_tvs = growThetaTyVars eq_constraints (tyCoVarsOfTypes no_quant)
+ `minusVarSet` mono_tvs1
+ mono_tvs2 = mono_tvs1 `unionVarSet` constrained_tvs
+ -- A type variable is only "constrained" (so that the MR bites)
+ -- if it is not free in the environment (Trac #13785)
-- Always quantify over partial-sig qtvs, so they are not mono
-- Need to zonk them because they are meta-tyvar SigTvs
-- Note [Quantification and partial signatures], wrinkle 3
; psig_qtvs <- mapM zonkTcTyVarToTyVar $
concatMap (map snd . sig_inst_skols) psigs
- ; let mono_tvs = mono_tvs1 `delVarSetList` psig_qtvs
+ ; let mono_tvs = mono_tvs2 `delVarSetList` psig_qtvs
-- Warn about the monomorphism restriction
; warn_mono <- woptM Opt_WarnMonomorphism
@@ -863,11 +866,12 @@ decideMonoTyVars infer_mode name_taus psigs candidates
= False
pp_bndrs = pprWithCommas (quotes . ppr . fst) name_taus
- mr_msg = hang (text "The Monomorphism Restriction applies to the binding"
- <> plural name_taus <+> text "for" <+> pp_bndrs)
- 2 (text "Consider giving a type signature for"
- <+> if isSingleton name_taus then pp_bndrs
- else text "these binders")
+ mr_msg = hang (sep [ text "The Monomorphism Restriction applies to the binding"
+ <> plural name_taus
+ , text "for" <+> pp_bndrs ])
+ 2 (hsep [ text "Consider giving"
+ , text (if isSingleton name_taus then "it" else "them")
+ , text "a type signature"])
-------------------
defaultTyVarsAndSimplify :: TcLevel