skip to main content

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

Published:31 October 2022Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle Scholar
  3. Christal Baier and Joost P. Katoen. 2008. Principles of Model Checking. MIT Press, United States. isbn:978-0-262-02649-9 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. Docker. 2021. Docker - Build, Ship, and Run Any App, Anywhere. https://www.docker.com/ (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. Stephen Ellis, Shuofei Zhu, Nobuko Yoshida, and Linhai Song. 2022. fgg2go. https://github.com/sfzhu93/fgg2go Google ScholarGoogle Scholar
  14. 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 ScholarGoogle Scholar
  15. 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 ScholarGoogle Scholar
  16. 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 ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. gitchander. 2021. Permutation. https://github.com/gitchander/permutation (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. gRPC. 2021. A high performance, open-source universal RPC framework. https://github.com/grpc/grpc-go Google ScholarGoogle Scholar
  21. Raymond Hu. 2021. Mini prototype of FG/FGG/FGR in Go. https://github.com/rhu1/fgg Google ScholarGoogle Scholar
  22. 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 ScholarGoogle Scholar
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle ScholarCross RefCross Ref
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. Kubernetes. 2021. Production-Grade Container Orchestration. https://kubernetes.io/ (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  29. Alice Merrick. 2020. Go Developer Survey 2020 Results. https://blog.golang.org/survey2020-results (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  30. 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 ScholarGoogle ScholarCross RefCross Ref
  31. 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 ScholarGoogle ScholarCross RefCross Ref
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. 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 ScholarGoogle Scholar
  34. 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 ScholarGoogle Scholar
  35. 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 ScholarGoogle Scholar
  36. 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 ScholarGoogle Scholar
  37. Russ Cox. 2009. Go Data Structures: Interfaces. https://research.swtch.com/interfaces Google ScholarGoogle Scholar
  38. Michael Salib. 2004. Starkiller: A static type inferencer and compiler for Python. Ph.D. Dissertation. Massachusetts Institute of Technology. Google ScholarGoogle Scholar
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. IEEE Spectrum. 2022. Top Programming Languages - IEEE Spectrum. https://spectrum.ieee.org/top-programming-languages/ (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  41. Stack Overflow. 2021. 2021 Developer Survey. https://insights.stackoverflow.com/survey/2021 (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  42. Bjarne Stroustrup. 1997. The C++ Programming Language (3^ rd ed.). Addison Wesley. Google ScholarGoogle Scholar
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. 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 ScholarGoogle Scholar
  45. The Go Team. 2021. The go2go playground. https://go2goplay.golang.org/ (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  46. The Go Team. 2022. Go 1.18 Release Notes. https://tip.golang.org/doc/go1.18 (Accessed on 04/15/2022). Google ScholarGoogle Scholar
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  49. Dachuan Yu. 2004. Safety Verification of Low-Level Code. Ph.D. Dissertation. Google ScholarGoogle Scholar
  50. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Generic go to go: dictionary-passing, monomorphisation, and hybrid

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Article Metrics

          • Downloads (Last 12 months)229
          • Downloads (Last 6 weeks)23

          Other Metrics

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!