Changeset d3942b9 for doc/theses
- Timestamp:
- Oct 21, 2024, 12:34:46 PM (2 months ago)
- Branches:
- master
- Children:
- 42d81a7
- Parents:
- 187be97
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/mike_brooks_MMath/array.tex
r187be97 rd3942b9 504 504 TODO: summarize the C rules and add the case-comparison table 505 505 506 TODO: Discuss Recourse 507 508 TODO: Discuss dimension hoisting, which addresses the challenge of extra unification for cost calculation 506 The conservatism of the new rule set can leave a programmer needing a recourse, 507 when needing to use a dimension expression whose stability argument 508 is more subtle than current-state analysis. 509 This recourse is to declare an explicit constant for the dimension value. 510 Consider these two dimension expressions, 511 whose reuses are rejected by the blunt current-state rules: 512 \begin{cfa} 513 void f( int & nr, const int nv ) { 514 float x[nr]; 515 float (*xp)[nr] = & x; // reject: nr varying (no references) 516 float y[nv + 1]; 517 float (*yp)[nv + 1] = & y; // reject: ?+? unpredicable (no functions) 518 } 519 \end{cfa} 520 Yet, both dimension expressions are reused safely. 521 (The @nr@ reference is never written, not volatile 522 and control does not leave the function between the uses. 523 The name @?+?@ resolves to a function that is quite predictable.) 524 The programmer here can add the constant declarations: 525 \begin{cfa} 526 void f( int & nr, const int nv ) { 527 @const int nx@ = nr; 528 float x[nx]; 529 float (*xp)[nx] = & x; // acept 530 @const int ny@ = nv + 1; 531 float y[ny]; 532 float (*yp)[ny] = & y; // accept 533 } 534 \end{cfa} 535 The result is the originally intended semantics, 536 achieved by adding a superfluous ``snapshot it as of now'' directive. 537 538 The snapshotting trick is also used by the translation, though to achieve a different outcome. 539 Rather obviously, every array must be subscriptable, even a bizzarre one: 540 \begin{cfa} 541 array( float, rand(10) ) x; 542 x[0]; // 10% chance of bound-check failure 543 \end{cfa} 544 Less obvious is that the mechanism of subscripting is a function call, 545 which must communicate length accurately. 546 The bound-check above (callee logic) must use the actual allocated length of @x@, 547 without mistakenly reevaluating the dimension expression, @rand(10)@. 548 Adjusting the example to make the function's use of length more explicit: 549 \begin{cfa} 550 forall ( T * ) 551 void f( T * x ) { sout | sizeof(*x); } 552 float x[ rand(10) ]; 553 f( x ); 554 \end{cfa} 555 Considering that the partly translated function declaration is, loosely, 556 \begin{cfa} 557 void f( size_t __sizeof_T, void * x ) { sout | __sizeof_T; } 558 \end{cfa} 559 the translated call must not go like: 560 \begin{cfa} 561 float x[ rand(10) ]; 562 f( rand(10), &x ); 563 \end{cfa} 564 Rather, its actual translation is like: 565 \begin{cfa} 566 size_t __dim_x = rand(10); 567 float x[ __dim_x ]; 568 f( __dim_x, &x ); 569 \end{cfa} 570 The occurrence of this dimension hoisting during translation was present in the preexisting \CFA compiler. 571 But its cases were buggy, particularly with determining, ``Can hoisting be skipped here?'' 572 For skipping this hoisting is clearly desirable in some cases, 573 not the least of which is when the programmer has already done so manually. 574 My work includes getting these cases right, harmonized with the accept/reject criteria, and tested. 575 576 577 578 TODO: Discuss the interaction of this dimension hoisting with the challenge of extra unification for cost calculation 509 579 510 580 \section{Multidimensional Arrays}
Note: See TracChangeset
for help on using the changeset viewer.