[GHC] #10569: Treat an out-of-scope variable like a typed hole
#10569: Treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- If we have {{{ f x = x + y }}} GHC currently reports `Not in scope: y`, and halts. It would be cool to treat `y` as a typed hole, so that * The out-of-scope message would give its type * Using `-fdefer-type-errors` we could defer the error to runtime. This was suggested in #5910 [https://ghc.haskell.org/trac/ghc/ticket/5910#comment:19 comment 19], and [http://haskell.1045720.n5.nabble.com/fdefer-more-errors-td5809991.html this Haskell Cafe thread] -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by simonpj): * type: bug => feature request -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by Simon Peyton Jones <simonpj@…>): In [changeset:"fb7b6922573af76a954d939c85e6af7c39a19896/ghc"]: {{{ #!CommitTicketReference repository="ghc" revision="fb7b6922573af76a954d939c85e6af7c39a19896" Treat out-of-scope variables as holes This patch implements the idea in Trac #10569. * An out-of-scope variable is treated as a typed expression hole. * That is, we don't report it in the type checker, not the renamer, and we when we do report it, we give its type. * Moreover, we can defer the error to runtime with -fdefer-typed-holes In implementation terms: * The renamer turns an unbound variable into a HsUnboundVar * The type checker emits a Hole constraint for a HsUnboundVar, and turns it back into a HsVar It was a bit painful to implement because a whole raft of error messages change slightly. But there was absolutely nothing hard in principle. Holes are reported with a bunch of possibly-useful context, notably the "relevant bindings". I found that this was distracting clutter in the very common case of a mis-typed variable that is only accidentally not in scope, so I've arranged to print the context information only for true holes, that is ones starting with an underscore. Unbound data constructors use in patterns, like f (D x) = x are still reportd by the renamer, and abort compilation before type checking. }}} -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.10.1 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by simonpj): * status: new => closed * resolution: => fixed Comment: Well I did this in a fit of enthusiasm. I hope you like it. Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Optionally treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by ertes): * status: closed => new * version: 7.10.1 => 8.0.1 * resolution: fixed => Comment: Can we please make this behaviour optional, and ideally off by default? In an interactive rapid-prototyping workflow this is a major stumbling block, because you have to watch your code crash a few times until you have everything in place, particularly when you ''use now, import later''. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:5> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Optionally treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): ertes, can you please give a more in-depth description of what is causing you problems? I think the only difference with this patch is that out-of-scope errors also give the type of the variable which isn't in scope. Are you also using `-fdefer-type-errors`? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:6> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Optionally treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ertes): I'm using `-W` and `-fdefer-typed-holes`. Now ''any'' out of scope variable will cause my program to crash at run-time rather than just telling me that something is out of scope. Since I often have a lot of pending warnings to deal with, I don't see the scope warnings before run- time, and then it can take arbitrarily long to pop up, and I have to start the development cycle all over. Holes (a development tool) and scope errors (a programmer mistake) are fundamentally different things, and treating them as the same massively disrupts my workflow. In fact, after I explained this phenomenon in #haskell on Freenode, we first thought it's a GHC bug. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:7> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Optionally treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Well, you could not use `-fdefer-typed-holes`, couldn't you? After all, that too makes your program crash at runtime if you meet a hole. It'd be easy enough to put this behaviour behind a flag, say `-fdefer-out- of-scope-variables`. (I think it's quite nice to get the type info for an out-of-scope variable.) The only downside is yet another flag, user manual entry etc. Simon -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:8> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Optionally treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by ertes): Simon, but `-fdefer-typed-holes` is a very useful development tool, and when I enable that flag, I'm expecting underscored identifiers to behave differently. Let me just say that ''for me'' this new feature is more of a stumbling block than a useful tool, and there are two ways to fix it: to make it optional, or to implement #12157 (warning priorities). I'm fine with these errors being warnings, as long as I can at least make them show up at the top. "Not in scope" errors are genuine errors in my workflow. Don't get me wrong: I'm in favour of turning as many errors as possible into warnings, but since we don't have a system to prioritise warnings right now, some things should better stay errors. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:9> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Optionally treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by goldfire): To me, the problem here is that we've conflated two goals: 1. Adding type information to out-of-scope variables. 2. Allowing deferment of out-of-scope variables. I think (1) is a clear win (modulo #12092). But I tend to think (2) isn't. Even if someone is deferring type errors, I imagine most people don't want to defer scope errors. I personally favor adding the flag. (Important motivation: thinking about teaching Haskell and seeing if `-fdefer-type- errors` can help.) -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:10> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Optionally treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: new Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): OK. I'm fine with having a new flag. Does someone feel like implementing a patch? -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:11> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#10569: Treat an out-of-scope variable like a typed hole -------------------------------------+------------------------------------- Reporter: simonpj | Owner: Type: feature request | Status: closed Priority: normal | Milestone: 8.0.1 Component: Compiler | 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: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * status: new => closed * resolution: => fixed Comment: I made #12170 with a standalone description as it seems like a good newcomer ticket. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10569#comment:12> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC