[GHC] #12091: 'Variable not in scope" when using GHCi with `-fobject-code`
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: bug | Status: new Priority: high | Milestone: Component: GHCi | Version: 8.0.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: #7253 Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Since b98ff3ccb14e36145404f075349c8689762a2913 was landed (#7253), you don't need `let` to define stuff in GHCi: {{{ $ ghci Prelude> x = 3 Prelude> x 3 }}} But when using `-fobject-code`, this results in an error: {{{ $ ghci -fobject-code Prelude> x = 3 Prelude> x <interactive>:2:1: error: Variable not in scope: x }}} Very strange. CC @roshats, who implemented this feature, but the bug is probably in some part of the code he didn't touch. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: bug | Status: new Priority: high | Milestone: Component: GHCi | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): I know the problem but I don't know how to fix it. `let x = ...` is compiled as a statement, `x = ...` is compiled as a declaration. Desugarer dumps unused declarations if the target is not `HscInterpreted` or `HscNothing` (see `DynFlags.targetRetainsAllBindings`), but nothing like that is done for statements. Since `-fobject-code` sets target something other than `HscInterpreted` and `HscNothing`, `x` gets dumped. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: bug | Status: new Priority: high | Milestone: Component: GHCi | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): This is related with @roshats's patch as that's where we choose to compile `x = ...` as a statement instead of declaration (by "desugaring" it into `let x = ...`). Maybe we can do that now, unless someone has a better idea. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: Type: bug | Status: new Priority: high | Milestone: Component: GHCi | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"22259c17c5e3043e5fa5b354f339f9b0d66167db/ghc" 22259c17/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="22259c17c5e3043e5fa5b354f339f9b0d66167db" testsuite: Failing testcase for #12091 Just as it says on the can Test Plan: validate Reviewers: austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2489 GHC Trac Issues: #12091 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: (none) Type: bug | Status: patch Priority: high | Milestone: Component: GHCi | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253, #14108 | Differential Rev(s): Phab:D3849 Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => patch * differential: => Phab:D3849 * related: #7253 => #7253, #14108 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: (none) Type: bug | Status: patch Priority: high | Milestone: Component: GHCi | Version: 8.0.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253, #14108 | Differential Rev(s): Phab:D3849 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ben Gamari <ben@…>): In [changeset:"ddb870bf7055ccc8ff8b86c161f31aad81d01add/ghc" ddb870b/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="ddb870bf7055ccc8ff8b86c161f31aad81d01add" Don't drop GHCi-defined functions with -fobject-code enabled The desugarer was using `targetRetainsAllBindings` as a litmus test for determining if a function was defined in interactive mode (and thus should be exported). However, there is a corner case where one can be in interactive mode and have `targetRetainsAllBindings` return `False`: if `-fobject-code` is enabled (since the target will no longer be `HscInteractive`). In such a scenario, we should fall back on a different test for determining if we are in a GHCi session. I chose to use `isInteractiveModule`, which appears to do the trick. Test Plan: make test TEST=T12091 Reviewers: austin, bgamari Subscribers: rwbarton, thomie GHC Trac Issues: #12091 Differential Revision: https://phabricator.haskell.org/D3849 }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.4.1 Component: GHCi | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253, #14108 | Differential Rev(s): Phab:D3849 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed * milestone: => 8.4.1 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.4.1 Component: GHCi | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253, #14108 | Differential Rev(s): Phab:D3849 Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): I reverted ddb870bf7055ccc8ff8b86c161f31aad81d01add in https://gitlab.haskell.org/ghc/ghc/merge_requests/97, which fixes the difference between `x = ...` and `let x = ...` in GHCi. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.4.1 Component: GHCi | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253, #14108 | Differential Rev(s): Phab:D3849 Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): The MR in comment:7 is merged as a34ee6154. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#12091: 'Variable not in scope" when using GHCi with `-fobject-code` -------------------------------------+------------------------------------- Reporter: thomie | Owner: (none) Type: bug | Status: closed Priority: high | Milestone: 8.4.1 Component: GHCi | Version: 8.0.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #7253, #14108 | Differential Rev(s): Phab:D3849 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Ömer Sinan Ağacan <omeragacan@…>): In [changeset:"a34ee61545930d569d0dbafb3a4a5db3a7a711e5/ghc" a34ee615/ghc]: {{{ #!CommitTicketReference repository="ghc" revision="a34ee61545930d569d0dbafb3a4a5db3a7a711e5" Refactor GHCi UI to fix #11606, #12091, #15721, #16096 Instead of parsing and executing a statement or declaration directly we now parse them first and then execute in a separate step. This gives us the flexibility to inspect the parsed declaration before execution. Using this we now inspect parsed declarations, and if it's a single declaration of form `x = y` we execute it as `let x = y` instead, fixing a ton of problems caused by poor declaration support in GHCi. To avoid any users of the modules I left `execStmt` and `runDecls` unchanged and added `execStmt'` and `runDecls'` which work on parsed statements/declarations. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12091#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC