[commit: ghc] ghc-8.0: Keep the bindings local during defaultCallStacks (829b968)
git at git.haskell.org
git at git.haskell.org
Thu Aug 25 16:37:35 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.0
Link : http://ghc.haskell.org/trac/ghc/changeset/829b9682969a5dabd3a75b82864c48c2e6a19ee8/ghc
>---------------------------------------------------------------
commit 829b9682969a5dabd3a75b82864c48c2e6a19ee8
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Wed Aug 17 14:35:19 2016 +0100
Keep the bindings local during defaultCallStacks
defaultCallStacks generates evidence bindings for call stacks,
but wasn't setting the binding site correctly. As a result
they were simply discarded in the case of pattern synonyms,
giving rise to Trac #12489.
The fix is easy; and I added an ASSERT to catch the error earlier.
(cherry picked from commit f352e5cd7bb629fe0ca3b913bfbe7bee43d62f3a)
>---------------------------------------------------------------
829b9682969a5dabd3a75b82864c48c2e6a19ee8
compiler/typecheck/TcPatSyn.hs | 4 +++-
compiler/typecheck/TcSMonad.hs | 6 +++++-
compiler/typecheck/TcSimplify.hs | 9 ++++++---
testsuite/tests/patsyn/should_compile/T12489.hs | 5 +++++
testsuite/tests/patsyn/should_compile/all.T | 1 +
5 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/compiler/typecheck/TcPatSyn.hs b/compiler/typecheck/TcPatSyn.hs
index 5113856..73c46e8 100644
--- a/compiler/typecheck/TcPatSyn.hs
+++ b/compiler/typecheck/TcPatSyn.hs
@@ -293,8 +293,10 @@ tcCheckPatSynDecl psb at PSB{ psb_id = lname@(L _ name), psb_args = details
-- Solve the constraints now, because we are about to make a PatSyn,
-- which should not contain unification variables and the like (Trac #10997)
+ ; empty_binds <- simplifyTop (mkImplicWC implics)
+
-- Since all the inputs are implications the returned bindings will be empty
- ; _ <- simplifyTop (mkImplicWC implics)
+ ; MASSERT2( isEmptyBag empty_binds, ppr empty_binds )
-- ToDo: in the bidirectional case, check that the ex_tvs' are all distinct
-- Otherwise we may get a type error when typechecking the builder,
diff --git a/compiler/typecheck/TcSMonad.hs b/compiler/typecheck/TcSMonad.hs
index 3b4b842..e825dd4 100644
--- a/compiler/typecheck/TcSMonad.hs
+++ b/compiler/typecheck/TcSMonad.hs
@@ -16,7 +16,7 @@ module TcSMonad (
TcS, runTcS, runTcSDeriveds, runTcSWithEvBinds,
failTcS, warnTcS, addErrTcS,
runTcSEqualities,
- nestTcS, nestImplicTcS,
+ nestTcS, nestImplicTcS, setEvBindsTcS,
runTcPluginTcS, addUsedGREs, deferTcSForAllEq,
@@ -2477,6 +2477,10 @@ checkForCyclicBinds ev_binds
| bind@(EvBind { eb_lhs = bndr, eb_rhs = rhs}) <- bagToList ev_binds ]
#endif
+setEvBindsTcS :: Maybe EvBindsVar -> TcS a -> TcS a
+setEvBindsTcS m_ref (TcS thing_inside)
+ = TcS $ \ env -> thing_inside (env { tcs_ev_binds = m_ref })
+
nestImplicTcS :: Maybe EvBindsVar -> TyCoVarSet -- bound in this implication
-> TcLevel -> TcS a
-> TcS (a, TyCoVarSet) -- also returns any vars used when filling
diff --git a/compiler/typecheck/TcSimplify.hs b/compiler/typecheck/TcSimplify.hs
index c8702b4..f3c4b5b 100644
--- a/compiler/typecheck/TcSimplify.hs
+++ b/compiler/typecheck/TcSimplify.hs
@@ -177,9 +177,12 @@ defaultCallStacks wanteds
handle_simples simples
= catBagMaybes <$> mapBagM defaultCallStack simples
- handle_implic implic = do
- wanteds <- defaultCallStacks (ic_wanted implic)
- return (implic { ic_wanted = wanteds })
+ handle_implic implic
+ = do { wanteds <- setEvBindsTcS (ic_binds implic) $
+ -- defaultCallStack sets a binding, so
+ -- we must set the correct binding group
+ defaultCallStacks (ic_wanted implic)
+ ; return (implic { ic_wanted = wanteds }) }
defaultCallStack ct
| Just _ <- isCallStackPred (ctPred ct)
diff --git a/testsuite/tests/patsyn/should_compile/T12489.hs b/testsuite/tests/patsyn/should_compile/T12489.hs
new file mode 100644
index 0000000..205799b
--- /dev/null
+++ b/testsuite/tests/patsyn/should_compile/T12489.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE PatternSynonyms, ViewPatterns #-}
+
+module T12489 where
+pattern P :: a -> b
+pattern P a <- (undefined -> a)
diff --git a/testsuite/tests/patsyn/should_compile/all.T b/testsuite/tests/patsyn/should_compile/all.T
index 9a0c853..00d3b87 100644
--- a/testsuite/tests/patsyn/should_compile/all.T
+++ b/testsuite/tests/patsyn/should_compile/all.T
@@ -53,3 +53,4 @@ test('T11351', normal, compile, [''])
test('T11633', normal, compile, [''])
test('T12094', normal, compile, [''])
test('T12484', normal, compile, [''])
+test('T12489', normal, compile, [''])
More information about the ghc-commits
mailing list