Title:
|
Practicable Prolog specialisation
|
In software development an emphasis is placed on creating reusable general programs which solve a wide class of problems, however it is a struggle to balance generality with efficiency. Highly parameterised molecular code is reusable but suffers a penalty in terms of efficiency, in contrast carefully optimising the code by hand produces faster programs which are less general and have fewer opportunities for reuse. Partial evaluation is an automatic technique for program optimisation that optimises programs by exploiting known data. While partial evaluation is improving, the uptake by mainstream users is disappointing. The aim of this thesis is to make partial evaluation accessible to a wider audience. A basic partial evaluation algorithm is given and then extended to handle the features encountered in real life Prolog implementations including constraint logic programming, coroutining and non-declarative constructs. Offline partial evaluation methods rely on an annotated version of the source program to control the specialisation process. A graphical development environment for specialising logic programs is presented allowing users to create, visualise and modify their annotated source programs. An algorithm for automatically generating annotations is given using state of the art termination analysis, combined with type-based abstract interpretation for propagating the binding types. The algorithm has been fully implemented and we report on performance of the process on a series of benchmarks. In addition to an algorithm for generating a safe set of annotations we also investigate the generation of optimal annotations. A self-tuning system, which derives its own specialisation control for the particular Prolog compiler and architecture by trial and error is developed. The system balances the desire for faster code against code explosion and specialisation time. Additionally it is demonstrated that the developed partial evaluator is self-applicable. The attempts to self-apply partial evaluators for logic programs have, of yet, not been all that successful. Compared to earlier attempts, the system is effective and surprisingly simple. The power and efficiency of the implementation is evaluated using the specialisation of a series of non-trivial interpreters.
|