[commit: ghc] ghc-8.0: Hide derived OccNames from user (4a8b2ca)

git at git.haskell.org git at git.haskell.org
Tue Jan 19 10:05:52 UTC 2016


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

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/4a8b2ca082ec1d0966b197be1f190889f31189cd/ghc

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

commit 4a8b2ca082ec1d0966b197be1f190889f31189cd
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Mon Jan 18 23:12:51 2016 +0100

    Hide derived OccNames from user
    
    This hides derived OccNames from the Names returned from
    runDeclsWithLocation and clarifies the documentation. This is done to
    ensure that these names (originating from, e.g., derived Generic
    instances and type representation bindings) don't show up in ghci output
    when run with `:set +t`. This fixes #11051.
    
    Test Plan: Validate with included tests
    
    Reviewers: austin
    
    Reviewed By: austin
    
    Subscribers: thomie, hvr
    
    Differential Revision: https://phabricator.haskell.org/D1794
    
    GHC Trac Issues: #11051
    
    (cherry picked from commit d2ea7f94cb21662857cd50c95ff41943e5911a9b)


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

4a8b2ca082ec1d0966b197be1f190889f31189cd
 compiler/main/InteractiveEval.hs            | 8 +++++---
 testsuite/tests/ghci/scripts/T11051a.script | 3 +++
 testsuite/tests/ghci/scripts/T11051a.stdout | 1 +
 testsuite/tests/ghci/scripts/T11051b.script | 5 +++++
 testsuite/tests/ghci/scripts/T11051b.stdout | 1 +
 testsuite/tests/ghci/scripts/all.T          | 2 ++
 6 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs
index 47d282e..6356928 100644
--- a/compiler/main/InteractiveEval.hs
+++ b/compiler/main/InteractiveEval.hs
@@ -235,8 +235,9 @@ runStmtWithLocation source linenumber expr step = do
 runDecls :: GhcMonad m => String -> m [Name]
 runDecls = runDeclsWithLocation "<interactive>" 1
 
-runDeclsWithLocation
- :: GhcMonad m => String -> Int -> String -> m [Name]
+-- | Run some declarations and return any user-visible names that were brought
+-- into scope.
+runDeclsWithLocation :: GhcMonad m => String -> Int -> String -> m [Name]
 runDeclsWithLocation source linenumber expr =
   do
     hsc_env <- getSession
@@ -246,7 +247,8 @@ runDeclsWithLocation source linenumber expr =
     hsc_env <- getSession
     hsc_env' <- liftIO $ rttiEnvironment hsc_env
     modifySession (\_ -> hsc_env')
-    return (map getName tyThings)
+    return $ filter (not . isDerivedOccName . nameOccName)
+           $ map getName tyThings
 
 
 withVirtualCWD :: GhcMonad m => m a -> m a
diff --git a/testsuite/tests/ghci/scripts/T11051a.script b/testsuite/tests/ghci/scripts/T11051a.script
new file mode 100644
index 0000000..96fadeb
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T11051a.script
@@ -0,0 +1,3 @@
+-- Ensure that type representation bindings aren't visible to user
+:set +t
+data Hi
diff --git a/testsuite/tests/ghci/scripts/T11051a.stdout b/testsuite/tests/ghci/scripts/T11051a.stdout
new file mode 100644
index 0000000..44fb93ca
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T11051a.stdout
@@ -0,0 +1 @@
+data Hi
diff --git a/testsuite/tests/ghci/scripts/T11051b.script b/testsuite/tests/ghci/scripts/T11051b.script
new file mode 100644
index 0000000..dd42074
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T11051b.script
@@ -0,0 +1,5 @@
+-- ensure that derived Generics types aren't visible to user
+:set +t
+:set -XDeriveGeneric
+import GHC.Generics
+data Hello = Hello Int deriving (Eq, Generic)
diff --git a/testsuite/tests/ghci/scripts/T11051b.stdout b/testsuite/tests/ghci/scripts/T11051b.stdout
new file mode 100644
index 0000000..7eb3f08
--- /dev/null
+++ b/testsuite/tests/ghci/scripts/T11051b.stdout
@@ -0,0 +1 @@
+data Hello = Hello Int
diff --git a/testsuite/tests/ghci/scripts/all.T b/testsuite/tests/ghci/scripts/all.T
index c1bda85..7a6225c 100755
--- a/testsuite/tests/ghci/scripts/all.T
+++ b/testsuite/tests/ghci/scripts/all.T
@@ -237,3 +237,5 @@ test('T11252', normal, ghci_script, ['T11252.script'])
 
 test('T10576a', expect_broken(10576), ghci_script, ['T10576a.script'])
 test('T10576b', expect_broken(10576), ghci_script, ['T10576b.script'])
+test('T11051a', normal, ghci_script, ['T11051a.script'])
+test('T11051b', normal, ghci_script, ['T11051b.script'])



More information about the ghc-commits mailing list