Affiliation:
1. Massachusetts Institute of Technology, USA
2. Stanford University, USA
3. University of California at Berkeley, USA
Abstract
Higher-order functions pose a challenge for both static program analyses and optimizing compilers.
To simplify the analysis and compilation of languages with higher-order functions, a rich body of
prior work has proposed a variety of
defunctionalization
techniques, which can eliminate
higher-order functions from a program by transforming the program to a semantically-equivalent
first-order representation. Several modern languages take this a step further,
specializing
higher-order functions with respect to the functions on which they operate, and in turn allowing
compilers to generate more efficient code. However, existing specializing defunctionalization
techniques restrict how function values may be used, forcing implementations to fall back on costly
dynamic alternatives. We propose
lambda set specialization
(LSS), the first specializing
defunctionalization technique which imposes no restrictions on how function values may be used. We
formulate LSS in terms of a polymorphic type system which tracks the flow of function values through
the program, and use this type system to recast specialization of higher-order functions with
respect to their arguments as a form of type monomorphization. We show that our type system admits a
simple and tractable type inference algorithm, and give a formalization and fully-mechanized proof
in the Isabelle/HOL proof assistant showing soundness and completeness of the type inference
algorithm with respect to the type system. To show the benefits of LSS, we evaluate its impact on
the run time performance of code generated by the MLton compiler for Standard ML, the OCaml
compiler, and the new Morphic functional programming language. We find that pre-processing with LSS
achieves run time speedups of up to 6.85x under MLton, 3.45x for OCaml, and 78.93x for Morphic.
Publisher
Association for Computing Machinery (ACM)
Subject
Safety, Risk, Reliability and Quality,Software
Reference28 articles.
1. A modular, polyvariant and type-based closure analysis
2. Type-driven defunctionalization
3. Practical and effective higher-order optimizations
4. Julia: A Fresh Approach to Numerical Computing
5. William Brandon Benjamin Driscoll Frank Dai and Wilson Berkow. 2023. Morphic Research Language. https://morphic-lang.org [Online] William Brandon Benjamin Driscoll Frank Dai and Wilson Berkow. 2023. Morphic Research Language. https://morphic-lang.org [Online]