Generic Go to Go: Dictionary-Passing, Monomorphisation, and Hybrid

Stephen Ellis, Shuofei Zhu, Nobuko Yoshida, Linhai Song
8/14/2022
cs.PL

Official code: sfzhu93/fgg2go (4 stars, Go, CC-BY-4.0, last commit 2023-01-24).

Abstract

Go is a popular statically-typed industrial programming language. To aid the type safe reuse of code, the recent Go release (Go 1.18) published on 15th March 2022 includes bounded parametric polymorphism via generic types.

Show full abstract

Go 1.18 implements generic types using combination of monomorphisation and call-graph based dictionary-passing called hybrid. This hybrid approach can be viewed as an optimised form of monomorphisation that statically generates specialised methods and types based on possible instantiations. A monolithic dictionary supplements information lost during monomorphisation, and it is structured according to the program's call graph. Unfortunately, the hybrid approach still suffers from code bloat, poor compilation speed, and limited code coverage. In this paper we propose and formalise a new non-specialising call-site based dictionary-passing translation. Our call-site based translation creates individual dictionaries for each type parameter, with dictionary construction occurring in place of instantiation, overcoming the limitations of hybrid. We prove it correct using a novel and general bisimulation up to technique. To better understand how different generics translations approaches work in practice, we benchmark five translators, Go 1.18, two existing monomorphisation translators, our dictionary-passing translator, and erasure translator. Our findings reveal several suggestions for improvements for Go 1.18 -- specifically how to overcome the expressiveness limitations of generic Go, and improve compile time and compiled code size performance of Go 1.18.

View on arXivView PDF

Code Implementations(1)

sfzhu93/fgg2goOfficial100%
CC-BY-4.0
40Go, MakefileSep 15, 20223 years agoCC-BY-4.0

Similar Papers

Cite this paper

@article{ellis2022generic,
  title  = {Generic Go to Go: Dictionary-Passing, Monomorphisation, and Hybrid},
  author = {Stephen Ellis and Shuofei Zhu and Nobuko Yoshida and Linhai Song},
  year   = {2022},
  eprint = {2208.06810},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2208.06810}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2208.06810.svg)](https://codeofpaper.com/paper/2208.06810)

Discussion