ModIface passed to interface plugins have bottom fields for unclear reasons
Plugin.interfaceLoadAction
is called after loading an interface by
loadInterface
.
loadInterface
updates some fields of the ModIface
before adding it to the
PackageIfaceTable
(eps_PIT
), making them bottoming:
; let { final_iface = iface {
mi_decls = panic "No mi_decls in PIT",
mi_insts = panic "No mi_insts in PIT",
mi_fam_insts = panic "No mi_fam_insts in PIT",
mi_rules = panic "No mi_rules in PIT",
mi_anns = panic "No mi_anns in PIT"
}
}
...
updateEps_ $ \ eps -> ... add final_iface to PIT ...
; -- invoke plugins
res <- withPlugins dflags interfaceLoadAction final_iface
; return (Succeeded res)
}
There are two problems with this:
-
Whatever the motivation for clearing these fields out is, it's not documented in the relevant places. A plugin author using this callback will probably look at the
ModIface
documentation, but not atEPS
documentation, which is the only place where we mention that these fields are bottom:eps_PIT :: !PackageIfaceTable, -- ^ The 'ModIface's for modules in external packages -- whose interfaces we have opened. -- The declarations in these interface files are held in the -- 'eps_decls', 'eps_inst_env', 'eps_fam_inst_env' and 'eps_rules' -- fields of this record, not in the 'mi_decls' fields of the -- interface we have sucked in.
-
Passing values with bottom fields to plugins is bad from UX point of view.
The same bottom fields caused other problems to me before, in a different context. See #17470.
I propose one of these two:
-
Even in EPS documentation I don't see an explanation of why we need to clear these fields. Just keep them. We already keep the values alive in EPS, removing them from
ModIface
won't save us memory or anything else. -
Pass
ModIface
without removing these fields to the plugins so that a plugin can easily look at the annotations, rules etc. without having to go through undocumented stuff. Note that if we absolutely need to remove these from ModIface then we can still do it, this doesn't prevent us from removing the fields in the ModIface we put into the EPS.