[GHC] #9207: Detect obvious cases of infinite recursion.
GHC
ghc-devs at haskell.org
Sat Nov 17 21:37:40 UTC 2018
#9207: Detect obvious cases of infinite recursion.
-------------------------------------+-------------------------------------
Reporter: mrugiero | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.4.4
Resolution: | Keywords: infinite
| recursion
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 bebarker):
* status: closed => new
* version: 7.8.2 => 8.4.4
* resolution: invalid =>
Comment:
I respectfully disagree with Fuuzetsu's suggestion that there are no
obvious cases, here is an example that came up for me recently. I'm
somewhat new to Haskell but am also fairly familiar with writing recursive
functions in other languages. Probably, this was difficult for me to spot
because I wrote it:
{{{#!haskell
loadImage :: MonadIO m => FilePath -> m HicoImage
loadImage fpath = liftIO $ loadImage fpath
where
loadImg :: FilePath -> IO HicoImage
loadImg fp = Image <$> SDL.Image.load fp
}}}
Now, there are several issues with this function stylistically that
probably would have prevented this, such as not really needing the `where`
clause and choosing bad naming conventions (`loadImage` and `loadImg`).
The good news is for folks who know more about GHC than myself, I think,
is this snippet I found in
[https://www.reddit.com/r/haskell/comments/6hng6n/which_haskell_features_prevent_guaranteed_loop/dizzvvv
another discussion] regarding detecting "syntactic cycles" with GHC. To
quote:
Core differentiates between a single
[https://downloads.haskell.org/~ghc/8.4.4/docs/html/libraries/ghc-8.4.4/CoreSyn.html#v:NonRec
NonRec] binding at a time vs. a
[https://downloads.haskell.org/~ghc/8.4.4/docs/html/libraries/ghc-8.4.4/CoreSyn.html#v:Rec
Rec] binding group.
The part of GHC which does the conversion from a single, recursive group
to these let nestings is called the Occurence Analyzer. It's basically a
strongly connected component analysis, once you have figured out all
edges.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9207#comment:11>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list