emacs.d/clones/lisp/HyperSpec-7-0/HyperSpec/Issues/iss007_w.htm
2023-01-18 20:30:47 +01:00

166 lines
12 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 ALLOW-LOCAL-INLINE 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/iss006_w.htm">
<LINK REL=UP HREF="../Issues/iss007.htm">
<LINK REL=NEXT HREF="../Issues/iss008_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/iss006_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss007.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss008_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue ALLOW-LOCAL-INLINE Writeup</H2>
<PRE><B>Forum:</B> Compiler<P>
<B>Issue:</B> <A HREF="iss007.htm">ALLOW-LOCAL-INLINE</A><P>
<B>References:</B> CLtL p. 156, 159<P>
Related issues: PROCLAIM-INLINE-WHERE<P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit History:</B> 21 Sept. 88 V1 by David Gray<P>
27 Oct. 88 V2 by David Gray - new proposal<P>
9 Nov. 88 V3 by David Gray - expanded problem<P>
description and discussion sections.<P>
30 Dec. 88 V4 by Sandra Loosemore -- suggestions from Pitman<P>
<P>
<B>Problem Description:<P>
</B><P>
The proposal PROCLAIM-INLINE-WHERE:BEFORE (which was accepted by X3J13<P>
on 10/12/88) clarifies the use of <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> proclamations, but there<P>
remains a similar problem with the use of a local (<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A><P>
...)): how can the compiler expand the function <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> if it didn't<P>
know that the necessary information should have been saved when the<P>
function was compiled?<P>
<P>
Note that an <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> proclamation does two things:<P>
<P>
(1) It tells the compiler to do extra things when it sees the<P>
function -definition-, to make it possible to code the function<P>
<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A>.<P>
<P>
(2) It tells the compiler to code -calls- to the function <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A>.<P>
<P>
In order for local <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> declarations to be useful, we need part 1<P>
without part 2.<P>
<P>
Proposal <A HREF="iss007.htm">ALLOW-LOCAL-INLINE:INLINE-NOTINLINE</A><P>
<P>
Clarify that to define a function FOO which is not <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> by default<P>
but for which (<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> FOO)) will make FOO be locally inlined,<P>
the proper definition sequence is:<P>
<P>
(<A REL=DEFINITION HREF="../Body/f_procla.htm#proclaim"><B>PROCLAIM</B></A> '(<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> foo))<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> foo ...)<P>
(<A REL=DEFINITION HREF="../Body/f_procla.htm#proclaim"><B>PROCLAIM</B></A> '(<A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A> foo))<P>
<P>
The <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> proclamation preceding the <A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> ensures that compiler will<P>
save the information necessary for <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> expansion, and the <A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A><P>
proclamation following the <A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>DEFUN</B></A> prevents it from being expanded<P>
<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> everywhere. <P>
<P>
Note that while implementations are never required to perform <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A><P>
expansion of function calls, many implementations that do support<P>
<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> expansion will not be able to respond to local <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> requests<P>
if this technique is not followed.<P>
<P>
Rationale:<P>
<P>
Local <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> declarations are of little use without some way of<P>
alerting the compiler to the possibility of <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> expansion before<P>
the function is compiled. This seems the simplest solution since it<P>
just clarifies existing practice instead of adding a new feature to<P>
the language.<P>
<P>
A compiler could use some heuristic to save the definitions of functions<P>
that are short enough to look like good candidates for <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> expansion,<P>
but then the user is never sure what to expect. It is possible that a<P>
compiler could simply save all definitions (assuming availability<P>
of adequate storage space) but we shouldn't <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> that.<P>
<P>
Test Cases/Examples: <P>
<P>
Given the following input to <A REL=DEFINITION HREF="../Body/f_cmp_fi.htm#compile-file"><B>COMPILE-FILE</B></A>, does F1 get expanded <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A><P>
in F2, and does F3 get expanded <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> in F4?<P>
<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> f1 (a) (+ a 100))<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> f2 (b) (<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>declare</B></A> (<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> f1)) (f1 b))<P>
(<A REL=DEFINITION HREF="../Body/f_procla.htm#proclaim"><B>proclaim</B></A> '(<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> f3))<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> f3 (a) (+ a 100))<P>
(<A REL=DEFINITION HREF="../Body/f_procla.htm#proclaim"><B>proclaim</B></A> '(<A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>notinline</B></A> f3))<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> f4 (b) (f3 b)) ;F3 is <A REL=DEFINITION HREF="../Body/a_not.htm#not"><B>not</B></A> <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A>.<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> f5 (c) (<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>declare</B></A> (<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> f3)) (f3 c)) ;F3 is <A REL=DEFINITION HREF="../Body/s_locall.htm#locally"><B>locally</B></A> <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A>.<P>
(<A REL=DEFINITION HREF="../Body/m_defun.htm#defun"><B>defun</B></A> f6 (c) (f3 c)) ;The local effect is <A REL=DEFINITION HREF="../Body/a_not.htm#not"><B>not</B></A> <P>
; persistent.<P>
<P>
Current Practice:<P>
<P>
In the example above, using Symbolics, Lucid, or Explorer, F1 is not<P>
expanded in F2, but F3 is expanded in F5.<P>
<P>
Cost to implementors:<P>
<P>
None, since this is a clarification in accordance with current<P>
practice.<P>
<P>
Cost to users:<P>
<P>
None.<P>
<P>
Benefits:<P>
<P>
Users will be able to use (<A REL=DEFINITION HREF="../Body/s_declar.htm#declare"><B>DECLARE</B></A> (<A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> ...)) with greater assurance<P>
that it will really do something.<P>
<P>
Costs of Non-Adoption: <P>
<P>
Users will not know how to reliably request <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> expansion on a<P>
local basis. This technique is not obvious, and even the need<P>
for it likely to be apparent only to people who understand something<P>
about how the compiler does <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> expansion.<P>
<P>
Discussion:<P>
<P>
Version 1 of this issue included proposal<P>
ALLOW-LOCAL-INLINE:PROCLAIM-ALLOW-INLINE to make an addition to the<P>
language:<P>
(<A REL=DEFINITION HREF="../Body/f_procla.htm#proclaim"><B>PROCLAIM</B></A> '(ALLOW-INLINE foo))<P>
This was met with a lack of enthusiasm since it was pointed out that<P>
the same effect could be obtained by using a combination of <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> and<P>
<A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A>.<P>
<P>
This is may not be completely true, however, since people's thinking<P>
about <A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A> has evolved in the direction of a declaration that<P>
tells the compiler &quot;assume nothing about this function&quot;. Thus, a<P>
<A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A> proclamation might suppress some optimizations that would<P>
have occurred if there had never been an <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> and <A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A>.<P>
<P>
Ideally, it would be nice to have multiple levels of control instead<P>
of just <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> or <A REL=DEFINITION HREF="../Body/d_inline.htm#notinline"><B>NOTINLINE</B></A> -- something like:<P>
* always <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A><P>
* maybe <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A> (let the compiler decide)<P>
* just save the definition for possible local <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A><P>
* default<P>
* never <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>inline</B></A><P>
<P>
Pitman has said that he generally approves of the direction of this<P>
proposal, but he has also expressed concerns about how the persistance<P>
of <A REL=DEFINITION HREF="../Body/d_inline.htm#inline"><B>INLINE</B></A> proclamations may cause confusion when functions are redefined<P>
in an incremental development environment.<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>