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. 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.
翻译:Go是一种流行的静态型工业编程语言。为了帮助安全重用代码的类型,最近于2022年3月15日出版的Go发行(Go 1.18)中包括了以通用类型出现的受约束的参数多元形体。Go 1.18使用单形和呼-呼-呼-基于字典的浏览混合翻译组合来实施通用类型。这种混合方法可以被视为一种优化的单形形式,这种单形形式根据可能的即时即时生成特殊的方法和类型。单形词典补充了在单一化过程中丢失的信息,并且根据该方案的调用图表来构建。不幸的是,混合方法仍然受到代码布局、低编速度和有限代码覆盖的制约。在本文件中,我们提议并正式采用新的非专门化呼-呼-呼-以字典为基础的字典浏览翻译组合。我们基于呼-调的翻译为每种参数创建了单独的词典,在快速化的基础上建立词典,克服混合的局限性。我们证明它是正确的,我们使用一种新式和通用的缩-通用方法的缩式翻译方式如何具体地改进了我们的版本,我们现有的五级翻译版本。Go Go Go 18 改进了我们现有的版本版本版本的翻译格式,我们现有的版本。