Commit 921fd890 authored by Roland Senn's avatar Roland Senn Committed by Krzysztof Gogolewski
Browse files

Fix #12525: Remove derived bindings from the TyThings from getBindings

Summary:
Remove derived OccNames from the list of TyThings returned by the function GHC.getBindings.
Therefore the output of the `:show bindings `command will not contain names generated by GHC.

Test Plan: make test TEST=T12525

Reviewers: austin, hvr, alanz, angerman, thomie, bgamari, osa1

Reviewed By: osa1

Subscribers: simonpj, osa1, rwbarton, carter

GHC Trac Issues: #12525

Differential Revision: https://phabricator.haskell.org/D5326
parent 65517979
...@@ -2927,10 +2927,12 @@ showBindings :: GHCi () ...@@ -2927,10 +2927,12 @@ showBindings :: GHCi ()
showBindings = do showBindings = do
bindings <- GHC.getBindings bindings <- GHC.getBindings
(insts, finsts) <- GHC.getInsts (insts, finsts) <- GHC.getInsts
docs <- mapM makeDoc (reverse bindings)
-- reverse so the new ones come last
let idocs = map GHC.pprInstanceHdr insts let idocs = map GHC.pprInstanceHdr insts
fidocs = map GHC.pprFamInst finsts fidocs = map GHC.pprFamInst finsts
binds = filter (not . isDerivedOccName . getOccName) bindings -- #12525
-- See Note [Filter bindings]
docs <- mapM makeDoc (reverse binds)
-- reverse so the new ones come last
mapM_ printForUserPartWay (docs ++ idocs ++ fidocs) mapM_ printForUserPartWay (docs ++ idocs ++ fidocs)
where where
makeDoc (AnId i) = pprTypeAndContents i makeDoc (AnId i) = pprTypeAndContents i
...@@ -2951,6 +2953,29 @@ showBindings = do ...@@ -2951,6 +2953,29 @@ showBindings = do
printTyThing :: TyThing -> GHCi () printTyThing :: TyThing -> GHCi ()
printTyThing tyth = printForUser (pprTyThing showToHeader tyth) printTyThing tyth = printForUser (pprTyThing showToHeader tyth)
{-
Note [Filter bindings]
~~~~~~~~~~~~~~~~~~~~~~
If we don't filter the bindings returned by the function GHC.getBindings,
then the :show bindings command will also show unwanted bound names,
internally generated by GHC, eg:
$tcFoo :: GHC.Types.TyCon = _
$trModule :: GHC.Types.Module = _ .
The filter was introduced as a fix for Trac #12525 [1]. Comment:1 [2] to this
ticket contains an analysis of the situation and suggests the solution
implemented above.
The same filter was also implemented to fix Trac #11051 [3]. See the
Note [What to show to users] in compiler/main/InteractiveEval.hs
[1] https://ghc.haskell.org/trac/ghc/ticket/12525
[2] https://ghc.haskell.org/trac/ghc/ticket/12525#comment:1
[3] https://ghc.haskell.org/trac/ghc/ticket/11051
-}
showBkptTable :: GHCi () showBkptTable :: GHCi ()
showBkptTable = do showBkptTable = do
st <- getGHCiState st <- getGHCiState
......
x = ()
let y = ()
class Foo a
:show bindings
x :: () = _
y :: () = ()
class Foo a
...@@ -27,6 +27,7 @@ test('T11328', just_ghci, ghci_script, ['T11328.script']) ...@@ -27,6 +27,7 @@ test('T11328', just_ghci, ghci_script, ['T11328.script'])
test('T11825', just_ghci, ghci_script, ['T11825.script']) test('T11825', just_ghci, ghci_script, ['T11825.script'])
test('T12128', just_ghci, ghci_script, ['T12128.script']) test('T12128', just_ghci, ghci_script, ['T12128.script'])
test('T12456', just_ghci, ghci_script, ['T12456.script']) test('T12456', just_ghci, ghci_script, ['T12456.script'])
test('T12525', just_ghci, ghci_script, ['T12525.script'])
test('T12549', just_ghci, ghci_script, ['T12549.script']) test('T12549', just_ghci, ghci_script, ['T12549.script'])
test('BinaryArray', normal, compile_and_run, ['']) test('BinaryArray', normal, compile_and_run, [''])
test('T14125a', just_ghci, ghci_script, ['T14125a.script']) test('T14125a', just_ghci, ghci_script, ['T14125a.script'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment