[GHC] #7989: "No constructor has all these fields" message can be improved
#7989: "No constructor has all these fields" message can be improved -----------------------------+---------------------------------------------- Reporter: akio | Owner: Type: feature request | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- When a record update syntax contains fields from multiple constructors, you get an error message like this: {{{ module Foo where data A = A {a0, a1 :: Int} data B = B {b0, b1 :: Int} f x = x { a0 = 3, a1 = 2, b0 = 4, b1 = 5 } }}} {{{ datacon.hs:6:7: No constructor has all these fields: `a0', `a1', `b0', `b1' In the expression: x {a0 = 3, a1 = 2, b0 = 4, b1 = 5} In an equation for `f': f x = x {a0 = 3, a1 = 2, b0 = 4, b1 = 5} }}} However, this message becomes rather unhelpful when you are updating many (say 100) fields at once, because it doesn't say which field is causing the problem. I think it would be better if it only listed two conflicting field names like: {{{ No constructor has these two fields: `a0', `b0' }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved -----------------------------+---------------------------------------------- Reporter: akio | Owner: Type: feature request | Status: new Priority: normal | Component: Compiler Version: 7.7 | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Blockedby: Blocking: | Related: -----------------------------+---------------------------------------------- Comment(by akio): I'm preparing a patch. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by simonpj): * difficulty: => Unknown Comment: Good idea. I'd happily review a patch. Simon -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Changes (by akio): * status: new => patch Comment: I attached a proposed patch. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by simonpj): Thanks. Comment on line 1527 looks incomplete? -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:4> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by monoidal): Do you handle this situation? {{{ data T = A { x,y :: Int} | B { y,z :: Int } | C { z,x :: Int} f a = a { x=0, y=0, z=0 } }}} Error message here cannot mention only two fields. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by akio): Replying to [comment:5 monoidal]:
Do you handle this situation?
[...]
Error message here cannot mention only two fields.
You are right, I wasn't thinking of that situation. I rewrote the patch. -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by simonpj): OK.... It's not easy to understand that code! Maybe it would be worth a few more named intermediate values, with types, and a comment? You could produce a very big set when a very small set exists, couldn't you? Could you ameliorate that as follows? Use `T` to mean the data type of the first field in `rbinds`. * Sort the `membership` list in order of increasing number of `True` fields. So the earlier fields `f` in the list have few `T` constructors that have field `f`. * Now a field with a different type will be right at the front of the list. * And the `(&&)` process will terminate more quickly because of all the `False` items. Simon -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by akio): I updated the patch. Replying to [comment:7 simonpj]:
OK.... It's not easy to understand that code! Maybe it would be worth a few more named intermediate values, with types, and a comment?
I did this.
You could produce a very big set when a very small set exists, couldn't
you? Yes, the size of the set is only bounded by the number of constructors.
Could you ameliorate that as follows? Use `T` to mean the data type of
the first field in `rbinds`.
* Sort the `membership` list in order of increasing number of `True` fields. So the earlier fields `f` in the list have few `T` constructors that have field `f`. * Now a field with a different type will be right at the front of the list. * And the `(&&)` process will terminate more quickly because of all the `False` items.
I implemented this. However I'm afraid that the worst-case behavior of the algorithm hasn't changed much. Given a datatype with 2N constructors and 2N fields, it can find a set of N fields even though there is one with just 2 fields. (an example is when the constructor ```i``` has the field ```j``` iff ```mod (i + j) (2*N) < N```) -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by simonpj@…): commit a7798e95112409b6ec958e509dbdc46bc53cf5e4 {{{ Author: Simon Peyton Jones <simonpj@microsoft.com> Date: Tue Jun 25 14:16:29 2013 +0100 Comments for Trac #7989 compiler/typecheck/TcExpr.lhs | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ---------------------------------+------------------------------------------ Reporter: akio | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Os: Unknown/Multiple Architecture: Unknown/Multiple | Failure: Other Difficulty: Unknown | Testcase: Blockedby: | Blocking: Related: | ---------------------------------+------------------------------------------ Comment(by aljee@…): commit d67b99347f5af146b699b1df174687a4de08fa1a {{{ Author: Takano Akio <aljee@hyper.cx> Date: Mon Jun 17 18:42:09 2013 +0900 Improve "No data constructor has all these fields" message (#7989) compiler/typecheck/TcExpr.lhs | 55 ++++++++++++++++++++++++++++++++++++++--- 1 files changed, 51 insertions(+), 4 deletions(-) }}} -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#7989: "No constructor has all these fields" message can be improved ------------------------------------------+--------------------------------- Reporter: akio | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: fixed | Keywords: Os: Unknown/Multiple | Architecture: Unknown/Multiple Failure: Other | Difficulty: Unknown Testcase: typecheck/should_fail/T7989 | Blockedby: Blocking: | Related: ------------------------------------------+--------------------------------- Changes (by simonpj): * status: patch => closed * testcase: => typecheck/should_fail/T7989 * resolution: => fixed Comment: Thank you! I committed and added some extra comments and a test. Simon -- Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7989#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC