mirror of
https://github.com/dhil/phd-dissertation
synced 2026-03-13 11:08:25 +00:00
Compare commits
2 Commits
326b1f1a50
...
a2e53135b3
| Author | SHA1 | Date | |
|---|---|---|---|
| a2e53135b3 | |||
| 7d4bf2224f |
45
thesis.bib
45
thesis.bib
@@ -74,6 +74,18 @@
|
|||||||
year = {1996}
|
year = {1996}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@article{KumarBD98,
|
||||||
|
author = {Sanjeev Kumar and
|
||||||
|
Carl Bruggeman and
|
||||||
|
R. Kent Dybvig},
|
||||||
|
title = {Threads Yield Continuations},
|
||||||
|
journal = {{LISP} Symb. Comput.},
|
||||||
|
volume = {10},
|
||||||
|
number = {3},
|
||||||
|
pages = {223--236},
|
||||||
|
year = {1998}
|
||||||
|
}
|
||||||
|
|
||||||
# Programming with continuations
|
# Programming with continuations
|
||||||
@InProceedings{FriedmanHK84,
|
@InProceedings{FriedmanHK84,
|
||||||
author = {Daniel P. Friedman
|
author = {Daniel P. Friedman
|
||||||
@@ -912,8 +924,6 @@
|
|||||||
year = {2000}
|
year = {2000}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# CPS for effect handlers
|
# CPS for effect handlers
|
||||||
@inproceedings{HillerstromLAS17,
|
@inproceedings{HillerstromLAS17,
|
||||||
author = {Daniel Hillerstr{\"{o}}m and
|
author = {Daniel Hillerstr{\"{o}}m and
|
||||||
@@ -953,6 +963,23 @@
|
|||||||
year = {2020}
|
year = {2020}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# SECD machine
|
||||||
|
@article{Landin64,
|
||||||
|
author = {Peter J. Landin},
|
||||||
|
title = {The Mechanical Evaluation of Expressions},
|
||||||
|
journal = {The Computer Journal},
|
||||||
|
volume = {6},
|
||||||
|
number = {4},
|
||||||
|
pages = {308-320},
|
||||||
|
year = {1964},
|
||||||
|
month = {01},
|
||||||
|
issn = {0010-4620},
|
||||||
|
OPTdoi = {10.1093/comjnl/6.4.308},
|
||||||
|
OPTurl = {https://doi.org/10.1093/comjnl/6.4.308},
|
||||||
|
OPTeprint = {https://academic.oup.com/comjnl/article-pdf/6/4/308/1067901/6-4-308.pdf},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# CEK & C
|
# CEK & C
|
||||||
@InProceedings{FelleisenF86,
|
@InProceedings{FelleisenF86,
|
||||||
title={Control Operators, the {SECD}-machine, and the $\lambda$-Calculus},
|
title={Control Operators, the {SECD}-machine, and the $\lambda$-Calculus},
|
||||||
@@ -2408,4 +2435,18 @@
|
|||||||
pages = {241--252},
|
pages = {241--252},
|
||||||
publisher = {{ACM}},
|
publisher = {{ACM}},
|
||||||
year = {1987}
|
year = {1987}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Stack copying technique without direct access to the stack.
|
||||||
|
@inproceedings{PettyjohnCMKF05,
|
||||||
|
author = {Greg Pettyjohn and
|
||||||
|
John Clements and
|
||||||
|
Joe Marshall and
|
||||||
|
Shriram Krishnamurthi and
|
||||||
|
Matthias Felleisen},
|
||||||
|
title = {Continuations from generalized stack inspection},
|
||||||
|
booktitle = {{ICFP}},
|
||||||
|
pages = {216--227},
|
||||||
|
publisher = {{ACM}},
|
||||||
|
year = {2005}
|
||||||
}
|
}
|
||||||
184
thesis.tex
184
thesis.tex
@@ -514,59 +514,68 @@ handlers.
|
|||||||
|
|
||||||
\chapter{Continuations}
|
\chapter{Continuations}
|
||||||
\label{ch:continuations}
|
\label{ch:continuations}
|
||||||
|
|
||||||
|
A continuation represents the remainder of computation at a given
|
||||||
|
point during evaluation. Continuations are one of those canonical
|
||||||
|
ideas, that have been discovered multiple times and whose definition
|
||||||
|
predates their use~\cite{Reynolds93}. The term `continuation' was
|
||||||
|
coined by \citet{StracheyW74}, who used continuations to give a
|
||||||
|
denotational semantics to programming languages with unrestricted
|
||||||
|
jumps~\cite{StracheyW00}.
|
||||||
|
|
||||||
% The significance of continuations in the programming languages
|
% The significance of continuations in the programming languages
|
||||||
% literature is inescapable as continuations have found widespread use .
|
% literature is inescapable as continuations have found widespread use .
|
||||||
%
|
%
|
||||||
|
|
||||||
A continuation is an abstract data structure that captures the
|
% A continuation is an abstract data structure that captures the
|
||||||
remainder of the computation from some given point in the computation.
|
% remainder of the computation from some given point in the computation.
|
||||||
%
|
% %
|
||||||
The exact nature of the data structure and the precise point at which
|
% The exact nature of the data structure and the precise point at which
|
||||||
the remainder of the computation is captured depends largely on the
|
% the remainder of the computation is captured depends largely on the
|
||||||
exact notion of continuation under consideration.
|
% exact notion of continuation under consideration.
|
||||||
%
|
% %
|
||||||
It can be difficult to navigate the existing literature on
|
% It can be difficult to navigate the existing literature on
|
||||||
continuations as sometimes the terminologies for different notions of
|
% continuations as sometimes the terminologies for different notions of
|
||||||
continuations are overloaded or even conflated.
|
% continuations are overloaded or even conflated.
|
||||||
%
|
% %
|
||||||
As there exist several notions of continuations, there exist several
|
% As there exist several notions of continuations, there exist several
|
||||||
mechanisms for programmatic manipulation of continuations. These
|
% mechanisms for programmatic manipulation of continuations. These
|
||||||
mechanisms are known as control operators.
|
% mechanisms are known as control operators.
|
||||||
%
|
% %
|
||||||
A substantial amount of existing literature has been devoted to
|
% A substantial amount of existing literature has been devoted to
|
||||||
understand how to program with individual control operators, and to a
|
% understand how to program with individual control operators, and to a
|
||||||
lesser extent how the various operators compare.
|
% lesser extent how the various operators compare.
|
||||||
|
|
||||||
The purpose of this chapter is to provide a contemporary and
|
% The purpose of this chapter is to provide a contemporary and
|
||||||
unambiguous characterisation of the notions of continuations in
|
% unambiguous characterisation of the notions of continuations in
|
||||||
literature. This characterisation is used to classify and discuss a
|
% literature. This characterisation is used to classify and discuss a
|
||||||
wide range of control operators from the literature.
|
% wide range of control operators from the literature.
|
||||||
|
|
||||||
% Undelimited control: Landin's J~\cite{Landin98}, Reynolds'
|
% % Undelimited control: Landin's J~\cite{Landin98}, Reynolds'
|
||||||
% escape~\cite{Reynolds98a}, Scheme75's catch~\cite{SussmanS75} ---
|
% % escape~\cite{Reynolds98a}, Scheme75's catch~\cite{SussmanS75} ---
|
||||||
% which was based the less expressive MacLisp catch~\cite{Moon74},
|
% % which was based the less expressive MacLisp catch~\cite{Moon74},
|
||||||
% callcc is a procedural variation of catch. It was invented in
|
% % callcc is a procedural variation of catch. It was invented in
|
||||||
% 1982~\cite{AbelsonHAKBOBPCRFRHSHW85}.
|
% % 1982~\cite{AbelsonHAKBOBPCRFRHSHW85}.
|
||||||
|
|
||||||
A full formal comparison of the control operators is out of scope of
|
% A full formal comparison of the control operators is out of scope of
|
||||||
this chapter. The literature contains comparisons of various control
|
% this chapter. The literature contains comparisons of various control
|
||||||
operators along various dimensions, e.g.
|
% operators along various dimensions, e.g.
|
||||||
%
|
% %
|
||||||
\citet{Thielecke02} studies a handful of operators via double
|
% \citet{Thielecke02} studies a handful of operators via double
|
||||||
barrelled continuation passing style. \citet{ForsterKLP19} compare the
|
% barrelled continuation passing style. \citet{ForsterKLP19} compare the
|
||||||
relative expressiveness of untyped and simply-typed variations of
|
% relative expressiveness of untyped and simply-typed variations of
|
||||||
effect handlers, shift/reset, and monadic reflection by means of
|
% effect handlers, shift/reset, and monadic reflection by means of
|
||||||
whether they are macro-expressible. Their work demonstrates that in an
|
% whether they are macro-expressible. Their work demonstrates that in an
|
||||||
untyped setting each operator is macro-expressible, but in most cases
|
% untyped setting each operator is macro-expressible, but in most cases
|
||||||
the macro-translations do not preserve typeability, for instance the
|
% the macro-translations do not preserve typeability, for instance the
|
||||||
simple type structure is insufficient to type the image of
|
% simple type structure is insufficient to type the image of
|
||||||
macro-translation between effect handlers and shift/reset.
|
% macro-translation between effect handlers and shift/reset.
|
||||||
%
|
% %
|
||||||
However, \citet{PirogPS19} show that with a polymorphic type system
|
% However, \citet{PirogPS19} show that with a polymorphic type system
|
||||||
the translation preserve typeability.
|
% the translation preserve typeability.
|
||||||
%
|
% %
|
||||||
\citet{Shan04} shows that dynamic delimited control and static
|
% \citet{Shan04} shows that dynamic delimited control and static
|
||||||
delimited control is macro-expressible in an untyped setting.
|
% delimited control is macro-expressible in an untyped setting.
|
||||||
|
|
||||||
\section{Classifying continuations}
|
\section{Classifying continuations}
|
||||||
|
|
||||||
@@ -2254,7 +2263,7 @@ implementation strategies.
|
|||||||
\hline
|
\hline
|
||||||
Effekt & Lexical effect handlers & ??\\
|
Effekt & Lexical effect handlers & ??\\
|
||||||
\hline
|
\hline
|
||||||
Frank & N-ary effect handlers & Abstract machine \\
|
Frank & N-ary effect handlers & CEK machine \\
|
||||||
\hline
|
\hline
|
||||||
Gauche & callcc, shift/reset & Virtual machine \\
|
Gauche & callcc, shift/reset & Virtual machine \\
|
||||||
\hline
|
\hline
|
||||||
@@ -2272,8 +2281,8 @@ implementation strategies.
|
|||||||
\hline
|
\hline
|
||||||
Racket & callcc, \textCallcomc{}, cupto, fcontrol, control/prompt, shift/reset, splitter, spawn & Segmented stacks\\
|
Racket & callcc, \textCallcomc{}, cupto, fcontrol, control/prompt, shift/reset, splitter, spawn & Segmented stacks\\
|
||||||
\hline
|
\hline
|
||||||
Rhino JavaScript & JI & Interpreter \\
|
% Rhino JavaScript & JI & Interpreter \\
|
||||||
\hline
|
% \hline
|
||||||
Scala & shift/reset & CPS\\
|
Scala & shift/reset & CPS\\
|
||||||
\hline
|
\hline
|
||||||
SML/NJ & callcc & CPS\\
|
SML/NJ & callcc & CPS\\
|
||||||
@@ -2339,24 +2348,70 @@ slight variation of segmented stacks optimised for one-shot
|
|||||||
continuations, which has been adapted by Multicore
|
continuations, which has been adapted by Multicore
|
||||||
OCaml~\cite{DolanEHMSW17}.
|
OCaml~\cite{DolanEHMSW17}.
|
||||||
|
|
||||||
\dhil{TODO: abstract machines}
|
Full stack copying and segmented stacks both depend on being able to
|
||||||
|
manipulate the stack directly. This is seldom possible if the language
|
||||||
Continuation passing style (CPS) is a particular idiomatic notation
|
implementer do not have control over the target runtime,
|
||||||
for programs, where every aspect of control flow is made explicit,
|
e.g. compilation to JavaScript. However, it is possible to emulate
|
||||||
which makes it a good fit for implementing control abstractions.
|
stack copying and segmented stacks in lieu of direct stack access. For
|
||||||
|
example, \citet{PettyjohnCMKF05} describe a technique that emulates
|
||||||
|
stack copying by piggybacking on the facile stack inception facility
|
||||||
|
provided by exception handlers in order to lazily reify the control
|
||||||
|
stack.
|
||||||
%
|
%
|
||||||
Using trampolines CPS is even a viable strategy in environments that
|
\citet{KumarBD98} emulated segmented stacks via threads. Each thread
|
||||||
lack proper tail calls such as JavaScript~\cite{GanzFW99}.
|
has its own local stack, and as such, a collection of threads
|
||||||
|
effectively models segmented stacks. To actually implement
|
||||||
|
continuations as threads \citeauthor{KumarBD98} also made use of
|
||||||
|
standard synchronisation primitives.
|
||||||
|
%
|
||||||
|
The advantage of these techniques is that they are generally
|
||||||
|
applicable and portable. The disadvantage is the performance overhead
|
||||||
|
induced by emulation.
|
||||||
|
|
||||||
% \paragraph{Continuation marks}
|
Abstract and virtual machines are a form of full machine emulation. An
|
||||||
|
abstract machine is an idealised machine. Abstract machines, such as
|
||||||
|
the CEK machine~\cite{FelleisenF86}, are attractive because they
|
||||||
|
provide a suitably high-level framework for defining language
|
||||||
|
semantics in terms of control string manipulations, whilst admitting a
|
||||||
|
direct implementation.
|
||||||
|
%
|
||||||
|
We will discuss abstract machines in more detail in
|
||||||
|
Chapter~\ref{ch:abstract-machine}.
|
||||||
|
%
|
||||||
|
The term virtual machine typically connotes an abstract machine that
|
||||||
|
works on a byte code representation of programs, whereas the default
|
||||||
|
connotation of abstract machine is a machine that works on a rich
|
||||||
|
abstract syntax tree representation of programs.
|
||||||
|
% \citeauthor{Landin64}'s SECD machine was the
|
||||||
|
% first abstract machine for evaluating $\lambda$-calculus
|
||||||
|
% terms~\cite{Landin64,Danvy04}.
|
||||||
|
%
|
||||||
|
% Either machine model has an explicit representation of the control
|
||||||
|
% state in terms of an environment and a control string. Thus either machine can to the
|
||||||
|
% interpretative overhead.
|
||||||
|
The disadvantage of abstract machines is their interpretative
|
||||||
|
overhead, although, techniques such as just-in-time compilation can be
|
||||||
|
utilised to reduce this overhead.
|
||||||
|
|
||||||
% \paragraph{Continuation passing style}
|
Continuation passing style (CPS) is a canonical implementation
|
||||||
|
strategy for continuations --- the word `continuation' even feature in
|
||||||
% \paragraph{Abstract and virtual machines}
|
its name.
|
||||||
|
%
|
||||||
% \paragraph{Segmented stacks}
|
CPS is a particular idiomatic notation for programs, where every
|
||||||
|
function takes an additional argument, the current continuation, as
|
||||||
% \paragraph{Stack copying}
|
input and every function call appears in tail position. Consequently,
|
||||||
|
every aspect of control flow is made explicit, which makes CPS a good
|
||||||
|
fit for implementing control abstraction. In classic CPS the
|
||||||
|
continuation argument is typically represented as a heap allocated
|
||||||
|
closure~\cite{Appel92}, however, as we shall see in
|
||||||
|
Chapter~\ref{ch:cps} richer representations of continuations are
|
||||||
|
possible.
|
||||||
|
%
|
||||||
|
At first thought it may seem that CPS will not work well in
|
||||||
|
environments that lack proper tail calls such as JavaScript. However,
|
||||||
|
the contrary is true, because the stackless nature of CPS means it can
|
||||||
|
readily be implemented with a trampoline~\cite{GanzFW99}. Alas, at the
|
||||||
|
cost of the indirection induced by the trampoline.
|
||||||
|
|
||||||
\part{Design}
|
\part{Design}
|
||||||
|
|
||||||
@@ -8391,6 +8446,7 @@ then in the image $\cps{M}\,k \reducesto^\ast k\,\cps{V}$.
|
|||||||
\paragraph{Partial evaluation}
|
\paragraph{Partial evaluation}
|
||||||
|
|
||||||
\chapter{Abstract machine semantics}
|
\chapter{Abstract machine semantics}
|
||||||
|
\label{ch:abstract-machine}
|
||||||
\dhil{The text is this chapter needs to be reworked}
|
\dhil{The text is this chapter needs to be reworked}
|
||||||
|
|
||||||
In this chapter we develop an abstract machine that supports deep and
|
In this chapter we develop an abstract machine that supports deep and
|
||||||
|
|||||||
Reference in New Issue
Block a user