A Type- and Control-Flow Analysis for System F

Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8241)

Abstract

We present a monovariant flow analysis for System F (with recursion). The flow analysis yields both control-flow information, approximating the \(\lambda \)- and \(\varLambda \)-expressions that may be bound to variables, and type-flow information, approximating the type expressions that may instantiate type variables. Moreover, the two flows are mutually beneficial: the control flow determines which \(\varLambda \)-expressions may be applied to which type expressions (and, hence, which type expressions may instantiate which type variables), while the type flow filters the \(\lambda \)- and \(\varLambda \)-expressions that may be bound to variables (by rejecting expressions with static types that are incompatible with the static type of the variable under the type flow). As is typical for a monovariant control-flow analysis, control-flow information is expressed as an abstract environment mapping variables to sets of (syntactic) \(\lambda \)- and \(\varLambda \)-expressions that occur in the program under analysis. Similarly, type-flow information is expressed as an abstract environment mapping type variables to sets of (syntactic) types that occur in the program under analysis. Compatibility of static types (with free type variables) under a type flow is decided by interpreting the abstract environment as productions for a regular-tree grammar and querying if the languages generated by taking the types in question as starting terms have a non-empty intersection.

References

  1. 1.
    Aiken, A.: Introduction to set constraint-based program analysis. Sci. Comput. Program. 35(2–3), 79–111 (1999)MathSciNetCrossRefMATHGoogle Scholar
  2. 2.
    Aiken, A., Murphy, B.R.: Implementing regular tree expressions. In: Conference on Functional Programming Languages and Computer Architecture (FPCA). LNCS, vol. 523, pp. 427–447, August 1991Google Scholar
  3. 3.
    Aiken, A., Murphy, B.R.: Static type inference in a dynamically typed language. In: Symposium on Principles of Programming Languages (POPL), pp. 279–290, January 1991Google Scholar
  4. 4.
    Cejtin, H., Jagannathan, S., Weeks, S.: Flow-directed closure conversion for typed languages. In: Smolka, G. (ed.) ESOP 2000. LNCS, vol. 1782, pp. 56–71. Springer, Heidelberg (2000)Google Scholar
  5. 5.
    Cousot, P., Cousot, R.: Compositional and inductive semantic definitions in fixpoint, equational, constraint, closure-condition, rule-based and game-theoretic form, invited paper. In: Conference on Computer Aided Verification (CAV). LNCS, vol. 939, pp. 293–308, July 1995Google Scholar
  6. 6.
    Cousot, P., Cousot, R.: Formal language, grammar and set-constraint-based program analysis by abstract interpretation. In: Conference on Functional Programming Languages and Computer Architecture (FPCA), pp. 170–181, June 1995Google Scholar
  7. 7.
    Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations. In: Conference on Programming Language Design and Implementation (PLDI), pp. 237–247, June 1993Google Scholar
  8. 8.
    Fluet, M.: A type- and control-flow analysis for System F. Tech. rep., Rochester Institute of Technology. https://ritdml.rit.edu/handle/1850/15920, February 2013
  9. 9.
    Gecseg, F., Steinby, M.: Tree Automata. Akademiai Kiado, Budapest (1984)MATHGoogle Scholar
  10. 10.
    Girard, J.Y.: Une extension de l’interpretation de Gödel à l’analyse, et son application à l’élimination des coupures dans l’analyse et la théorie des types. In: Scandinavian Logic Symposium. Stud. Logic Found. Math. 63, 63–92 (1971)MathSciNetCrossRefGoogle Scholar
  11. 11.
    Harper, R., Morrisett, G.: Compiling polymorphism using intensional type analysis. In: Symposium on Principles of Programming Languages (POPL), pp. 130–141, Januay 1995Google Scholar
  12. 12.
    Heintze, N.: Set-based program analysis of ML programs. In: Conference on Lisp and Functional Programming (LFP), pp. 306–317, June 1994Google Scholar
  13. 13.
    Heintze, N., Jaffar, J.: A finite presentation theorem for approximating logic programs. In: Symposium on Principles of Programming Languages (POPL), pp. 197–209, January 1990Google Scholar
  14. 14.
    Henglein, F.: Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst. 15(2), 253–289 (1993)CrossRefGoogle Scholar
  15. 15.
    Jagannathan, S., Weeks, S., Wright, A.K.: Type-directed flow analysis for typed intermediate languages. In: International Symposium on Static Analysis (SAS). LNCS, vol. 1302, pp. 232–249, September 1997Google Scholar
  16. 16.
    Jones, N.D.: Flow analysis of lambda expressions (preliminary version). In: International Colloquium on Automata, Languages and Programming (ICALP). LNCS, vol. 115, pp. 114–128, July 1981Google Scholar
  17. 17.
    Jones, N.D.: Flow analysis of lazy higher-order functional programs. In: Abramsky, S., Hankin, C. (eds.) Abstract Interpretation of Declarative Languages, Chap. 4, pp. 103–122. Ellis Horwood, Chicheste (1987)Google Scholar
  18. 18.
    Jones, N.D., Muchnick, S.S.: Flow analysis and optimization of LISP-like structures. In: Symposium on Principles of Programming Languages (POPL), pp. 244–256, January 1979Google Scholar
  19. 19.
    Kfoury, A., Tiuryn, J., Urzyczyn, P.: Type reconstruction in the presence of polymorphic recursion. ACM Trans. Program. Lang. Syst. 15(2), 290–311 (1993)CrossRefGoogle Scholar
  20. 20.
    Launchbury, J., Peyton Jones, S.: Lazy functional state threads. In: Conference on Programming Language Design and Implementation (PLDI), pp. 24–35, June 1994Google Scholar
  21. 21.
    Launchbury, J., Peyton Jones, S.: State in Haskell. Lisp Symbolic Comput. 8(4), 293–341 (1995)CrossRefGoogle Scholar
  22. 22.
    Midtgaard, J.: Control-flow analysis of functional programs. ACM Comput. Surv. 44(3), 10:1–10:33 (2012)CrossRefGoogle Scholar
  23. 23.
    Midtgaard, J., Adams, M., Might, M.: A structural soundness proof for Shivers’s escape technique. In: International Symposium on Static Analysis (SAS). LNCS, vol. 7460, pp. 352–369, September 2012Google Scholar
  24. 24.
    Mishra, P., Reddy, U.S.: Declaration-free type checking. In: Symposium on Principles of Programming Languages (POPL), pp. 7–21. ACM, January 1985Google Scholar
  25. 25.
    Mycroft, A.: Polymorphic type schemes and recursive definitions. In: International Symposium on Programming. LNCS, vol. 167, pp. 217–228, April 1984Google Scholar
  26. 26.
    Nielson, F., Nielson, H.R., Hankin, C.: Principles of Program Analysis. Springer, Heidelberg (1999)CrossRefMATHGoogle Scholar
  27. 27.
    Palsberg, J.: Type-based analysis and applications. In: Workshop on Programming Analysis for Software Tools and Engineering (PASTE), pp. 20–27 (2001)Google Scholar
  28. 28.
    Peyton Jones, S.: Compiling Haskell by program transformation: A report from the trenches. In: European Symposium on Programming (ESOP). LNCS, vol. 1058, pp. 18–44, April 1996Google Scholar
  29. 29.
    Pottier, F., Gauthier, N.: Polymorphic typed defunctionalization and concretization. Higher-Order Symbolic Comput. 19(1), 125–162 (2006)CrossRefMATHGoogle Scholar
  30. 30.
    Reppy, J.: Type-sensitive control-flow analysis. In: Workshop on ML (ML). pp. 74–83, September 2006Google Scholar
  31. 31.
    Reynolds, J.: Towards a theory of type structure. In: International Symposium on Programming. LNCS, vol. 19, pp. 408–425, April 1974Google Scholar
  32. 32.
    Rossberg, A., Russo, C., Dreyer, D.: F-ing modules. In: Workshop on Types in Language Design and Implementation (TLDI), pp. 89–102, January 2010Google Scholar
  33. 33.
    Serrano, M.: Control flow analysis: a functional languages compilation paradigm. In: Symposium on Applied Computing (SAC), pp. 118–122, Feburary 1995Google Scholar
  34. 34.
    Sestoft, P.: Replacing function parameters by global variables. In: Conference on Functional Programming Languages and Computer, Architecture (FPCA), pp. 39–53, September 1989Google Scholar
  35. 35.
    Shivers, O.: Control-flow analysis in Scheme. In: Conference on Programming Language Design and Implementation (PLDI), pp. 164–174, June 1988Google Scholar
  36. 36.
    Shivers, O.: Control-Flow Analysis of Higher-Order Languages or Taming Lambda. Ph.D. thesis, School of Computer Science, Carnegie Mellon University, Pittsburgh, Pennsylvania, Technical Report CMU-CS-91-145, May 1991Google Scholar
  37. 37.
    Sulzmann, M., Chakravarty, M.M.T., Peyton Jones, S., Donnelly, K.: System F with type equality coercions. In: Workshop on Types in Language Design and Implementation (TLDI), pp. 53–66, January 2007Google Scholar
  38. 38.
    Tarditi, D., Morrisett, G., Cheng, P., Stone, C., Harper, R., Lee, P.: TIL: a type-directed optimizing compiler for ML. In: Conference on Programming Language Design and Implementation (PLDI), pp. 181–192, May 1996Google Scholar
  39. 39.
    Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Inf. Comput. 115(1), 38–94 (1994)MathSciNetCrossRefMATHGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2013

Authors and Affiliations

  1. 1.Computer Science DepartmentRochester Institute of TechnologyRochesterUSA

Personalised recommendations