Changeset 82e5670


Ignore:
Timestamp:
Mar 24, 2024, 9:52:45 PM (9 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
6a8c773
Parents:
f5fbcad
Message:

add material from background

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/mike_brooks_MMath/array.tex

    rf5fbcad r82e5670  
    510510
    511511\subsection{Retire pointer arithmetic}
     512
     513
     514\section{\CFA}
     515
     516XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \\
     517moved from background chapter \\
     518XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \\
     519
     520Traditionally, fixing C meant leaving the C-ism alone, while providing a better alternative beside it.
     521(For later:  That's what I offer with array.hfa, but in the future-work vision for arrays, the fix includes helping programmers stop accidentally using a broken C-ism.)
     522
     523\subsection{\CFA features interacting with arrays}
     524
     525Prior work on \CFA included making C arrays, as used in C code from the wild,
     526work, if this code is fed into @cfacc@.
     527The quality of this this treatment was fine, with no more or fewer bugs than is typical.
     528
     529More mixed results arose with feeding these ``C'' arrays into preexisting \CFA features.
     530
     531A notable success was with the \CFA @alloc@ function,
     532which type information associated with a polymorphic return type
     533replaces @malloc@'s use of programmer-supplied size information.
     534\begin{cfa}
     535// C, library
     536void * malloc( size_t );
     537// C, user
     538struct tm * el1 = malloc(      sizeof(struct tm) );
     539struct tm * ar1 = malloc( 10 * sizeof(struct tm) );
     540
     541// CFA, library
     542forall( T * ) T * alloc();
     543// CFA, user
     544tm * el2 = alloc();
     545tm (*ar2)[10] = alloc();
     546\end{cfa}
     547The alloc polymorphic return compiles into a hidden parameter, which receives a compiler-generated argument.
     548This compiler's argument generation uses type information from the left-hand side of the initialization to obtain the intended type.
     549Using a compiler-produced value eliminates an opportunity for user error.
     550
     551TODO: fix in following: even the alloc call gives bad code gen: verify it was always this way; walk back the wording about things just working here; assignment (rebind) seems to offer workaround, as in bkgd-cfa-arrayinteract.cfa
     552
     553Bringing in another \CFA feature, reference types, both resolves a sore spot of the last example, and gives a first example of an array-interaction bug.
     554In the last example, the choice of ``pointer to array'' @ar2@ breaks a parallel with @ar1@.
     555They are not subscripted in the same way.
     556\begin{cfa}
     557ar1[5];
     558(*ar2)[5];
     559\end{cfa}
     560Using ``reference to array'' works at resolving this issue.  TODO: discuss connection with Doug-Lea \CC proposal.
     561\begin{cfa}
     562tm (&ar3)[10] = *alloc();
     563ar3[5];
     564\end{cfa}
     565The implicit size communication to @alloc@ still works in the same ways as for @ar2@.
     566
     567Using proper array types (@ar2@ and @ar3@) addresses a concern about using raw element pointers (@ar1@), albeit a theoretical one.
     568TODO xref C standard does not claim that @ar1@ may be subscripted,
     569because no stage of interpreting the construction of @ar1@ has it be that ``there is an \emph{array object} here.''
     570But both @*ar2@ and the referent of @ar3@ are the results of \emph{typed} @alloc@ calls,
     571where the type requested is an array, making the result, much more obviously, an array object.
     572
     573The ``reference to array'' type has its sore spots too.
     574TODO see also @dimexpr-match-c/REFPARAM_CALL@ (under @TRY_BUG_1@)
     575
     576TODO: I fixed a bug associated with using an array as a T.  I think.  Did I really?  What was the bug?
Note: See TracChangeset for help on using the changeset viewer.