[GHC] #15481: TH fails to recover from reifyFixity with -fexternal-interpreter
GHC
ghc-devs at haskell.org
Thu Sep 20 15:21:36 UTC 2018
#15481: TH fails to recover from reifyFixity with -fexternal-interpreter
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone: 8.8.1
Component: Template Haskell | Version: 8.4.3
Resolution: | Keywords: RemoteGHCi
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by RyanGlScott):
I now understand the underlying problem slightly better than before. One
of the culprits appears to be whether `addErrTc` is used to accumulate
errors (as opposed to `failWithTc`, which throws errors immediately).
`reifyFixity` only calls `addErrTc` when used in the program above,
whereas if you swap out `reifyFixity` for something like `reify` or
`reifyConStrictness`, you'll end up reaching a code path that uses
`failWithTc`. (Similarly, adding an explicit use of `fail` will also cause
`failWithTc` to be invoked.)
For some peculiar reason, `recover` is able to successfully recover from
errors added via `failWithTc` when `-fexternal-interpreter` is enabled,
but not errors added via `addErrTc`. I don't know why that is the case,
however. There is a `Note [TH recover with -fexternal-interpreter]`
[http://git.haskell.org/ghc.git/blob/4eebc8016f68719e1ccdf460754a97d1f4d6ef05:/compiler/typecheck/TcSplice.hs#l1066
here], but I can't glean any nuggets of wisdom from that.
Given that `failWithTc` appears to be recovered more reliably than
`addErrTc`, one way to fix this bug is to just error more eagerly in
`qReifyFixity`, like so:
{{{#!diff
diff --git a/compiler/typecheck/TcSplice.hs
b/compiler/typecheck/TcSplice.hs
index c26ba0d..000c84c 100644
--- a/compiler/typecheck/TcSplice.hs
+++ b/compiler/typecheck/TcSplice.hs
@@ -866,7 +866,7 @@ instance TH.Quasi TcM where
qLookupName = lookupName
qReify = reify
- qReifyFixity nm = lookupThName nm >>= reifyFixity
+ qReifyFixity nm = checkNoErrs (lookupThName nm) >>= reifyFixity
qReifyInstances = reifyInstances
qReifyRoles = reifyRoles
qReifyAnnotations = reifyAnnotations
}}}
This makes the original program in this ticket recover successfully, even
with `-fexternal-interpreter`. That being said, I'm not sure if it's
really the "right" way to fix this bug, since there appears to be some
underlying issue in the way `-fexternal-interpreter` interacts with
`addErrTc`.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15481#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list