Next: Objectives
Up: First Year Plan of Optimisation
Previous: First Year Plan of Optimisation
Subsections
A number of optimisations and potential optimisations in lazy
functional languages relate to knowledge about the number of times a
value is accessed or used . While some significant work has
been done towards providing a theoretical framework for this notion,
it has yet to be applied to a real-world system. I propose in this
thesis to rectify the omission.
Turner, Wadler, and Mossin [TWM95a] identify three
potential optimisations based on usage information:
- Program transformation
or inlining : If a variable is accessed at most once then occurrences
of that variable may be replaced by the (inlined) expression bound to
that variable.
- Thunk update avoidance: If a thunk (suspension) is
accessed at most once then it need not be overwritten with its value
after it is evaluated.
- Update-in-place: If a data structure such as an array is
accessed at most once then that structure may safely be updated in
place rather than copied without violating referential transparency.
For example, consider the following code fragment
(we use here a generic Haskell-like [PH+97]
language):
let x = 1 + 2 in
let y = x + 3 in
y + y
Here we can replace x in the binding of y by 1+2, since x is
used only once (when y is demanded the first time). This enables us
to remove the outer let-binding altogether, potentially saving a
closure. However, we can not replace either occurrence of y
(or both) in the inner let with x+3, as this would result in the
addition being performed twice. A usage type system would note that
x is used once but y is used more than once, and thus permit
inlining of x but not y. This notion of the safety of a
transformation, i.e., that it is guaranteed not to duplicate work, is
introduced by Peyton Jones as
-safety [PJS97, §4.1].
As Turner et. al. go on to explain, usages cannot be
determined by a trivial syntactic analysis, despite first appearances.
Their paper goes on to present one solution to the problem.
Mogensen [Mog97] gives a related system that has
greater resolution with regard to data structures, and also differs in
other significant ways.
The papers describing these usage types contain statements such as the
following:
...[O]ur method provides a sound basis for a number of
transformations that were previously dealt with in an ad hoc manner in
the Glasgow Haskell compiler. [TWM95a]
But as yet, the method has not actually been applied in practice! In
a detailed discussion of the problem, alluding to
Turner et. al. 's solution, Peyton Jones states:
...[W]e have developed a linear type system that does take
account of call by need evaluation. ... Our implementation of this
linear type system is incomplete ... but we are optimistic that it
will provide a systematic way of addressing an area we have only dealt
with informally to date, and which has bitten us badly more than
once. [PJS97, §4.2]
This is the precise motivation for my thesis.
What little implementation has been done so far has been done only for
very tiny example languages. In the Glasgow FP spirit of ``theory
meets practice'', we wish to extend usage types to cover a real
functional language, and discover how they actually work in practice.
There are three parts to the thesis. First, I intend to construct a
usage type system for GHC's core language
and provide a usage-type inference algorithm for it. Second, I intend
to prove some formal properties of various optimising transformations
using the usage type information, demonstrating for example
-safety. Finally, I hope to demonstrate actual performance
benefits in real-world applications (or failing that, to show that
usage types do not provide significant benefits).
In the remainder of this paper I elaborate my objectives, consider
potential risks to the completion of this project, detail the
supervision arrangements, and give my plan of work for the immediate
future.
Next: Objectives
Up: First Year Plan of Optimisation
Previous: First Year Plan of Optimisation
Keith S. Wansbrough
1/9/1998