Changeset d3942b9 for doc/theses


Ignore:
Timestamp:
Oct 21, 2024, 12:34:46 PM (2 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
42d81a7
Parents:
187be97
Message:

Thesis, array, C typing rules, add discussion dimension hoisting.

File:
1 edited

Legend:

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

    r187be97 rd3942b9  
    504504TODO: summarize the C rules and add the case-comparison table
    505505
    506 TODO: Discuss Recourse
    507 
    508 TODO: Discuss dimension hoisting, which addresses the challenge of extra unification for cost calculation
     506The conservatism of the new rule set can leave a programmer needing a recourse,
     507when needing to use a dimension expression whose stability argument
     508is more subtle than current-state analysis.
     509This recourse is to declare an explicit constant for the dimension value.
     510Consider these two dimension expressions,
     511whose 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}
     520Yet, both dimension expressions are reused safely.
     521(The @nr@ reference is never written, not volatile
     522and control does not leave the function between the uses.
     523The name @?+?@ resolves to a function that is quite predictable.)
     524The 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}
     535The result is the originally intended semantics,
     536achieved by adding a superfluous ``snapshot it as of now'' directive.
     537
     538The snapshotting trick is also used by the translation, though to achieve a different outcome.
     539Rather 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}
     544Less obvious is that the mechanism of subscripting is a function call,
     545which must communicate length accurately.
     546The bound-check above (callee logic) must use the actual allocated length of @x@,
     547without mistakenly reevaluating the dimension expression, @rand(10)@.
     548Adjusting 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}
     555Considering 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}
     559the translated call must not go like:
     560\begin{cfa}
     561        float x[ rand(10) ];
     562        f( rand(10), &x );
     563\end{cfa}
     564Rather, 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}
     570The occurrence of this dimension hoisting during translation was present in the preexisting \CFA compiler.
     571But its cases were buggy, particularly with determining, ``Can hoisting be skipped here?''
     572For skipping this hoisting is clearly desirable in some cases,
     573not the least of which is when the programmer has already done so manually.
     574My work includes getting these cases right, harmonized with the accept/reject criteria, and tested.
     575
     576
     577
     578TODO: Discuss the interaction of this dimension hoisting with the challenge of extra unification for cost calculation
    509579
    510580\section{Multidimensional Arrays}
Note: See TracChangeset for help on using the changeset viewer.