[GHC] #13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Keywords: | Operating System: Windows Architecture: | Type of failure: Compile-time Unknown/Multiple | crash or panic Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- In Haskell, 1. The scope of definitions can be controled. 2. The same name can be used to define both a function and a field of record. 3. The user can use that name in record pattern matching when only the function is within scope. For example {{{ FuncId{ name = nm } }}} resulting in the following bug {{{ [38 of 39] Compiling TxsUtils ( src\TxsUtils.hs, .stack- work\dist\1f7101f2\build\Txs Utils.o ) ghc.EXE: panic! (the 'impossible' happened) (GHC version 8.0.2 for x86_64-unknown-mingw32): translateConPatVec: lookup Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by pjljvdlaar): * Attachment "defs.zip" added. Example to reproduce the bug: use stack build -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): I bet this is a dup of #12158, which needs attention from someone. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by pjljvdlaar): The issue occurs on line 157 of TxsUtils.hs @simonpj. I doubt it: the scoping is important, otherwise a nice warning is generated. {{{ C:\Users\pilaar\Desktop\TheMa\Experiments\Haskell\defs\src\TxsUtils.hs:157:37: error: Ambiguous occurrence `name' It could refer to either `TxsDefs.name', imported from `TxsDefs' at src\TxsUtils.hs:26:1-14 (and originally defined in `Ident') or `FuncId.name', imported from `FuncId' at src\TxsUtils.hs:28:1-13 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): I reduced the example to something with 4 files and no dependencies. To reproduce `ghc Repo.hs`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * Attachment "repo.zip" added. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Triggers an assertion failure with a `DEBUG` compiler. {{{ [1 of 4] Compiling FuncId2 ( FuncId2.hs, FuncId2.o ) [2 of 4] Compiling Ident2 ( Ident2.hs, Ident2.o ) [3 of 4] Compiling TxsDefs2 ( TxsDefs2.hs, TxsDefs2.o ) ghc-stage2: panic! (the 'impossible' happened) (GHC version 8.3.20170412 for x86_64-apple-darwin): ASSERT failed! file compiler/typecheck/TcRnExports.hs, line 604 Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: mpickering Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * owner: (none) => mpickering -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: mpickering Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): I put the test up on phab. https://phabricator.haskell.org/D3535 The problem is in TcPat.find_field_ty but I can't see how to cleanly fix it. In the renamer we don't care yet whether a record selector is the right one for the data constructor. When we check in the type checker, all the verify is that the `OccName` of the selector is one of the field labels of the right data constructor. We don't compare `Name`s at all like we should do because of something to do with ORF. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * owner: mpickering => (none) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): I think this is exactly #12158 as Simon suggested. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the
'impossible' happened) in ghc
-------------------------------------+-------------------------------------
Reporter: pjljvdlaar | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.2
Resolution: | Keywords:
Operating System: Windows | Architecture:
Type of failure: Compile-time | Unknown/Multiple
crash or panic | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Phyx-): * os: Windows => Unknown/Multiple -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #13840 Comment: #13840 is another occurrence of this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: #13840 => #13840, #13973 Comment: So is #13973. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): #14087 | Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: #13840, #13973 => #13840, #13973, #14087 * milestone: => 8.4.1 Comment: And #14087. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): #14087 | Wiki Page: | -------------------------------------+------------------------------------- Comment (by sighingnow): Maybe we should throw a type error when pattern name mismatch, rather than just panic. Use the case from #13973 as an example, {{{#!haskell -- Record.hs module Record (Record(..)) where data Record = Record { field1 :: Int, field2 :: Int } -- Test.hs module Test (foo) where import qualified Record as Rec field2 :: () field2 = () foo :: Rec.Record -> Int foo Rec.Record{field2 = field2} = field2 }}} In function `translateConPatVec` (in `compiler/deSugar/Check.hs`, during the desugar pass), we can't know whether the pattern label comes from the record fields, or just another ordinary symbol. When pattern name lookup (`lookup name zipped`) fails, **we could reach a conclusion** that `name` must not be one of the record fields. Then the compiler can throw an error like {{{ Test.hs:11:16: error: Record field not in scope: ‘field2’ Perhaps you meant one of these: ‘Rec.field1’ (imported from Record), ‘Rec.field2’ (imported from Record), }}} (Noticing that `Record field not in scope` has point out that the missing item is a record field label, rather than other ordinary variable, without causing any confusion.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): #14087 | Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * cc: adamgundry (added) Comment: Adam, might you look at this, since it seems to be in ORF-land? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): #14087 | Wiki Page: | -------------------------------------+------------------------------------- Comment (by adamgundry): @simonpj thanks for pointing me to this ticket.
The problem is in TcPat.find_field_ty but I can't see how to cleanly fix it.
@mpickering part of the fix is surely to compare the selector names (which we have available). I've implemented this in 52110a7966848538583acb65f6e064aadc751260 and it fixes the original test case. However, the related bug #13847 remains: this patch is too liberal as it accepts examples where the field label is in scope only qualified, but it is used unqualified, and `DisambiguateRecordFields` is not enabled. Several of the other related bugs demonstrate this, so my patch causes them to be accepted (without a panic, but without an error either). I'm out of time to investigate further for now, unfortunately. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): #14087 | Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Thanks Adam! I think you are saying * This patch fixes #13644 * And it fixes #13973, #14087, #13973, #13840, and #12158 * But not #13847 Right? If so, let's add regression tests for the others; and then close this one. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

@simonpj thanks for pointing me to this ticket.
The problem is in TcPat.find_field_ty but I can't see how to cleanly fix it.
@mpickering part of the fix is surely to compare the selector names (which we have available). I've implemented this in 52110a7966848538583acb65f6e064aadc751260 and it fixes the original test case.
However, the related bug #13847 remains: this patch is too liberal as it accepts examples where the field label is in scope only qualified, but it is used unqualified, and `DisambiguateRecordFields` is not enabled. Several of the other related bugs demonstrate this, so my patch causes
#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Compile-time | Unknown/Multiple crash or panic | Test Case: Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): #14087 | Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Replying to [comment:16 adamgundry]: them to be accepted (without a panic, but without an error either).
I'm out of time to investigate further for now, unfortunately.
Is it not currently implemented like it is to enabled ORF to work properly? I think your patch changes it back to how it used to work? I can possibly try to create a test case tomorrow. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash or panic | rename/should_fail/T13644 Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): Phab:D3988 #14087 | Wiki Page: | -------------------------------------+------------------------------------- Changes (by adamgundry): * testcase: => rename/should_fail/T13644 * status: new => patch * differential: => Phab:D3988 Comment: Looking at this again, I realised that the fix to #13847 is entirely analogous. Diff away! @mpickering I probably broke this when implementing ORF, but AFAICS there is no ORF-related reason for us to compare field labels here, because we already know the selector names we want. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:19 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13644: overloaded name used in record pattern matching leads to panic! (the
'impossible' happened) in ghc
-------------------------------------+-------------------------------------
Reporter: pjljvdlaar | Owner: (none)
Type: bug | Status: patch
Priority: normal | Milestone: 8.4.1
Component: Compiler | Version: 8.0.2
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Compile-time | Test Case:
crash or panic | rename/should_fail/T13644
Blocked By: | Blocking:
Related Tickets: #13840, #13973, | Differential Rev(s): Phab:D3988
#14087 |
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13644: overloaded name used in record pattern matching leads to panic! (the 'impossible' happened) in ghc -------------------------------------+------------------------------------- Reporter: pjljvdlaar | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.0.2 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash or panic | rename/should_fail/T13644 Blocked By: | Blocking: Related Tickets: #13840, #13973, | Differential Rev(s): Phab:D3988 #14087 | Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13644#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC