ABSTRACT
Defunctionalization is a program transformation that removes all first-class functions from a source program, yielding an equivalent target program that contains only first-order functions. As originally described by Reynolds, defunctionalization transforms an untyped higher-order source program into an untyped first-order target program that uses a single, global dispatch function. In addition to being limited to untyped languages, a drawback of this approach is that obscures control flow, making it appear as though the code associated with every source function could be invoked at every call site of the target program. Subsequent work has extended defunctionalization to both simply-typed and polymorphically-typed languages, but the latter continues to use a single, global dispatch function. Other work has extended defunctionalization to be guided by a control-flow analysis of a simply-typed source program, where the types of the target program exactly capture the results of the flow analysis and make it apparent which (limited) set of functions can be invoked at each call site. Our work draws inspiration from these previous approaches and proposes a novel flow-directed defunctionalization for a polymorphically-typed source language. Guided by a type- and control-flow analysis, which exploits well-typedness of the source program to filter flows that are incompatible with static types, the transformation must construct evidence that filtered flows are impossible in order to ensure the well-typedness of the target program.
- Connor Adsit and Matthew Fluet. 2014. An Efficient Type- and Control-Flow Analysis for System F. In IFL’14: Proceedings of the 26nd International Symposium on Implementation and Application of Functional Languages, Sam Tobin-Hochstadt (Ed.). Association for Computing Machinery, Boston, MA, USA, Article 3, 14 pages.Google Scholar
- Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard. 2003. A Functional Correspondence between Evaluators and Abstract Machines. In PPDP’03: Proceedings of the 5th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, Dale Miller(Ed.). Association for Computing Machinery, Uppsala, Sweden, 8–19.Google ScholarDigital Library
- Alexander Aiken and Brian R. Murphy. 1991. Implementing regular tree expressions. In FPCA’91: Proceedings of the Fifth ACM Conference on Functional Programming Languages and Computer Architecture(Lecture Notes in Computer Science, Vol. 523), John Hughes (Ed.). Springer-Verlag, Cambridge, Massachusetts, 427–447.Google ScholarCross Ref
- Brian Aydemir, Arthur Charguéraud, Benjamin C. Pierce, Randy Pollack, and Stephanie Weirich. 2008. Engineering formal metatheory. In POPL’08: Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, George C. Necula and Philip Wadler (Eds.). Association for Computing Machinery, San Francisco, California, 3–15.Google ScholarDigital Library
- Jeffrey M. Bell, Françoise Bellegarde, and James Hook. 1997. Type-Driven Defunctionalization, See Tofte [30], 25–37.Google Scholar
- Urban Boquist and Thomas Johnsson. 1997. The GRIN Project: A Highly Optimising Back End for Lazy Functional Languages. In IFL’96: Selected Papers of the 8th Workshop on Implementation of Functional Languages, Werner Kluge (Ed.). Springer-Verlag, Bad Godesberg, Germany, 58–84.Google Scholar
- Chris Casinghino, Vilhelm Sjöberg, and Stephanie Weirich. 2014. Combining Proofs and Programs in a Dependently Typed Language. In POPL’14: Proceedings of the 41st Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Peter Sewell (Ed.). Association for Computing Machinery, San Diego, California, 33–45.Google ScholarDigital Library
- Henry Cejtin, Suresh Jagannathan, and Stephen Weeks. 2000. Flow-directed closure conversion for typed languages. In ESOP’00: Proceedings of the Ninth European Symposium on Programming(Lecture Notes in Computer Science, Vol. 1782), Gert Smolka (Ed.). Springer-Verlag, Berlin, Germany, 56–71.Google ScholarCross Ref
- Arthur Charguéraud. 2012. The Locally Nameless Representation. Journal of Automated Reasoning 49, 3 (2012), 363–408.Google ScholarCross Ref
- Chiyan Chen and Hongwei Xi. 2005. Combining Programming with Theorem Proving. In ICFP’05: Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming, Benjamin C. Pierce (Ed.). Association for Computing Machinery, Tallin, Estonia, 66–77.Google Scholar
- James Cheney and Ralf Hinze. 2003. First-class Phantom Types. Technical Report TR2003-1901. Cornell University, Ithaca, NY, USA.Google Scholar
- Olivier Danvy and Lasse R. Nielsen. 2001. Defunctionalization at Work. In PPDP’01: Proceedings of the 3rd ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, Harald Søndergaard(Ed.). Association for Computing Machinery, Firenze, Italy, 162–174. Extended version available as the technical report BRICS RS-01-23.Google ScholarDigital Library
- Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The essence of compiling with continuations. In PLDI’93: Proceedings of the ACM SIGPLAN 1993 Conference on Programming Languages Design and Implementation, Robert Cartwright (Ed.). ACM, Albuquerque, New Mexico, 237–247.Google ScholarDigital Library
- Matthew Fluet. 2013. A Type- and Control-Flow Analaysis for System F. In IFL’12: Post-Proceedings of the 24th International Symposium on Implementation and Application of Functional Languages(Lecture Notes in Computer Science), Ralf Hinze (Ed.). Springer-Verlag, Oxford, England, 122–139.Google Scholar
- Georgios Fourtounis and Nikolaos S. Papaspyrou. 2013. Supporting separate compilation in a defunctionalizing compiler. In SLATE’13: Proceedings of the Second Symposium on Languages, Applications and Technologies(OASICS, Vol. 29), José Paulo Leal, Ricardo Rocha, and Alberto Simões (Eds.). Schloss Dagstuhl - Leibniz-Zentrum für Informatik.Google Scholar
- Georgios Fourtounis, Nikolaos S. Papaspyrou, and Panagiotis Theofilopoulos. 2014. Modular Polymorphic Defunctionalization. Computer Science and Information Systems 11, 4 (2014), 1417–1434.Google ScholarCross Ref
- Kirsten L. Solberg Gasser, Flemming Nielson, and Hanne Riis Nielson. 1997. Systematic Realisation of Control Flow Analyses for CML, See Tofte [30], 38–51.Google Scholar
- Ralf Hinze. 2003. Fun with Phantom Types. In The Fun of Programming, Jeremy Gibbons and Oege de Moor (Eds.). Palgrave Macmillan, 245–262.Google Scholar
- Flemming Nielson and Hanne Riis Nielson. 1997. Infinitary Control Flow Analysis: a Collecting Semantics for Closure Analysis. In POPL’97: Proceedings of the 24th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Neil D. Jones(Ed.). Association for Computing Machinery, Paris, France, 332–345.Google ScholarDigital Library
- Flemming Nielson and Hanne Riis Nielson. 1999. Interprocedural Control Flow Analysis. In ESOP’99: Proceedings of the Eighth European Symposium on Programming(Lecture Notes in Computer Science, Vol. 1576), S. Doaitse Swierstra (Ed.). Springer-Verlag, Amsterdam, The Netherlands, 20–39.Google Scholar
- Flemming Nielson, Hanne Riis Nielson, and Chris Hankin. 1999. Principles of Program Analysis. Springer-Verlag.Google Scholar
- Hanne Riis Nielson and Flemming Nielson. 1998. Flow Logics for Constraint Based Analysis. In CC’98: Proceedings of the 7th International Conference on Compiler Construction(Lecture Notes in Computer Science, Vol. 1383), Kai Koskimies (Ed.). Springer-Verlag, London, UK, 109–127.Google Scholar
- François Pottier and Nadji Gauthier. 2004. Polymorphic typed defunctionalization. In POPL’04: Proceedings of the 31st Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Xavier Leroy (Ed.). Association for Computing Machinery, Venice, Italy, 89–98.Google ScholarDigital Library
- François Pottier and Nadji Gauthier. 2006. Polymorphic Typed Defunctionalization and Concretization. Higher-Order and Symbolic Computation 19, 1 (2006), 125–162.Google ScholarDigital Library
- John C. Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In ACM’72: Proceedings of 25th ACM National Conference, Rosemary Shields (Ed.). Association for Computing Machinery, Boston, MA, USA, 717–740. Reprinted as [], with a foreword [].Google Scholar
- Tim Sheard. 2004. Languages of the Future. In OOPSLA’04: Proceedings of the 2004 ACM International Conference on Object Oriented Programming Systems, Languages, and Applications, Doug Schmidt (Ed.). Association for Computing Machinery, Vancouver, BC, Cananda, 116–119.Google Scholar
- Olin Shivers. 1991. Control-Flow Analysis of Higher-Order Languages or Taming Lambda. Ph.D. Dissertation. School of Computer Science, Carnegie Mellon University, Pittsburgh, Pennsylvania. Technical Report CMU-CS-91-145.Google Scholar
- Antonis Stampoulis and Zhong Shao. 2010. VeriML: Typed Computation of Logical Terms inside a Language with Effects. In ICFP’10: Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming, Stephanie Weirich (Ed.). ACM, Baltimore, Maryland, 333–344.Google ScholarDigital Library
- Nikhil Swamy, Juan Chen, Cédric Fournet, Pierre-Yves Strub, Karthikeyan Bhargavan, and Jean Yang. 2011. Secure Distributed Programming with Value-Dependent Types. In ICFP’11: Proceedings of the 16th ACM SIGPLAN International Conference on Functional Programming, Olivier Danvy (Ed.). ACM, Tokyo, Japan, 266–278.Google Scholar
- Mads Tofte (Ed.). 1997. ICFP’97: Proceedings of the Second ACM SIGPLAN International Conference on Functional Programming. Association for Computing Machinery, Amsterdam, The Netherlands.Google Scholar
- Andrew Tolmach. 1997. Combining closure conversion with closure analysis using algebraic types. In Proceedings of the 1997 ACM SIGPLAN Workshop on Types in Compilation (TIC’97). Amsterdam, The Netherlands. Available as technical report BCCS-97-03, Computer Science Department, Boston College.Google Scholar
- Andrew Tolmach and Dino P. Oliva. 1998. From ML to Ada: Strongly-typed language interoperability via source translation. Journal of Functional Programming 8, 4 (1998), 367–412.Google ScholarDigital Library
- Stephanie Weirich, Antoine Voizard, Pedro Henrique Azevedo de Amorim, and Richard A. Eisenberg. 2017. A Specification for Dependent Types in Haskell. Proceedings of the ACM on Programming Languages 1, ICFP, Article 31 (Aug. 2017), 29 pages.Google ScholarDigital Library
- Hongwei Xi, Chiyan Chen, and Gang Chen. 2003. Guarded Recursive Datatype Constructors. In POPL’03: Proceedings of the 30th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Greg Morrisett (Ed.). Association for Computing Machinery, New Orleans, LA, USA, 224–235.Google Scholar
- Jeremy Yallop and Leo White. 2014. Lightweight Higher-Kinded Polymorphism. In FLOPS’14: Proceedings of the 15th International Symposium on Functional and Logic Programming(Lecture Notes in Computer Science, Vol. 8475), Michael Codish and Eijiro Sumii (Eds.). Springer-Verlag, Kanazawa, Japan, 119–135.Google Scholar
Recommendations
An Efficient Type- and Control-Flow Analysis for System F
IFL '14: Proceedings of the 26nd 2014 International Symposium on Implementation and Application of Functional LanguagesAt IFL'12, we presented a novel monovariant flow analysis for System F (with recursion) that yields both type-flow and control-flow information. [5] The type-flow information approximates the type expressions that may instantiate type variables and the ...
Polymorphic typed defunctionalization and concretization
Defunctionalization is a program transformation that eliminates functions as first-class values. We show that defunctionalization can be viewed as a type-preserving transformation of an extension of F with guarded algebraic data types into ...
Polymorphic typed defunctionalization
POPL '04: Proceedings of the 31st ACM SIGPLAN-SIGACT symposium on Principles of programming languagesDefunctionalization is a program transformation that aims to turn a higher-order functional program into a first-order one, that is, to eliminate the use of functions as first-class values. Its purpose is thus identical to that of closure conversion. It ...
Comments