通用Go to Go:字典传递、单体化和混合
Generic Go to Go: Dictionary-Passing, Monomorphisation, and Hybrid
摘要:
Go是一种流行的静态类型工业程序设计语言。为了帮助代码的类型安全重用,2022年3月15日发布的最新Go版本(Go 1.18)包括通过泛型类型的有界参数多态性。Go 1.18使用单态化和基于调用图的字典传递的组合来实现泛型类型,称为混合。这种混合方法可以被视为单态化的优化形式,它基于可能的实例化静态生成专门的方法和类型。单片字典补充了在单态化过程中丢失的信息,并且它是根据程序的调用图来构造的。不幸的是,混合方法仍然存在代码膨胀、编译速度慢和代码覆盖率有限的问题。在本文中,我们提出了一个新的非专门的调用网站的字典传递翻译,并正式。我们基于调用站点的翻译为每个类型参数创建单独的字典,字典构造代替实例化,克服了混合的限制。我们证明它是正确的,使用一种新的和一般的互模拟技术。为了更好地理解不同的泛型翻译方法在实践中是如何工作的,我们对五个翻译器进行了基准测试,Go 1.18,两个现有的单态化翻译器,我们的字典传递翻译器和擦除翻译器。我们的研究结果揭示了Go 1.18的几个改进建议-特别是如何克服通用Go的表现力限制,并改善Go 1.18的编译时间和编译代码大小性能。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。