Towards automatic resource bound analysis for OCaml

This article presents a resource analysis system for OCaml programs. The system automatically derives worst-case resource bounds for higher-order polymorphic programs with user-defined inductive types. The technique is parametric in the resource and can derive bounds for time, memory allocations and energy usage. The derived bounds are multivariate resource polynomials which are functions of different size parameters that depend on the standard OCaml types. Bound inference is fully automatic and reduced to a linear optimization problem that is passed to an off-the-shelf LP solver. Technically, the analysis system is based on a novel multivariate automatic amortized resource analysis (AARA). It builds on existing work on linear AARA for higher-order programs with user-defined inductive types and on multivariate AARA for first-order programs with built-in lists and binary trees. This is the first amortized analysis, that automatically derives polynomial bounds for higher-order functions and polynomial bounds that depend on user-defined inductive types. Moreover, the analysis handles a limited form of side effects and even outperforms the linear bound inference of previous systems. At the same time, it preserves the expressivity and efficiency of existing AARA techniques. The practicality of the analysis system is demonstrated with an implementation and integration with Inria's OCaml compiler. The implementation is used to automatically derive resource bounds for 411 functions and 6018 lines of code derived from OCaml libraries, the CompCert compiler, and implementations of textbook algorithms. In a case study, the system infers bounds on the number of queries that are sent by OCaml programs to DynamoDB, a commercial NoSQL cloud database service.

[1]  Amr Sabry,et al.  Proving the correctness of reactive systems using sized types , 1996, POPL '96.

[2]  Elvira Albert,et al.  Cost Analysis of Java Bytecode , 2007, ESOP.

[3]  Paul C. Kocher,et al.  Timing Attacks on Implementations of Diffie-Hellman, RSA, DSS, and Other Systems , 1996, CRYPTO.

[4]  Shan Lu,et al.  Understanding and detecting real-world performance bugs , 2012, PLDI.

[5]  Martin Hofmann,et al.  Static prediction of heap space usage for first-order functional programs , 2003, POPL '03.

[6]  Martin Hofmann,et al.  Amortized Resource Analysis with Polynomial Potential , 2010, ESOP.

[7]  Jürgen Giesl,et al.  Analyzing Innermost Runtime Complexity of Term Rewriting by Dependency Pairs , 2013, Journal of Automated Reasoning.

[8]  Steffen Jost,et al.  Automatic amortised analysis of dynamic memory allocation for lazy functional programs , 2012, ICFP.

[9]  Jennifer Paykin,et al.  A static cost analysis for a higher-order language , 2012, PLPV.

[10]  Brian Campbell,et al.  Amortised Memory Analysis Using the Depth of Data Structures , 2009, ESOP.

[11]  Guy E. Blelloch,et al.  Cache and I/O efficent functional algorithms , 2013, POPL.

[12]  Xavier Leroy,et al.  The ZINC experiment : an economical implementation of the ML language , 1990 .

[13]  Ugo Dal Lago,et al.  Linear Dependent Types and Relative Completeness , 2011, LICS.

[14]  Dan S. Wallach,et al.  Denial of Service via Algorithmic Complexity Attacks , 2003, USENIX Security Symposium.

[15]  Elvira Albert,et al.  Automatic Inference of Resource Consumption Bounds , 2012, LPAR.

[16]  Jürgen Giesl,et al.  Alternating Runtime and Size Complexity Analysis of Integer Programs , 2014, TACAS.

[17]  Pavol Cerný,et al.  Segment Abstraction for Worst-Case Execution Time Analysis , 2015, ESOP.

[18]  Isil Dillig,et al.  Static detection of asymptotic performance bugs in collection traversals , 2015, PLDI.

[19]  Karl Crary,et al.  Resource bound certification , 2000, POPL '00.

[20]  Martin Hofmann,et al.  Automatic Type Inference for Amortised Heap-Space Analysis , 2013, ESOP.

[21]  Zhong Shao,et al.  Compositional certified resource bounds , 2015, PLDI.

[22]  Daniel R. Licata,et al.  Denotational cost semantics for functional languages with inductive types , 2015, ICFP.

[23]  Sumit Gulwani,et al.  Bound Analysis of Imperative Programs with the Size-Change Abstraction , 2011, SAS.

[24]  Elvira Albert,et al.  Cost analysis of object-oriented bytecode programs , 2012, Theor. Comput. Sci..

[25]  Umut A. Acar,et al.  Refinement Types for Incremental Computational Complexity , 2015, ESOP.

[26]  Martin Hofmann,et al.  Amortised Resource Analysis and Typed Polynomial Interpretations , 2014, RTA-TLCA.

[27]  Martin Hofmann,et al.  Multivariate amortized resource analysis , 2012, TOPL.

[28]  Sumit Gulwani,et al.  SPEED: precise and efficient static estimation of program computational complexity , 2009, POPL '09.

[29]  Ugo Dal Lago,et al.  The geometry of types , 2012, POPL.

[30]  Pedro B. Vasconcelos Space cost analysis using sized types , 2008 .

[31]  Samir Genaim,et al.  On the Limits of the Classical Approach to Cost Analysis , 2012, SAS.

[32]  Thomas A. Henzinger,et al.  ABC: Algebraic Bound Computation for Loops , 2010, LPAR.

[33]  Martin Hofmann,et al.  Static determination of quantitative resource usage for higher-order programs , 2010, POPL '10.

[34]  Zhong Shao,et al.  Type-Based Amortized Resource Analysis with Integers and Arrays , 2014, FLOPS.

[35]  Robert J. Vanderbei,et al.  Linear Programming: Foundations and Extensions , 1998, Kluwer international series in operations research and management service.

[36]  Martin Hofmann,et al.  Amortized Resource Analysis with Polymorphic Recursion and Partial Big-Step Operational Semantics , 2010, APLAS.

[37]  Elvira Albert,et al.  Closed-Form Upper Bounds in Static Cost Analysis , 2011, Journal of Automated Reasoning.

[38]  R. Tarjan Amortized Computational Complexity , 1985 .

[39]  Steffen Jost,et al.  Type-Based Allocation Analysis for Co-recursion in Lazy Functional Languages , 2015, ESOP.

[40]  Ugo Dal Lago,et al.  Analysing the complexity of functional programs: higher-order meets first-order , 2015, ICFP.

[41]  Martin Hofmann,et al.  Multivariate Amortised Resource Analysis for Term Rewrite Systems , 2015, TLCA.

[42]  Bernd Grobauer,et al.  Cost recurrences for DML programs , 2001, ICFP '01.

[43]  Jan Hoffmann,et al.  Types with potential: polynomial resource bounds via automatic amortized analysis , 2011 .

[44]  Nils Anders Danielsson Lightweight semiformal time complexity analysis for purely functional data structures , 2008, POPL '08.

[45]  Helmut Veith,et al.  A simple and scalable static analysis for bound analysis and amortized complexity analysis , 2014, Software Engineering.

[46]  Xavier Leroy,et al.  Formal verification of a realistic compiler , 2009, CACM.

[47]  Ben Wegbreit,et al.  Mechanical program analysis , 1975, CACM.

[48]  Kevin Hammond,et al.  Inferring Cost Equations for Recursive, Polymorphic and Higher-Order Functional Programs , 2003, IFL.

[49]  Robert Atkey,et al.  Amortised Resource Analysis with Separation Logic , 2010, ESOP.

[50]  Martin Hofmann,et al.  Type-Based Amortised Heap-Space Analysis , 2006, ESOP.

[51]  Guy E. Blelloch,et al.  A provable time and space efficient implementation of NESL , 1996, ICFP '96.

[52]  Elvira Albert,et al.  Non-cumulative Resource Analysis , 2015, TACAS.

[53]  Paul Feautrier,et al.  Multi-dimensional Rankings, Program Termination, and Complexity Bounds of Flowchart Programs , 2010, SAS.

[54]  Georg Moser,et al.  A combination framework for complexity , 2013, Inf. Comput..

[55]  Anna Philippou,et al.  Tools and Algorithms for the Construction and Analysis of Systems , 2018, Lecture Notes in Computer Science.

[56]  Ralph Benzinger,et al.  Automated higher-order complexity analysis , 2004, Theor. Comput. Sci..

[57]  Damien Doligez,et al.  The OCaml system release 4.07: Documentation and user's manual , 2013 .

[58]  Marco Gaboardi,et al.  Relational cost analysis , 2017, POPL.

[59]  Reiner Hähnle,et al.  Resource Analysis of Complex Programs with Cost Equations , 2014, APLAS.