Changeset 36dfdac


Ignore:
Timestamp:
Dec 11, 2024, 7:53:36 PM (6 days ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
bad15f7
Parents:
5d3d281
Message:

Enable partial autogen for types declared inside functions.

Done by giving pass cores finer grained error-recovery points, which causes Resolver's existing error-recovery logic to kick in for autogens within function bodies.

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Pass.impl.hpp

    r5d3d281 r36dfdac  
    218218        __pass::resultNstmt<container_t> new_kids;
    219219        for ( auto value : enumerate( statements ) ) {
     220                size_t i = value.idx;
     221                const Stmt * stmt = value.val;
    220222                try {
    221                         size_t i = value.idx;
    222                         const Stmt * stmt = value.val;
    223223                        __pedantic_pass_assert( stmt );
    224224                        const ast::Stmt * new_stmt = stmt->accept( *this );
     
    246246                        new_kids.take_all( stmts_after );
    247247                } catch ( SemanticErrorException &e ) {
     248                        if ( auto dstmt = dynamic_cast<const DeclStmt *>( stmt ) ) {
     249                                assert( dstmt->decl->unique() );
     250                                auto & declLink = const_cast< ptr<Decl> & >( dstmt->decl );
     251                  if ( !__pass::on_error (core, declLink, 0) ) goto handled;
     252                        }
    248253                        errors.append( e );
     254                  handled:;
    249255                }
    250256        }
  • tests/raii/.expect/partial.txt

    r5d3d281 r36dfdac  
     1====== Top-level declarations ======
    12test1
    23custom ctor
     
    1516custom ctor
    1617custom dtor
     18====== Function-nested declarations ======
     19test1
     20custom ctor
     21test2
     22custom ctor
     23custom dtor
     24custom dtor
     25test3
     26test4
     27custom ctor
     28custom dtor
     29test5
     30custom ctor
     31custom dtor
     32test6
     33custom ctor
     34custom dtor
  • tests/raii/partial.cfa

    r5d3d281 r36dfdac  
    77#define BAD(...)
    88#endif
     9
     10void testAllNested() {
     11
     12    // Declaring your own empty ctor leaves an autogen dtor usable
     13    struct thing1 {};
     14    void ?{}( thing1 & this ) {  printf( "custom ctor\n"); }
     15    void test1() {
     16        printf("test1\n");
     17        thing1 x;
     18    }
     19
     20    // Declaring your own empty ctor and dtor leaves an autogen copy ctor usable
     21    struct thing2 {};
     22    void  ?{}( thing2 & this ) {  printf( "custom ctor\n"); }
     23    void ^?{}( thing2 & this ) {  printf( "custom dtor\n"); }
     24    void test2() {
     25        printf("test2\n");
     26        thing2 x;
     27        thing2 y = x;
     28    }
     29
     30    // Deleting the autogen copy ctor also deletes the autogen empty ctor
     31    struct thing3 {};
     32    void  ?{}( thing3 &, thing3 ) = void;
     33    void test3() {
     34        printf("test3\n");
     35        BAD( thing3 x; )  // Unique best alternative includes deleted identifier
     36    }
     37
     38    struct thing456 {};
     39    void    ?{}( thing456 & this ) {  printf( "custom ctor\n"); }
     40    void    ?{}( thing456 &, thing456 ) = void;
     41    thing456 & ?=?( thing456 &, thing456 ) = void;
     42    void   ^?{}( thing456 & this ) {  printf( "custom dtor\n"); }
     43
     44    struct wrapper1 { thing456 x; };
     45    struct wrapper2 { wrapper1 x; };
     46
     47    // Deleting some autogens and declaring your own for the others leaves yours usable
     48    // and the deleted ones cleanly deleted
     49    void test4() {
     50        printf("test4\n");
     51        thing456 x;
     52        BAD(  thing456 y = x;  )   // Unique best alternative includes deleted identifier
     53    }
     54
     55    // Wrapping v4 leaves yours usable via autogen
     56    // and the autogen-lifts of your deleted ones are not usable
     57    void test5() {
     58        printf("test5\n");
     59        wrapper1 x;
     60        BAD(  wrapper1 y = x;  )  //  Unique best alternative includes deleted identifier
     61    }
     62
     63    // Wrapping again works similarly
     64    void test6() {
     65        printf("test6\n");
     66        wrapper2 x;
     67        BAD(  wrapper2 y = x;  )  //  Unique best alternative includes deleted identifier
     68    }
     69
     70    test1();
     71    test2();
     72    test3();
     73    test4();
     74    test5();
     75    test6();
     76}
     77
     78// ===== Repeat, now as top-level declarations
    979
    1080// Declaring your own empty ctor leaves an autogen dtor usable
     
    67137
    68138int main() {
     139    printf("====== Top-level declarations ======\n");
    69140    test1();
    70141    test2();
     
    73144    test5();
    74145    test6();
     146    printf("====== Function-nested declarations ======\n");
     147    testAllNested();
    75148}
Note: See TracChangeset for help on using the changeset viewer.