[commit: ghc] ghc-8.0: Avoid mangled/derived names in GHCi autocomplete (fixes #11328) (6704660)

git at git.haskell.org git at git.haskell.org
Tue Feb 2 16:42:59 UTC 2016


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

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/670466039ac63a94af9e136212da8d511f02b935/ghc

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

commit 670466039ac63a94af9e136212da8d511f02b935
Author: Adam Gundry <adam at well-typed.com>
Date:   Mon Feb 1 16:41:03 2016 +0100

    Avoid mangled/derived names in GHCi autocomplete (fixes #11328)
    
    This changes `getRdrNamesInScope` to use field labels rather than
    selector names for fields from modules with `DuplicateRecordFields`
    enabled. Moreover, it filters out derived names (e.g. type
    representation bindings) that shouldn't show up in autocomplete.
    
    Test Plan: New test ghci/should_run/T11328
    
    Reviewers: kolmodin, austin, bgamari, simonpj
    
    Reviewed By: bgamari, simonpj
    
    Subscribers: simonpj, thomie
    
    Differential Revision: https://phabricator.haskell.org/D1870
    
    GHC Trac Issues: #11328
    
    (cherry picked from commit dd0b7c78f64f2498594d3ef89d3bf884402f14d9)


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

670466039ac63a94af9e136212da8d511f02b935
 compiler/basicTypes/RdrName.hs                | 4 ++--
 compiler/main/InteractiveEval.hs              | 5 ++++-
 testsuite/tests/ghci/should_run/T11328.script | 4 ++++
 testsuite/tests/ghci/should_run/T11328.stdout | 5 +++++
 testsuite/tests/ghci/should_run/all.T         | 1 +
 5 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/compiler/basicTypes/RdrName.hs b/compiler/basicTypes/RdrName.hs
index 6e0350d..62771e9 100644
--- a/compiler/basicTypes/RdrName.hs
+++ b/compiler/basicTypes/RdrName.hs
@@ -629,10 +629,10 @@ greUsedRdrName gre at GRE{ gre_name = name, gre_lcl = lcl, gre_imp = iss }
     occ = greOccName gre
 
 greRdrNames :: GlobalRdrElt -> [RdrName]
-greRdrNames GRE{ gre_name = name, gre_lcl = lcl, gre_imp = iss }
+greRdrNames gre at GRE{ gre_lcl = lcl, gre_imp = iss }
   = (if lcl then [unqual] else []) ++ concatMap do_spec (map is_decl iss)
   where
-    occ    = nameOccName name
+    occ    = greOccName gre
     unqual = Unqual occ
     do_spec decl_spec
         | is_qual decl_spec = [qual]
diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs
index 6e3f77b..d07a88f 100644
--- a/compiler/main/InteractiveEval.hs
+++ b/compiler/main/InteractiveEval.hs
@@ -790,13 +790,16 @@ getNamesInScope :: GhcMonad m => m [Name]
 getNamesInScope = withSession $ \hsc_env -> do
   return (map gre_name (globalRdrEnvElts (ic_rn_gbl_env (hsc_IC hsc_env))))
 
+-- | Returns all 'RdrName's in scope in the current interactive
+-- context, excluding any that are internally-generated.
 getRdrNamesInScope :: GhcMonad m => m [RdrName]
 getRdrNamesInScope = withSession $ \hsc_env -> do
   let
       ic = hsc_IC hsc_env
       gbl_rdrenv = ic_rn_gbl_env ic
       gbl_names = concatMap greRdrNames $ globalRdrEnvElts gbl_rdrenv
-  return gbl_names
+  -- Exclude internally generated names; see e.g. Trac #11328
+  return (filter (not . isDerivedOccName . rdrNameOcc) gbl_names)
 
 
 -- | Parses a string as an identifier, and returns the list of 'Name's that
diff --git a/testsuite/tests/ghci/should_run/T11328.script b/testsuite/tests/ghci/should_run/T11328.script
new file mode 100644
index 0000000..410e4b7
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T11328.script
@@ -0,0 +1,4 @@
+:seti -XDuplicateRecordFields
+data T = MkT { foo :: Int }
+:complete repl "foo"
+:complete repl "$"
diff --git a/testsuite/tests/ghci/should_run/T11328.stdout b/testsuite/tests/ghci/should_run/T11328.stdout
new file mode 100644
index 0000000..272da79
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T11328.stdout
@@ -0,0 +1,5 @@
+1 1 ""
+"foo"
+2 2 ""
+"$"
+"$!"
diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T
index 68c7407..930f14b 100644
--- a/testsuite/tests/ghci/should_run/all.T
+++ b/testsuite/tests/ghci/should_run/all.T
@@ -22,3 +22,4 @@ test('T9914',      just_ghci, ghci_script, ['T9914.script'])
 test('T9915',      just_ghci, ghci_script, ['T9915.script'])
 test('T10145',     just_ghci, ghci_script, ['T10145.script'])
 test('T7253',      just_ghci, ghci_script, ['T7253.script'])
+test('T11328',     just_ghci, ghci_script, ['T11328.script'])



More information about the ghc-commits mailing list