Changeset cfbc56ec for libcfa


Ignore:
Timestamp:
Jan 10, 2024, 12:01:02 PM (4 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
4d689e2, b262cb3
Parents:
40002c5
Message:

Enable array RAII and provide uninit(-), a uNoCtor equivalent.

Enable construction/destruction of "new" CFA array elements,
which was previously deactivated to avoid a compiler performance issue.
The enabled RAII steps more carefully around the performance issue.

Provide uninit(-), with tests covering the typical use case:

struct Foo;
void ?{}( Foo & this, int i ) { printf( "ctor at %d\n", i ); }
uninit(Foo) a[10]; no prints
for (i; 10) (a[i]){ i };
prints
array(uninit(Foo), 10) b; no prints
for (i; 10) (b[i]){ i };
prints

Location:
libcfa/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    r40002c5 rcfbc56ec  
    4848        math.trait.hfa \
    4949        math.hfa \
     50        raii.hfa \
    5051        time_t.hfa \
    5152        virtual_dtor.hfa \
  • libcfa/src/collections/array.hfa

    r40002c5 rcfbc56ec  
    131131
    132132    static inline void __taglen( tag(arpk(N, S, Timmed, Tbase)), tag(N) ) {}
    133 
    134     // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa)
    135     static inline void ?{}( arpk(N, S, Timmed, Tbase) & this ) {
    136         void ?{}( S (&inner)[N] ) {}
    137         ?{}(this.strides);
    138     }
    139     static inline void ^?{}( arpk(N, S, Timmed, Tbase) & this ) {
    140         void ^?{}( S (&inner)[N] ) {}
    141         ^?{}(this.strides);
     133}
     134
     135// RAII pattern has workarounds for
     136//  - Trac 226:  Simplest handling would be, require immediate element to be otype, let autogen
     137//    raii happen.  Performance on even a couple dimensions is unacceptable because of exponential
     138//    thunk creation: ?{}() needs all four otype funcs from next level, so does ^?{}(), so do the
     139//    other two.  This solution offers ?{}() that needs only ?{}(), and similar for ^?{}.
     140
     141forall( [N], S & | sized(S), Timmed &, Tbase & | { void ?{}( Timmed & ); } )
     142static inline void ?{}( arpk(N, S, Timmed, Tbase) & this ) {   
     143    void ?{}( S (&)[N] ) {}
     144    ?{}(this.strides);
     145
     146    for (i; N) ?{}( (Timmed &) this.strides[i] );
     147}
     148
     149forall( [N], S & | sized(S), Timmed &, Tbase & | { void ^?{}( Timmed & ); } )
     150static inline void ^?{}( arpk(N, S, Timmed, Tbase) & this ) {
     151    void ^?{}( S (&)[N] ) {}
     152    ^?{}(this.strides);
     153
     154    for (i; N ) {
     155        ^?{}( (Timmed &) this.strides[N-i-1] );
    142156    }
    143157}
     
    147161//
    148162
    149 forall( Te )
     163forall( Te * )
    150164static inline Te mkar_( tag(Te) ) {}
    151165
Note: See TracChangeset for help on using the changeset viewer.