[GHC] #8305: ghci macros override built-ins for command expansion

#8305: ghci macros override built-ins for command expansion ------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #8113 | ------------------------------------+------------------------------------- I have a ghci macro `:tsu` from the ghc-vis package, which I installed a long time ago. In HEAD ghci (since the patch for #8113) this causes `:t` to expand to `:tsu`, rather than `:type`. That happened to result in a weird error the first time I tried to use `:t` (something like `Prelude.read: no parse`), and it took me a while to diagnose that my `.ghci` file was the issue! I don't like this new behavior because it forces me to either change my ghci habits (start using `:type` instead of `:t`) or avoid macros starting with any letter that I currently use as a single-letter ghci command. I set this ticket priority to highest because in any event this new behavior shouldn't sneak in to a GHC release unnoticed. Below is my proposal for how `:commands` should be interpreted now that built-in commands can be overridden (#8113), copied from a comment I made recently on that ticket. ---- I suppose what I specifically want to happen when I enter a `:command` is an algorithm like this. If the name I entered is an exact match for a macro or built-in, use that name. Otherwise, try to complete the name to the name of a ''built-in'' in the traditional way. If this succeeds, use the resulting name. Otherwise, try to complete the name to the name of a macro, and use the resulting name if that succeeds, otherwise give up. In all cases where we got a name, use the ''macro'' of that name if there is one, and otherwise use the built-in. (Obviously, for `::command`, ignore macros entirely.) In other words, built-ins should take precedence over macros for the purpose of name ''completion'', but macros should take precedence over built-ins for the purpose of name ''lookup''. This is backwards- compatible from the perspective of the user who is not aware of the change—`:t` will always mean `:type`, as long as the user has no macro named `:t`, just like in previous versions of ghci—while still allowing the aware user to redefine exactly what `:type` means. And it's flexible enough in that if the user really wants `:t` to complete to some other macro `:test` that they've written, they can always define another macro `:t` to expand to `:test`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Changes (by rwbarton): * version: 7.6.3 => 7.7 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Comment (by carter): so the priority would be: exact match macro > exact match builtin > expands to built-in > expands to macro ? sounds reasonable to me. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Comment (by rwbarton): With the caveat that if we "expand to built-in" and there is a macro of the same name, we use the macro instead. But this makes it all sound more confusing than it really is. I imagine two stages in the interpretation of a ghci command: first name completion (`String -> String`), then name resolution (`String -> Maybe (Either UserMacro BuiltinCommand)`). I want the name completion to work exactly as in every previous released version of ghci: `:t` always means the same thing as `:type` unless the user has a macro named specifically `:t`. This is important so that anyone who's not using the new ability to override built-ins has an unchanged ghci experience. The name resolution step now prefers macros over built-ins, to allow the user (or a tool like cabal sandboxes) to override the meaning of built-in commands. The #8113 patch implements the desired new name resolution behavior, but it changes the name completion behavior at the same time. Here are some example scenarios. 1. User has a macro `:time`, and enters `:t 3`. * ''ghci 7.6 behavior'' `:type 3` * ''current HEAD behavior'' `:time 3` * ''my desired behavior'' `:type 3`, like ghci 7.6 2. User has a macro `:type`, and enters `:t 3`. * ''ghci 7.6 behavior'' `:type 3`, with the built-in `:type` (built-ins can't be overridden in 7.6) * ''current HEAD behavior'' `:type 3`, with the user's `:type` macro * ''my desired behavior'' `:type 3`, with the user's `:type` macro, like current HEAD 2. User has a macro `:time` and also a macro `:type`, and enters `:t 3`. * ''ghci 7.6 behavior'' `:type 3`, with the built-in `:type` * ''current HEAD behavior'' `:time 3` * ''my desired behavior'' `:type 3`, with the user's `:type` macro; different from both 7.6 and HEAD -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Comment (by carter): hrm, this is subtle enough that if other people are ok with it, would definitely merit entry in the manual! this does suggest that it might be worth having an easy to disable warning when you load macros which disable standard shorthands like :i :k :t , right? (i could be wrong there). I really should learn more about ghci macros it sounds like. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Comment (by simonpj): However this is resolved (and I don't have an opinion myself), can we please have careful, precise documentation in the user manual? Thanks! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: new Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Changes (by hvr): * cc: hvr (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Changes (by hvr): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Comment (by thoughtpolice): Thank you Herbert. This patch looks nice - please commit and add documentation. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion
-------------------------------------+------------------------------------
Reporter: rwbarton | Owner:
Type: bug | Status: patch
Priority: highest | Milestone: 7.8.1
Component: GHCi | Version: 7.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets: #8113
-------------------------------------+------------------------------------
Comment (by Herbert Valerio Riedel

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: rwbarton Type: bug | Status: patch Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Changes (by hvr): * owner: => rwbarton Comment: ...assigning to rwbarton as he agreed to write the documentation part :-) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion
-------------------------------------+------------------------------------
Reporter: rwbarton | Owner: rwbarton
Type: bug | Status: patch
Priority: highest | Milestone: 7.8.1
Component: GHCi | Version: 7.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets: #8113
-------------------------------------+------------------------------------
Comment (by Austin Seipp

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: rwbarton Type: bug | Status: closed Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 -------------------------------------+------------------------------------ Changes (by thoughtpolice): * status: patch => closed * resolution: => fixed Comment: I went ahead and wrote some up myself based on Reid's examples. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8305: ghci macros override built-ins for command expansion -------------------------------------+------------------------------------ Reporter: rwbarton | Owner: rwbarton Type: bug | Status: closed Priority: highest | Milestone: 7.8.1 Component: GHCi | Version: 7.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #8113 #3858 -------------------------------------+------------------------------------ Changes (by hvr): * related: #8113 => #8113 #3858 Comment: I just noticed the related ticket #3858 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8305#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC