🤖 AI Summary
This work addresses the challenge of formally modeling the interplay among structural subtyping, generics, and non-uniform runtime representations in the Go programming language. To this end, it introduces WG, a core calculus that, for the first time, unifies these three mechanisms within a single formal framework. The approach employs a type-directed compilation strategy to translate high-level types—including type unions and generic methods—into a lower-level LWG language. By incorporating runtime type conversions and adapter methods, the scheme enables efficient compilation without requiring runtime code generation while remaining compatible with separate compilation. This research thus provides both a precise formal foundation and a practical implementation pathway for key Go language features.
📝 Abstract
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.