Precise inference of expressive units of measurement types
Tongtong Xiang, Jeff Y. Luo, Werner Dietl
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.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get e6d925ee-fd7e-4427-b0f7-c2ffaa4d8758Cited by top-tier papers3
- Scalability and precision by combining expressive type systems and deductive verificationFlorian Lanzinger, Alexander Weigl, Mattias Ulbrich, Werner DietlOOPSLA 2021 · 6 citations
- Practical Inference of Nullability TypesNima Karimipour, Justin Pham, Lazaro Clapp, Manu SridharanFSE 2023 · 6 citations
- Pluggable Type Inference for FreeMartin Kellogg, Daniel Daskiewicz, Loi Ngo Duc Nguyen, Muyeed Ahmed et al.ASE 2023 · 4 citations
Related papers
- Understanding and Detecting Annotation-Induced Faults of Static AnalyzersHuaien Zhang, Yu Pei, Shuyun Liang, Shin Hwei TanFSE 2024 · 4 citations
- Usability-Oriented Design of Liquid Types for JavaCatarina Gamboa, Paulo Canelas, Christopher Steven Timperley, Alcides FonsecaICSE 2023 · 9 citations
- SA4U: Practical Static Analysis for Unit Type Error DetectionMax Taylor, Johnathon Aurand, Feng Qin, Xiaorui Wang et al.ASE 2022 · 5 citations
- MixedSAND: Semantic Annotation of Mixed-unit Numeric DataAmir Behrad Khorram Nazari, Davood Rafiei, Mario A. NascimentoWWW 2025 · 1 citation
- Flexible Type-Based Resource Estimation in Quantum Circuit Description LanguagesAndrea Colledan, Ugo Dal LagoPOPL 2025 · 3 citations
