Changeset 82e5670
- Timestamp:
- Mar 24, 2024, 9:52:45 PM (9 months ago)
- Branches:
- master
- Children:
- 6a8c773
- Parents:
- f5fbcad
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/array.tex
rf5fbcad r82e5670 510 510 511 511 \subsection{Retire pointer arithmetic} 512 513 514 \section{\CFA} 515 516 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \\ 517 moved from background chapter \\ 518 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \\ 519 520 Traditionally, 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 525 Prior work on \CFA included making C arrays, as used in C code from the wild, 526 work, if this code is fed into @cfacc@. 527 The quality of this this treatment was fine, with no more or fewer bugs than is typical. 528 529 More mixed results arose with feeding these ``C'' arrays into preexisting \CFA features. 530 531 A notable success was with the \CFA @alloc@ function, 532 which type information associated with a polymorphic return type 533 replaces @malloc@'s use of programmer-supplied size information. 534 \begin{cfa} 535 // C, library 536 void * malloc( size_t ); 537 // C, user 538 struct tm * el1 = malloc( sizeof(struct tm) ); 539 struct tm * ar1 = malloc( 10 * sizeof(struct tm) ); 540 541 // CFA, library 542 forall( T * ) T * alloc(); 543 // CFA, user 544 tm * el2 = alloc(); 545 tm (*ar2)[10] = alloc(); 546 \end{cfa} 547 The alloc polymorphic return compiles into a hidden parameter, which receives a compiler-generated argument. 548 This compiler's argument generation uses type information from the left-hand side of the initialization to obtain the intended type. 549 Using a compiler-produced value eliminates an opportunity for user error. 550 551 TODO: 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 553 Bringing 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. 554 In the last example, the choice of ``pointer to array'' @ar2@ breaks a parallel with @ar1@. 555 They are not subscripted in the same way. 556 \begin{cfa} 557 ar1[5]; 558 (*ar2)[5]; 559 \end{cfa} 560 Using ``reference to array'' works at resolving this issue. TODO: discuss connection with Doug-Lea \CC proposal. 561 \begin{cfa} 562 tm (&ar3)[10] = *alloc(); 563 ar3[5]; 564 \end{cfa} 565 The implicit size communication to @alloc@ still works in the same ways as for @ar2@. 566 567 Using proper array types (@ar2@ and @ar3@) addresses a concern about using raw element pointers (@ar1@), albeit a theoretical one. 568 TODO xref C standard does not claim that @ar1@ may be subscripted, 569 because no stage of interpreting the construction of @ar1@ has it be that ``there is an \emph{array object} here.'' 570 But both @*ar2@ and the referent of @ar3@ are the results of \emph{typed} @alloc@ calls, 571 where the type requested is an array, making the result, much more obviously, an array object. 572 573 The ``reference to array'' type has its sore spots too. 574 TODO see also @dimexpr-match-c/REFPARAM_CALL@ (under @TRY_BUG_1@) 575 576 TODO: 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.