[GHC] #14293: View patterns with locally defined functions in restructuring don't compile
GHC
ghc-devs at haskell.org
Wed Nov 14 11:32:43 UTC 2018
#14293: View patterns with locally defined functions in restructuring don't compile
-------------------------------------+-------------------------------------
Reporter: heisenbug | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.2.1
Resolution: | Keywords: ViewPatterns
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: #15893 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
I've realised that it may be simpler than I thought.
Currently `RnBinds.rnLocalValBindsLHS` looks like this
{{{
rnLocalValBindsLHS fix_env binds
= do { binds' <- rnValBindsLHS (localRecNameMaker fix_env) binds
; let bound_names = collectHsValBinders binds'
...
}}}
I think instead we can do this
{{{
= do { let bound_rdr_names = collectHsValBinders binds'
; bound_names <- mapM newLocalBndrRn bound_rdr_name
; binds' <- bindLocalNames bound_names $
addLocalFixities fix_env bound_names $
rnValBindsLHS (localRecNameMaker fix_env) binds
...
}}}
Take an tricky example binding
{{{
(f, f -> x) = e
}}}
The idea is
1. Find all the `RdrName` binders from bindings, here `f` and `x`.
2. Make fresh `Names` for each of them, say `f_34` and `x_88`.
3. Extend the environment with bindings `f :-> f_34` and `x :-> x_88`.
4. Then rename the LHSs; but when we find a binder (say the `RdrName`
`f`),
`localRecNameMaker` should ''look it up'' in the environment, rather
than making
a fresh `Name` (that's been done already).
Result is the pattern `(f_34, f_34 -> x_88)`.
5. After that, everything is as before.
To do this we need to persuade `localRecNameMaker` to look up rather than
make a fresh `Name`.
I think we can do this easily, by altering the `LetMk` case of
`newPatName`.
We need to make exactly the same change in `rnSrcDecls`, for the same
reason.
I think that's it!
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14293#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list