1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss141_w.htm
2024-04-01 10:24:07 +02:00

148 lines
8.2 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Issue DYNAMIC-EXTENT-FUNCTION Writeup</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="../Issues/iss140_w.htm">
<LINK REL=UP HREF="../Issues/iss141.htm">
<LINK REL=NEXT HREF="../Issues/iss142_w.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="../Issues/iss140_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss141.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss142_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue DYNAMIC-EXTENT-FUNCTION Writeup</H2>
<PRE><B>Forum:</B> CLEANUP<P>
<B>Issue:</B> <A HREF="iss141.htm">DYNAMIC-EXTENT-FUNCTION</A><P>
<B>References:</B> Scope and Extent<P>
Issue <A REL=DEFINITION HREF="../Body/d_dynami.htm#dynamic-extent"><B>DYNAMIC-EXTENT</B></A><P>
<B>Category:</B> ADDITION<P>
<B>Edit history:</B> 04-Apr-89, Version 1 by Loosemore<P>
11-Jun-89, Version 2 by Loosemore<P>
<P>
<P>
<B>Problem Description:<P>
</B><P>
Proposal <A HREF="iss142.htm">DYNAMIC-EXTENT:NEW-DECLARATION</A>, passed at the March 89 <P>
meeting, provides a mechanism for declaring that the values of<P>
variables have only dynamic (rather than indefinite) extent. It<P>
would be useful to have similar functionality to indicate that<P>
functional bindings may have only dynamic extent. (For example,<P>
this would permit compilers to stack-allocate closures.)<P>
<P>
<B>Proposal (DYNAMIC-EXTENT-FUNCTION:EXTEND):<P>
</B><P>
Extend the <A REL=DEFINITION HREF="../Body/d_dynami.htm#dynamic-extent"><B>DYNAMIC-EXTENT</B></A> declaration to accept arguments that are<P>
lists of the form (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> &lt;name&gt;) where &lt;name&gt; is a function name,<P>
as well as symbols.<P>
<P>
A (<A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> &lt;name&gt;) list appearing in a <A REL=DEFINITION HREF="../Body/d_dynami.htm#dynamic-extent"><B>DYNAMIC-EXTENT</B></A> declaration is<P>
used to declare that the lexically visible functional binding of &lt;name&gt;<P>
has dynamic extent. Except for the interpretation of &lt;name&gt; as the<P>
name of a function instead of the name of a variable, such a declaration<P>
otherwise has semantics that are identical to those already described<P>
in proposal <A HREF="iss142.htm">DYNAMIC-EXTENT:NEW-DECLARATION</A>.<P>
<P>
<B>Rationale:<P>
</B><P>
This permits a programmer to offer advice to an implementation about<P>
what functions may be stack-allocated for efficiency.<P>
<P>
It may be difficult or impossible for a compiler to infer this<P>
same information statically.<P>
<P>
<B>Current Practice:<P>
</B><P>
JonL says that Lucid's compiler can stack-allocate closures, but they<P>
have no mechanism for programmers to give the compiler permission to<P>
do so.<P>
<P>
HPCL-I has an UPWARD-CLOSURES declaration that pervasively affects<P>
all closures created within the scope of the declaration.<P>
<P>
The Symbolics Genera compiler can often infer when functions can be <P>
implemented to have dynamic extent. Also, if a function has a<P>
SYS:DOWNWARD-FUNCTION declaration in front of its body, then the<P>
function is implemented with dynamic extent regardless of whether<P>
the compiler thinks all uses are &quot;downward&quot;. (This declaration is<P>
rather peculiar because its scope is actually larger than the <A REL=DEFINITION HREF="../Body/a_lambda.htm#lambda"><B>lambda</B></A><P>
expression containing the declaration; implementationally, it's the<P>
surrounding function definition.)<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
No cost is forced since implementations are permitted to simply<P>
ignore the <A REL=DEFINITION HREF="../Body/d_dynami.htm#dynamic-extent"><B>DYNAMIC-EXTENT</B></A> declaration. <P>
<P>
<B>Cost to Users:<P>
</B><P>
None. This change is upward compatible.<P>
<P>
There may be some hidden costs to debugging using this declaration (or any<P>
feature which permits the user to access dynamic extent objects without<P>
the compiler proving that they are appropriate). If the user misdeclares<P>
something and returns a pointer into the stack (or stores it in the heap),<P>
an undefined situation may result and the integrity of the Lisp storage<P>
mechanism may be compromised. Debugging these situations may be tricky,<P>
but users who have asked for this feature have indicated a willingness<P>
to deal with such costs. Nevertheless, the perils should be clearly<P>
documented and casual users should not be encouraged to use this<P>
declaration.<P>
<P>
<B>Cost of Non-Adoption:<P>
</B><P>
Some portable code would be forced to run more slowly (due to<P>
GC overhead), or to use non-portable language features.<P>
<P>
<B>Benefits:<P>
</B><P>
The cost of non-adoption is avoided.<P>
<P>
<B>Aesthetics:<P>
</B><P>
This declaration allows a fairly low level optimization to work<P>
by asking the user to <A REL=DEFINITION HREF="../Body/f_provid.htm#provide"><B>provide</B></A> only very high level information.<P>
The alternatives (sharpsign conditionals, some of which may<P>
lead to more bit-picky abstractions) are far less aesthetic.<P>
<P>
<B>Discussion:<P>
</B><P>
Loosemore supports <A HREF="iss141.htm">DYNAMIC-EXTENT-FUNCTION:EXTEND</A>.<P>
<P>
This proposal does not attempt to address the issue of specifying<P>
dynamic extent for anonymous closures (which is really a special case<P>
of the more general problem of specifying dynamic extent for unnamed<P>
objects of any type). It's possible, although often awkward, to<P>
restructure the program to give the object a name and explicitly<P>
identify its extent.<P>
<P>
One possible solution to the problem of dynamic extent for anonymous<P>
lambdas would be to clarify that a reference to a closed-over variable<P>
or function appearing lexically within a <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> form is enough to<P>
cause its value to be &quot;saved&quot; when the <A REL=DEFINITION HREF="../Body/a_fn.htm#function"><B>FUNCTION</B></A> form is executed,<P>
regardless of whether or not that reference is actually executed when<P>
the resulting function is called. Then, if all of the closed-over<P>
functions and variables referenced within a closure are declared to<P>
have dynamic extent, the closure could be assumed to have dynamic<P>
extent as well. (More precisely, its maximum extent would be the<P>
intersection of the extents of the closed-over functions and<P>
variables.)<P>
-------<P>
<P>
</PRE>
<HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>