Changeset a8e8c67


Ignore:
Timestamp:
Jan 31, 2023, 2:59:20 PM (22 months ago)
Author:
caparsons <caparson@…>
Branches:
ADT, ast-experimental, master
Children:
757099e
Parents:
96ddc62
Message:

fixed non-inline actor/message bug and cleaned up Actor pass

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Actors.cpp

    r96ddc62 ra8e8c67  
    3636    StructDecl * parentDecl;
    3737    bool insideStruct = false;
    38 
     38    bool namedDecl = false;
     39
     40    // finds and sets a ptr to the Allocation enum, which is needed in the next pass
    3941    void previsit( const EnumDecl * decl ) {
    4042        if( decl->name == "Allocation" ) *allocationDecl = decl;
    4143    }
    4244
     45    // finds and sets a ptr to the actor, message, and request structs, which are needed in the next pass
    4346    void previsit( const StructDecl * decl ) {
    4447        GuardValue(insideStruct);
     
    4750        if( decl->name == "actor" ) *actorDecl = decl;
    4851        if( decl->name == "message" ) *msgDecl = decl;
    49         if( decl->name == "request" ) *requestDecl = decl;       
     52        if( decl->name == "request" ) *requestDecl = decl;
    5053        }
    5154
     55    // this catches structs of the form:
     56    //     struct dummy_actor { actor a; };
     57    // since they should be:
     58    //     struct dummy_actor { inline actor; };
     59    void previsit ( const ObjectDecl * decl ) {
     60        if ( insideStruct && ! decl->name.empty() ) {
     61            GuardValue(namedDecl);
     62            namedDecl = true;
     63        }
     64    }
     65
     66    // this collects the valid actor and message struct decl pts
    5267    void postvisit( const StructInstType * node ) {
    5368        if ( ! *actorDecl || ! *msgDecl ) return;
    54         if ( insideStruct ) {
    55             if ( node->aggr() == *actorDecl ) { // C_TODO: see if we need to check for empty name
     69        if ( insideStruct && !namedDecl ) {
     70            if ( node->aggr() == *actorDecl ) {
    5671                actorStructDecls.insert( parentDecl );
    5772            } else if ( node->aggr() == *msgDecl ) {
     
    100115            iter->second.emplace( make_pair( otherDecl, data ) );
    101116        } else { // else create inner map for key
    102             map.emplace( make_pair( decl, unordered_map<const StructDecl *, FwdDeclData *>( { make_pair( otherDecl, data ) } ) ) ); // C_TODO: maybe emplace?
     117            map.emplace( make_pair( decl, unordered_map<const StructDecl *, FwdDeclData *>( { make_pair( otherDecl, data ) } ) ) );
    103118        }
    104119    }
     
    118133        unordered_map<const StructDecl *, unordered_map<const StructDecl *, FwdDeclData *>> & otherMap =  isMsg ? actorMap : msgMap;
    119134        auto iter = map.find( decl );
    120 
    121135        list<FunctionDecl *> toInsertAfter; // this is populated with decls that are ready to insert
    122136        if ( iter == map.end() ) return toInsertAfter;
    123137       
     138        // iterate over inner map
    124139        unordered_map<const StructDecl *, FwdDeclData *> & currInnerMap = iter->second;
    125 
    126         cout << "a" << endl;
    127         // iterate over inner map
    128140        for ( auto innerIter = currInnerMap.begin(); innerIter != currInnerMap.end(); ) {
    129             cout << "b: " << decl->name << endl;
    130141            FwdDeclData * currentDatum = innerIter->second;
    131             printf("P: %p\n", currentDatum->fwdDecl );
    132 
    133142            bool readyToInsert = isMsg ? currentDatum->foundMsg() : currentDatum->foundActor();
    134143            if ( ! readyToInsert ) { ++innerIter; continue; }
    135144           
    136             cout << "c" << endl;
    137145            // readyToInsert is true so we are good to insert the forward decl of the message fn
    138146            toInsertAfter.push_back( currentDatum->fwdDecl );
    139147
    140             cout << "d" << endl;
    141 
     148            // need to remove from other map before deleting
     149            // find inner map in other map ( other map is actor map if original is msg map and vice versa )
    142150            const StructDecl * otherDecl = isMsg ? currentDatum->actorDecl : currentDatum->msgDecl;
    143 
    144             // need to remove from other map before deleting
    145             // find inner map of FwdDeclData in other map ( other map is actor map if original is msg map and vice versa )
    146151            auto otherMapIter = otherMap.find( otherDecl );
    147152
    148153            unordered_map<const StructDecl *, FwdDeclData *> & otherInnerMap = otherMapIter->second;
    149154
    150             cout << "e" << endl;
    151155            // find the FwdDeclData we need to remove in the other inner map
    152156            auto otherInnerIter = otherInnerMap.find( decl );
    153157
    154             cout << "f" << endl;
    155             // now we are safe to delete the FwdDeclData since we are done with it
    156             // have to delete before we invalidate the iterator
    157             delete currentDatum; // C_TODO: move down since this no longer iterator dependant
    158 
    159             cout << "g" << endl;
    160158            // remove references to deleted FwdDeclData from current inner map
    161159            innerIter = currInnerMap.erase( innerIter ); // this does the increment so no explicit inc needed
    162160
    163             cout << "h" << endl;
    164161            // remove references to deleted FwdDeclData from other inner map
    165162            otherInnerMap.erase( otherInnerIter );
     
    168165            if ( otherInnerMap.empty() )
    169166                otherMap.erase( otherDecl );
     167
     168            // now we are safe to delete the FwdDeclData since we are done with it
     169            // and we have removed all references to it from our data structures
     170            delete currentDatum;
    170171        }
    171172
Note: See TracChangeset for help on using the changeset viewer.