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.
Supplemental Material
Available for Download
Appendix
- 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 Scholar
- Oscar Bennich-Björkman and Steve McKeever. 2018. The next 700 unit of measurement checkers. In Software Language Engineering (SLE). 121-132.Google Scholar
- Tom Benson. 2014. Reynolds Number. https://www.grc.nasa.gov/WWW/BGH/reynolds.htmlGoogle Scholar
- Mars Climate Orbiter Mishap Investigation Board. 1999. Mars climate orbiter mishap investigation board: Phase I report. Jet Propulsion Laboratory.Google Scholar
- Gilad Bracha. 2004. Pluggable type systems. In OOPSLA workshop on revival of dynamic languages, Vol. 4.Google Scholar
- Travis Carlson and Eric Van Wyk. 2017. Type qualifiers as composable language extensions. In Generative Programming: Concepts & Experiences (GPCE). ACM, 91-103.Google Scholar
- 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 Scholar
Cross Ref
- The Coq Development Team. 2004. The Coq Proof Assistant. https://coq.inria.frGoogle Scholar
- Daikon. 2003. Fix bug that printed milliseconds, not seconds. https://github.com/codespecs/daikon/commit/ a421b229bbed7da94bd3636c0eb03b716d151d5dGoogle Scholar
- Daikon. 2004. Multiply dkconfig_compile_timeout by 1000 to convert from seconds to milliseconds. https://github.com/ codespecs/daikon/commit/1c74cbe4e1fe74d2ef2fc30c577482786d0aca5cGoogle Scholar
- Jean-Marie Dautelle and Werner Keil. 2010. JSR 275: Units Specification API. https://jcp.org/en/jsr/detail?id= 275Google Scholar
- Jean-Marie Dautelle, Werner Keil, and Leonardo Lima. 2016. JSR 363: Units of Measurement API. https://jcp.org/en/jsr/ detail?id= 363Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Werner Dietl, Sophia Drossopoulou, and Peter Müller. 2007. Generic Universe Types. In European Conference on ObjectOriented Programming (ECOOP). Springer, 28-53.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- Narain H. Gehani. 1977. Units of measure as a data attribute. Computer Languages 2, 3 ( 1977 ), 93-111.Google Scholar
- Narain H. Gehani. 1985. Ada's derived types and units of measure. Software: Practice and Experience 15, 6 ( 1985 ), 555-569.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- Wesley Johnston. 2012. Close by swipe velocity checks are wrong. https://bugzilla.mozilla.org/show_bug. cgi?id=765069Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Andrew Kennedy. 2009. Types for units-of-measure: Theory and practice. In Central European Functional Programming School. Springer, 268-305.Google Scholar
Digital Library
- Andrew J Kennedy. 1997. Relational parametricity and units of measure. In Principles of Programming Languages (POPL). ACM, 442-455.Google Scholar
- Sebastian Krings and Michael Leuschel. 2013. Inferring physical units in B models. In Software Engineering and Formal Methods (SEFM). Springer, 137-151.Google Scholar
- Andreas Gullberg Larsen. 2018. Units.NET. https://github.com/angularsen/UnitsNetGoogle Scholar
- Jens Melzer. 2015. Autoboxing Performance. https://efective-java.com/ 2015 /01/autoboxing-performanceGoogle Scholar
- 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 Scholar
- Sam Owre, Indranil Saha, and Natarajan Shankar. 2012. Automatic dimensional analysis of cyber-physical systems. In Formal Methods. Springer, 356-371.Google Scholar
- 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 Scholar
Digital Library
- Matthias C. Schabel and Steven Watanabe. 2010. Boost.Units. http://www.boost.org/doc/libs/1_65_1/doc/html/boost_units. htmlGoogle Scholar
- Scott Wlaschin. 2012. Units of measure-Type safety for numerics. https://fsharpforfunandprofit.com/posts/units-of-measureGoogle Scholar
- Andrew K Wright and Matthias Felleisen. 1994. A syntactic approach to type soundness. Information and Computation 115, 1 ( 1994 ), 38-94.Google Scholar
Index Terms
Precise inference of expressive units of measurement types
Recommendations
Polymorphic type inference and abstract data types
Many statically typed programming languages provide an abstract data type construct, such as the module in Modula-2. However, in most of these languages, implementations of abstract data types are not first-class values. Thus, they cannot be assigned to ...
Type checking and inference for polymorphic and existential types
CATS '09: Proceedings of the Fifteenth Australasian Symposium on Computing: The Australasian Theory - Volume 94This paper proves undecidability of type checking and type inference problems in some variants of typed lambda calculi with polymorphic and existential types. First, type inference in the domain-free polymorphic lambda calculus is proved to be ...
Kinded type inference for parameteric overloading
AbstractParameteric overloading refers to the combination of parameteric polymorphism and overloading of polymorphic operators. The formal basis for parametric overloading, proposed by Kaes and extended by Wadler and Blott, is based on type predicates. In ...






Comments