Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Precise inference of expressive units of measurement types

Published: 13 November 2020 Publication History

Abstract

Ensuring computations are unit-wise consistent is an important task in software development. Numeric computations are usually performed with primitive types instead of abstract data types, which results in very weak static guarantees about correct usage and conversion of units. This paper presents PUnits, a pluggable type system for expressive units of measurement types and a precise, whole-program inference approach for these types. PUnits can be used in three modes: (1) modularly check the correctness of a program, (2) ensure a possible unit typing exists, and (3) annotate a program with units. Annotation mode allows human inspection and is essential since having a valid typing does not guarantee that the inferred specification expresses design intent. PUnits is the first units type system with this capability. Compared to prior work, PUnits strikes a novel balance between expressiveness, inference complexity, and annotation effort. We implement PUnits for Java and evaluate it by specifying the correct usage of frequently used JDK methods. We analyze 234k lines of code from eight open-source scientific computing projects with PUnits. We compare PUnits against an encapsulation-based units API (the javax.measure package) and discovered unit errors that the API failed to find. PUnits infers 90 scientific units for five of the projects and generates well-specified applications. The experiments show that PUnits is an effective, sound, and scalable alternative to using encapsulation-based units APIs, enabling Java developers to reap the performance benefits of using primitive types instead of abstract data types for unit-wise consistent scientific computations.

Supplementary Material

Auxiliary Archive (oopsla20main-p67-p-archive.zip)
Appendix
Auxiliary Presentation Video (oopsla20main-p67-p-video.mp4)
This is a presentation video of my talk at OOPSLA 2020 on our paper. It presents PUnits, a pluggable type system for expressive units of measurement types and a precise, whole-program inference approach for these types. PUnits can be used in three modes: (1) modularly check the correctness of a program, (2) ensure a possible unit typing exists, and (3) annotate a program with units. Annotation mode allows human inspection and is essential since having a valid typing does not guarantee that the inferred specification expresses design intent. We implement PUnits for Java. The experiments show that PUnits is an effective, sound, and scalable alternative to using encapsulation-based units APIs, enabling Java developers to reap the performance benefits of using primitive types instead of abstract data types for unit-wise consistent scientific computations.

References

[1]
Eric Allen, David Chase, Victor Luchangco, Jan-Willem Maessen, and Guy L Steele Jr. 2004. Object-oriented units of measurement. Object-Oriented Programming, Systems, Languages & Applications (OOPSLA) 39, 10 ( 2004 ), 384-403.
[2]
Oscar Bennich-Björkman and Steve McKeever. 2018. The next 700 unit of measurement checkers. In Software Language Engineering (SLE). 121-132.
[3]
Tom Benson. 2014. Reynolds Number. https://www.grc.nasa.gov/WWW/BGH/reynolds.html
[4]
Mars Climate Orbiter Mishap Investigation Board. 1999. Mars climate orbiter mishap investigation board: Phase I report. Jet Propulsion Laboratory.
[5]
Gilad Bracha. 2004. Pluggable type systems. In OOPSLA workshop on revival of dynamic languages, Vol. 4.
[6]
Travis Carlson and Eric Van Wyk. 2017. Type qualifiers as composable language extensions. In Generative Programming: Concepts & Experiences (GPCE). ACM, 91-103.
[7]
Charles Zhuo Chen and Werner Dietl. 2018. Don't Miss the End: Preventing Unsafe End-of-File Comparisons. In NASA Formal Methods Symposium. Springer, 87-94.
[8]
The Coq Development Team. 2004. The Coq Proof Assistant. https://coq.inria.fr
[9]
Daikon. 2003. Fix bug that printed milliseconds, not seconds. https://github.com/codespecs/daikon/commit/ a421b229bbed7da94bd3636c0eb03b716d151d5d
[10]
Daikon. 2004. Multiply dkconfig_compile_timeout by 1000 to convert from seconds to milliseconds. https://github.com/ codespecs/daikon/commit/1c74cbe4e1fe74d2ef2fc30c577482786d0aca5c
[11]
Jean-Marie Dautelle and Werner Keil. 2010. JSR 275: Units Specification API. https://jcp.org/en/jsr/detail?id= 275
[12]
Jean-Marie Dautelle, Werner Keil, and Leonardo Lima. 2016. JSR 363: Units of Measurement API. https://jcp.org/en/jsr/ detail?id= 363
[13]
Leonardo De Moura and Nikolaj Bjørner. 2008. Z3: An eficient SMT solver. In Tools and Algorithms for the Construction and Analysis of Systems (TACAS). Springer, 337-340.
[14]
Werner Dietl, Stephanie Dietzel, Michael D Ernst, Kivanç Muşlu, and Todd W Schiller. 2011a. Building and using pluggable type-checkers. In International Conference on Software Engineering (ICSE). ACM, 681-690.
[15]
Werner Dietl, Sophia Drossopoulou, and Peter Müller. 2007. Generic Universe Types. In European Conference on ObjectOriented Programming (ECOOP). Springer, 28-53.
[16]
Werner Dietl, Michael D Ernst, and Peter Müller. 2011b. Tunable Static Inference for Generic Universe Types. In European Conference on Object-Oriented Programming (ECOOP). Springer, 333-357.
[17]
Michael D Ernst, Alex Buckley, Werner Dietl, Doug Lea, Srikanth Sankaran, and Oracle. 2012. JSR 308: Annotations on Java Types. https://jcp.org/en/jsr/detail?id= 308
[18]
Michael D Ernst, Jef H Perkins, Philip J Guo, Stephen McCamant, Carlos Pacheco, Matthew S Tschantz, and Chen Xiao. 2007. The Daikon system for dynamic detection of likely invariants. Science of computer programming 69, 1-3 ( 2007 ), 35-45.
[19]
Narain H. Gehani. 1977. Units of measure as a data attribute. Computer Languages 2, 3 ( 1977 ), 93-111.
[20]
Narain H. Gehani. 1985. Ada's derived types and units of measure. Software: Practice and Experience 15, 6 ( 1985 ), 555-569.
[21]
Sudheendra Hangal and Monica S Lam. 2009. Automatic dimension inference and checking for object-oriented programs. In International Conference on Software Engineering (ICSE). IEEE Computer Society, 155-165.
[22]
Mark Hills, Feng Chen, and Grigore Roşu. 2012. A rewriting logic approach to static checking of units of measurement in C. Electronic Notes in Theoretical Computer Science 290 ( 2012 ), 51-67.
[23]
Lingxiao Jiang and Zhendong Su. 2006. Osprey: a practical type system for validating dimensional unit correctness of C programs. In International Conference on Software Engineering (ICSE). ACM, 262-271.
[24]
Wesley Johnston. 2012. Close by swipe velocity checks are wrong. https://bugzilla.mozilla.org/show_bug. cgi?id=765069
[25]
Nahid Juma, Werner Dietl, and Mahesh Tripunitara. 2020. A computational complexity analysis of tunable type inference for Generic Universe Types. Theoretical Computer Science 814 ( 2020 ), 189-209.
[26]
Ted Kaminski, Lucas Kramer, Travis Carlson, and Eric Van Wyk. 2017. Reliable and automatic composition of language extensions to C: the ableC extensible language framework. Proceedings of the ACM on Programming Languages 1, OOPSLA ( 2017 ), 98.
[27]
Andrew Kennedy. 2009. Types for units-of-measure: Theory and practice. In Central European Functional Programming School. Springer, 268-305.
[28]
Andrew J Kennedy. 1997. Relational parametricity and units of measure. In Principles of Programming Languages (POPL). ACM, 442-455.
[29]
Sebastian Krings and Michael Leuschel. 2013. Inferring physical units in B models. In Software Engineering and Formal Methods (SEFM). Springer, 137-151.
[30]
Andreas Gullberg Larsen. 2018. Units.NET. https://github.com/angularsen/UnitsNet
[31]
Jens Melzer. 2015. Autoboxing Performance. https://efective-java.com/ 2015 /01/autoboxing-performance
[32]
Dominic Orchard, Andrew Rice, and Oleg Oshmyan. 2015. Evolving Fortran types with inferred units-of-measure. Journal of Computational Science 9 ( 2015 ), 156-162.
[33]
Sam Owre, Indranil Saha, and Natarajan Shankar. 2012. Automatic dimensional analysis of cyber-physical systems. In Formal Methods. Springer, 356-371.
[34]
Matthew M Papi, Mahmood Ali, Telmo Luis Correa Jr, Jef H Perkins, and Michael D Ernst. 2008. Practical pluggable types for Java. In International Symposium on Software Testing and Analysis (ISSTA). ACM, 201-212.
[35]
Matthias C. Schabel and Steven Watanabe. 2010. Boost.Units. http://www.boost.org/doc/libs/1_65_1/doc/html/boost_units. html
[36]
Scott Wlaschin. 2012. Units of measure-Type safety for numerics. https://fsharpforfunandprofit.com/posts/units-of-measure
[37]
Andrew K Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Information and Computation 115, 1 ( 1994 ), 38-94.

Cited By

View all
  • (2024)OppropBERL: A GNN and BERT-Style Reinforcement Learning-Based Type Inference2024 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER)10.1109/SANER60148.2024.00021(131-136)Online publication date: 12-Mar-2024
  • (2023)Managing Quantities and Units of Measurement in Code BasesUpdates on Software Usability10.5772/intechopen.108014Online publication date: 22-Feb-2023
  • (2023)Practical Inference of Nullability TypesProceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering10.1145/3611643.3616326(1395-1406)Online publication date: 30-Nov-2023
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 4, Issue OOPSLA
November 2020
3108 pages
EISSN:2475-1421
DOI:10.1145/3436718
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 13 November 2020
Published in PACMPL Volume 4, Issue OOPSLA

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Dimensional analysis
  2. Pluggable type system
  3. Scientific computing
  4. Type inference
  5. Units of measurements

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)195
  • Downloads (Last 6 weeks)31
Reflects downloads up to 03 Oct 2024

Other Metrics

Citations

Cited By

View all
  • (2024)OppropBERL: A GNN and BERT-Style Reinforcement Learning-Based Type Inference2024 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER)10.1109/SANER60148.2024.00021(131-136)Online publication date: 12-Mar-2024
  • (2023)Managing Quantities and Units of Measurement in Code BasesUpdates on Software Usability10.5772/intechopen.108014Online publication date: 22-Feb-2023
  • (2023)Practical Inference of Nullability TypesProceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering10.1145/3611643.3616326(1395-1406)Online publication date: 30-Nov-2023
  • (2023)Pluggable Type Inference for Free2023 38th IEEE/ACM International Conference on Automated Software Engineering (ASE)10.1109/ASE56229.2023.00186(1542-1554)Online publication date: 11-Sep-2023
  • (2023)Acknowledging Implementation Trade-Offs When Developing with Units of MeasurementModel-Driven Engineering and Software Development10.1007/978-3-031-38821-7_2(25-47)Online publication date: 4-Aug-2023
  • (2023)Towards a Theory of Conversion Relations for Prefixed Units of MeasureRelational and Algebraic Methods in Computer Science10.1007/978-3-031-28083-2_16(258-273)Online publication date: 3-Apr-2023
  • (2021)Scalability and precision by combining expressive type systems and deductive verificationProceedings of the ACM on Programming Languages10.1145/34855205:OOPSLA(1-29)Online publication date: 15-Oct-2021

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media