[GHC] #8466: Aggregate “ambiguous import” errors for the same name

#8466: Aggregate “ambiguous import” errors for the same name ------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- When porting legacy code, such an error happens frequently. But instead of {{{ [5 of 5] Compiling Main ( src/main.hs, dist/build/DAG- Tournament/DAG-Tournament-tmp/Main.o ) src/main.hs:302:23: Ambiguous occurrence `eventButton' It could refer to either `Graphics.UI.Gtk.eventButton', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventButton', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:302:54: Ambiguous occurrence `eventClick' It could refer to either `Graphics.UI.Gtk.eventClick', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventClick', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:305:23: Ambiguous occurrence `eventButton' It could refer to either `Graphics.UI.Gtk.eventButton', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventButton', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:305:54: Ambiguous occurrence `eventClick' It could refer to either `Graphics.UI.Gtk.eventClick', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventClick', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:330:23: Ambiguous occurrence `eventModifier' It could refer to either `Graphics.UI.Gtk.eventModifier', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventModifier', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:332:23: Ambiguous occurrence `eventModifier' It could refer to either `Graphics.UI.Gtk.eventModifier', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventModifier', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:334:23: Ambiguous occurrence `eventKeyName' It could refer to either `Graphics.UI.Gtk.eventKeyName', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventKeyName', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:338:23: Ambiguous occurrence `eventKeyName' It could refer to either `Graphics.UI.Gtk.eventKeyName', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventKeyName', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 src/main.hs:345:23: Ambiguous occurrence `eventKeyName' It could refer to either `Graphics.UI.Gtk.eventKeyName', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventKeyName', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 }}} I’d really prefer to read {{{ [5 of 5] Compiling Main ( src/main.hs, dist/build/DAG- Tournament/DAG-Tournament-tmp/Main.o ) src/main.hs:302:23: Ambiguous occurrence `eventButton' It could refer to either `Graphics.UI.Gtk.eventButton', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventButton', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 (also at src/main.hs:305:23, src/main.hs:302:54: Ambiguous occurrence `eventClick' It could refer to either `Graphics.UI.Gtk.eventClick', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventClick', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 (also at src/main.hs:305:54) src/main.hs:330:23: Ambiguous occurrence `eventModifier' It could refer to either `Graphics.UI.Gtk.eventModifier', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventModifier', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 (also at src/main.hs:332:23) src/main.hs:334:23: Ambiguous occurrence `eventKeyName' It could refer to either `Graphics.UI.Gtk.eventKeyName', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventKeyName', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 (also at src/main.hs:338:23 and src/main.hs:345:23) }}} or some other kind of aggregation of the information. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): I see your point, though it's in conflict with the report for #5867. Error messages need to be presented systematically so that editors can find the place. I'm not sure it's worth changing anything here. Other opinions welcome. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): I find it strange to arrange feedback primarily targeted for human consumption in a way that suits programs. Either the programs use a different interface, e.g. some `ghc --machine-parsable-errors` option (in which case a properly machine-readable format like XML or JSON might be good), or they simply have to learn to parse the format that the compiler generates for its human users. A compromise would be a format that is both easy to read by humans, but requires little adjustment in error message parsers: {{{ src/main.hs:334:23: src/main.hs:338:23: src/main.hs:345:23: Ambiguous occurrence `eventKeyName' It could refer to either `Graphics.UI.Gtk.eventKeyName', imported from `Graphics.UI.Gtk' at src/main.hs:10:1-22 (and originally defined in `Graphics.UI.Gtk.Gdk.EventM') or `Graphics.UI.Gtk.Gdk.Events.eventKeyName', imported from `Graphics.UI.Gtk.Gdk.Events' at src/main.hs:12:1-33 }}} But it’s indeed minor, so if there is disagreement, then its probably not worth working on. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): I do rather agree with you, but it's a user question so let's get more user feedback. A very simple, but brutal, way to achieve this would be to aggregate error messages that were identical, as strings. We don't keep them as data, so the string (or rather `SDoc`) is all we have to do on. You could try this in `printMsgBag` in `ErrUtils`. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): Interesting, the field `errMsgSpans` of `ErrMsg` already has tpye `[SrcSpan]` (and not `SrcSpan`) as if someone was preparing this feature. Tracing the git history, I find that the type was introduced in 29da2cf3011c292bc4261601aff85afb13e24d54 from ten years ago by simonmar, but without an explanation of the choice... I’ll see if indeed nothing breaks if I change this to `SrcSpan` before attempting to combine the error messages. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): Indeed, `SrcSpan` works just the same. Once a second pair of eyes went over it, 8e748c66506e228c9d12f63458d026182843c466 could be pulled into master, as a minor code-cleanup patch. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by simonpj): But if you want to aggregate, as suggested by this ticket, we'd need to undo the change you propose? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): I was planning to do the aggregation not inside `ErrMsg`, but rather have a `groupAndSort` function that returns `[[ErrMsg]]`. Anyways, I find it cleaner to start from cleaned-up code, independent of whether my changes would then take the same form. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): I gave it a shot in 132a3d8fa5a018fec927ada0ae1c0eb6e4a5a1d5, now instead of {{{ $ ghc Errors.hs [1 of 1] Compiling Main ( Errors.hs, Errors.o ) Errors.hs:1:6: Not in scope: `foo' Errors.hs:3:6: Not in scope: `bar' Errors.hs:5:7: Not in scope: `foo' Errors.hs:5:11: Not in scope: `foo' }}} we’d get {{{ $ ./inplace/bin/ghc-stage2 Errors.hs [1 of 1] Compiling Main ( Errors.hs, Errors.o ) Errors.hs:1:6: Not in scope: ‛foo’ (also at Errors.hs:5:7-9, Errors.hs:5:11-13) Errors.hs:3:6: Not in scope: ‛bar’ }}} which I believe is an improvement, at least for our human consumers of error messages. It’s not ready to be merged, though: Not all fields of an `ErrMsg` have an `Eq` instance. In particular, this code merges error messages if their `errMsgShortString` and severity agree, even if `errMsgExtraInfo` (which is an `SDoc`) and `errMsgMsgContext` differ. I have not yet seen enough of GHC’s code to assess if that is sufficient, or if there is a risk of throwing away important information. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by tibbe): I don't think we should do this. It will break a bunch of tools that depend on this standardized error format (e.g. Emacs and vi). If you insist I think it should be off by default and behind a flag. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by nomeata): * status: new => closed * resolution: => wontfix Comment: Nah, off by default makes no sense for a feature that should help users finding their way in error messages. In that case, this bug should be marked as wontfix, either until the majority opinions on this changes or, eventually, in some shiny future, every programmatic consumer of error messages uses a proper API for that and we are free to format our error messages the way it suits the readers most. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): Although; what would you say if such behaviour is dependent on whether stderr is a terminal or not? That seems to be a common way to distinguish plain from fancy output (think git, which does not use color or a pager if you pipe to grep). Or is that then too confusing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8466: Aggregate “ambiguous import” errors for the same name -------------------------------------+------------------------------------ Reporter: nomeata | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by nomeata): (Deleting the wip-branch, hence attaching my attempt here, mostly for I-don’t-like-to-delete-stuff reasons.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8466#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC