[commit: ghc] master: Fix #12525: Remove derived bindings from the TyThings from getBindings (921fd89)

git at git.haskell.org git at git.haskell.org
Sat Nov 17 12:52:50 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/921fd890abe0e7267962c9439098b03c94ebdb9b/ghc

>---------------------------------------------------------------

commit 921fd890abe0e7267962c9439098b03c94ebdb9b
Author: Roland Senn <rsx at bluewin.ch>
Date:   Sat Nov 17 12:22:23 2018 +0100

    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


>---------------------------------------------------------------

921fd890abe0e7267962c9439098b03c94ebdb9b
 ghc/GHCi/UI.hs                                | 29 +++++++++++++++++++++++++--
 testsuite/tests/ghci/should_run/T12525.script |  4 ++++
 testsuite/tests/ghci/should_run/T12525.stdout |  3 +++
 testsuite/tests/ghci/should_run/all.T         |  1 +
 4 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index bfcaabf..3de49b4 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -2927,10 +2927,12 @@ showBindings :: GHCi ()
 showBindings = do
     bindings <- GHC.getBindings
     (insts, finsts) <- GHC.getInsts
-    docs     <- mapM makeDoc (reverse bindings)
-                  -- reverse so the new ones come last
     let idocs  = map GHC.pprInstanceHdr insts
         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)
   where
     makeDoc (AnId i) = pprTypeAndContents i
@@ -2951,6 +2953,29 @@ showBindings = do
 printTyThing :: TyThing -> GHCi ()
 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 = do
   st <- getGHCiState
diff --git a/testsuite/tests/ghci/should_run/T12525.script b/testsuite/tests/ghci/should_run/T12525.script
new file mode 100644
index 0000000..db0dec0
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T12525.script
@@ -0,0 +1,4 @@
+x = ()
+let y = ()
+class Foo a
+:show bindings
diff --git a/testsuite/tests/ghci/should_run/T12525.stdout b/testsuite/tests/ghci/should_run/T12525.stdout
new file mode 100644
index 0000000..31049e1
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T12525.stdout
@@ -0,0 +1,3 @@
+x :: () = _
+y :: () = ()
+class Foo a
diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T
index 855b603..3dfea76 100644
--- a/testsuite/tests/ghci/should_run/all.T
+++ b/testsuite/tests/ghci/should_run/all.T
@@ -27,6 +27,7 @@ test('T11328',     just_ghci, ghci_script, ['T11328.script'])
 test('T11825',     just_ghci, ghci_script, ['T11825.script'])
 test('T12128',     just_ghci, ghci_script, ['T12128.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('BinaryArray', normal, compile_and_run, [''])
 test('T14125a',    just_ghci, ghci_script, ['T14125a.script'])



More information about the ghc-commits mailing list