Abstract. Hofmann and Jost have presented a heap space analysis [1] that finds linear space bounds for many functional programs. It uses an amortised analysis: assigning hypothetical amounts of free space (called potential) to data structures in proportion to their sizes using type annotations. Constraints on these annotations in the type system ensure that the total potential assigned to the input is an upper bound on the total memory required to satisfy all allocations. We describe a related system for bounding the stack space requirements which uses the depth of data structures, by expressing potential in terms of maxima as well as sums. This is achieved by adding extra structure to typing contexts (inspired by O'Hearn's bunched typing [2] ) to describe the form of the bounds. We will also present the extra steps that must be taken to construct a typing during the analysis. Obtaining bounds on the resource requirements of programs can be crucial for ensuring that they enjoy reliability and security properties, particularly for use in constrained systems such as mobile phones, smartcards and embedded systems. Hofmann and Jost have presented a type-based amortised analysis for finding upper bounds on the heap memory required for programs in a simple functional programming language [1] . The form of these bounds is limited to linear functions with respect to the size of the program's input. Fortunately, this is sufficient for a wide variety of interesting programs. Moreover, the analysis was successfully used to certify such bounds in a Proof Carrying Code system [3] . However, it is also important to bound the stack space requirements, especially for functional programs where it is easy to cause excessive stack usage by accident. The Hofmann-Jost analysis has previously been adapted to measure stack space [4, 5] , but the form of the bounds was again limited to linear functions in terms of the total size of the input. In this work we present a similar analysis where bounds are given as max-plus expressions on the depth of data structures. This is far more precise for programs operating on tree-structured data. Like Hofmann-Jost, our analysis consists of two parts: a type-system which certifies that a given bound really is an upper bound on the stack memory requirements, and an inference procedure based on Linear Programming for that
Recently, Campbell REF gives a type-based approach to stack space analysis.
Amortised memory analysis using the depth of data structures
In Proceedings of ESOP 2009: European Symposium on Programming, LNCS 5502
Computer Science