Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,868
    • Issues 4,868
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #21547
Closed
Open
Created May 10, 2022 by Tom Smeding@tomsmeding

Panic from refineFromInScope when using Typeable with TH

Summary

Using Typeable in TemplateHaskell doesn't seem to work.

Using Typeable in TemplateHaskell (as shown below) is useful because as far as I'm aware, there is no other way to determine the Type of the instantiation of a polymorphic function in the Q monad. That is to say, in the below reproducer, Typeable is really an XY problem; what I really want is to use the Type corresponding to the monomorphic instantiation of a in the body of foo. This is allowed to fail in whatever way you like if a doesn't end up being instantiated to a monomorphic type. Hence Typeable seems to have the right semantics, but it doesn't work, as shown.

Steps to reproduce

https://git.tomsmeding.com/ghc-refinefrominscope-panic-repro

Foo.hs:

module Foo where
import Data.Typeable
import Language.Haskell.TH

foo :: Typeable a => Code Q a -> Code Q ()
foo = undefined

Main.hs:

{-# LANGUAGE TemplateHaskell #-}
module Main where
import Foo

data T a = T a deriving (Show)

main :: IO ()
main =
  let x = $$(foo [|| T () ||])
  in return ()

Compiling:

$ ghc-9.2.2 Main.hs Foo.hs
[1 of 2] Compiling Foo              ( Foo.hs, Foo.o, Foo.dyn_o )
[2 of 2] Compiling Main             ( Main.hs, Main.o, Main.dyn_o )
ghc: panic! (the 'impossible' happened)
  (GHC version 9.2.2:
        refineFromInScope
  InScope {wild_00 $dQuote_a2Jf}
  $tcT
  Call stack:
      CallStack (from HasCallStack):
        callStackDoc, called at compiler/GHC/Utils/Panic.hs:181:37 in ghc:GHC.Utils.Panic
        pprPanic, called at compiler/GHC/Core/Opt/Simplify/Env.hs:706:30 in ghc:GHC.Core.Opt.Simplify.Env

Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug

Expected behavior

Don't panic. :)

Environment

  • GHC version used: 9.2.2 from ghcup

Optional:

  • Operating System: Arch Linux
  • System Architecture: amd64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking