The Semantics of Future and Its Use in Program Optimization
Total Page:16
File Type:pdf, Size:1020Kb
The Semantics of Future and Its Use in Program Optimization Cormac Flanagan Matthias Felleisen Department of Computer Science Rice University Houston Texas Abstract pression had immediately returned Instead of a prop er value though it returns a placeholder When a program The future annotations of MultiLisp provide a simple op eration requires sp ecic knowledge ab out the value metho d for taming the implicit parallelism of functional of some subcomputation but nds a placeholder in its programs Past research concerning futures has fo cused place the runtime system p erforms a touch op eration on implementation issues In this pap er we present a se which synchronizes the appropriate parallel threads ries of op erational semantics for an idealized functional Past researchonfutures has almost exclusively con language with futures with varying degrees of inten centrated on the ecient implementation of the under sionality Wedevelop a setbased analysis algorithm lying task creation mechanism and from the most intensional semantics and use that al on the extension of the concept to rstclass continu gorithm to p erform touch optimization on programs ations In contrast the driving force b ehind Exp eriments with the Gambit compiler indicates that our eort is the desire to develop a semantic frame this optimization substantially reduces program execu work and semantically wellfounded optimizations for tion times languages with future The sp ecic example wecho ose to consider is the development of an algorithm for re moving provablyredundant touch op erations from pro Implicit Parallelism via Annotations grams Our primary results are a series of semantics for a functional language with futures and a program Programs in functional languages oer numerous opp or analysis The rst semantics denes future to b e a tunities for executing program comp onents in parallel semanticallytransparent annotation The second one In a callbyvalue language for example the evalua validates that a future expression interpreted as pro cess tion of every function application could spawn a par The last one is a lowlevel rene creation is correct allel thread for each subexpression However if sucha ment which explicates just enough information to p er strategy were applied indiscriminately the execution of mit the derivation of a setbased program analysis a program would generate far to o many parallel threads The secondary result is a touch optimization algorithm The overhead of managing these threads would clearly based on the analysis with its correctness pro of The outweigh any b enets from parallel execution algorithm was added to the Gambit Scheme compiler The future annotations of MultiLisp and its and pro duced signicant sp eedups on a standard set of Scheme successors provide a simple metho d for taming benchmarks the implicit parallelism of functional programs If a pro The presentation of our results pro ceeds as follows grammer b elieves that the parallel evaluation of some The second section intro duces an idealized functional expression out weighs the overhead of creating a sepa language with futures together with its denitional rate task he may annotate the expression with the key sequential semantics that interprets futures as noops word future An annotated functional program has the The third section presents an equivalent parallel seman same observable b ehavior as the original program but tics for futures and the fourth section contains the low the runtime system maycho ose to evaluate the future level renement of that semantics The fth section dis expression in parallel with the rest of the program If it cusses the cost of touch op erations and presents a prov do es the evaluation will pro ceed as if the annotated ex ably correct algorithm for eliminating unnecessary touch Supp orted in part by NSF grant CCR Texas ATP grant op erations The latter is based on the setbased analy and a sabbatical at Carnegie Mellon University sis algorithm of the sixth section The seventh section presents exp erimental results demonstrating the eec tiveness of this optimization Section eight discusses re To app ear in the nd Annual ACM SIGPLAN SIGACT Symp osium on Principles of Programming lated work For more details we refer the interested Languages San Francisco California January reader to two technical rep orts on this work If the argument is not a pair then the transition rule M x Terms a pro duces the state error j let xV M The rule for future pretends that future is the iden j let x future M M j let x car y M tity op eration It demands that the b o dy of a future j let x cdr y M expression is rst reduced to a value and then replaces j let x if yM M M the name for the future expression with this value j let x apply yz M The denition of the transition function relies on the V Value c j x j x M j cons xy Values notion of evaluation contextsAnevaluation context E x Vars fxyzg Variables c Const ftrue false g Constants is a term with a hole in place of the next subterm to be evaluated eg in the term let xM M the next Figure The Anormalized Language a subterm to b e evaluated is M andthus the denition of evaluation contexts includes let x E M Amachine state is a nal state if it is a value or the state error No transitions are p ossible from a nal AFunctional Language with Futures state and for any state that is not a nal state there is a unique transition step from that state to its succes Syntax Given the goal of developing a seman sor state This implies that the relation eval is a total tics that is useful for proving the soundness of opti c function Either the transition sequence for a program mizations wedevelop the denitional semantics for fu P terminates in a nal state in whichcaseeval P is tures for an intermediate representation of an idealized c an answer or error or else the transition sequence is functional language Sp ecicallywe use the subset of innite in which case eval P Since the evalua Anormal forms of an extended calculuslikelan c guage that includes conditionals and a future construct tics tor eval obviously agrees with the sequential seman c of the underlying functional language future is clearly see Figure The language also includes primitives for nothing but an annotation list manipulation which serve to illustrate the treatment of primitive op erations and an unsp ecied set of basic constants numb ers b o oleans AParallel Op erational Semantics The key prop erty of terms in Anormal form is that eachintermediate value is explicitly named and that The sequential C machine denes future as an anno the order of execution follows the lexical nesting of let tation and ignores the intension of future as an advi expressions The use of Anormal forms facilitates the sory instruction concerning parallel evaluation Toun compiletime analysis of programs and it simplies derstand this intensional asp ect of futurewe need a the denition of abstract machines semantics of future that mo dels the concurrentevalua Wework with the usual conventions and terminology tion of future expressions of the lamb da calculus when discussing syntactic issues In particular the substitution op eration M x V re The P C machine The state space of the P C places all free o ccurrences of x within M by V X de machine is dened in the rst part of Figure The notes the set of closed terms of typ e X terms values set of P C values includes the values of the sequen and M P denotes that the term M o ccurs in the pro tial C machine constants variables closures and pairs gram P Also we use the following notations through whichwe refer to as proper values To mo del futures the out the pap er P denotes the p owerset constructor P C machine also includes a new class of values called f A B denotes that f is a total function from placeholder variables A placeholder variable p repre A to B and f A B denotes that f is a partial p sents the result of a computation that is in progress function from A to B Once the computation terminates all o ccurrences of the placeholder are replaced by the value returned bythe Denitional Semantics The semantics of a computation is a function from closed programs to results A re ts a single thread of Each C machine state represen sult is either an answer whichisaclosedvalue with control To mo del parallel threads the P C machine all expressions replaced by procedureor error in includes additional states of the form flet pS S dicating that some program op eration was misapplied The primary substate S is initially the b o dy of a fu or if the program do es not terminate We sp ecify the ture expression and the secondary substate S is ini denitional semantics of the language using a sequential tially the evaluation context surrounding the future ex abstract machine called the C machine see Figure pression The placeholder p represents the result of S whose states are either closed terms over the runtime in S The usual conventions for binding constructs like language or else the sp ecial state error and whose c and let apply to flet The function FP returns the deterministic transition rules are the typical leftmost set of free placeholders in a state The evaluation of outermost reductions of the calculus Each transi S is mandatory since it is guaranteed to contribute to tion rule also sp ecies the error semantics of a particular the completion of the program The evaluation of S is class of expressions For example the transition rule for speculative since suchwork may not