[GHC] #14108: GHCi doesn't remember let-less function declarations with -fobject-code

#14108: GHCi doesn't remember let-less function declarations with -fobject-code -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.2.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- GHCi supports two styles of function declaration: those using an explicit `let` keyword, and those without. This GHCi session demonstrates both: {{{ $ /opt/ghc/8.2.1/bin/ghci GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/Documents/Hacking/Haskell/trifecta/.ghci Loaded GHCi configuration from /home/rgscott/.ghci λ> let foo1 :: Int; foo1 = 42 λ> foo1 42 λ> foo2 :: Int; foo2 = 42 λ> foo2 42 }}} But if using GHCi with the `-fobject-code` enabled, then the `let`-less style of declaration no longer works: {{{ $ /opt/ghc/8.2.1/bin/ghci -fobject-code GHCi, version 8.2.1: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/Documents/Hacking/Haskell/trifecta/.ghci Loaded GHCi configuration from /home/rgscott/.ghci λ> let foo1 :: Int; foo1 = 42 λ> foo1 42 λ> foo2 :: Int; foo2 = 42 λ> foo2 <interactive>:4:1: error: • Variable not in scope: foo2 • Perhaps you meant ‘foo1’ (line 1) }}} Originally noticed [https://github.com/ekmett/trifecta/pull/73#issuecomment-321829537 here]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14108 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14108: GHCi doesn't remember let-less function declarations with -fobject-code -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): I believe I've identified the culprit. It turns out that the binding for `foo2` is discarded entirely during desugaring—in particular, the function [http://git.haskell.org/ghc.git/blob/c6462ab02882779d7e33f2cac00cd89a9ac192f1... addExportFlagsAndRules] is to blame. Normally, the `HscTarget` argument is `HscInterpreted`, on which `targetRetainsAllBindings` returns `True`, causing `addExportFlagsAndRules` to set the `foo2` `Id` as exported. However, when the `HscTarget` argument is, say, `HscAsm` (which can happen when `-fobject-code` is enabled), then `targetRetainsAllBindings` returns `False`. As a result, `addExportFlagsAndRules` checks if the `foo2` `Id` is contained in either the `keep_alive` or `exported` sets—but in GHCi, both of those are always empty, so `foo2` isn't marked as exported, causing the desugarer to discard it later. Bummer. This makes me believe that we should alter `addExportFlagsAndRules` so that it always marks local bindings as exported when we're in an interactive module (i.e., in GHCi). I'll experiment with this approach. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14108#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14108: GHCi doesn't remember let-less function declarations with -fobject-code -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 8.2.1 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #12091 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => closed * resolution: => duplicate * related: => #12091 Comment: Well whaddya know, this is a duplicate of #12091. Luckily, I already have a patch whipped up for this, so I'll just change the ticket number :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14108#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC