Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3694848.3694857acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

Unboxing Virgil ADTs for Fun and Profit

Published: 22 October 2024 Publication History

Abstract

Algebraic Data Types (ADTs) are an increasingly common feature in modern programming languages. In many implementations, values of non-nullary, multi-case ADTs are allocated on the heap, which may reduce performance and increase memory usage. This work explores annotation-guided optimizations to ADT representation in Virgil, a systems-level programming language that compiles to x86, x86-64, WebAssembly and the Java Virtual Machine. We extend Virgil with annotations: #unboxed to eliminate the overhead of heap allocation via automatic compiler transformation to a scalar representation, and #packed, to enable programmer-expressed bit-layouts. These annotations allow programmers to both save memory and manipulate data in formats dictated by hardware. We dedicate this work as an homage and echo of work done in collaboration with Jens in the work entitled "A Declarative Approach to Generating Machine Code Tools", an unpublished manuscript from 2005. In fact, this work inherits some syntactic conventions from that prior work. The performance impact of these representation changes was evaluated on a variety of workloads in terms of execution time and memory usage, but we don't include all of that because Jens like semantics and type systems better!

References

[1]
[n. d.]. Documentation - The Zig Programming Language. https://ziglang.org/documentation/master/##packed-struct
[2]
2023. Layouts. https://github.com/titzer/virgil/blob/master/doc/tutorial/Layouts.md
[3]
(Apple). [n. d.]. Type Layout. https://github.com/apple/swift/blob/main/docs/ABI/TypeLayout.rst
[4]
Noah Lev Bartell-Mangel. 2022. Filling a Niche: Using Spare Bits to Optimize Data Representations.
[5]
Thaïs Baudon, Gabriel Radanne, and Laure Gonnord. 2023. Bit-Stealing Made Legal: Compilation for Custom Memory Representations of Algebraic Data Types. Proc. ACM Program. Lang., 7, ICFP (2023), Article 216, aug, 34 pages. https://doi.org/10.1145/3607858
[6]
Nicolas Chataing, Stephen Dolan, Gabriel Scherer, and Jeremy Yallop. 2023. Unboxed data constructors – or, how cpp decides a halting problem. arxiv:2311.07369.
[7]
Nicolas Chataing, Stephen Dolan, Gabriel Scherer, and Jeremy Yallop. 2024. Unboxed Data Constructors: Or, How cpp Decides a Halting Problem. Proc. ACM Program. Lang., 8, POPL (2024), Article 51, jan, 31 pages. https://doi.org/10.1145/3632893
[8]
Richard Eisenberg. 2022. Unboxed Types. https://github.com/goldfirere/ocaml-rfcs/blob/unboxed-types/rfcs/unboxed-types.md
[9]
Cordelia Hall, Simon L. Peyton Jones, and Patrick M. Sansom. 1995. Unboxing using Specialisation. In Functional Programming, Glasgow 1994, Kevin Hammond, David N. Turner, and Patrick M. Sansom (Eds.). Springer London, London. 96–110. isbn:978-1-4471-3573-9
[10]
Hejsil. [n. d.]. More control over the data layout of tagged unions. https://github.com/ziglang/zig/issues/1922
[11]
(Microsoft). [n. d.]. StructLayoutAttribute. https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.structlayoutattribute?view=net-8.0
[12]
Liam O’Connor, Zilin Chen, Partha Susarla, Christine Rizkallah, Gerwin Klein, and Gabriele Keller. 2018. Bringing Effortless Refinement of Data Layouts to Cogent. In Leveraging Applications of Formal Methods, Verification and Validation. Modeling: 8th International Symposium, ISoLA 2018, Limassol, Cyprus, November 5-9, 2018, Proceedings, Part I. Springer-Verlag, Berlin, Heidelberg. 134–149. isbn:978-3-030-03417-7 https://doi.org/10.1007/978-3-030-03418-4_9
[13]
the8472. [n. d.]. Improve niche placement by trying two strategies and picking the better result. https://github.com/rust-lang/rust/pull/108106
[14]
Ben L. Titzer. 2006. Virgil: objects on the head of a pin. In Proceedings of the 21st Annual ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages, and Applications (OOPSLA ’06). Association for Computing Machinery, New York, NY, USA. 191–208. isbn:1595933484 https://doi.org/10.1145/1167473.1167489
[15]
Ben L. Titzer. 2013. Harmonizing classes, functions, tuples, and type parameters in Virgil III. SIGPLAN Not., 48, 6 (2013), Jun, 85–94. issn:0362-1340 https://doi.org/10.1145/2499370.2491962
[16]
Ben L. Titzer, Jonathan K. Lee, and Jens Palsberg. 2006. A Declarative Approach to Generating Machine Code Tools. http://web.cs.ucla.edu/~palsberg/draft/TitzerLeePalsberg06.pdf
[17]
Mingzhe Wang, Jie Liang, Chijin Zhou, Zhiyong Wu, Xinyi Xu, and Yu Jiang. 2022. Odin: On-Demand Instrumentation with on-the-Fly Recompilation. In Proceedings of the 43rd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI 2022). Association for Computing Machinery, New York, NY, USA. 1010–1024. isbn:9781450392655 https://doi.org/10.1145/3519939.3523428
[18]
Stephen Weeks. 2006. Whole-Program Compilation in MLton. In Proceedings of the 2006 Workshop on ML (ML ’06). Association for Computing Machinery, New York, NY, USA. 1. isbn:1595934839 https://doi.org/10.1145/1159876.1159877

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
JENSFEST '24: Proceedings of the Workshop Dedicated to Jens Palsberg on the Occasion of His 60th Birthday
October 2024
58 pages
ISBN:9798400712579
DOI:10.1145/3694848
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for third-party components of this work must be honored. For all other uses, contact the owner/author(s).

Sponsors

In-Cooperation

  • SIGAda: SIGAda

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 22 October 2024

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. ADTs
  2. Virgil
  3. data layout
  4. monormophization
  5. unboxing

Qualifiers

  • Research-article

Funding Sources

  • National Science Foundation

Conference

JENSFEST '24
Sponsor:

Upcoming Conference

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 37
    Total Downloads
  • Downloads (Last 12 months)37
  • Downloads (Last 6 weeks)5
Reflects downloads up to 09 Jan 2025

Other Metrics

Citations

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media