Opened 7 months ago

Last modified 6 months ago

#16195 merge bug

Program with trivial polymorphism leads to out of scope dictionary

Reported by: mpickering Owned by:
Priority: high Milestone: 8.8.1
Component: Compiler Version: 8.7
Keywords: TypedTemplateHaskell Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: th/T16195
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Almost certainly due to c2455e647501c5a382861196b64df3dd05b620a2

A trivial program now causes a core lint error due to an out-of-scope dictionary.

module A where

foo :: Code (IO ())
foo = [|| return () ||]
module B where

main :: IO ()
main = $$foo
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
    In the expression: return @ IO $dMonad_a4od @ () ()
    Out of scope: $dMonad_a4od :: Monad m_a4oc[tau:0]
*** Offending Program ***
Rec {
$trModule :: Module
$trModule = Module (TrNameS "main"#) (TrNameS "B"#)

main :: IO ()
main = return @ IO $dMonad_a4od @ () ()
end Rec }

*** End of Offense ***

Change History (6)

comment:1 Changed 7 months ago by mpickering

I tried adding a call to captureTopConstraints around the zonkTcGblEnv where the splices are run but it doesn't seem to capture any evidence.

comment:2 Changed 7 months ago by mpickering

Status: newpatch

comment:3 Changed 6 months ago by monoidal

Status: patchmerge

I understand we'd like to merge this, since the commit causing the regression is in ghc-8.8.

comment:4 Changed 6 months ago by simonpj

Do we have a regression test?

comment:5 Changed 6 months ago by monoidal

Test Case: th/T16195

comment:6 Changed 6 months ago by Marge Bot <ben+marge-bot@…>

In a48753b/ghc:

Capture and simplify constraints arising from running typed splices

This fixes a regression caused by #15471 where splicing in a trivial
program such as `[|| return () ||]` would fail as the dictionary for
`return` would never get bound in the module containing the splice.

Arguably this is symptomatic of a major problem affecting TTH where we
serialise renamed asts and then retype check them. The reference to the
dictionary should be fully determined at the quote site so that splicing
doesn't have to solve any implicits at all. It's a coincidence this
works due to coherence but see #15863 and #15865 for examples where
things do go very wrong.

Fixes #16195
Note: See TracTickets for help on using tickets.