Skip to content
GitLab
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 5,246
    • Issues 5,246
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 564
    • Merge requests 564
  • 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 CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20670
Closed
Open
Issue created Nov 12, 2021 by Simon Hengel@sol

Setting -XTemplateHaskell in GHCi unloads modules that were specified on the command-line

Summary

Running :set -XTemplateHaskell in ghci (in some situations) has two side effects:

  1. The scope is cleared
  2. Any modules that were specified on the command line are unloaded

While (1) is inconvenient, I have a hard time considering (2) as acceptable.

This also breaks doctest.

I haven't been able to reproduce the issue without cabal exec (e.g. with a .ghc.enviroment-file). Not exactly sure what's the difference.

From the ghci output

package flags have changed, resetting and loading new packages...

I guess that it's somehow related to this code: https://gitlab.haskell.org/ghc/ghc/-/blob/master/ghc/GHCi/UI.hs#L3120

Steps to reproduce

Given:

-- foo.cabal
cabal-version: 3.6
name:           foo
version:        0.0.0
library
  build-depends: base
-- Foo.hs
module Foo where
foo :: Int
foo = 23

Run:

$ cabal build . && cabal exec ghci Foo.hs 
ghci> foo
23
ghci> :set -XTemplateHaskell
package flags have changed, resetting and loading new packages...
ghci> foo

Expected behavior

foo should still be in scope:

ghci> foo
23

Actual behavior

foo is not in scope:

ghci> foo

<interactive>:3:1: error: Variable not in scope: foo

Environment

  • GHC version used: 9.2.1
$ cabal --version && uname -s -m
cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library 
Linux x86_64
Edited Nov 12, 2021 by Simon Hengel
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking