[GHC] #16096: let x = ... and x = ... are not the same in GHCi

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- With #7253 we implemented support for `x = ...` in GHCi which is supposed to do the same thing as `let x = ...`, but they're currently different, as observed in #16089, #15721, and probably in other tickets. Here's a reproducer: {{{ ~ $ ghci -ddump-bcos GHCi, version 8.4.4: http://www.haskell.org/ghc/ :? for help ... λ:1> let x = [True,False] ==================== Proto-BCOs ==================== ProtoBCO ExprTopLevel_E0#0 []: let sat_s1vF = ... in ... bitmap: 0 [] PUSH_G GHC.Types.[] PUSH_G GHC.Types.False PACK : 2 PUSH_L 0 PUSH_G GHC.Types.True PACK : 2 PUSH_G GHC.Types.[] PUSH_L 1 PACK : 2 PUSH_L 0 PUSH_APPLY_P PUSH_G GHC.Base.returnIO SLIDE 3 3 ENTER λ:2> x = [True,False] ==================== Proto-BCOs ==================== ProtoBCO x1_r1wJ#0 []: GHC.Types.: @ GHC.Types.Bool GHC.Types.False (GHC.Types.[] @ GHC.Types.Bool) bitmap: 0 [] PUSH_G GHC.Types.[] PUSH_G GHC.Types.False PACK : 2 ENTER ProtoBCO Ghci2.x#0 []: GHC.Types.: @ GHC.Types.Bool GHC.Types.True x1_r1wJ bitmap: 0 [] PUSH_G x1_r1wJ PUSH_G GHC.Types.True PACK : 2 ENTER ... }}} Expected behavior: these two should generate the same byte code, and should be subject to same checks (e.g. for shadowing). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by osa1: Old description:
With #7253 we implemented support for `x = ...` in GHCi which is supposed to do the same thing as `let x = ...`, but they're currently different, as observed in #16089, #15721, and probably in other tickets. Here's a reproducer:
{{{ ~ $ ghci -ddump-bcos GHCi, version 8.4.4: http://www.haskell.org/ghc/ :? for help
...
λ:1> let x = [True,False]
==================== Proto-BCOs ==================== ProtoBCO ExprTopLevel_E0#0 []: let sat_s1vF = ... in ... bitmap: 0 [] PUSH_G GHC.Types.[] PUSH_G GHC.Types.False PACK : 2 PUSH_L 0 PUSH_G GHC.Types.True PACK : 2 PUSH_G GHC.Types.[] PUSH_L 1 PACK : 2 PUSH_L 0 PUSH_APPLY_P PUSH_G GHC.Base.returnIO SLIDE 3 3 ENTER
λ:2> x = [True,False]
==================== Proto-BCOs ==================== ProtoBCO x1_r1wJ#0 []: GHC.Types.: @ GHC.Types.Bool GHC.Types.False (GHC.Types.[] @ GHC.Types.Bool) bitmap: 0 [] PUSH_G GHC.Types.[] PUSH_G GHC.Types.False PACK : 2 ENTER
ProtoBCO Ghci2.x#0 []: GHC.Types.: @ GHC.Types.Bool GHC.Types.True x1_r1wJ bitmap: 0 [] PUSH_G x1_r1wJ PUSH_G GHC.Types.True PACK : 2 ENTER
... }}}
Expected behavior: these two should generate the same byte code, and should be subject to same checks (e.g. for shadowing).
New description: With #7253 we implemented support for `x = ...` in GHCi which is supposed to do the same thing as `let x = ...`, but they're currently different, as observed in #16089, #15721, and probably in other tickets. Here's a reproducer: {{{ ~ $ ghci -ddump-bcos GHCi, version 8.4.4: http://www.haskell.org/ghc/ :? for help ... λ:1> let x = [True,False] ==================== Proto-BCOs ==================== ProtoBCO ExprTopLevel_E0#0 []: let sat_s1vF = ... in ... bitmap: 0 [] PUSH_G GHC.Types.[] PUSH_G GHC.Types.False PACK : 2 PUSH_L 0 PUSH_G GHC.Types.True PACK : 2 PUSH_G GHC.Types.[] PUSH_L 1 PACK : 2 PUSH_L 0 PUSH_APPLY_P PUSH_G GHC.Base.returnIO SLIDE 3 3 ENTER λ:2> x = [True,False] ==================== Proto-BCOs ==================== ProtoBCO x1_r1wJ#0 []: GHC.Types.: @ GHC.Types.Bool GHC.Types.False (GHC.Types.[] @ GHC.Types.Bool) bitmap: 0 [] PUSH_G GHC.Types.[] PUSH_G GHC.Types.False PACK : 2 ENTER ProtoBCO Ghci2.x#0 []: GHC.Types.: @ GHC.Types.Bool GHC.Types.True x1_r1wJ bitmap: 0 [] PUSH_G x1_r1wJ PUSH_G GHC.Types.True PACK : 2 ENTER ... }}} Expected behavior: these two should generate the same byte code, and should be subject to same checks (e.g. for shadowing). (Example above uses 8.4.4, but this can be reproduced with GHC HEAD too) -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): The problem is this: in `GHCi.UI.runStmt` we use GHC's `parseStmt` to parse the statements. If the parser fails then we assume it's a declaration. For statements we do `run_stmt`, for decls we do `run_decl`. So effectively we compile `x = 1` as a top-level binding (a declaration) but `let x = 1` is compiled as if it's a `do` statement. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * owner: (none) => osa1 Comment: I have a fix, will submit a diff soon. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Two things to keep in mind when fixing this: * #11606 is also caused by this discrepancy, so it would be worth checking to see if this is fixed. * I had to implement a hack in my fix for #12091 (ddb870bf7055ccc8ff8b86c161f31aad81d01add) to account for this discrepancy, so if this is fixed, we might be able to remove this hack. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: patch Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5473 Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * status: new => patch * differential: => Phab:D5473 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: patch Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11606 | Differential Rev(s): Phab:D5473 Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * related: => #11606 Comment: Confirmed that Phab:5473 fixes #11606 as well. I suspect we can also remove the hack for #12091 because with this we treat `x = y` as `let x = y`, which doesn't have the problem mentioned in #12091, but I haven't verified this yet. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: patch Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11606 | Differential Rev(s): Phab:D5473 Wiki Page: | -------------------------------------+------------------------------------- Comment (by osa1): Actually Phab:D5473 even fixes #16089, but in an unexpected way. I'll update #16089. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: patch Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11606 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * differential: Phab:D5473 => Comment: https://gitlab.haskell.org/ghc/ghc/merge_requests/97 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: closed Priority: normal | Milestone: Component: GHCi | Version: 8.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #11606 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by osa1): * status: patch => closed * resolution: => fixed Comment: Fixed with a34ee6154. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi -------------------------------------+------------------------------------- Reporter: osa1 | Owner: osa1 Type: bug | Status: closed Priority: normal | Milestone: 8.8.1 Component: GHCi | Version: 8.6.3 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | ghci/should_run/T16096 Blocked By: | Blocking: Related Tickets: #11606 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * testcase: => ghci/should_run/T16096 * milestone: => 8.8.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16096#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#16096: let x = ... and x = ... are not the same in GHCi
-------------------------------------+-------------------------------------
Reporter: osa1 | Owner: osa1
Type: bug | Status: closed
Priority: normal | Milestone: 8.8.1
Component: GHCi | Version: 8.6.3
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
| ghci/should_run/T16096
Blocked By: | Blocking:
Related Tickets: #11606 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ömer Sinan Ağacan
participants (1)
-
GHC