concept-compile.tex 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  1. % -*- Mode: TeX -*-
  2. %% Compilation
  3. % Rob MacLachlan wants some general discussion of inlining...
  4. %
  5. % The most general statement of what I think that NOTINLINE does is:
  6. % NOTINLINE inhibits any special-casing of calls to the named function.
  7. % NOTINLINE requires that the call be done as though there was a run-time
  8. % indirection through the SYMBOL-FUNCTION.
  9. %
  10. % In particular:
  11. % NOTINLINE inhibits the (otherwise legal) compile-time resolution of
  12. % function calls to the same DEFUN or defined in the same file. [This is
  13. % indeed explicitly allowed in the semantics of compilation.]
  14. %
  15. % Implementations should also be encouraged to suppress any sort of inline
  16. % coding when a function (+, CAR, whatever) is declared NOTINLINE. Although
  17. % users can't portably exploit this (due to the illegality of redefinition),
  18. % some facilities such as TRACE may benefit from this capability.
  19. %
  20. % Of course, it is possible that any of these actions are considered "inline
  21. % expansion". If so, there should at the very least be a glossary entry for
  22. % inline expansion explaining this rather odd interpretation.
  23. \def\sim#1#2#3{{\cal S}\sub{#1}(#2,#3)}
  24. %The nature of the processing performed during compilation is discussed
  25. %in \secref\CompilationSemantics. Following \secref\CompilationSemantics\ is
  26. %a discussion of the behavior of \funref{compile-file} and the
  27. %interface between \funref{compile-file} and \funref{load}.
  28. \beginsubSection{Compiler Terminology}
  29. \DefineSection{CompilationTerms}
  30. % Reference: Issue CONSTANT-COMPILABLE-TYPES
  31. The following terminology is used in this section.
  32. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  33. The \newterm{compiler} is a utility that translates code into an
  34. \term{implementation-dependent} form that might be represented or
  35. executed efficiently.
  36. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  37. The term \newterm{compiler} refers to both of the \term{functions}
  38. \funref{compile} and \funref{compile-file}.
  39. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  40. %In this section,
  41. The term \newterm{compiled code} refers to
  42. \term{objects} representing compiled programs, such as \term{objects} constructed
  43. by \funref{compile} or by \funref{load} when \term{loading} a \term{compiled file}.
  44. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  45. The term \newterm{implicit compilation} refers to \term{compilation}
  46. performed during \term{evaluation}.
  47. \DefineSection{ConstantModification}
  48. %!!! This needs to be revisited. -kmp 12-Mar-91
  49. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  50. The term \newterm{literal object} refers to
  51. a quoted \term{object}
  52. or a \term{self-evaluating object}
  53. or an \term{object} that is a substructure of such an \term{object}.
  54. %% The following info is not in the glossary. -kmp 27-Jul-93
  55. A \term{constant variable} is not itself a \term{literal object}.
  56. %% I believe this discussion belongs somewhere other than in this terminology
  57. %% section. I have added notes to the discussion of self-evaluating objects
  58. %% and QUOTE. --sjl 3 Mar 92
  59. % \issue{CONSTANT-MODIFICATION:DISALLOW}
  60. % The consequences are undefined if \term{literal objects} are destructively modified.
  61. % \endissue{CONSTANT-MODIFICATION:DISALLOW}
  62. %% \editornote{KMP: I don't think this is really right. I think that we said that
  63. %% it's ok to modify literal objects in code processed by COMPILE and EVAL. It's only
  64. %% literal objects in file compilation that are suspect, no?}
  65. %% \editornote{SJL: No, it's an error to modify any literal constant.}
  66. %% "constants" => "literal constants" per Moon#4(first public review) -kmp 5-May-93
  67. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  68. %% Note that there is more specific verbiage here than in Glossary.
  69. %% (The Glossary cross-references this section.)
  70. The term \newterm{coalesce} is defined as follows.
  71. Suppose \f{A} and \f{B} are two \term{literal constants} in the \term{source code},
  72. and that \f{A'} and \f{B'} are the corresponding \term{objects} in the \term{compiled code}.
  73. If \f{A'} and \f{B'} are \funref{eql} but
  74. \f{A} and \f{B} are not \funref{eql}, then it is said
  75. that \f{A} and \f{B} have been coalesced by the compiler.
  76. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  77. The term \newterm{minimal compilation} refers to actions the compiler
  78. must take at \term{compile time}. These actions are specified in
  79. \secref\CompilationSemantics.
  80. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  81. The verb \newterm{process} refers to performing \term{minimal compilation},
  82. determining the time of evaluation for a \term{form},
  83. and possibly \term{evaluating} that \term{form} (if required).
  84. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  85. The term \newterm{further compilation} refers to
  86. \term{implementation-dependent} compilation beyond \term{minimal compilation}.
  87. %% The next sentence doesn't appear in the Glossary. -kmp 27-Jul-93
  88. That is, \term{processing} does not imply complete compilation.
  89. Block compilation and generation of machine-specific instructions are
  90. examples of further compilation.
  91. Further compilation is permitted to take place at \term{run time}.
  92. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  93. Four different \term{environments} relevant to compilation are
  94. distinguished:
  95. the \term{startup environment},
  96. the \term{compilation environment},
  97. the \term{evaluation environment}, and
  98. the \term{run-time environment}.
  99. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  100. The \newterm{startup environment} is
  101. the \term{environment} of the \term{Lisp image}
  102. from which the \term{compiler} was invoked.
  103. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  104. %% This text is, however, much more verbose/detailed.
  105. The \newterm{compilation environment} is maintained by the compiler
  106. and is used to hold definitions and declarations to be used internally
  107. by the compiler. Only those parts of a definition needed for correct
  108. compilation are saved. The \term{compilation environment} is used
  109. as the \term{environment} \term{argument} to macro expanders called by
  110. the compiler. It is unspecified whether a definition available in the
  111. \term{compilation environment} can be used in an \term{evaluation}
  112. initiated in the \term{startup environment} or \term{evaluation environment}.
  113. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  114. The \newterm{evaluation environment} is a \term{run-time environment}
  115. in which macro expanders and code specified by \specref{eval-when}
  116. to be evaluated are evaluated. All evaluations initiated by the
  117. \term{compiler} take place in the \term{evaluation environment}.
  118. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  119. The \newterm{run-time environment} is the
  120. \term{environment} in which the program being compiled will be executed.
  121. %% This text is missing from, but not inconsistent with, the Glossary. -kmp 27-Jul-93
  122. The \term{compilation environment} inherits from
  123. the \term{evaluation environment},
  124. and the \term{compilation environment} and \term{evaluation environment}
  125. might be \term{identical}.
  126. The \term{evaluation environment} inherits from
  127. the \term{startup environment},
  128. and the \term{startup environment} and \term{evaluation environment}
  129. might be \term{identical}.
  130. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  131. The term \newterm{compile time} refers to the duration of time that
  132. the compiler is processing \term{source code}.
  133. At \term{compile time},
  134. only the \term{compilation environment}
  135. and the \term{evaluation environment}
  136. are available.
  137. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  138. The term \newterm{compile-time definition} refers to a definition in
  139. the \term{compilation environment}.
  140. For example, when compiling a file,
  141. the definition of a function might be retained in the \term{compilation environment}
  142. if it is declared \declref{inline}.
  143. This definition might not be available in the \term{evaluation environment}.
  144. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  145. The term \newterm{run time} refers to the duration of time that the
  146. loader is loading compiled code or compiled code is being executed.
  147. %% The following info is not in the glossary. -kmp 27-Jul-93
  148. At run time, only the \term{run-time environment} is available.
  149. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  150. The term \newterm{run-time definition} refers to a definition in the
  151. \term{run-time environment}.
  152. %% Checked to be consistent with glossary. -kmp 27-Jul-93
  153. The term \newterm{run-time compiler} refers to \thefunction{compile}
  154. or \term{implicit compilation}, for which the compilation and run-time
  155. \term{environments} are maintained in the same \term{Lisp image}.
  156. %% The following info is not in the glossary. -kmp 27-Jul-93
  157. Note that when the \term{run-time compiler} is used,
  158. the \term{run-time environment}
  159. and \term{startup environment}
  160. are the same.
  161. \endsubSection%{Compiler Terminology}
  162. \beginsubSection{Compilation Semantics}
  163. \DefineSection{CompilationSemantics}
  164. Conceptually, compilation is a process that traverses code, performs
  165. certain kinds of syntactic and semantic analyses using information
  166. (such as proclamations and \term{macro} definitions) present in the
  167. \term{compilation environment}, and produces equivalent, possibly
  168. more efficient code.
  169. \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  170. \beginsubsubsection{Compiler Macros}
  171. \DefineSection{CompilerMacros}
  172. A \term{compiler macro} can be defined for a \term{name}
  173. that also names a \term{function} or \term{macro}.
  174. %Given that we have to allow macros, it's too bad we can't just
  175. %say "any operator" in the previous. Why exclude special forms? -Barrett 13-Oct-91
  176. % Changed symbol => function name below; --sjl 3 Mar 92
  177. That is, it is possible for a
  178. \term{function name} to name both a \term{function} and a \term{compiler macro}.
  179. A \term{function name} names a \term{compiler macro} if \funref{compiler-macro-function}
  180. is \term{true} of the \term{function name} in the \term{lexical environment} in which
  181. it appears. Creating a \term{lexical binding} for the \term{function name}
  182. not only creates a new local \term{function} or
  183. \term{macro} definition, but also \term{shadows}\meaning{2} the \term{compiler macro}.
  184. The \term{function} returned by \funref{compiler-macro-function}
  185. is a \term{function} of two arguments, called the
  186. expansion function. To expand a \term{compiler macro},
  187. the expansion function is invoked by calling the \term{macroexpand hook} with
  188. the expansion function as its first argument,
  189. the entire compiler macro \term{form} as its second argument,
  190. and the current compilation \term{environment}
  191. (or with the current lexical \term{environment},
  192. if the \term{form} is being processed by something
  193. other than \funref{compile-file})
  194. as its third argument.
  195. The \term{macroexpand hook}, in turn, calls the expansion function with the
  196. \term{form} as its first argument and the \term{environment} as its second argument.
  197. The return value from the expansion function, which is passed through
  198. by the \term{macroexpand hook}, might either be the \term{same} \term{form},
  199. or else a form that can, at the discretion of the \term{code} doing the expansion,
  200. be used in place of the original \term{form}.
  201. \displaythree{Defined names applicable to compiler macros}{
  202. *macroexpand-hook*&compiler-macro-function&define-compiler-macro\cr
  203. }
  204. \beginsubsubsubsection{Purpose of Compiler Macros}
  205. The purpose of the \term{compiler macro} facility is to permit
  206. selective source code transformations as optimization advice
  207. to the \term{compiler}. When a \term{compound form} is being
  208. processed (as by the compiler), if the \term{operator} names a
  209. \term{compiler macro} then the \term{compiler macro function} may be
  210. invoked on the form, and the resulting expansion recursively processed
  211. in preference to performing the usual processing on the original \term{form}
  212. according to its normal interpretation as a \term{function form} or
  213. \term{macro form}.
  214. A \term{compiler macro function}, like a \term{macro function},
  215. is a \term{function} of two \term{arguments}: the entire call \term{form}
  216. and the \term{environment}. Unlike an ordinary \term{macro function}, a
  217. \term{compiler macro function} can decline to provide an expansion merely by
  218. returning a value that is the \term{same} as the original \term{form}.
  219. The consequences are undefined if a \term{compiler macro function}
  220. destructively modifies any part of its \term{form} argument.
  221. The \term{form} passed to the compiler macro function can either be a \term{list}
  222. whose \term{car} is the function name, or a \term{list} whose \term{car} is
  223. \funref{funcall} and whose \term{cadr} is a list \f{(function \param{name})};
  224. note that this affects destructuring of the form argument by the
  225. \term{compiler macro function}.
  226. \macref{define-compiler-macro} arranges for destructuring of arguments to be
  227. performed correctly for both possible formats.
  228. % Already explained in more detail in the previous section. -- sjl 3 Mar 92
  229. % When a \term{compiler macro function} is called as part of processing by the
  230. % evaluator or compiler, it is invoked by calling the \term{macroexpand hook}.
  231. When \funref{compile-file} chooses to expand a \term{top level form} that is
  232. a \term{compiler macro} \term{form}, the expansion is also treated as a \term{top level form}
  233. for the purposes of \specref{eval-when} processing; \seesection\TopLevelForms.
  234. %% Superfluous. -kmp
  235. %(just as would happen for the expansion of a \term{macro form}).
  236. \endsubsubsubsection%{Purpose of Compiler Macros}
  237. \beginsubsubsubsection{Naming of Compiler Macros}
  238. \term{Compiler macros} may be defined for \term{function names} that name
  239. \term{macros} as well as \term{functions}.
  240. %!!! Isn't this said elsewhere? Does it need to be repeated here? -kmp 1-Jun-91
  241. % Yes, it's in the packages chapter. --sjl 5 Mar 92
  242. % (It is not permitted to define
  243. % a \term{compiler macro} for a \term{name} that is an \term{external symbol} of
  244. % \thepackage{common-lisp}.)
  245. \term{Compiler macro} definitions are strictly global. There is no provision
  246. for defining local \term{compiler macros} in the way that \specref{macrolet}
  247. defines local \term{macros}. Lexical bindings of a function name shadow any
  248. compiler macro definition associated with the name as well as its
  249. global \term{function} or \term{macro} definition.
  250. Note that the presence of a compiler macro definition does not affect
  251. the values returned by
  252. \issue{SYNTACTIC-ENVIRONMENT-ACCESS:RETRACTED-MAR91}
  253. %by \macref{function-information}, or other accessors [sic]
  254. \endissue{SYNTACTIC-ENVIRONMENT-ACCESS:RETRACTED-MAR91}
  255. functions that access \term{function} definitions (\eg \funref{fboundp})
  256. or \term{macro} definitions (\eg \funref{macroexpand}).
  257. Compiler macros are global, and the function
  258. \funref{compiler-macro-function} is sufficient to resolve their interaction
  259. with other lexical and global definitions.
  260. \endsubsubsubsection%{Naming of Compiler Macros}
  261. \beginsubsubsubsection{When Compiler Macros Are Used}
  262. The presence of a \term{compiler macro} definition for a \term{function} or \term{macro}
  263. indicates that it is desirable for the \term{compiler} to use the expansion
  264. of the \term{compiler macro} instead of the original \term{function form} or
  265. \term{macro form}. However, no language processor
  266. (compiler, evaluator, or other code walker) is ever required to actually
  267. invoke \term{compiler macro functions}, or to
  268. make use of the resulting expansion if it does invoke
  269. a \term{compiler macro function}.
  270. When the \term{compiler} encounters a \term{form} during processing that represents
  271. a call to a \term{compiler macro} \term{name} (that is not declared \declref{notinline}),
  272. the \term{compiler} might expand the \term{compiler macro},
  273. and might use the expansion in place of the original \term{form}.
  274. When \funref{eval} encounters a \term{form} during processing that represents
  275. a call to a \term{compiler macro} \term{name} (that is not declared \declref{notinline}),
  276. \funref{eval} might expand the \term{compiler macro},
  277. and might use the expansion in place of the original \term{form}.
  278. There are two situations in which a \term{compiler macro} definition must not be
  279. applied by any language processor:
  280. \beginlist
  281. \itemitem{\bull}
  282. The global function name binding associated with the compiler
  283. macro is shadowed by a lexical binding of the function name.
  284. \itemitem{\bull}
  285. The function name has been declared or proclaimed \declref{notinline} and
  286. the call form appears within the scope of the declaration.
  287. \endlist
  288. It is unspecified whether \term{compiler macros} are expanded or used in any other
  289. situations.
  290. \beginsubsubsubsubsection{Notes about the Implementation of Compiler Macros}
  291. Although it is technically permissible, as described above,
  292. for \funref{eval} to treat \term{compiler macros} in the same situations
  293. as \term{compiler} might, this is not necessarily a good idea in
  294. \term{interpreted implementations}.
  295. \term{Compiler macros} exist for the purpose of trading compile-time speed
  296. for run-time speed. Programmers who write \term{compiler macros} tend to
  297. assume that the \term{compiler macros} can take more time than normal \term{functions}
  298. and \term{macros} in order to produce code which is especially optimal for use
  299. at run time. Since \funref{eval} in an \term{interpreted implementation}
  300. might perform semantic analysis of the same form multiple times, it might be
  301. inefficient in general for the \term{implementation} to choose to call
  302. \term{compiler macros} on every such \term{evaluation}.
  303. Nevertheless, the decision about what to do in these situations is left to
  304. each \term{implementation}.
  305. \endsubsubsubsubsection%{Notes about the Implementation of Compiler Macros}
  306. \endsubsubsubsection%{When Compiler Macros Are Used}
  307. \endsubsubsection%{Compiler Macros}
  308. \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  309. \beginsubsubsection{Minimal Compilation}
  310. \DefineSection{MinimalCompilation}
  311. % Fixed major problems in this section.
  312. % See proposal COMPILED-FUNCTION-REQUIREMENTS:TIGHTEN, item (1).
  313. % -- sjl 3 Mar 92
  314. \term{Minimal compilation} is defined as follows:
  315. \beginlist
  316. \issue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  317. %!!! This looks questionable. -kmp 11-Mar-91
  318. % This item is definitely wrong. I commented it out. -- sjl 3 Mar 92
  319. % \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  320. % \itemitem{\bull} All \term{compiler macro} calls appearing in the
  321. % source code being compiled are expanded at compile time in such a way
  322. % that they will not be expanded again at run time.
  323. % \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  324. %% Reinstated per X3J13 vote, with some clarifications. -kmp 7-Apr-92
  325. \itemitem{\bull} All \term{compiler macro}\idxterm{compiler macro} calls appearing in the
  326. \term{source code} being compiled are expanded, if at all, at compile time;
  327. they will not be expanded at run time.
  328. \endissue{KMP-COMMENTS-ON-SANDRA-COMMENTS:X3J13-MAR-92}
  329. % I made some minor wording changes to this paragraph. -- sjl 3 Mar 92
  330. \itemitem{\bull} All \term{macro}\idxterm{macro} and
  331. \term{symbol macro}\idxterm{symbol macro} calls
  332. appearing in the source code being compiled are expanded at compile time
  333. in such a way that they will not be expanded again at run time.
  334. \specref{macrolet}\idxref{macrolet}
  335. and
  336. \specref{symbol-macrolet}\idxref{symbol-macrolet}
  337. are effectively replaced by
  338. \term{forms} corresponding to their bodies in which calls to
  339. \term{macros} are replaced by their expansions.
  340. % I made some minor wording changes to this paragraph. -- sjl 3 Mar 92
  341. \itemitem{\bull}
  342. The first \term{argument} in a \specref{load-time-value}\idxref{load-time-value}
  343. \term{form}
  344. in \term{source code} processed by \funref{compile}\idxref{compile}
  345. is \term{evaluated} at \term{compile time};
  346. in \term{source code} processed by \funref{compile-file}\idxref{compile-file},
  347. the compiler arranges for it to be \term{evaluated} at \term{load time}.
  348. In either case, the result of the \term{evaluation}
  349. is remembered and used later as the value of the
  350. \specref{load-time-value} \term{form} at \term{execution time}.
  351. % I think the previous paragraph was supposed to replace this one, not
  352. % augment it. It adds nothing but confusion. -- sjl 3 Mar 92
  353. % \specref{load-time-value} forms in the source code will be evaluated
  354. % at compile time when compiled by \funref{compile} or at load time
  355. % when compiled by \funref{compile-file}, and the result of
  356. % evaluation will be used as a constant at run time.
  357. \endlist
  358. \endsubsubsection%{Minimal Compilation}
  359. \beginsubsubsection{Semantic Constraints}
  360. \DefineSection{SemanticConstraints}
  361. %% Removed per Dalton #1 (first public review). -kmp 10-May-93
  362. % % Fixed some garbled language in this section.
  363. % % See proposal COMPILE-ENVIRONMENT-CONSISTENCY:CLARIFY.
  364. % % -- sjl 3 Mar 92
  365. %
  366. % Conforming code must be structured so that its results and observable
  367. % side effects are the same whether or not compilation takes place.
  368. %
  369. % Additional constraints about the consistency of the compilation and
  370. % run-time \term{environments} imply additional semantic constraints on
  371. % conforming programs. Conforming programs obeying these constraints
  372. % have the same behavior whether evaluated or compiled.
  373. %
  374. % The following are the semantic constraints:
  375. %% and replaced with:
  376. All \term{conforming programs} must obey the following constraints,
  377. which are designed to minimize the observable differences
  378. between compiled and interpreted programs:
  379. \beginlist
  380. % This entire item seems to have gotten totally garbled. See replacement
  381. % text below. -- sjl 3 Mar 92
  382. % \itemitem{\bull} Any \term{form} that is a \term{list}
  383. % beginning with a \term{symbol} that does not name a
  384. % \term{special form},
  385. % %%This is questionable. -kmp 11-Mar-91
  386. % %%Moon and Barrett thought so, too. Removed. -kmp 13-Oct-91
  387. % % \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  388. % % a \term{compiler macro},
  389. % % \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  390. % or a \term{macro}
  391. % defined in the compilation environment is a function call.
  392. % \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  393. % (This implies that \term{setf expanders} must be available at compile time.)
  394. % \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  395. \itemitem{\bull} Definitions of any referenced \term{macros}
  396. must be present in the \term{compilation environment}.
  397. Any \term{form} that is a \term{list}
  398. beginning with a \term{symbol} that does not name a
  399. \term{special operator} or a \term{macro} defined in the
  400. \term{compilation environment} is treated by the compiler as a
  401. function call.
  402. % This garbled item also replaced. -- sjl 3 Mar 92
  403. % \itemitem{\bull} Any binding of a \term{variable} not declared
  404. % \declref{special} is a lexical binding.
  405. \itemitem{\bull} \declref{Special} proclamations for \term{dynamic variables}
  406. must be made in the \term{compilation environment}. Any \term{binding}
  407. for which there is no \declref{special} declaration or proclamation in
  408. the \term{compilation environment} is treated by the compiler as
  409. a \term{lexical binding}.
  410. % Minor rewording. -- sjl 3 Mar 92.
  411. \itemitem{\bull} The definition of a function that is defined and
  412. declared \declref{inline} in the \term{compilation environment} must be
  413. the same at run time.
  414. %% Barrett didn't like this. The paragraph that follows is a negotiated rewrite to clarify.
  415. %% -kmp 13-Oct-91
  416. % \itemitem{\bull} Within a named function $F$, a recursive call to $F$
  417. % refers to $F$, unless that function has been declared \declref{notinline}.
  418. \itemitem{\bull} Within a \term{function} named $F$, the compiler may
  419. (but is not required to)
  420. assume that an apparent recursive call to a \term{function} named $F$
  421. refers to the same definition of $F$,
  422. unless that function has been declared \declref{notinline}.
  423. The consequences of redefining such a recursively defined \term{function} $F$
  424. while it is executing are undefined.
  425. \itemitem{\bull} A call within a file to a named function that is
  426. defined in the same file refers to that function, unless that function
  427. has been declared \declref{notinline}. The consequences are unspecified
  428. if functions are redefined individually at run time or multiply
  429. defined in the same file.
  430. % I believe this item has been made unnecessary by issue
  431. % LISP-SYMBOL-REDEFINITION. -- sjl 3 Mar 92
  432. % \itemitem{\bull} A call to a built-in Common Lisp function refers to
  433. %that function. Any built-in \clisp\ function might be proclaimed \declref{inline}.
  434. \itemitem{\bull} The argument syntax and number of return values for
  435. all functions whose \declref{ftype} is declared at compile time must
  436. remain the same at run time.
  437. % Reference: CLtL page 69
  438. %"same" => "similar" per Moon
  439. \itemitem{\bull} \term{Constant variables} defined in
  440. the \term{compilation environment} must have a \term{similar} value at
  441. run time. A reference to
  442. %the name of a constant
  443. a \term{constant variable}
  444. in \term{source code} is equivalent to a reference to
  445. %an \term{object} \funref{eql} to
  446. a \term{literal} \term{object} that is the \term{value} of the \term{constant variable}.
  447. % The following paragraph from issue COMPILE-ENVIRONMENT-CONSISTENCY
  448. % seems likely to change:
  449. % No, we later voted down the proposal to change it. -- sjl 3 Mar 92
  450. \itemitem{\bull} Type definitions made with \macref{deftype} or
  451. \macref{defstruct} in the \term{compilation environment} must
  452. retain the same definition at run time. Classes defined by \macref{defclass}
  453. in the \term{compilation environment} must be defined
  454. at run time to have the same \term{superclasses} and same
  455. \term{metaclass}.
  456. This implies that \term{subtype}/\term{supertype} relationships of
  457. \term{type specifiers} must not change between \term{compile time} and \term{run time}.
  458. % Ref: CLtL page 153
  459. \itemitem{\bull} Type declarations present in the compilation
  460. \term{environment} must accurately describe the corresponding values at run time;
  461. otherwise, the consequences are undefined. It is permissible
  462. for an unknown \term{type} to appear in a declaration at
  463. compile time, though a warning might be signaled in such a case.
  464. \itemitem{\bull} Except in the situations explicitly listed above, a
  465. \term{function} defined in the \term{evaluation environment}
  466. is permitted to have a different definition or a different \term{signature}
  467. at run time, and the run-time definition prevails.
  468. \endlist
  469. \term{Conforming programs} should not be written using any additional
  470. assumptions about consistency between the run-time
  471. \term{environment} and the startup, evaluation, and compilation
  472. \term{environments}.
  473. Except where noted, when a compile-time and a run-time definition are
  474. different, one of the following occurs at run time:
  475. \beginlist
  476. \item{\bull} an error \oftype{error} is signaled
  477. \item{\bull} the compile-time definition prevails
  478. \item{\bull} the run-time definition prevails
  479. \endlist
  480. If the \term{compiler} processes a \term{function form} whose \term{operator}
  481. is not defined at compile time, no error is signaled at compile time.
  482. \endsubsubsection%{Semantic Constraints}
  483. \endsubSection%{Compilation Semantics}
  484. \beginsubSection{File Compilation}
  485. \DefineSection{FileCompilation}
  486. \Thefunction{compile-file} performs compilation of
  487. \term{forms} in a file following the rules specified in \secref\CompilationSemantics,
  488. and produces an output file that can be loaded by using \funref{load}.
  489. Normally, the \term{top level forms} appearing in a file compiled with
  490. \funref{compile-file} are evaluated only when the resulting
  491. compiled file is loaded, and not when the file is compiled. However,
  492. % the use of ``must'' is problematic here --sjl 7 Mar 92
  493. %some forms in the file must be evaluated at compile time so the
  494. it is typically the case that some forms in the file need to be evaluated
  495. at compile time so the
  496. remainder of the file can be read and compiled correctly.
  497. \Thespecform{eval-when} can be used to control
  498. whether a \term{top level form} is evaluated at compile time, load
  499. time, or both. It is possible to specify any of three situations with
  500. \specref{eval-when}, denoted by the symbols \kwd{compile-toplevel},
  501. \kwd{load-toplevel}, and \kwd{execute}. For top level
  502. \specref{eval-when} forms, \kwd{compile-toplevel} specifies that the
  503. compiler must evaluate the body at compile time, and {\tt
  504. :load-toplevel} specifies that the compiler must arrange to evaluate
  505. the body at load time. For non-top level \specref{eval-when} forms,
  506. \kwd{execute} specifies that the body must be executed in the run-time
  507. \term{environment}.
  508. The behavior of this \term{form} can be more precisely understood in
  509. terms of a model of how \funref{compile-file} processes forms in
  510. a file to be compiled. There are two processing modes, called
  511. ``not-compile-time'' and ``compile-time-too''.
  512. Successive forms are read from the file by \funref{compile-file}
  513. and processed in not-compile-time mode; in this mode,
  514. \funref{compile-file} arranges for forms to be evaluated only at load time
  515. and not at compile time. When \funref{compile-file} is in
  516. compile-time-too mode, forms are evaluated both at compile time and
  517. load time.
  518. \beginsubsubsection{Processing of Top Level Forms}
  519. \DefineSection{TopLevelForms}
  520. Processing of \term{top level forms} in the file compiler is defined
  521. as follows:
  522. \beginlist
  523. \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  524. \itemitem{1.} If the \term{form} is a \term{compiler macro form}
  525. (not disabled by a \declref{notinline} \term{declaration}),
  526. % Not clear what ``expand'' means here. --sjl 7 Mar 92
  527. %the \term{implementation} might or might not choose to expand the \term{form} and,
  528. the \term{implementation} might or might not choose to compute
  529. the \term{compiler macro expansion} of the \term{form} and,
  530. having performed the expansion, might or might not choose to process the result
  531. as a \term{top level form} in the same processing mode
  532. (compile-time-too or not-compile-time).
  533. %% Added for Moon. -kmp 16-Feb-92
  534. If it declines to obtain or use the expansion, it must process the original \term{form}.
  535. \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  536. \itemitem{2.} If the form is a \term{macro form},
  537. %% Probably better to do without this. -kmp,kab 13-Oct-91
  538. % \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  539. % (and was not processed as a \term{compiler macro}),
  540. % \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  541. % Not clear what ``expand'' means here. --sjl 7 Mar 92
  542. %it is expanded and the result is processed as a \term{top level form} in
  543. its \term{macro expansion} is computed and processed as a
  544. \term{top level form} in
  545. the same processing mode (compile-time-too or not-compile-time).
  546. \itemitem{3.} If the form is a \specref{progn} form, each of its
  547. body \term{forms} is sequentially processed as a
  548. \term{top level form} in the same processing mode.
  549. \itemitem{4.} If the form is a \specref{locally},
  550. \specref{macrolet}, or \specref{symbol-macrolet},
  551. \funref{compile-file} establishes the appropriate bindings and processes the
  552. body forms as \term{top level forms} with those bindings in effect
  553. in the same processing mode. (Note that this implies that the lexical
  554. \term{environment} in which \term{top level forms} are processed
  555. is not necessarily the \term{null lexical environment}.)
  556. \itemitem{5.} If the form is an \specref{eval-when}\idxref{eval-when} form, it is
  557. handled according to \thenextfigure.
  558. \boxfig
  559. {\dimen0=.75pc
  560. \tabskip \dimen0 plus .5 fil
  561. \offinterlineskip
  562. \halign to \hsize {\strut#\hfil\tabskip \dimen0 plus 1fil&#\hfil\tabskip
  563. \dimen0 plus .5 fil&#\hfil\tabskip \dimen0 plus 1fil&#\hfil\tabskip \dimen0 plus 1fil
  564. &#\hfil&#\hfil&#\hfil\cr
  565. \noalign{\vskip -11pt}
  566. \hfil\b{CT} &\hfil\b{LT} &\hfil\b{E} &\hfil\b{Mode}&\hfil\b{Action}&\hfil\b{New Mode}\cr
  567. \noalign{\hrule}
  568. Yes&Yes&\hfil---&\hfil---&Process&compile-time-too\cr
  569. No&Yes&Yes&\hfil CTT&Process&compile-time-too\cr
  570. No&Yes&Yes&\hfil NCT&Process&not-compile-time\cr
  571. No&Yes&No&\hfil---&Process&not-compile-time\cr
  572. Yes&No&\hfil---&\hfil---&Evaluate&\hfil---\cr
  573. No&No&Yes&\hfil CTT&Evaluate&\hfil---\cr
  574. No&No&Yes&\hfil NCT&Discard&\hfil---\cr
  575. No&No&No&\hfil---&Discard&\hfil---\cr
  576. \noalign{\vskip -9pt}
  577. }}
  578. \caption{EVAL-WHEN processing}
  579. \endfig
  580. Column \b{CT} indicates whether \kwd{compile-toplevel} is specified.
  581. Column \b{LT} indicates whether \kwd{load-toplevel} is specified.
  582. Column \b{E} indicates whether \kwd{execute} is specified.
  583. Column \b{Mode} indicates the processing mode;
  584. a dash (---) indicates that the processing mode is not relevant.
  585. The \b{Action} column specifies one of three actions:
  586. \beginlist
  587. \item{}\b{Process:} process the body as \term{top level forms} in the
  588. specified mode.
  589. \item{}\b{Evaluate:} evaluate the body in the dynamic execution
  590. context of the compiler, using the \term{evaluation environment} as
  591. the global environment and the \term{lexical environment} in which
  592. the \specref{eval-when} appears.
  593. \item{}\b{Discard:} ignore the \term{form}.
  594. \endlist
  595. The \b{New Mode} column indicates the new processing mode.
  596. A dash (---) indicates the compiler remains in its current mode.
  597. \itemitem{6.} Otherwise, the form is a \term{top level form} that
  598. is not one of the special cases. In compile-time-too mode, the
  599. compiler first evaluates the form in the evaluation
  600. \term{environment} and then minimally compiles it. In not-compile-time
  601. mode, the \term{form} is simply minimally compiled. All \term{subforms}
  602. are treated as \term{non-top-level forms}.
  603. Note that \term{top level forms} are processed in the order in
  604. which they textually appear in the file and that each
  605. \term{top level form} read by the compiler is processed before the next is
  606. read. However, the order of processing (including macro expansion) of
  607. \term{subforms} that are not \term{top level forms} and the order of
  608. further compilation is unspecified as long as Common Lisp semantics
  609. are preserved.
  610. \endlist
  611. \specref{eval-when} forms cause compile-time evaluation only at
  612. top level. Both \kwd{compile-toplevel} and \kwd{load-toplevel} situation specifications
  613. are ignored for \term{non-top-level forms}. For \term{non-top-level forms},
  614. an \specref{eval-when}
  615. specifying the \kwd{execute} situation is treated as an \term{implicit progn}
  616. including the \term{forms} in the body of the \specref{eval-when} \term{form};
  617. otherwise, the \term{forms} in the body are ignored.
  618. \beginsubsubsubsection{Processing of Defining Macros}
  619. \DefineSection{DefiningMacros}
  620. % The material below was in its own section (3.2.6), but I think it
  621. % logically belongs here. --sjl 3 Mar 92
  622. \issue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  623. Defining \term{macros} (such as \macref{defmacro} or \macref{defvar})
  624. appearing within a file being processed by \funref{compile-file}
  625. normally have compile-time side effects which affect how subsequent \term{forms}
  626. in the same \term{file} are compiled. A convenient model for explaining how these
  627. side effects happen is that the defining macro expands into one or
  628. more \specref{eval-when} \term{forms}, and that the calls which cause the compile-time
  629. side effects to happen appear
  630. in the body of an \f{(eval-when (:compile-toplevel) ...)} \term{form}.
  631. %RPG: What does this mean and is it worth saying?
  632. %Sandra: I think it's fairly important for this information to remain,
  633. % since it's what licenses implementations to use what we've been calling
  634. % "remote environments" to keep track of compile-time definitions.
  635. %KAB: I agree.
  636. The compile-time side effects may cause information about the definition to
  637. be stored differently than if the defining macro had been processed in the
  638. `normal' way (either interpretively or by loading the compiled file).
  639. In particular, the information stored by the defining \term{macros} at compile time
  640. might or might not be available to the interpreter (either during or after compilation),
  641. or during subsequent calls to the \term{compiler}. For example,
  642. the following code is nonportable because it assumes that the \term{compiler}
  643. stores the macro definition of \f{foo} where it is available to the interpreter:
  644. \code
  645. (defmacro foo (x) `(car ,x))
  646. (eval-when (:execute :compile-toplevel :load-toplevel)
  647. (print (foo '(a b c))))
  648. \endcode
  649. A portable way to do the same thing would be to include the macro
  650. definition inside the \specref{eval-when} \term{form}, as in:
  651. \code
  652. (eval-when (:execute :compile-toplevel :load-toplevel)
  653. (defmacro foo (x) `(car ,x))
  654. (print (foo '(a b c))))
  655. \endcode
  656. \endissue{COMPILE-FILE-HANDLING-OF-TOP-LEVEL-FORMS:CLARIFY}
  657. % end of moved material.
  658. \Thenextfigure\ lists macros that make definitions
  659. available both in the compilation and run-time \term{environments}.
  660. It is not specified whether definitions made available in the
  661. \term{compilation environment} are available in the evaluation
  662. \term{environment}, nor is it specified whether they are available
  663. in subsequent compilation units or subsequent invocations of the
  664. compiler. As with \specref{eval-when}, these compile-time side
  665. effects happen only when the defining macros appear at
  666. top level.
  667. \issue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  668. \issue{PROCLAIM-ETC-IN-COMPILE-FILE:NEW-MACRO}
  669. \issue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  670. \issue{CLOS-MACRO-COMPILATION:MINIMAL}
  671. % Removed DEFGENERIC, DEFINE-METHOD-COMBINATION, and DEFMETHOD for KAB.
  672. % He says they "might" but don't have to. -kmp 8-Feb-92
  673. \displaythree{Defining Macros That Affect the Compile-Time Environment}{
  674. declaim&define-modify-macro&defsetf\cr
  675. defclass&define-setf-expander&defstruct\cr
  676. defconstant&defmacro&deftype\cr
  677. define-compiler-macro&defpackage&defvar\cr
  678. define-condition&defparameter&\cr
  679. }
  680. \endissue{CLOS-MACRO-COMPILATION:MINIMAL}
  681. \endissue{DEFINE-COMPILER-MACRO:X3J13-NOV89}
  682. \endissue{PROCLAIM-ETC-IN-COMPILE-FILE:NEW-MACRO}
  683. \endissue{SETF-METHOD-VS-SETF-METHOD:RENAME-OLD-TERMS}
  684. \endsubsubsubsection%{Processing of Defining Macros}
  685. \beginsubsubsubsection{Constraints on Macros and Compiler Macros}
  686. \DefineSection{ConstraintsOnMacros}
  687. % Fixed major omission -- issue MACRO-SUBFORMS-TOP-LEVEL-P had not
  688. % been incorporated into the document yet. --sjl 3 Mar 92
  689. \issue{MACRO-SUBFORMS-TOP-LEVEL-P:ADD-CONSTRAINTS}
  690. Except where explicitly stated otherwise, no \term{macro} defined in
  691. the \clisp\ standard produces an expansion that could cause any of the
  692. \term{subforms} of the \term{macro form} to be treated as
  693. \term{top level forms}. If an \term{implementation} also provides a
  694. \term{special operator} definition of a \clisp\ \term{macro},
  695. the \term{special operator} definition must be semantically equivalent
  696. in this respect.
  697. \term{Compiler macro} expansions must also have the same
  698. top level evaluation semantics as the \term{form} which they replace.
  699. This is of concern both to \term{conforming implementations} and to
  700. \term{conforming programs}.
  701. \endissue{MACRO-SUBFORMS-TOP-LEVEL-P:ADD-CONSTRAINTS}
  702. \endsubsubsubsection%{Constraints on Macros and Compiler Macros}
  703. \endsubsubsection%{Processing of Top Level Forms}
  704. \endsubSection%{File Compilation}
  705. %% Moon thought this section was stupid and wanted it moved into next section.
  706. % \beginsubSection{Compiler/Loader Interface}
  707. % % Reference: Issue QUOTE-SEMANTICS
  708. %
  709. %
  710. % \endsubSection%{Compiler/Loader Interface}
  711. \beginsubSection{Literal Objects in Compiled Files}
  712. \DefineSection{LiteralsInCompiledFiles}
  713. % Reference: Issue QUOTE-SEMANTICS
  714. %"constants" => "literal objects" per Moon #4(first public review) --kmp 5-May-93
  715. The functions \funref{eval} and \funref{compile} are
  716. required to ensure that \term{literal objects} referenced within the resulting
  717. interpreted or compiled code objects are the \term{same} as the
  718. corresponding \term{objects} in the \term{source code}.
  719. \funref{compile-file}, on the other hand,
  720. must produce a \term{compiled file} that, when loaded with
  721. \funref{load}, constructs the \term{objects} defined by the
  722. \term{source code} and produces references to them.
  723. In the case of \funref{compile-file}, \term{objects}
  724. constructed by \funref{load} of the \term{compiled file} cannot be spoken
  725. of as being the \term{same} as the \term{objects} constructed at
  726. compile time, because the \term{compiled file} may be loaded into a different
  727. \term{Lisp image} than the one in which it was compiled. This section
  728. defines the concept of \term{similarity} which relates
  729. \term{objects} in the \term{evaluation environment} to the
  730. corresponding \term{objects} in the \term{run-time environment}.
  731. The constraints on \term{literal objects} described in this section
  732. apply only to \funref{compile-file};
  733. \funref{eval} and \funref{compile} do not copy or coalesce constants.
  734. \beginsubsubsection{Externalizable Objects}
  735. \DefineSection{ExternalizableObjects}
  736. \issue{CONSTANT-COMPILABLE-TYPES:SPECIFY}
  737. The fact that the \term{file compiler} represents \term{literal} \term{objects}
  738. externally in a \term{compiled file} and must later reconstruct suitable
  739. equivalents of those \term{objects} when that \term{file} is loaded
  740. imposes a need for constraints on the nature of the \term{objects} that can be
  741. used as \term{literal} \term{objects} in \term{code} to be processed
  742. by the \term{file compiler}.
  743. An \term{object} that can be used as a \term{literal} \term{object}
  744. in \term{code} to be processed by the \term{file compiler} is called an
  745. \newterm{externalizable object}.
  746. We define that two \term{objects} are \newterm{similar} if they satisfy
  747. a two-place conceptual equivalence predicate (defined below), which is
  748. independent of the \term{Lisp image} so that the two \term{objects} in
  749. different \term{Lisp images} can be understood to be equivalent under
  750. this predicate. Further, by inspecting the definition of this conceptual
  751. predicate, the programmer can anticipate what aspects of an \term{object}
  752. are reliably preserved by \term{file compilation}.
  753. The \term{file compiler} must cooperate with the \term{loader} in order to
  754. assure that in each case where an \term{externalizable object} is processed
  755. as a \term{literal object}, the \term{loader} will construct a \term{similar}
  756. \term{object}.
  757. The set of \term{objects} that are \newtermidx{externalizable objects}{externalizable object} are those
  758. for which the new conceptual term ``\term{similar}'' is defined, such that
  759. when a \term{compiled file} is \term{loaded}, an \term{object} can be constructed
  760. which can be shown to be \term{similar} to the original \term{object} which
  761. existed at the time the \term{file compiler} was operating.
  762. \endissue{CONSTANT-COMPILABLE-TYPES:SPECIFY}
  763. \endsubsubsection%{Externalizable Objects}
  764. \beginsubsubsection{Similarity of Literal Objects}
  765. \DefineSection{Similarity}
  766. \beginsubsubsubsection{Similarity of Aggregate Objects}
  767. %Moon thinks this section is unnecessary.
  768. Of the \term{types} over which \term{similarity} is defined,
  769. some are treated as aggregate objects. For these types,
  770. \term{similarity} is defined recursively.
  771. We say that an \term{object} of these types has certain ``basic qualities''
  772. and to satisfy the \term{similarity} relationship, the values of the
  773. corresponding qualities of the two \term{objects} must also be similar.
  774. \endsubsubsubsection%{Similarity of Aggregate Objects}
  775. % What was left of this section made no sense at all, so I removed
  776. % the whole thing. --sjl 3 Mar 92
  777. % \beginsubsubsubsection{Similarity of Circular Objects}
  778. % %Moon: I think this section is BS and should be deleted, but RPG might disagree.
  779. %
  780. % %!!! This discussion needs to be reworked since we're not doing "depth-limited gunk" anymore.
  781. % This kind of definition has problems with any circular or ``infinitely
  782. % recursive'' object such as a list that is an element of itself.
  783. % %% !!!! RPG thinks we should flush this part. But that leaves the previous sentence
  784. % %% in a precarious situation. I see no reason really why circular objects are
  785. % %% a problem. Can't we just use the same tricks that make printing circular objects work?
  786. % %% And if that's right, how do I express it??
  787. % %% -kmp 26-Jan-92
  788. % % We use
  789. % % the idea of depth-limited comparison, and say that two objects are
  790. % % \term{similar} if they are \term{similar} at all finite levels. This
  791. % % idea is implicit in the definitions below, and applies in all the
  792. % % places where qualities of two \term{objects} are required to be \term{similar}.
  793. %
  794. % \endsubsubsubsection%{Similarity of Circular Objects}
  795. % The following terms are used throughout this proposal:
  796. %
  797. % The term "constant" [now "literal object" -kmp 8-Oct-91]
  798. % refers to a quoted object or self-evaluating object,
  799. % not a constant variable.
  800. %
  801. % The term "source code" is used to refer to the objects constructed
  802. % when COMPILE-FILE calls READ, and additional objects constructed by
  803. % macroexpansion during COMPILE-FILE.
  804. %
  805. % The term "compiled code" is used to refer to objects constructed by
  806. % LOAD.
  807. %
  808. \beginsubsubsubsection{Definition of Similarity}
  809. Two \term{objects} $S$ (in \term{source code}) and $C$ (in \term{compiled code})
  810. are defined to be \term{similar} if and only if
  811. they are both of one of the \term{types} listed here
  812. (or defined by the \term{implementation})
  813. and they both satisfy all additional requirements of \term{similarity}
  814. indicated for that \term{type}.
  815. \beginlist
  816. \itemitem{\typeref{number}}
  817. Two \term{numbers} $S$ and $C$ are \term{similar} if they are of the same \term{type}
  818. and represent the same mathematical value.
  819. \itemitem{\typeref{character}}
  820. % Two \term{characters} $S$ and $C$ are \term{similar} if they both
  821. % represent the same \term{character}.
  822. %% Tentatively replaced. Mail sent to Quinquevirate to confirm. -kmp 29-Jan-92
  823. %% Lots of mail ensued ("Similarity of characters"), but this looks like it'll do for now.
  824. %% We should maybe return to it later in Public Review when there's more time. -kmp 4-Feb-92
  825. Two \term{simple} \term{characters} $S$ and $C$ are \term{similar}
  826. if they have \term{similar} \term{code} \term{attributes}.
  827. \term{Implementations} providing additional, \term{implementation-defined}
  828. \term{attributes} must define whether and how \term{non-simple} \term{characters}
  829. can be regarded as \term{similar}.
  830. \itemitem{\typeref{symbol}}
  831. Two \term{apparently uninterned} \term{symbols} $S$ and $C$ are \term{similar}
  832. if their
  833. %% Per Moon#6 (first public review). -kmp 5-May-93
  834. %\term{print names}
  835. \term{names}
  836. are \term{similar}.
  837. \issue{COMPILE-FILE-SYMBOL-HANDLING:NEW-REQUIRE-CONSISTENCY}
  838. Two \term{interned} symbols $S$ and $C$ are \term{similar}
  839. if their \term{names} are \term{similar},
  840. and if either $S$ is accessible in the \term{current package} at compile time
  841. and $C$ is accessible in the \term{current package} at load time,
  842. or $C$ is accessible in the \term{package} that is \term{similar} to
  843. the \term{home package} of $S$.
  844. (Note that \term{similarity} of
  845. %% Per Moon#6 (first public review). -kmp 5-May-93
  846. %\term{interned}
  847. \term{symbols} is dependent
  848. on neither the \term{current readtable} nor how \thefunction{read} would
  849. parse the \term{characters} in the \term{name} of the \term{symbol}.)
  850. \endissue{COMPILE-FILE-SYMBOL-HANDLING:NEW-REQUIRE-CONSISTENCY}
  851. \itemitem{\typeref{package}}
  852. Two \term{packages} $S$ and $C$ are \term{similar} if their \term{names} are \term{similar}.
  853. Note that although a \term{package} \term{object} is an \term{externalizable object},
  854. the programmer is responsible for ensuring that the corresponding \term{package} is
  855. already in existence when code referencing it as a \term{literal} \term{object}
  856. is \term{loaded}. The \term{loader} finds the corresponding \term{package} \term{object}
  857. as if by calling \funref{find-package} with that \term{name} as an \term{argument}.
  858. An error is signaled by the \term{loader} if no \term{package} exists at load time.
  859. \itemitem{\typeref{random-state}}
  860. Two \term{random states} $S$ and $C$ are \term{similar} if $S$
  861. would always produce the same sequence of pseudo-random numbers
  862. as a \term{copy}\meaning{5} of $C$
  863. when given as the \param{random-state} \term{argument} to \thefunction{random},
  864. assuming equivalent \param{limit} \term{arguments} in each case.
  865. (Note that since $C$ has been processed by the \term{file compiler},
  866. it cannot be used directly as an \term{argument} to \funref{random}
  867. because \funref{random} would perform a side effect.)
  868. \itemitem{\typeref{cons}}
  869. Two \term{conses}, $S$ and $C$, are \term{similar} if
  870. the \term{car}\meaning{2} of $S$ is \term{similar} to the \term{car}\meaning{2} of $C$,
  871. and the \term{cdr}\meaning{2} of $S$ is \term{similar} to the \term{cdr}\meaning{2} of $C$.
  872. \itemitem{\typeref{array}}
  873. Two one-dimensional \term{arrays}, $S$ and $C$, are \term{similar} if
  874. the \term{length} of $S$ is \term{similar} to the \term{length} of $C$,
  875. the \term{actual array element type} of $S$ is \term{similar} to
  876. the \term{actual array element type} of $C$,
  877. and each \term{active} \term{element} of $S$ is \term{similar} to
  878. the corresponding \term{element} of $C$.
  879. Two \term{arrays} of \term{rank} other than one, $S$ and $C$, are \term{similar} if
  880. the \term{rank} of $S$ is \term{similar} to the \term{rank} of $C$,
  881. each \term{dimension}\meaning{1} of $S$ is \term{similar} to
  882. the corresponding \term{dimension}\meaning{1} of $C$,
  883. the \term{actual array element type} of $S$ is \term{similar} to
  884. the \term{actual array element type} of $C$,
  885. and each \term{element} of $S$ is \term{similar} to
  886. the corresponding \term{element} of $C$.
  887. In addition,
  888. if $S$ is a \term{simple array}, then $C$ must also be a \term{simple array}.
  889. If $S$ is a \term{displaced array},
  890. has a \term{fill pointer},
  891. or is \term{actually adjustable},
  892. $C$ is permitted to lack any or all of these qualities.
  893. \itemitem{\typeref{hash-table}}
  894. Two \term{hash tables} $S$ and $C$ are \term{similar} if they meet the following
  895. three requirements:
  896. \beginlist
  897. \item{1.} They both have the same test
  898. (\eg they are both \funref{eql} \term{hash tables}).
  899. \item{2.} There is a unique one-to-one correspondence between the keys of
  900. the two \term{hash tables}, such that the corresponding keys are
  901. \term{similar}.
  902. \item{3.} For all keys, the values associated with two corresponding keys
  903. are \term{similar}.
  904. \endlist
  905. If there is more than one possible one-to-one correspondence between
  906. the keys of $S$ and $C$, the consequences are unspecified.
  907. A \term{conforming program} cannot use a table such as $S$ as an
  908. \term{externalizable constant}.
  909. \itemitem{\typeref{pathname}}
  910. Two \term{pathnames} $S$ and $C$ are \term{similar} if all corresponding
  911. \term{pathname components} are \term{similar}.
  912. \itemitem{\typeref{function}}
  913. \issue{CONSTANT-FUNCTION-COMPILATION:NO}
  914. \term{Functions} are not \term{externalizable objects}.
  915. \endissue{CONSTANT-FUNCTION-COMPILATION:NO}
  916. \itemitem{\typeref{structure-object} and \typeref{standard-object}}
  917. \issue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  918. A general-purpose concept of \term{similarity} does not exist for \term{structures}
  919. and \term{standard objects}.
  920. However, a \term{conforming program} is permitted to define a \funref{make-load-form}
  921. \term{method} for any \term{class} $K$ defined by that \term{program} that is
  922. a \term{subclass} of either \typeref{structure-object} or \typeref{standard-object}.
  923. The effect of such a \term{method} is to define that an \term{object} $S$ of \term{type} $K$
  924. in \term{source code} is \term{similar} to an \term{object} $C$ of \term{type} $K$
  925. in \term{compiled code} if $C$ was constructed from \term{code} produced by
  926. calling \funref{make-load-form} on $S$.
  927. \endissue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  928. \endlist
  929. \endsubsubsection%{Similarity of Literal Objects}
  930. \beginsubsubsection{Extensions to Similarity Rules}
  931. Some \term{objects}, such as \term{streams}, \typeref{readtables}, and \typeref{methods}
  932. are not \term{externalizable objects} under the definition of similarity given above.
  933. That is, such \term{objects} may not portably appear as \term{literal} \term{objects}
  934. in \term{code} to be processed by the \term{file compiler}.
  935. An \term{implementation} is permitted to extend the rules of similarity,
  936. so that other kinds of \term{objects} are \term{externalizable objects}
  937. for that \term{implementation}.
  938. If for some kind of \term{object}, \term{similarity} is
  939. neither defined by this specification
  940. nor by the \term{implementation},
  941. then the \term{file compiler} must signal an error upon encountering such
  942. an \term{object} as a \term{literal constant}.
  943. \endsubsubsection%{Extensions to Similarity Rules}
  944. \beginsubsubsection{Additional Constraints on Externalizable Objects}
  945. % What was left of this paragraph didn't add anything to what was
  946. % already stated above, so I removed the whole thing. --sjl 3 Mar 92
  947. % %% Moon wanted this removed because it was redundant
  948. % %% and also because EQ isn't the only problem.
  949. % % Note that some \term{hash tables} that use
  950. % % \funref{eq} as test function may not be similar to themselves.
  951. % %% KMP thinks this phrase is both superfluous and clumsy.
  952. % % One consequence of the restrictions on constants
  953. % % and the definition of similarity is that
  954. % A \term{hash table}
  955. % %cannot be used as a constant
  956. % is not an \term{externalizable object}
  957. % if it contains two \term{similar} keys
  958. % %% Moon thinks this is superfluous.
  959. % %where the values associated with those keys are also similar.
  960. If two \term{literal objects} appearing in the source code for a single file
  961. processed with
  962. %\funref{compile-file}
  963. the \term{file compiler}
  964. are the \term{identical},
  965. the corresponding \term{objects} in the \term{compiled code}
  966. must also be the \term{identical}.
  967. \issue{CONSTANT-COLLAPSING:GENERALIZE}
  968. % However, if two \term{objects} are \funref{eql} in the
  969. % compiled code, the corresponding \term{objects} in the source code
  970. % might not have been \funref{eql}.
  971. % \term{Objects} \oftype{array}, \typeref{character}, \typeref{cons},
  972. % \typeref{hash-table}, \typeref{number}, \typeref{pathname},
  973. % \typeref{random-state}, and \typeref{string} may be coalesced
  974. % if they are similar.
  975. With the exception of \term{symbols} and \term{packages}, any two
  976. %constants
  977. \term{literal objects}
  978. in \term{code} being processed by
  979. %\funref{compile-file}
  980. the \term{file compiler}
  981. may be \term{coalesced}
  982. if and only if they are \term{similar};
  983. if they are either both \term{symbols} or both \term{packages},
  984. they may only be \term{coalesced} if and only if they are \term{identical}.
  985. \endissue{CONSTANT-COLLAPSING:GENERALIZE}
  986. \issue{CONSTANT-CIRCULAR-COMPILATION:YES}
  987. \term{Objects} containing circular references can
  988. %legitimately appear as constants to be compiled.
  989. be \term{externalizable objects}.
  990. The \term{file compiler} is required to preserve \funref{eql}ness of
  991. substructures within a \term{file}.
  992. %compiled with \funref{compile-file}.
  993. Preserving \funref{eql}ness means that subobjects that are
  994. %\funref{eql}
  995. the \term{same}
  996. in the \term{source code} must
  997. %remain
  998. be
  999. %\funref{eql}
  1000. the \term{same}
  1001. %after being compiled.
  1002. in the corresponding \term{compiled code}.
  1003. %that is, things don't get "less EQL" after compilation.
  1004. %(Note that coalescing of constants implies that things may get "more
  1005. %EQL".)
  1006. \endissue{CONSTANT-CIRCULAR-COMPILATION:YES}
  1007. In addition, the following are constraints on the handling of
  1008. \term{literal objects} by the \term{file compiler}:
  1009. \beginlist
  1010. \item{}\b{array:} If an \term{array} in the source code is a
  1011. \term{simple array}, then the corresponding \term{array}
  1012. in the compiled code will also be a \term{simple array}. If
  1013. an \term{array} in the source code is displaced, has a
  1014. \term{fill pointer}, or is \term{actually adjustable}, the corresponding
  1015. \term{array} in the compiled code might lack any or all of these
  1016. qualities. If an \term{array} in the source code has a fill
  1017. pointer, then the corresponding \term{array} in the compiled
  1018. code might be only the size implied by the fill pointer.
  1019. \item{}\b{packages:} The loader is required to find the
  1020. corresponding \term{package} \term{object} as if by calling
  1021. \funref{find-package} with the package name as an argument.
  1022. An error \oftype{package-error} is signaled if no
  1023. \term{package} of that name exists at load time.
  1024. %!!! Barmar notes that this is not a constraint on the compiler (as list heading suggests)
  1025. \item{}\b{random-state:} A constant \term{random state}
  1026. object cannot be used as the state argument
  1027. to \thefunction{random} because \funref{random} modifies this data structure.
  1028. \item{}\b{structure, standard-object:}
  1029. \term{Objects} of \term{type} \typeref{structure-object} and \typeref{standard-object}
  1030. may appear in compiled constants if there is an
  1031. appropriate \funref{make-load-form} method defined for that
  1032. \term{type}.
  1033. \issue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  1034. \DefineSection{CallingMakeLoadForm}
  1035. % %\funref{compile-file}
  1036. % The \term{file compiler}
  1037. % calls \funref{make-load-form} on any \term{object}
  1038. % that is referenced as a \term{literal object}
  1039. % if the \term{object}'s \term{metaclass} is
  1040. % \typeref{standard-class}, \typeref{structure-class},
  1041. % % any user-defined \term{metaclass}
  1042. % % \editornote{KMP: Do we want to talk about user-defined metaclasses?}
  1043. % % that is not a \term{subclass} of \typeref{built-in-class},
  1044. % or any of a possibly empty \term{implementation-defined} set
  1045. % of other \term{metaclasses}.
  1046. % %\funref{compile-file}
  1047. % The \term{file compiler}
  1048. % will call \funref{make-load-form}
  1049. % once for any given \term{object} within a single \term{file}.
  1050. % Barrett: Commented out the above, replacing it with appropriately
  1051. % massaged text from newer issue.
  1052. \issue{MAKE-LOAD-FORM-CONFUSION:REWRITE}
  1053. The \term{file compiler} calls \funref{make-load-form} on any \term{object}
  1054. that is referenced as a \term{literal object} if the \term{object} is a
  1055. \term{generalized instance} of \typeref{standard-object},
  1056. \typeref{structure-object}, \typeref{condition}, or any of a
  1057. (possibly empty) \term{implementation-dependent} set of other \term{classes}.
  1058. The \term{file compiler} only calls \funref{make-load-form} once for
  1059. any given \term{object} within a single \term{file}.
  1060. \endissue{MAKE-LOAD-FORM-CONFUSION:REWRITE}
  1061. \endissue{LOAD-OBJECTS:MAKE-LOAD-FORM}
  1062. \issue{COMPILE-FILE-SYMBOL-HANDLING:NEW-REQUIRE-CONSISTENCY}
  1063. \item{}\b{symbol:} In order to guarantee that \term{compiled files} can be \term{loaded}
  1064. correctly, users must ensure that the \term{packages} referenced in those \term{files}
  1065. are defined consistently at compile time and load time. \term{Conforming programs}
  1066. must satisfy the following requirements:
  1067. \beginlist
  1068. \itemitem{1.} The \term{current package} when a \term{top level form} in the \term{file}
  1069. is processed by \funref{compile-file} must be the same as the \term{current package}
  1070. when the \term{code} corresponding to that \term{top level form} in the
  1071. \term{compiled file} is executed by \funref{load}. In particular:
  1072. \beginlist
  1073. \itemitem{a.} Any \term{top level form} in a \term{file} that alters
  1074. the \term{current package} must change it to a \term{package}
  1075. of the same \term{name} both at compile time and at load time.
  1076. \itemitem{b.} If the first \term{non-atomic} \term{top level form} in the \term{file}
  1077. is not an \macref{in-package} \term{form}, then the \term{current package}
  1078. at the time \funref{load} is called must be a \term{package} with the
  1079. same \term{name} as the package that was the \term{current package}
  1080. at the time \funref{compile-file} was called.
  1081. \endlist
  1082. \itemitem{2.} For all \term{symbols}
  1083. appearing lexically within a \term{top level form} that
  1084. were \term{accessible} in the \term{package} that was the \term{current package}
  1085. during processing of that \term{top level form} at compile time, but
  1086. whose \term{home package} was another \term{package}, at load time there must
  1087. be a \term{symbol} with the same \term{name} that is \term{accessible} in both the
  1088. load-time \term{current package} and in the \term{package}
  1089. with the same \term{name} as the
  1090. compile-time \term{home package}.
  1091. \itemitem{3.} For all \term{symbols} represented in the \term{compiled file}
  1092. that were \term{external symbols} in
  1093. their \term{home package} at compile time, there must be a \term{symbol} with the
  1094. same \term{name} that is an \term{external symbol} in the \term{package}
  1095. with the same \term{name} at load time.
  1096. \endlist
  1097. If any of these conditions do not hold, the \term{package} in which the \term{loader} looks
  1098. for the affected \term{symbols} is unspecified. \term{Implementations} are permitted
  1099. to signal an error or to define this behavior.
  1100. \endissue{COMPILE-FILE-SYMBOL-HANDLING:NEW-REQUIRE-CONSISTENCY}
  1101. \endlist
  1102. \endsubsubsection%{Additional Constraints on Externalizable Objects}
  1103. \endsubSection%{Literal Objects in Compiled Files}
  1104. \beginsubsection{Exceptional Situations in the Compiler}
  1105. \DefineSection{FileCompilerExceptions}
  1106. \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  1107. %% The following text was added by COMPILER-DIAGNOSTICS and then later removed.
  1108. %\funref{compile-file} is required to handle the \misc{abort} restart by
  1109. %aborting the smallest feasible part of the compilation.
  1110. %\funref{compile-file} is allowed to establish a default
  1111. %condition handler. If such a condition handler is established,
  1112. %however, it must first resignal the \term{condition} to give any
  1113. %user-established handlers a chance to \term{handle} it. If all user error
  1114. %handlers decline, the default handler \term{handles} the
  1115. %\term{condition} in an implementation-specific way; for example, it might turn
  1116. %errors into warnings.
  1117. \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  1118. \issue{COMPILER-WARNING-STREAM}
  1119. \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  1120. %\funref{compile-file} is permitted to issue warnings through \term{error output}.
  1121. \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  1122. \endissue{COMPILER-WARNING-STREAM}
  1123. % Reference: Issue COMPILER-DIAGNOSTICS
  1124. % The STYLE-WARNING condition needs to be integrated into the section
  1125. % describing the hierarchy of condition types.
  1126. \funref{compile} and \funref{compile-file} are permitted to
  1127. signal errors and warnings, including errors due to compile-time
  1128. processing of \f{(eval-when (:compile-toplevel) ...)} forms,
  1129. macro expansion, and conditions signaled by the compiler itself.
  1130. \term{Conditions} \oftype{error} might be signaled by the compiler
  1131. in situations where the compilation cannot proceed without intervention.
  1132. In addition to situations for which the standard specifies that
  1133. \term{conditions} \oftype{warning} must or might be signaled,
  1134. warnings might be signaled in situations where the compiler can
  1135. determine that the consequences are undefined or that a run-time
  1136. error will be signaled. Examples of this situation are as follows:
  1137. violating type declarations,
  1138. altering or assigning the value of a constant defined with \macref{defconstant},
  1139. calling built-in Lisp functions with a wrong number of arguments or malformed keyword
  1140. argument lists,
  1141. and using unrecognized declaration specifiers.
  1142. The compiler is permitted to issue warnings about matters of
  1143. programming style as conditions \oftype{style-warning}.
  1144. Examples of this situation are as follows:
  1145. redefining a function using a different argument list,
  1146. calling a function with a wrong number of arguments,
  1147. not declaring \declref{ignore} of a local variable that is not referenced,
  1148. and referencing a variable declared \declref{ignore}.
  1149. %% KAB didn't think this one was very convincing. KMP was not sure but figured
  1150. %% it wouldn't hurt anything to remove it.
  1151. % and using \term{declaration specifiers}
  1152. % described in the standard but ignored by the compiler.
  1153. Both \funref{compile} and \funref{compile-file} are permitted
  1154. (but not required) to \term{establish} a \term{handler}
  1155. for \term{conditions} \oftype{error}. For example, they
  1156. might signal a warning, and restart compilation from some
  1157. \term{implementation-dependent} point in order to let the
  1158. compilation proceed without manual intervention.
  1159. Both \funref{compile} and \funref{compile-file} return three
  1160. values, the second two indicating whether the source code being compiled
  1161. contained errors and whether style warnings were issued.
  1162. % Reference: issue WITH-COMPILATION-UNIT
  1163. Some warnings might be deferred until the end of compilation.
  1164. See \macref{with-compilation-unit}.
  1165. % This paragraph is redundant, so I removed it. --sjl 3 Mar 92
  1166. % \issue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  1167. % \funref{compile-file} is permitted, but not required, to establish a \term{handler}
  1168. % for \typeref{error} \term{conditions}. For example, such a \term{handler} might issue
  1169. % a warning and restart compilation from some \term{implementation-dependent}
  1170. % point in order to let the compilation proceed without manual intervention.
  1171. % \endissue{COMPILER-DIAGNOSTICS:USE-HANDLER}
  1172. \endsubSection%{Exceptional Situations in the Compiler}
  1173. % merged section "File Compilation of Top Level Forms" with
  1174. % section "Processing of Defining Macros", above. --sjl 3 Mar 92