
#15783: Quoting an internal variable causes an error when splicing -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Template Haskell | Version: 8.6.1 Resolution: | Keywords: 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): Another curious thing. If you compile `B.hs` with `-ddump-simpl`, you'll get this: {{{ $ /opt/ghc/8.6.1/bin/ghc B.hs -fforce-recomp -ddump-simpl [1 of 1] Compiling B ( B.hs, B.o ) ==================== Tidy Core ==================== Result size of Tidy Core = {terms: 24, types: 9, coercions: 0, joins: 0/0} -- RHS size: {terms: 9, types: 1, coercions: 0, joins: 0/0} f :: Language.Haskell.TH.Syntax.Q (Language.Haskell.TH.Syntax.TExp Integer) [GblId] f = Language.Haskell.TH.Syntax.unsafeTExpCoerce @ Integer (Language.Haskell.TH.Lib.Internal.varE (Language.Haskell.TH.Syntax.mkNameG_v (GHC.CString.unpackCString# "main"#) (GHC.CString.unpackCString# "B"#) (GHC.CString.unpackCString# "d"#))) <Typeable stuff elided> }}} Now change the typed quote to an untyped one (i.e., change `f = [|| d ||]` to `f = [| d |]`) and recompile it: {{{ $ /opt/ghc/8.6.1/bin/ghc B.hs -fforce-recomp -ddump-simpl [1 of 1] Compiling B ( B.hs, B.o ) ==================== Tidy Core ==================== Result size of Tidy Core = {terms: 25, types: 7, coercions: 0, joins: 0/0} -- RHS size: {terms: 8, types: 0, coercions: 0, joins: 0/0} f :: Language.Haskell.TH.Lib.Internal.ExpQ [GblId] f = Language.Haskell.TH.Lib.Internal.varE (Language.Haskell.TH.Syntax.mkNameG_v (GHC.CString.unpackCString# "main"#) (GHC.CString.unpackCString# "B"#) (GHC.CString.unpackCString# "d"#)) -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} d :: Integer [GblId, Caf=NoCafRefs, Unf=OtherCon []] d = 0 <Typeable stuff elided> }}} Notice that `d` actually makes an appearance this time! This makes me wonder if `d` is being mistakenly removed under the pretense of it being dead code. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15783#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler