Incremental units-of-measure verification
Matthew Danish, Dominic Orchard, Andrew Rice
TL;DR
This paper addresses the challenge of verifying units-of-measure in scientific Fortran programs by introducing a lightweight, incrementally adoptable static verification system. It adopts a global constraint-solving approach over unit variables and uses a modified Hermite Normal Form to infer and check polymorphic units across modular Fortran code, enabling interprocedural polymorphism and scalable analysis. The authors implement the approach as an extension of CamFort, demonstrate module-based partitioning with fsmod files, and show practical improvements in scalability and real-world case studies such as the Weather Research and Forecast Model, including detection of undocumented unit conversions. The work significantly reduces the burden of annotating large legacy codebases while providing precise, static guarantees about unit consistency, with potential to prevent costly numerical errors in scientific computing.
Abstract
Despite an abundance of proposed systems, the verification of units-of-measure within programs remains rare in scientific computing. We attempt to address this issue by providing a lightweight static verification system for units-of-measure in Fortran programs which supports incremental annotation of large projects. We take the opposite approach to the most mainstream existing deployment of units-of-measure typing (in F#) and generate a global, rather than local, constraints system for a program. We show that such a system can infer (and check) polymorphic units specifications for under-determined parts of the program. Not only does this ability allow checking of partially annotated programs but it also allows the global constraint problem to be partitioned. This partitioning means we can scale to large programs by solving constraints for each program module independently and storing inferred units at module boundaries (separate verification). We provide an implementation of our approach as an extension to an open-source Fortran analysis tool.
