A type-based analysis for stack allocation in functional languages

  • John Hannan
Contributed Papers
Part of the Lecture Notes in Computer Science book series (LNCS, volume 983)


We consider the problem of detecting when bindings for variables in a higher-order, call-by-value functional language can be allocated on a stack. We use an annotated type system to infer information about the occurrence and extent of variables in a simple higher-order functional language and combine this system with a translation to an annotated language which explicitly indicates when stack allocation can be performed. This technique supports both stack and heap allocation of variable bindings. Only the stack allocated bindings need follow the protocol for stacks: their extent must coincide with their scope. Heap allocated bindings can have any extent and their allocation has no impact on the stack allocated ones. The type system uses a simple notion of annotated types in which types encode not only the typical simple type information, but also information about the use of variables. We demonstrate the use of our analysis by defining both an operational semantics and an abstract machine which utilize both a stack and an environment for variable allocation.


Type System Free Variable Target Language Operational Semantic Source Language 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    M. Abadi, L. Cardelli, P.-L. Curien, and J.-J. Lévy. Explicit substitutions. Journal of Functional Programming, 1(4):375–416, October 1991.Google Scholar
  2. 2.
    Torben Amtoft. Minimal thunkification. In Patrick Courot, Moreno Falaschi, Gilberto Filè, and Antoine Rauzy, editors, Third International Workshop on Static Analysis, volume 724 of Lecture Notes in Computer Science, pages 218–229. Springer-Verlag, 1993.Google Scholar
  3. 3.
    Anindya Banerjee and David A. Schmidt. Stackability in the simply-typed call-by-value lambda calculus. In Baudoin Le Charlier, editor, First International Static Analysis Symposium, volume 864 of Lecture Notes in Computer Science, pages 131–146. Springer-Verlag, 1994.Google Scholar
  4. 4.
    Luis Damas. Type Assignment in Programming Language. PhD thesis, University of Edinburgh, 1985. Available as CST-33-85.Google Scholar
  5. 5.
    Benjamin Goldberg and Young Gil Park. Higher order esape analysis: Optimizing stack allocation in functional program implementations. In Neil Jones, editor, Proceedings of the Third European Symposium on Programming, volume 432 of Lecture Notes in Computer Science, pages 152–160. Springer-Verlag, 1990.Google Scholar
  6. 6.
    John Hannan. Type systems for closure conversions. In Hanne Riis Nielson and Kirsten Lackner Solberg, editors, Participants' Proceedings of the Workshop on Types for Program Analysis, pages 48–62. Aarhus University, DAIMI PB-493, May 1995.Google Scholar
  7. 7.
    John Hannan and Dale Miller. From operational semantics to abstract machines. Mathematical Structures in Computer Science, 2(4):415–459, 1992. Appears in a special issue devoted to the 1990 ACM Conference on Lisp and Functional Programming.Google Scholar
  8. 8.
    John Hannan and Frank Pfenning. Compiler verification in LF. In Andre Scedrov, editor, Proceedings of the Seventh Annual IEEE Symposium on Logic in Computer Science, pages 407–418. IEEE Computer Society Press, 1992.Google Scholar
  9. 9.
    Fritz Henglein. Iterative fixed point computation for type-based stritness analysis. In Baudouin Le Charlier, editor, First International Static Analysis Symposium, volume 864 of Lecture Notes in Computer Science, pages 395–407. Springer-Verlag, 1994.Google Scholar
  10. 10.
    Peter Sestoft. Analysis and Efficient Implementation of Functional Programs. Rapport nr 92/6, DIKU, Copenhagen, October 1991.Google Scholar
  11. 11.
    Mads Tofte. Operational Semantics and Polymorphic Type Inference. PhD thesis, University of Edinburgh, 1987.Google Scholar
  12. 12.
    Mads Tofte and Jean-Pierre Talpin. Implementation of the typed call-by-value λ-calculus using a stack of regions. In Conf. Rec. 21st ACM Symposium on Principles of Programming Languages, pages 188–201,1994.Google Scholar
  13. 13.
    Mitchell Wand and Paul Steckler. Selective and lightweight closure conversion. In Conf. Rec. 21st ACM Symposium on Principles of Programming Languages, 1994.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1995

Authors and Affiliations

  • John Hannan
    • 1
  1. 1.Department of Computer Science and EngineeringThe Pennsylvania State UniversityUniversity ParkUSA

Personalised recommendations