1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss355_w.htm

172 lines
9.5 KiB
HTML
Raw Normal View History

2024-04-01 10:24:07 +02:00
<!-- 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 UNINITIALIZED-ELEMENTS 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/iss354_w.htm">
<LINK REL=UP HREF="../Issues/iss355.htm">
<LINK REL=NEXT HREF="../Issues/iss356_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/iss354_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss355.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss356_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue UNINITIALIZED-ELEMENTS Writeup</H2>
<PRE><B>Forum:</B> Public Review<P>
<B>Issue:</B> <A HREF="iss355.htm">UNINITIALIZED-ELEMENTS</A><P>
<B>Forum:</B> CLEANUP<P>
<B>References:</B> <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> (p308), <A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A> (pp287-288)<P>
Moon's public review comment #3 (X3J13/92-3203)<P>
Issue <A HREF="iss019.htm">BOA-AUX-INITIALIZATION</A><P>
<B>Category:</B> CLARIFICATION<P>
<B>Edit history:</B> 24-Jun-91, Version 1 by Hornig<P>
12-Aug-91, Version 2 by Pitman (flesh out Problem Description<P>
and Examples, light editing of other sections, add endorsement)<P>
20-Dec-92, Version 3 by Loosemore (update writeup to reflect<P>
draft 12.24; proposal is unchanged)<P>
08-Jan-93, Version 4 by Loosemore (more comments from Moon)<P>
<B>Status:</B> Version 2 failed 4-5-1 at Dec 1991 meeting<P>
Version 4 passed 9-0-0 at Mar 1993 meeting<P>
<P>
<P>
<B>Problem Description:<P>
</B><P>
CLtL says of <A REL=DEFINITION HREF="../Body/t_array.htm#array"><B>ARRAY</B></A> element initial values (p287):<P>
<P>
If the :initial-element option is omitted, the initial <P>
values of the array elements are undefined (unless the<P>
:initial-contents or :displaced-to option is used.)<P>
<P>
[Similar remarks are made for :initial-contents and<P>
:displaced-to.]<P>
<P>
CLtL says of <A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> slot initial values (p308):<P>
<P>
If no default-init is specified, then the initial contents <P>
of the slot are undefined and implementation-dependent.<P>
<P>
From this wording, the draft specification (12.24) has chosen to say that<P>
uninitialized array elements have an &quot;implementation-dependent value&quot;, <P>
but that &quot;the consequences are undefined&quot; if an attempt is made to read <P>
an uninitialized <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> slot. <P>
<P>
Aside from the inconsistency being a source of confusion, the language<P>
in the array section would seem to prevent implementations from<P>
diagnosing references to uninitialized array slots in high-safety code,<P>
something that would be very helpful in debugging.<P>
<P>
<P>
<B>Proposal UNINITIALIZED-ELEMENTS:CONSEQUENCES-UNDEFINED:<P>
</B><P>
Specify that the consequences of reading an uninitialized array<P>
element or <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> slot are undefined.<P>
<P>
<B>Test Case:<P>
</B><P>
#1: (<A REL=DEFINITION HREF="../Body/f_length.htm#length"><B>LENGTH</B></A> (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> (<A REL=DEFINITION HREF="../Body/f_aref.htm#aref"><B>AREF</B></A> (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A> 1) 0)))<P>
<P>
returned 1 under CLtL and draft 12.24<P>
but has undefined consequences under this proposal.<P>
<P>
<P>
#2: (<A REL=DEFINITION HREF="../Body/m_defstr.htm#defstruct"><B>DEFSTRUCT</B></A> (KONS (:CONC-NAME &quot;&quot;) (:CONSTRUCTOR KONS)) KAR KDR)<P>
(<A REL=DEFINITION HREF="../Body/f_length.htm#length"><B>LENGTH</B></A> (<A REL=DEFINITION HREF="../Body/a_list.htm#list"><B>LIST</B></A> (KAR (KONS))))<P>
<P>
returned 1 under CLtL <P>
but has undefined consequences under draft 12.24 and this proposal.<P>
<P>
<B>Rationale:<P>
</B><P>
This change will permit, but not <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A>, an implementation to detect<P>
reading of uninitialized values. Reading an uninitialized value usually<P>
indicates a programming error. Implementations which wish to ease<P>
debugging may detect this error and report it to the user.<P>
<P>
Implementations are already required to detect references to<P>
uninitialized symbol value and function cells in high safety mode,<P>
and to uninitialized slots in objects of types <A REL=DEFINITION HREF="../Body/t_std_ob.htm#standard-object"><B>STANDARD-OBJECT</B></A> <P>
and <A REL=DEFINITION HREF="../Body/e_cnd.htm#condition"><B>CONDITION</B></A> in all safety modes.<P>
<P>
<B>Current Practice:<P>
</B><P>
Symbolics currently initializes uninitialized array elements to a<P>
type-dependent value. Symbolics currently detects references to<P>
uninitialized <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> slots and calls the <A REL=DEFINITION HREF="../Body/f_slt_un.htm#slot-unbound"><B>SLOT-UNBOUND</B></A> generic<P>
function.<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
None.<P>
<P>
<B>Cost to Users:<P>
</B><P>
This change might affect user programs which read uninitialized slots<P>
but then do absolutely nothing with the value (such as those in the<P>
Examples section). In pracitce, there probably aren't a lot of<P>
programs with that property.<P>
<P>
<B>Cost of Non-Adoption:<P>
</B><P>
Users will not be able to detect this important <A REL=DEFINITION HREF="../Body/t_class.htm#class"><B>class</B></A> of programming<P>
errors reliably.<P>
<P>
<B>Benefits:<P>
</B><P>
High-safety implementations may continue to detect these problems.<P>
<P>
<B>Aesthetics:<P>
</B><P>
Most people think it is unaesthetic to read a value which has not been<P>
initialized.<P>
<P>
Some people think it is unaesthetic to have the language initialize <P>
things to unspecified values.<P>
<P>
<B>Editorial impact:<P>
</B><P>
The sections of text affected by this proposal are already flagged<P>
in the TeX sources for the draft.<P>
<P>
<B>Discussion:<P>
</B><P>
Hornig, Pitman, Moon, and Loosemore have expressed support for some<P>
version of this proposal.<P>
<P>
Version 2 of this proposal failed by a narrow margin at the December <P>
1991 meeting, but the same issue was raised again by Moon's public review<P>
comment #3.<P>
<P>
According to Kent Pitman, the current inconsistency arose because some <P>
people were concerned that &quot;implementations might have to blow out in<P>
the printer when someone did (<A REL=DEFINITION HREF="../Body/f_mk_ar.htm#make-array"><B>MAKE-ARRAY</B></A> 4)&quot;. But various people wanted <P>
reading uninitialized <A REL=DEFINITION HREF="../Body/f_docume.htm#structure"><B>structure</B></A> slots to have undefined consequences <P>
because &quot;the presence of CLOS and <A REL=DEFINITION HREF="../Body/t_stu_cl.htm#structure-class"><B>STRUCTURE-CLASS</B></A> and <A REL=DEFINITION HREF="../Body/f_slt_un.htm#slot-unbound"><B>SLOT-UNBOUND</B></A><P>
implies that it is reasonable for an implementation to call <A REL=DEFINITION HREF="../Body/f_slt_un.htm#slot-unbound"><B>SLOT-UNBOUND</B></A><P>
and for <A REL=DEFINITION HREF="../Body/f_slt_un.htm#slot-unbound"><B>SLOT-UNBOUND</B></A> to signal an error when such a slot is accessed&quot;.<P>
<P>
Moon says:<P>
I don't see anything in the <A REL=DEFINITION HREF="../Body/07_ffb.htm#standard"><B>standard</B></A> that requires the printer to<P>
&quot;blow out&quot; when printing an object for which there are applicable<P>
functions that have undefined consequences. After all, the printer is<P>
not (required to be) a portable program and is not required to call<P>
any particular functions (except for <A REL=DEFINITION HREF="../Body/f_pr_obj.htm#print-object"><B>PRINT-OBJECT</B></A> on instances of<P>
user-defined classes).<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>