Skip to content
Snippets Groups Projects
Forked from Glasgow Haskell Compiler / GHC
6976 commits behind the upstream repository.
sheaf's avatar
sheaf authored
This patch moves the field-based logic for disambiguating record updates
to the renamer. The type-directed logic, scheduled for removal, remains
in the typechecker.

To do this properly (and fix the myriad of bugs surrounding the treatment
of duplicate record fields), we took the following main steps:

  1. Create GREInfo, a renamer-level equivalent to TyThing which stores
     information pertinent to the renamer.
     This allows us to uniformly treat imported and local Names in the
     renamer, as described in Note [GREInfo].

  2. Remove GreName. Instead of a GlobalRdrElt storing GreNames, which
     distinguished between normal names and field names, we now store
     simple Names in GlobalRdrElt, along with the new GREInfo information
     which allows us to recover the FieldLabel for record fields.

  3. Add namespacing for record fields, within the OccNames themselves.
     This allows us to remove the mangling of duplicate field selectors.

     This change ensures we don't print mangled names to the user in
     error messages, and allows us to handle duplicate record fields
     in Template Haskell.

  4. Move record disambiguation to the renamer, and operate on the
     level of data constructors instead, to handle #21443.

     The error message text for ambiguous record updates has also been
     changed to reflect that type-directed disambiguation is on the way
     out.

(3) means that OccEnv is now a bit more complex: we first key on the
textual name, which gives an inner map keyed on NameSpace:

  OccEnv a ~ FastStringEnv (UniqFM NameSpace a)

Note that this change, along with (2), both increase the memory residency
of GlobalRdrEnv = OccEnv [GlobalRdrElt], which causes a few tests to
regress somewhat in compile-time allocation.

Even though (3) simplified a lot of code (in particular the treatment of
field selectors within Template Haskell and in error messages), it came
with one important wrinkle: in the situation of

  -- M.hs-boot
  module M where { data A; foo :: A -> Int }
  -- M.hs
  module M where { data A = MkA { foo :: Int } }

we have that M.hs-boot exports a variable foo, which is supposed to match
with the record field foo that M exports. To solve this issue, we add a
new impedance-matching binding to M

  foo{var} = foo{fld}

This mimics the logic that existed already for impedance-binding DFunIds,
but getting it right was a bit tricky.
See Note [Record field impedance matching] in GHC.Tc.Module.

We also needed to be careful to avoid introducing space leaks in GHCi.
So we dehydrate the GlobalRdrEnv before storing it anywhere, e.g. in
ModIface. This means stubbing out all the GREInfo fields, with the
function forceGlobalRdrEnv.
When we read it back in, we rehydrate with rehydrateGlobalRdrEnv.
This robustly avoids any space leaks caused by retaining old type
environments.

Fixes #13352 #14848 #17381 #17551 #19664 #21443 #21444 #21720 #21898 #21946 #21959 #22125 #22160 #23010 #23062 #23063

Updates haddock submodule

-------------------------
Metric Increase:
    MultiComponentModules
    MultiLayerModules
    MultiLayerModulesDefsGhci
    MultiLayerModulesNoCode
    T13701
    T14697
    hard_hole_fits
-------------------------
3f374399
History
Name Last commit Last update
..
T16104-plugin
T20803-plugin
annotation-plugin
defaulting-plugin
echo-plugin
hole-fit-plugin
hooks-plugin
plugin-recomp
rule-defining-plugin
shared-plugin
simple-plugin
FrontendPlugin.hs
HomePackagePlugin.hs
LinkerTicklingPlugin.hs
Makefile
MetaRemoveHelper.hs
PluginFilteredExport.hs
PluginRecompTest.hs
QuasiQuotation.hs
T10294.hs
T10294.stderr
T10294a.hs
T10420.hs
T10420.stdout
T10420a.hs
T11244.hs
T11244.stderr
T12567a.hs
T12567a.stderr
T12567b.hs
T14335.hs
T14335.stderr
T15858.script
T15858.stderr
T16104.hs
T16104.stdout
T16260.hs
T16260.stdout
T19926.hs
T19926.stderr
T20218.hs
T20218b.hs
T20218b.stderr
T20218b.stdout
T20417.stderr
T20803a.hs
T20803a.stderr
T20803b.hs
T20803b.stderr
all.T
frontend01.hs
frontend01.stdout
plugin-recomp-change-2.stderr
plugin-recomp-change-prof.stderr
plugin-recomp-change.stderr
plugin-recomp-flags.stderr
plugin-recomp-flags.stdout
plugin-recomp-impure.stderr
plugin-recomp-impure.stdout
plugin-recomp-pure.stderr
plugin-recomp-pure.stdout
plugin-recomp-test.hs
plugins-external.hs
plugins-external.stderr
plugins-external.stdout
plugins-ghci.hs
plugins-ghci.stdout
plugins-order-pragma.hs
plugins-order-pragma.stderr
plugins-order.hs
plugins-order.stderr
plugins01.hs
plugins01.stderr
plugins01.stdout
plugins02.hs
plugins02.stderr
plugins03.hs
plugins03.stderr
plugins04.hs
plugins04.stderr
plugins05.hs
plugins05.stdout
plugins06.hs
plugins07.hs
plugins07.stdout
plugins08.hs
plugins08.stderr
plugins08.stdout
plugins09.hs
plugins09.stdout
plugins10.hs
plugins10.stdout
plugins11.hs
plugins11.stdout
plugins12.hs
plugins13.hs
plugins14.hs
plugins15.hs
static-plugins-module.hs
static-plugins.hs