summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-04-26 13:47:54 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-04-26 13:47:54 +0100
commitd50cb3eda3912df0d75a8177f04783689b21dc9b (patch)
treee1be5265e6d909a678daae5ff847f98ede54f5f5 /compiler
parentd9d35d8c5a74636b41eb0591b8abedb24080d8e3 (diff)
downloadhaskell-d50cb3eda3912df0d75a8177f04783689b21dc9b.tar.gz
Do not generate derived instances in TH brackets
See Note [Deriving inside TH brackets] in TcInstDcls Fixes Trac #6005 (again)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/typecheck/TcInstDcls.lhs23
1 files changed, 22 insertions, 1 deletions
diff --git a/compiler/typecheck/TcInstDcls.lhs b/compiler/typecheck/TcInstDcls.lhs
index 6db2692fe1..776689084f 100644
--- a/compiler/typecheck/TcInstDcls.lhs
+++ b/compiler/typecheck/TcInstDcls.lhs
@@ -386,8 +386,12 @@ tcInstDecls1 tycl_decls inst_decls deriv_decls
-- more errors still
; traceTc "tcDeriving" empty
+ ; th_stage <- getStage -- See Note [Deriving inside TH brackets ]
; (gbl_env, deriv_inst_info, deriv_binds)
- <- tcDeriving tycl_decls inst_decls deriv_decls
+ <- if isBrackStage th_stage
+ then return (gbl_env, emptyBag, emptyValBindsOut)
+ else tcDeriving tycl_decls inst_decls deriv_decls
+
-- Check that if the module is compiled with -XSafe, there are no
-- hand written instances of Typeable as then unsafe casts could be
@@ -443,6 +447,23 @@ addFamInsts fam_insts thing_inside
things = map ATyCon tycons ++ map ACoAxiom axioms
\end{code}
+Note [Deriving inside TH brackets]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Given a declaration bracket
+ [d| data T = A | B deriving( Show ) |]
+
+there is really no point in generating the derived code for deriving(
+Show) and then type-checking it. This will happen at the call site
+anyway, and the type check should never fail! Moreover (Trac #6005)
+the scoping of the generated code inside the bracket does not seem to
+work out.
+
+The easy solution is simply not to generate the derived instances at
+all. (A less brutal solution would be to generate them with no
+bindings.) This will become moot when we shift to the new TH plan, so
+the brutal solution will do.
+
+
Note [Instance declaration cycles]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With -XDataKinds we can get this