## Static Determination of Quantitative Resource Usage for Higher-Order Programs (2010)

Venue: | IN: 37TH ACM SYMP. ON PRINCIPLES OF PROG. LANGS |

Citations: | 11 - 4 self |

### BibTeX

@INPROCEEDINGS{Jost10staticdetermination,

author = {Steffen Jost and Kevin Hammond and Hans-Wolfgang Loidl and Martin Hofmann},

title = { Static Determination of Quantitative Resource Usage for Higher-Order Programs},

booktitle = {IN: 37TH ACM SYMP. ON PRINCIPLES OF PROG. LANGS},

year = {2010},

publisher = {}

}

### OpenURL

### Abstract

We describe a new automatic static analysis for determining upper-bound functions on the use of quantitative resources for strict, higher-order, polymorphic, recursive programs dealing with possibly-aliased data. Our analysis is a variant of Tarjan’s manual amortised cost analysis technique. We use a type-based approach, exploiting linearity to allow inference, and place a new emphasis on the number of references to a data object. The bounds we infer depend on the sizes of the various inputs to a program. They thus expose the impact of specific inputs on the overall cost behaviour. The key novel aspect of our work is that it deals directly with polymorphic higher-order functions without requiring source-level transformations that could alter resource usage. We thus obtain safe and accurate compile-time bounds. Our work is generic in that it deals with a variety of quantitative resources. We illustrate our approach with reference to dynamic memory allocations/deallocations, stack usage, and worst-case execution time, using metrics taken from a real implementation on a simple micro-controller platform that is used in safety-critical automotive applications.

### Citations

308 | Definitional interpreters for higher-order programming languages
- Reynolds
- 1972
(Show Context)
Citation Context ...and efficiently. This is the first automatic amortised analysis that can determine costs for higher-order functions directly rather than relying on program transformations such as defunctionalisation =-=[34]-=- to transform higher-order programs into first-order ones. Such transformations are not acceptable for several reasons. Firstly, they usually change time and space properties. This is unacceptable in ... |

243 | Purely Functional Data Structures
- Okasaki
- 1998
(Show Context)
Citation Context ...tate. There are two main problems to be overcome. Firstly, devising a useful mapping from each machine state to the number representing its potential is a difficult task. Secondly, Okasaki notes that =-=[32]-=-: “As we have seen, amortized data structures are often tremendously effective in practice. [. . . ] traditional methods of amortization break in presence of persistence” Our type-based variant solves... |

199 | A static analyzer for large safetycritical software
- Blanchet, Cousot, et al.
- 2003
(Show Context)
Citation Context ...TimeM32: list[Cons<1714>:int,#|Nil<225>] -(684/0)-> int The first block in Table 1 compares the analysis bounds above with our measured results, applying sum to the initial segments of the input list =-=[1,2,3,4,5]-=- of lengths N = 1 . . . 5. Since we analyse and measure the entire code, including the costs for generating the test input, the absolute values given in the table are slightly higher than the values c... |

199 | A natural semantics of lazy evaluation
- Launchbury
- 1993
(Show Context)
Citation Context ...evaluation that will allow us to identify resource usage in the way we have done here. We are in the process of producing a cost model and analysis based on Launchbury’s semantics for graph reduction =-=[27]-=-, which incorporates notions of evaluation- and sharingcontexts to determine where potentials may be used. Acknowledgements We would like to thank our colleagues Pedro Vasconcelos and Hugo Simões (bot... |

165 |
as an assertion language for mutable data structures
- BI
- 2001
(Show Context)
Citation Context ...ns, since this is an orthogonal and complex problem that deserves its own treatment (see, for example, Walker and Morrisett’s alias types [41], or the bunched implication logic of Ishtiaq and O’Hearn =-=[23]-=-). We encapsulate this problem by adopting essentially a storeless semantics [35, 24]. While we do deal with explicit memory addresses, these should be considered as symbolic handles, as used, for exa... |

144 | Static prediction of heap space usage for first-order functional programs
- Hofmann, Jost
(Show Context)
Citation Context ...We also present the associated fully-automatic type inference, which has been implemented using a standard external linear programming solver. Our main novel contributions are to extend previous work =-=[19, 25]-=-: a) by analysing the resource usage of higher-order functions, which may be both polymorphic and mutually recursive, in a cost-preserving way; b) by dealing with polymorphism, also in a cost-preservi... |

144 |
Amortized Computational Complexity
- Tarjan
- 1985
(Show Context)
Citation Context ...the previously inferred annotated type for any function that is exported, and not its definition. Our automatic analysis is a variant of the amortised cost analysis that was first described by Tarjan =-=[38]-=-. Amortised cost analysis is a manual technique, which works as follows: using ingenuity, one devises a mapping from all possible machine states to a nonnegative rational number, henceforth referred t... |

142 | Type inference with polymorphic recursion
- Henglein
- 1993
(Show Context)
Citation Context ...tly on the stack. 6.6.1 Resource parametric recursion Interestingly, the eval function cannot be analysed under the boxed heap cost model — analysing this function would require polymorphic recursion =-=[15, 26]-=-, which we do not support. The second recursive call in the case dealing with LetOp requires a different type, since the annotated type of the first argument has changed. Function rho’ is more expensi... |

140 | Alias types for recursive data structures
- Walker, Morrisett
- 2001
(Show Context)
Citation Context ...tching (case! ). We do not deal with the safety of deallocations, since this is an orthogonal and complex problem that deserves its own treatment (see, for example, Walker and Morrisett’s alias types =-=[41]-=-, or the bunched implication logic of Ishtiaq and O’Hearn [23]). We encapsulate this problem by adopting essentially a storeless semantics [35, 24]. While we do deal with explicit memory addresses, th... |

131 | Proving the Correctness of Reactive Systems Using Sized Types
- Hughes, Pareto, et al.
- 1996
(Show Context)
Citation Context ...r example, Shkaravska et al. aim to extend the amortised cost approach to non-linear bounds using resource functions in the constraints, rather than simple variables [36]. 7.2 Sized Types Sized types =-=[22]-=- express bounds on data structure sizes. They are attached to types in the same way as the weights we have used here. The difference is that sized types express bounds on the size of the underlying da... |

121 |
Reliable and precise WCET determination for a real-life processor
- Ferdinand, Heckmann
- 2001
(Show Context)
Citation Context ...usually depend on the existence of concrete data values. Where they can be applied, impressive results can, however, be obtained even for large commercial applications. For example, AbsInt’s aiT tool =-=[11]-=-, and Cousot et al.’s ASTREE system [5] have both been deployed in the design of the software of Airbus Industrie’s Airbus A380. Typically, such tools are limited to non-recursive programs † , and may... |

120 | Resource bound certification
- Crary, Weirich
- 2000
(Show Context)
Citation Context ...order language [19], using an amortised cost model. This work uses a deallocation mechanism similar to that we have used here, but is built on a difference metric similar to that of Crary and Weirich =-=[9]-=-. The latter, however, only checks bounds, and does not infer them, as we do. Taha et al.’s GeHB [37] staged notation automatically generates first-order, heap-bounded LFPL programs from higher-order ... |

91 | A type system for bounded space and functional in-place update–extended abstract
- Hofmann
- 2000
(Show Context)
Citation Context ...work on automatic amortised cost analyses has been on determining the costs of first-order rather than higher-order programs. For example, Hofmann’s linearlytyped functional programming language LFPL =-=[17]-=- uses linear types to determine resource usage in terms of the number of constructors used by a program. First-order LFPL definitions can be computed in bounded space, even in the presence of general ... |

83 | Recursion and Dynamic DataStructures in Bounded Space; Towards Embedded ML Programming
- Hughes, Pareto
- 1999
(Show Context)
Citation Context ...pe checking algorithm for a simple higher-order, non-strict functional language to determine progress in a reactive system. This work was subsequently developed to describe space usage in Embedded ML =-=[21]-=-, a strict functional language using regions to control memory usage. Abel [1] extended higher-order sized types to allow higher-kinded types with embedded function spaces. He used this system to form... |

80 |
Co-induction in relational semantics
- Milner, Tofte
- 1991
(Show Context)
Citation Context ...d only if for all variables x ∈ Γ the co-inductively defined relation H �v V(x) :Γ(x) can be derived by the rules in Figure 3. We use a co-inductive definition for similar reasons as Milner and Tofte =-=[31]-=-. Note that there are no practical consequences of using a co-inductive definition here, since it is exclusively used as an invariant in our soundness proof. Only the proofs of following two lemmas re... |

76 | Hume: a domain-specific language for real-time embedded systems
- Hammond, Michaelson
- 2003
(Show Context)
Citation Context ...erlying abstract machine that counts resources used during the execution. For readability, the programs in this section use a more compact functional notation than Schopenhauer, expression-level Hume =-=[14]-=-, without a restriction to let-normal form. This Haskell-style notation uses multiple rules with pattern matching instead of toplevel, asymmetric case expressions. The basic type of integers is parame... |

61 | Calculating sized types
- Chin, Khoo
- 2001
(Show Context)
Citation Context ...ilding on information provided by ancillary analyses on termination and safe destruction. The focus of this work is on determining safety properties rather than resource usage, however. Chin and Khoo =-=[7]-=- introduced a type inference algorithm that is capable of computing size information from high-level program source. Chin et al. [8] presented a heap and a stack analysis for a low-level (assembler) l... |

56 |
Type Reconstruction in the Presence of Polymorphic Recursion
- Kfoury, Tiuryn, et al.
- 1993
(Show Context)
Citation Context ...tly on the stack. 6.6.1 Resource parametric recursion Interestingly, the eval function cannot be analysed under the boxed heap cost model — analysing this function would require polymorphic recursion =-=[15, 26]-=-, which we do not support. The second recursive call in the case dealing with LetOp requires a different type, since the annotated type of the first argument has changed. Function rho’ is more expensi... |

55 | A semantics for procedure local heaps and its abstractions
- Rinetzky, Bauer, et al.
- 2005
(Show Context)
Citation Context ...nt (see, for example, Walker and Morrisett’s alias types [41], or the bunched implication logic of Ishtiaq and O’Hearn [23]). We encapsulate this problem by adopting essentially a storeless semantics =-=[35, 24]-=-. While we do deal with explicit memory addresses, these should be considered as symbolic handles, as used, for example, in early versions of the JVM. A deallocated memory address is then simply overw... |

52 |
ACE: An Automatic Complexity Evaluator
- Métayer
- 1988
(Show Context)
Citation Context ...n-recursive programs † , and may require significant programmer effort to use effectively. We are aware of very little work that considers user-defined higher-order programs, though Le Métayer’s work =-=[28]-=- can handle predefined higher-order functions with known costs, and Benzinger’s work on worst-case complexity analysis for NuPrl [3] similarly supports higher-order functions if the complexity informa... |

46 | Speed: precise and efficient static estimation of program computational complexity
- Gulwani, Mehra, et al.
- 2009
(Show Context)
Citation Context ...sts that dependent on the size of data structures. This static analysis is combined with run-time size information to deliver dynamic granularity estimates. Gulwani, Mehra and Chilimbi’s SPEED system =-=[13]-=- uses a symbolic evaluation approach to calculate non-linear complexity bounds for C/C++ procedures using an abstract interpretationbased invariant generation tool. Precise loop bounds are calculated ... |

44 | Fully automatic, parametric worst-case execution time analysis
- Lisper
- 2003
(Show Context)
Citation Context ...applies regardless of the cost metric that we use. † There is, however, significant recent work on determining loop bounds for iterative programs as part of a worst-case execution time analysis, e.g. =-=[29]-=-. Our results for a range of higher-order programs demonstrate the high quality of the bounds that we can infer. For heap space, we can generally achieve an exact prediction. For worst-case execution ... |

28 |
A Polymorphic Lambda-Calculus with Sized Higher-Order Types
- Abel
- 2006
(Show Context)
Citation Context ...TimeM32: list[Cons<1714>:int,#|Nil<225>] -(684/0)-> int The first block in Table 1 compares the analysis bounds above with our measured results, applying sum to the initial segments of the input list =-=[1,2,3,4,5]-=- of lengths N = 1 . . . 5. Since we analyse and measure the entire code, including the costs for generating the test input, the absolute values given in the table are slightly higher than the values c... |

28 | Inferring Cost Equations for Recursive, Polymorphic and Higher-Order Functional Programs
- Vasconcelos, Hammond
- 2004
(Show Context)
Citation Context ...ue. Alternatively, knowing the sizes of potential-bearing entities captured in a closure would allow us to recharge their potential at each call. Combining our work with a “sized-type” analysis (e.g. =-=[40]-=-) might thus also avoid this limitation. Each function body is only analysed once, associating a set of constraints with the function. At each application, these constraints are copied from the type. ... |

24 |
Automated complexity analysis of nuprl extracted programs
- Benzinger
- 2001
(Show Context)
Citation Context ...TimeM32: list[Cons<1714>:int,#|Nil<225>] -(684/0)-> int The first block in Table 1 compares the analysis bounds above with our measured results, applying sum to the initial segments of the input list =-=[1,2,3,4,5]-=- of lengths N = 1 . . . 5. Since we analyse and measure the entire code, including the costs for generating the test input, the absolute values given in the table are slightly higher than the values c... |

23 | Automatic time-bound analysis for a higher-order language
- Gómez, Liu
- 2002
(Show Context)
Citation Context ...object-oriented bytecode language. It produces a closed-form upper bound function over the size of the input. Unlike our system, however, data-dependencies cannot be expressed. Finally, Gómez and Liu =-=[12]-=- have constructed an abstract interpretation for determining time bounds on higher-order programs. This executes an abstract version of the program that calculates cost parameters, but which otherwise... |

22 |
The strength of non size-increasing computation
- Hofmann
- 2002
(Show Context)
Citation Context ... bounded space, even in the presence of general recursion. Adding higher-order functions to LFPL raises the expressive power in terms of complexity theory from linear space (LFPL) to exponential time =-=[18]-=-. Hofmann and Jost subsequently described an automatic inference mechanism for heap-space consumption in a functional, first-order language [19], using an amortised cost model. This work uses a deallo... |

20 | Analysing memory resource bounds for low-level programs
- CHIN, NGUYEN, et al.
(Show Context)
Citation Context ...afety properties rather than resource usage, however. Chin and Khoo [7] introduced a type inference algorithm that is capable of computing size information from high-level program source. Chin et al. =-=[8]-=- presented a heap and a stack analysis for a low-level (assembler) language with explicit (de-)allocation. By inferring path-sensitive information and using symbolic evaluation they are able to infer ... |

20 | Eekelen. Polynomial Size Analysis for First-Order Functions
- Shkaravska, Kesteren, et al.
- 2007
(Show Context)
Citation Context ...analysing first-order programs. For example, Shkaravska et al. aim to extend the amortised cost approach to non-linear bounds using resource functions in the constraints, rather than simple variables =-=[36]-=-. 7.2 Sized Types Sized types [22] express bounds on data structure sizes. They are attached to types in the same way as the weights we have used here. The difference is that sized types express bound... |

19 |
Abstract storage structures
- Jonkers
- 1981
(Show Context)
Citation Context ...nt (see, for example, Walker and Morrisett’s alias types [41], or the bunched implication logic of Ishtiaq and O’Hearn [23]). We encapsulate this problem by adopting essentially a storeless semantics =-=[35, 24]-=-. While we do deal with explicit memory addresses, these should be considered as symbolic handles, as used, for example, in early versions of the JVM. A deallocated memory address is then simply overw... |

14 | Using the Run-Time Sizes of Data Structures to Guide Parallel-Thread Creation - Huelsbergen, Larus, et al. - 1994 |

13 | Live Heap Space Analysis for Languages with Garbage Collection
- Albert, Genaim, et al.
- 2009
(Show Context)
Citation Context |

13 | Amortized resource analysis with polynomial potential
- Hoffmann, Hofmann
- 2010
(Show Context)
Citation Context ...e inferred statically for a number of common data structures. Non-Linear Constraints. An extension of the amortised cost based approach to polynomial bounds for a first-order language is ongoing work =-=[16]-=-. We have also begun to investigate whether combining our approach with a sized-type analysis might also allow the inference of super-linear bounds, while still using efficient LP-solver technology (m... |

11 |
Lightweight semiformal time complexity analysis for purely functional data structures
- Danielsson
- 2008
(Show Context)
Citation Context ...the stack and heap costs of recursive functions. By including user-defined sizes, it is possible to infer sizes for algorithms on non-linear data structures, such as binary trees. Finally, Danielsson =-=[10]-=- has recently introduced a library of functions that he claims makes the analysis of a number of purely functional data structures and algorithms almost fully formal. He does this by using a dependent... |

10 | Amortised memory analysis using the depth of data structures
- Campbell
- 2009
(Show Context)
Citation Context ...or stack, the analysis delivers a linear bound, whereas the measured costs are logarithmic in general. Here, we could usefully apply a further extension of the amortised cost based analysis. Campbell =-=[6]-=- has developed methods for associating potential in relation to the depth of data structures. This is more suitable for stackspace usage. It also allows temporary “borrowing” of potential. The time bo... |

9 | Carbon Credits” for Resource-Bounded Computations using Amortised Analysis
- Jost, Loidl, et al.
- 2009
(Show Context)
Citation Context ...We also present the associated fully-automatic type inference, which has been implemented using a standard external linear programming solver. Our main novel contributions are to extend previous work =-=[19, 25]-=-: a) by analysing the resource usage of higher-order functions, which may be both polymorphic and mutually recursive, in a cost-preserving way; b) by dealing with polymorphism, also in a cost-preservi... |

9 |
Cost Inference and Analysis for Recursive Functional Programs
- Vasconcelos
- 2007
(Show Context)
Citation Context ...stract time- and heap-consumption from unannotated program source expressions based on the inference of sized types for recursive, polymorphic, and higher-order programs [40]. Vasconcelos’ PhD thesis =-=[39]-=- extended these previous approaches by using abstract interpretation techniques to automatically infer linear approximations of the sizes of recursive data types and the stack and heap costs of recurs... |

7 | Generating heap-bounded programs in a functional setting
- Taha, Ellner, et al.
- 2003
(Show Context)
Citation Context ...to that we have used here, but is built on a difference metric similar to that of Crary and Weirich [9]. The latter, however, only checks bounds, and does not infer them, as we do. Taha et al.’s GeHB =-=[37]-=- staged notation automatically generates first-order, heap-bounded LFPL programs from higher-order specifications, but likewise requires the use of non cost-preserving transformations. We are not awar... |

5 | A Sharing Analysis for SAFE
- Peña, Segura, et al.
- 2007
(Show Context)
Citation Context ...n spaces. He used this system to formalise termination checking but did not tackle resource consumption in general. A combination of sized types and regions is also being developed by Peña and Segura =-=[33]-=-, building on information provided by ancillary analyses on termination and safe destruction. The focus of this work is on determining safety properties rather than resource usage, however. Chin and K... |

2 |
lpsolve: Open Source (Mixed-Integer
- Berkelaar, Eikland, et al.
- 2004
(Show Context)
Citation Context ...necessary inequalities. We illustrate this process in more detail with a simple example in Section 6.1.2. In the final step, the constraints that have been gathered are solved by a standard LP-solver =-=[4]-=-. In practice, we have found that the sparse LPs that are generated can be easily solved, partly because they have a simple structure [19]. Furthermore, the number of constraints that are generated is... |

2 | Improvements to a resource analysis for Hume
- Loidl, Jost
- 2009
(Show Context)
Citation Context ...his capability here to infer bounds on the total number of function calls in a program expression. This metric is of particular interest for higher-order programs (this is discussed in more detail in =-=[30]-=-). The results for this resource are given in the second column of Table 2. The first variant exhibits the lowest number of function calls, since all three phases of the computation are covered by one... |