一句话:提出 Go 核心模型 WG 与运行时低级语言 LWG,给出兼顾结构子类型与泛型的类型导向编译方案。
Go 将泛型与类型之间的结构子类型同非一致的运行时表示相结合,使其形式化面临显著挑战,而既有工作遗漏了底层类型(underlying types)、类型并集与类型集、以及泛型方法等关键特性。本文提出 WG(Welterweight Go),一个刻画这些特性的 Go 核心模型;并设计低级语言 LWG,建模 Go 的运行时机制,尤其是原始结构体值与携带运行时类型信息(RTTI)的接口值之间的区分。作者给出从 WG 到 LWG 的类型导向编译,说明这些新特性可以被实现,同时满足 Go 的重要设计与实现目标:兼容分离编译、不在运行时生成代码。与基于静态单态化的既有方法不同,该编译策略使用运行时类型转换与适配器方法来处理结构子类型、泛型与运行时基础设施之间的复杂交互。
Go’s unique combination of structural subtyping between generics and types with non-uniform runtime representations presents significant challenges for formalising the language. We introduce WG (Welterweight Go), a core model of Go that captures key features excluded by prior work, including underlying types, type unions and type sets, and proposed new features, such as generic methods. We also develop LWG, a lower-level language that models Go’s runtime mechanisms, notably the distinction between raw struct values and interface values that carry runtime type information (RTTI). We give a type-directed compilation from WG to LWG that demonstrates how the proposed features can be implemented while observing important design and implementation goals for Go: compatibility with separate compilation, and no runtime code generation. Unlike existing approaches based on static monomorphisation, our compilation strategy uses runtime type conversions and adaptor methods to handle the complex interactions between structural subtyping, generics, and Go’s runtime infrastructure.
@article{paperbot3853,
title = {Welterweight Go: Boxing, Structural Subtyping, and Generics},
author = {Raymond Hu and Julien Lange and Bernardo Toninho and Philip Wadler and Robert Griesemer and Keith Randall},
journal = {Proceedings of the ACM on Programming Languages},
volume = {10},
number = {POPL},
year = {2026},
doi = {10.1145/3776721}
}