skip to main content

Precise inference of expressive units of measurement types

Published:13 November 2020Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

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.Google ScholarGoogle Scholar
  2. Oscar Bennich-Björkman and Steve McKeever. 2018. The next 700 unit of measurement checkers. In Software Language Engineering (SLE). 121-132.Google ScholarGoogle Scholar
  3. Tom Benson. 2014. Reynolds Number. https://www.grc.nasa.gov/WWW/BGH/reynolds.htmlGoogle ScholarGoogle Scholar
  4. Mars Climate Orbiter Mishap Investigation Board. 1999. Mars climate orbiter mishap investigation board: Phase I report. Jet Propulsion Laboratory.Google ScholarGoogle Scholar
  5. Gilad Bracha. 2004. Pluggable type systems. In OOPSLA workshop on revival of dynamic languages, Vol. 4.Google ScholarGoogle Scholar
  6. Travis Carlson and Eric Van Wyk. 2017. Type qualifiers as composable language extensions. In Generative Programming: Concepts & Experiences (GPCE). ACM, 91-103.Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarCross RefCross Ref
  8. The Coq Development Team. 2004. The Coq Proof Assistant. https://coq.inria.frGoogle ScholarGoogle Scholar
  9. Daikon. 2003. Fix bug that printed milliseconds, not seconds. https://github.com/codespecs/daikon/commit/ a421b229bbed7da94bd3636c0eb03b716d151d5dGoogle ScholarGoogle Scholar
  10. Daikon. 2004. Multiply dkconfig_compile_timeout by 1000 to convert from seconds to milliseconds. https://github.com/ codespecs/daikon/commit/1c74cbe4e1fe74d2ef2fc30c577482786d0aca5cGoogle ScholarGoogle Scholar
  11. Jean-Marie Dautelle and Werner Keil. 2010. JSR 275: Units Specification API. https://jcp.org/en/jsr/detail?id= 275Google ScholarGoogle Scholar
  12. Jean-Marie Dautelle, Werner Keil, and Leonardo Lima. 2016. JSR 363: Units of Measurement API. https://jcp.org/en/jsr/ detail?id= 363Google ScholarGoogle Scholar
  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.Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Werner Dietl, Sophia Drossopoulou, and Peter Müller. 2007. Generic Universe Types. In European Conference on ObjectOriented Programming (ECOOP). Springer, 28-53.Google ScholarGoogle Scholar
  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.Google ScholarGoogle Scholar
  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= 308Google ScholarGoogle Scholar
  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.Google ScholarGoogle Scholar
  19. Narain H. Gehani. 1977. Units of measure as a data attribute. Computer Languages 2, 3 ( 1977 ), 93-111.Google ScholarGoogle Scholar
  20. Narain H. Gehani. 1985. Ada's derived types and units of measure. Software: Practice and Experience 15, 6 ( 1985 ), 555-569.Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  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.Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Wesley Johnston. 2012. Close by swipe velocity checks are wrong. https://bugzilla.mozilla.org/show_bug. cgi?id=765069Google ScholarGoogle Scholar
  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.Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Andrew Kennedy. 2009. Types for units-of-measure: Theory and practice. In Central European Functional Programming School. Springer, 268-305.Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Andrew J Kennedy. 1997. Relational parametricity and units of measure. In Principles of Programming Languages (POPL). ACM, 442-455.Google ScholarGoogle Scholar
  29. Sebastian Krings and Michael Leuschel. 2013. Inferring physical units in B models. In Software Engineering and Formal Methods (SEFM). Springer, 137-151.Google ScholarGoogle Scholar
  30. Andreas Gullberg Larsen. 2018. Units.NET. https://github.com/angularsen/UnitsNetGoogle ScholarGoogle Scholar
  31. Jens Melzer. 2015. Autoboxing Performance. https://efective-java.com/ 2015 /01/autoboxing-performanceGoogle ScholarGoogle Scholar
  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.Google ScholarGoogle Scholar
  33. Sam Owre, Indranil Saha, and Natarajan Shankar. 2012. Automatic dimensional analysis of cyber-physical systems. In Formal Methods. Springer, 356-371.Google ScholarGoogle Scholar
  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.Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Matthias C. Schabel and Steven Watanabe. 2010. Boost.Units. http://www.boost.org/doc/libs/1_65_1/doc/html/boost_units. htmlGoogle ScholarGoogle Scholar
  36. Scott Wlaschin. 2012. Units of measure-Type safety for numerics. https://fsharpforfunandprofit.com/posts/units-of-measureGoogle ScholarGoogle Scholar
  37. Andrew K Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Information and Computation 115, 1 ( 1994 ), 38-94.Google ScholarGoogle Scholar

Index Terms

  1. Precise inference of expressive units of measurement types

              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

              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!