Skip to content

Fix sharing of 'IfaceTyConInfo' during core to iface type translation

Fixes #24530 (closed)

During heap analysis, we noticed that during generation of 'mi_extra_decls' we have lots of duplicates for the instances:

  • IfaceTyConInfo NotPromoted IfaceNormalTyCon
  • IfaceTyConInfo IsPromoted IfaceNormalTyCon

which should be shared instead of duplicated. This duplication increased the number of live bytes by around 200MB while loading the agda codebase into GHCi.

These instances are created during CoreToIface translation, in particular toIfaceTyCon.

The generated core looks like:

  = \ tc_sjJw ->
      case $wtoIfaceTyCon tc_sjJw of
      { (# ww_sjJz, ww1_sjNL, ww2_sjNM #) ->
      IfaceTyCon ww_sjJz (IfaceTyConInfo ww1_sjNL ww2_sjNM)

whichs removes causes the sharing to work propery.

Adding explicit sharing, with NOINLINE annotations, changes the core to:

  = \ tc_sjJq ->
      case $wtoIfaceTyCon tc_sjJq of { (# ww_sjNB, ww1_sjNC #) ->
      IfaceTyCon ww_sjNB ww1_sjNC

which looks much more like sharing is happening. We confirmed via ghc-debug that all duplications were eliminated and the number of live bytes are noticeably reduced.

Edited by Hannes Siebenhandl

Merge request reports