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.
- Ole Agesen, Stephen N. Freund, and John C. Mitchell. 1997. Adding Type Parameterization to the Java Language. In Proceedings of the 12th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’97). Association for Computing Machinery, New York, NY, USA. 49–65. isbn:0897919084 https://doi.org/10.1145/263698.263720
Google Scholar
Digital Library
- Eric Allen and Robert Cartwright. 2002. The Case for Run-Time Types in Generic Java. In Proceedings of the Inaugural Conference on the Principles and Practice of Programming, 2002 and Proceedings of the Second Workshop on Intermediate Representation Engineering for Virtual Machines, 2002 (PPPJ ’02/IRE ’02). National University of Ireland, Maynooth, County Kildare, IRL. 19–24. isbn:0 901519 87 1
Google Scholar
- Christal Baier and Joost P. Katoen. 2008. Principles of Model Checking. MIT Press, United States. isbn:978-0-262-02649-9
Google Scholar
Digital Library
- Gert-Jan Bottu, Ningning Xie, Koar Marntirosian, and Tom Schrijvers. 2019. Coherence of Type Class Resolution. Proc. ACM Program. Lang., 3, ICFP (2019), Article 91, jul, 28 pages. https://doi.org/10.1145/3341695
Google Scholar
Digital Library
- M.C. Browne, E.M. Clarke, and O. Grümberg. 1988. Characterizing finite Kripke structures in propositional temporal logic. Theoretical Computer Science, 59, 1 (1988), 115–131. issn:0304-3975 https://doi.org/10.1016/0304-3975(88)90098-9
Google Scholar
Digital Library
- Peter Canning, William Cook, Walter Hill, Walter Olthoff, and John C. Mitchell. 1989. F-Bounded Polymorphism for Object-Oriented Programming. In Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture (FPCA ’89). Association for Computing Machinery, New York, NY, USA. 273–280. isbn:0897913280 https://doi.org/10.1145/99370.99392
Google Scholar
Digital Library
- Jose Castanos, David Edelsohn, Kazuaki Ishizaki, Priya Nagpurkar, Toshio Nakatani, Takeshi Ogasawara, and Peng Wu. 2012. On the Benefits and Pitfalls of Extending a Statically Typed Language JIT Compiler for Dynamic Scripting Languages. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA ’12). Association for Computing Machinery, New York, NY, USA. 195–212. isbn:9781450315616 https://doi.org/10.1145/2384616.2384631
Google Scholar
Digital Library
- Clement Rey. 2018. go-internals. https://github.com/teh-cmc/go-internals/blob/master/chapter2_interfaces/README.md#anatomy-of-an-interface (Accessed on 04/15/2022).
Google Scholar
- Karl Crary, Stephanie Weirich, and Greg Morrisett. 1998. Intensional Polymorphism in Type-Erasure Semantics. SIGPLAN Not., 34, 1 (1998), sep, 301–312. issn:0362-1340 https://doi.org/10.1145/291251.289459
Google Scholar
Digital Library
- Docker. 2021. Docker - Build, Ship, and Run Any App, Anywhere. https://www.docker.com/ (Accessed on 04/15/2022).
Google Scholar
- Karel Driesen and Urs Hölzle. 1996. The Direct Cost of Virtual Function Calls in C++. In Proceedings of the 11th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’96). Association for Computing Machinery, New York, NY, USA. 306–323. isbn:089791788X https://doi.org/10.1145/236337.236369
Google Scholar
Digital Library
- Stephen Ellis, Shuofei Zhu, Nobuko Yoshida, and Linhai Song. 2022. Artifact of "Generic Go to Go: Dictionary-Passing, Monomorphisation, and Hybrid". https://doi.org/10.5281/zenodo.7067362
Google Scholar
Digital Library
- Stephen Ellis, Shuofei Zhu, Nobuko Yoshida, and Linhai Song. 2022. fgg2go. https://github.com/sfzhu93/fgg2go
Google Scholar
- Stephen Ellis, Shuofei Zhu, Nobuko Yoshida, and Linhai Song. 2022. fgg2go. https://archive.softwareheritage.org/browse/origin/directory/?origin_url=https://github.com/sfzhu93/fgg2go
Google Scholar
- Stephen Ellis, Shuofei Zhu, Nobuko Yoshida, and Linhai Song. 2022. Generic Go to Go: Dictionary-Passing, Monomorphisation, and Hybrid. https://doi.org/10.48550/ARXIV.2208.06810
Google Scholar
- Free Software Foundation. 2021. objdump(1) - Linux manual page. https://man7.org/linux/man-pages/man1/objdump.1.html (Accessed on 04/15/2022).
Google Scholar
- Andreas Gal, Brendan Eich, Mike Shaver, David Anderson, David Mandelin, Mohammad R. Haghighat, Blake Kaplan, Graydon Hoare, Boris Zbarsky, Jason Orendorff, Jesse Ruderman, Edwin W. Smith, Rick Reitmaier, Michael Bebenita, Mason Chang, and Michael Franz. 2009. Trace-Based Just-in-Time Type Specialization for Dynamic Languages. SIGPLAN Not., 44, 6 (2009), jun, 465–478. issn:0362-1340 https://doi.org/10.1145/1543135.1542528
Google Scholar
Digital Library
- gitchander. 2021. Permutation. https://github.com/gitchander/permutation (Accessed on 04/15/2022).
Google Scholar
- Robert Griesemer, Raymond Hu, Wen Kokke, Julien Lange, Ian Lance Taylor, Bernardo Toninho, Philip Wadler, and Nobuko Yoshida. 2020. Featherweight Go. Proc. ACM Program. Lang., 4, OOPSLA (2020), Article 149, nov, 29 pages. https://doi.org/10.1145/3428217
Google Scholar
Digital Library
- gRPC. 2021. A high performance, open-source universal RPC framework. https://github.com/grpc/grpc-go
Google Scholar
- Raymond Hu. 2021. Mini prototype of FG/FGG/FGR in Go. https://github.com/rhu1/fgg
Google Scholar
- Chung-Kil Hur, Georg Neis, Derek Dreyer, and Viktor Vafeiadis. 2014. A logical step forward in parametric bisimulations. Technical Report MPI-SWS-2014-003, MPI-SWS.
Google Scholar
- Atshushi Igarashi, Benjamin Pierce, and Philip Wadler. 1999. Featherweight Java: A Minimal Core Calculus for Java and GJ. In Proceedings of the 14th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’99). Association for Computing Machinery, New York, NY, USA. 132–146. isbn:1581132387 https://doi.org/10.1145/320384.320395
Google Scholar
Digital Library
- Cliff B. Jones. 1993. Constraining Inference in an Object-Based Design Model. In Proceedings of the International Joint Conference CAAP/FASE on Theory and Practice of Software Development (TAPSOFT ’93). Springer-Verlag, Berlin, Heidelberg. 136–150. isbn:3540566104 https://doi.org/10.1007/3-540-56610-4_61
Google Scholar
Cross Ref
- Mark P. Jones. 1995. Dictionary-Free Overloading by Partial Evaluation. Lisp Symb. Comput., 8, 3 (1995), sep, 229–248. issn:0892-4635 https://doi.org/10.1007/BF01019005
Google Scholar
Digital Library
- Andrew Kennedy and Don Syme. 2001. Design and Implementation of Generics for the .NET Common Language Runtime. In Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation (PLDI ’01). Association for Computing Machinery, New York, NY, USA. 1–12. isbn:1581134142 https://doi.org/10.1145/378795.378797
Google Scholar
Digital Library
- Kubernetes. 2021. Production-Grade Container Orchestration. https://kubernetes.io/ (Accessed on 04/15/2022).
Google Scholar
- Xavier Leroy. 2009. A Formally Verified Compiler Back-end. Journal of Automated Reasoning, 43, 4 (2009), Nov., 363. issn:1573-0670 https://doi.org/10.1007/s10817-009-9155-4
Google Scholar
Digital Library
- Alice Merrick. 2020. Go Developer Survey 2020 Results. https://blog.golang.org/survey2020-results (Accessed on 04/15/2022).
Google Scholar
- Robin Milner and Davide Sangiorgi. 1992. Barbed Bisimulation. In 19th ICALP, W. Kuich (Ed.) (LNCS, Vol. 623). Springer, 685–695. https://doi.org/10.1007/3-540-55719-9_114
Google Scholar
Cross Ref
- Martin Odersky, Enno Runne, and Philip Wadler. 2000. Two ways to bake your pizza—translating parameterised types into Java. In Generic Programming. Springer, 114–132. https://doi.org/10.1007/3-540-39953-4_10
Google Scholar
Cross Ref
- Martin Odersky and Philip Wadler. 1997. Pizza into Java: Translating Theory into Practice. In POPL ’97. ACM Press, 146–159. isbn:0-89791-853-3 https://doi.org/10.1145/263699.263715
Google Scholar
Digital Library
- Keith Randall. 2020. Generics implementation - Dictionaries. https://go.googlesource.com/proposal/+/refs/heads/master/design/generics-implementation-dictionaries.md (Accessed on 04/15/2022).
Google Scholar
- Keith Randall. 2020. Generics implementation - GC Shape Stenciling. https://go.googlesource.com/proposal/+/refs/heads/master/design/generics-implementation-gcshape.md (Accessed on 04/15/2022).
Google Scholar
- Keith Randall. 2020. Generics implementation - Stenciling. https://go.googlesource.com/proposal/+/refs/heads/master/design/generics-implementation-stenciling.md (Accessed on 04/15/2022).
Google Scholar
- Keith Randall. 2022. Go 1.18 Implementation of Generics via Dictionaries and Gcshape Stenciling. https://github.com/golang/proposal/blob/e9af402b19db4352e7831b33a3f47719e86a5267/design/generics-implementation-dictionaries-go1.18.md (Accessed on 04/15/2022).
Google Scholar
- Russ Cox. 2009. Go Data Structures: Interfaces. https://research.swtch.com/interfaces
Google Scholar
- Michael Salib. 2004. Starkiller: A static type inferencer and compiler for Python. Ph.D. Dissertation. Massachusetts Institute of Technology.
Google Scholar
- Jose H. Solorzano and Suad Alagić. 1998. Parametric Polymorphism for Java: A Reflective Solution. In Proceedings of the 13th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’98). Association for Computing Machinery, New York, NY, USA. 216–225. isbn:1581130058 https://doi.org/10.1145/286936.286959
Google Scholar
Digital Library
- IEEE Spectrum. 2022. Top Programming Languages - IEEE Spectrum. https://spectrum.ieee.org/top-programming-languages/ (Accessed on 04/15/2022).
Google Scholar
- Stack Overflow. 2021. 2021 Developer Survey. https://insights.stackoverflow.com/survey/2021 (Accessed on 04/15/2022).
Google Scholar
- Bjarne Stroustrup. 1997. The C++ Programming Language (3^ rd ed.). Addison Wesley.
Google Scholar
- Martin Sulzmann and Stefan Wehr. 2021. A Dictionary-Passing Translation of Featherweight Go. In Programming Languages and Systems: 19th Asian Symposium, APLAS 2021, Chicago, IL, USA, October 17–18, 2021, Proceedings. Springer-Verlag, Berlin, Heidelberg. 102–120. isbn:978-3-030-89050-6 https://doi.org/10.1007/978-3-030-89051-3_7
Google Scholar
Digital Library
- The Go Team. 2021. The Go Programming Language Specification - The Go Programming Language. https://https://golang.org/ref/spec#Function_types (Accessed on 04/15/2022).
Google Scholar
- The Go Team. 2021. The go2go playground. https://go2goplay.golang.org/ (Accessed on 04/15/2022).
Google Scholar
- The Go Team. 2022. Go 1.18 Release Notes. https://tip.golang.org/doc/go1.18 (Accessed on 04/15/2022).
Google Scholar
- Vlad Ureche, Cristian Talau, and Martin Odersky. 2013. Miniboxing: improving the speed to code size tradeoff in parametric polymorphism translations. In Proceedings of the 2013 ACM SIGPLAN international conference on Object oriented programming systems languages & applications. 73–92. https://doi.org/10.1145/2509136.2509537
Google Scholar
Digital Library
- Mirko Viroli and Antonio Natali. 2000. Parametric Polymorphism in Java: An Approach to Translation Based on Reflective Features. In Proceedings of the 15th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’00). Association for Computing Machinery, New York, NY, USA. 146–165. isbn:158113200X https://doi.org/10.1145/353171.353182
Google Scholar
Digital Library
- Dachuan Yu. 2004. Safety Verification of Low-Level Code. Ph.D. Dissertation.
Google Scholar
- Dachuan Yu, Andrew Kennedy, and Don Syme. 2004. Formalization of Generics for the .NET Common Language Runtime. In Proceedings of the 31st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’04). Association for Computing Machinery, New York, NY, USA. 39–51. isbn:158113729X https://doi.org/10.1145/964001.964005
Google Scholar
Digital Library
Index Terms
Generic go to go: dictionary-passing, monomorphisation, and hybrid
Recommendations
Converting java programs to use generic libraries
OOPSLA '04: Proceedings of the 19th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applicationsJava 1.5 will include a type system (called JSR-14) that supports <i>parametric polymorphism</i>, or <i>generic</i> classes. This will bring many benefits to Java programmers, not least because current Java practice makes heavy use of logically-generic ...
A Dictionary-Passing Translation of Featherweight Go
Programming Languages and SystemsAbstractThe Go programming language is an increasingly popular language but some of its features lack a formal investigation. This article explains Go’s resolution mechanism for overloaded methods and its support for structural subtyping by means of ...
Converting java programs to use generic libraries
OOPSLA '04Java 1.5 will include a type system (called JSR-14) that supports <i>parametric polymorphism</i>, or <i>generic</i> classes. This will bring many benefits to Java programmers, not least because current Java practice makes heavy use of logically-generic ...






Comments