paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Generic go to go: dictionary-passing, monomorphisation, and hybrid

Go 泛型到 Go:字典传递、单态化与混合方法
OOPSLA 6(OOPSLA2)2022匹配度 2/10 · 论文研究 Go 泛型的编译翻译方案与形式化正确性证明,属于编译器与形式语义领域,但未涉及用户核心关注的静态分析、LLM/Agent 与程序分析的交叉、浮点程序分析或贝叶斯程序分析,仅与 PL 理论形式化和工程实现的宽泛兴趣有微弱关联。引用 4 inbox
Stephen Ellis, Shuofei Zhu, Nobuko Yoshida, Linhai Song
crossref: 2026-09-10

AI 速览

一句话:提出基于调用点的字典传递泛型翻译并证明正确性,以克服 Go 1.18 混合方案的限制。

Go 1.18 通过泛型支持有界参数多态,其实现采用单态化与基于调用图的字典传递相结合的混合翻译。该方案会静态特化方法与类型,但仍存在代码膨胀、编译速度差和代码覆盖有限等问题。本文提出并形式化一种非特化的、基于调用点的字典传递翻译:为每个类型参数创建独立字典,并在实例化位置构造字典。作者使用一种新颖且通用的 bisimulation up to 技术证明其正确性,并通过基准测试比较 Go 1.18、两种单态化翻译器、本文翻译器与擦除翻译器,进而给出改进 Go 1.18 表达力、编译时间与生成代码大小的建议。

问题
Go 1.18 的泛型混合翻译仍导致代码膨胀、编译速度慢和代码覆盖有限,如何设计更优的泛型翻译并理解不同方案在实践中的表现。
方法
提出并形式化基于调用点的字典传递翻译,为每个类型参数在实例化处构建字典,并用通用 bisimulation up to 证明正确性;实现并基准测试五种翻译器。
评估
在基准上比较 Go 1.18、两种单态化翻译器、本文字典传递翻译器与擦除翻译器,分析编译时间、代码大小和表达力,并提出对 Go 1.18 的改进建议。
原文摘要(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 early 2022 includes bounded parametric polymorphism via generic types. Go 1.18 implements generic types using a 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 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 translation approaches work in practice, we benchmark five translators, Go 1.18, two existing monomorphisation translators, our dictionary-passing translator, and an 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.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot1420,
  title = {Generic go to go: dictionary-passing, monomorphisation, and hybrid},
  author = {Stephen Ellis and Shuofei Zhu and Nobuko Yoshida and Linhai Song},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {6},
  number = {OOPSLA2},
  year = {2022},
  doi = {10.1145/3563331}
}