skip to main content
10.1145/3462172.3462193acmotherconferencesArticle/Chapter ViewAbstractPublication PagesiflConference Proceedingsconference-collections
research-article
Public Access

Type- and Control-Flow Directed Defunctionalization

Published: 23 July 2021 Publication History

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.

References

[1]
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.
[2]
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.
[3]
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.
[4]
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.
[5]
Jeffrey M. Bell, Françoise Bellegarde, and James Hook. 1997. Type-Driven Defunctionalization, See Tofte [30], 25–37.
[6]
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.
[7]
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.
[8]
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.
[9]
Arthur Charguéraud. 2012. The Locally Nameless Representation. Journal of Automated Reasoning 49, 3 (2012), 363–408.
[10]
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.
[11]
James Cheney and Ralf Hinze. 2003. First-class Phantom Types. Technical Report TR2003-1901. Cornell University, Ithaca, NY, USA.
[12]
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.
[13]
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.
[14]
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.
[15]
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.
[16]
Georgios Fourtounis, Nikolaos S. Papaspyrou, and Panagiotis Theofilopoulos. 2014. Modular Polymorphic Defunctionalization. Computer Science and Information Systems 11, 4 (2014), 1417–1434.
[17]
Kirsten L. Solberg Gasser, Flemming Nielson, and Hanne Riis Nielson. 1997. Systematic Realisation of Control Flow Analyses for CML, See Tofte [30], 38–51.
[18]
Ralf Hinze. 2003. Fun with Phantom Types. In The Fun of Programming, Jeremy Gibbons and Oege de Moor (Eds.). Palgrave Macmillan, 245–262.
[19]
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.
[20]
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.
[21]
Flemming Nielson, Hanne Riis Nielson, and Chris Hankin. 1999. Principles of Program Analysis. Springer-Verlag.
[22]
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.
[23]
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.
[24]
François Pottier and Nadji Gauthier. 2006. Polymorphic Typed Defunctionalization and Concretization. Higher-Order and Symbolic Computation 19, 1 (2006), 125–162.
[25]
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 [].
[26]
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.
[27]
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.
[28]
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.
[29]
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.
[30]
Mads Tofte (Ed.). 1997. ICFP’97: Proceedings of the Second ACM SIGPLAN International Conference on Functional Programming. Association for Computing Machinery, Amsterdam, The Netherlands.
[31]
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.
[32]
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.
[33]
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.
[34]
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.
[35]
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.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Other conferences
IFL '20: Proceedings of the 32nd Symposium on Implementation and Application of Functional Languages
September 2020
161 pages
ISBN:9781450389631
DOI:10.1145/3462172
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 23 July 2021

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. control-flow analysis
  2. defunctionalization
  3. type-flow analysis

Qualifiers

  • Research-article
  • Research
  • Refereed limited

Funding Sources

  • NSF

Conference

IFL 2020

Acceptance Rates

Overall Acceptance Rate 19 of 36 submissions, 53%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)109
  • Downloads (Last 6 weeks)23
Reflects downloads up to 12 Jan 2025

Other Metrics

Citations

Cited By

View all

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media