Changeset 1ee74df for src


Ignore:
Timestamp:
Feb 4, 2025, 10:10:11 AM (8 weeks ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
332e93a
Parents:
dfe8f78
Message:

I am working on errors in actors and I got tripped up by some code that was much more complex than it had to be so I simplified it to show that this is all it has to be.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Concurrency/Actors.cpp

    rdfe8f78 r1ee74df  
    2929struct CollectactorStructDecls : public ast::WithGuards {
    3030        unordered_set<const StructDecl *> & actorStructDecls;
    31         unordered_set<const StructDecl *>  & messageStructDecls;
    32         const StructDecl ** requestDecl;
    33         const EnumDecl ** allocationDecl;
    34         const StructDecl ** actorDecl;
    35         const StructDecl ** msgDecl;
     31        unordered_set<const StructDecl *> & messageStructDecls;
     32        const StructDecl *& requestDecl;
     33        const EnumDecl *& allocationDecl;
     34        const StructDecl *& actorDecl;
     35        const StructDecl *& msgDecl;
    3636        StructDecl * parentDecl;
    3737        bool insideStruct = false;
     
    4040        // finds and sets a ptr to the allocation enum, which is needed in the next pass
    4141        void previsit( const EnumDecl * decl ) {
    42                 if( decl->name == "allocation" ) *allocationDecl = decl;
     42                if( decl->name == "allocation" ) allocationDecl = decl;
    4343        }
    4444
     
    4848                if ( decl->name == "actor" ) {
    4949                        actorStructDecls.insert( decl ); // skip inserting fwd decl
    50                         *actorDecl = decl;
     50                        actorDecl = decl;
    5151                } else if( decl->name == "message" ) {
    5252                        messageStructDecls.insert( decl ); // skip inserting fwd decl
    53                         *msgDecl = decl;
    54                 } else if( decl->name == "request" ) *requestDecl = decl;
    55                 else {
     53                        msgDecl = decl;
     54                } else if( decl->name == "request" ) {
     55                        requestDecl = decl;
     56                } else {
    5657                        GuardValue(insideStruct);
    5758                        insideStruct = true;
     
    7374        // this collects the derived actor and message struct decl ptrs
    7475        void postvisit( const StructInstType * node ) {
    75                 if ( ! *actorDecl || ! *msgDecl ) return;
     76                if ( !actorDecl || !msgDecl ) return;
    7677                if ( insideStruct && !namedDecl ) {
    7778                        auto actorIter = actorStructDecls.find( node->aggr() );
     
    8990  public:
    9091        CollectactorStructDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    91                 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl )
     92                const StructDecl *& requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *& msgDecl )
    9293                : actorStructDecls( actorStructDecls ), messageStructDecls( messageStructDecls ), requestDecl( requestDecl ),
    9394                allocationDecl( allocationDecl ), actorDecl(actorDecl), msgDecl(msgDecl) {}
     
    196197struct GenFuncsCreateTables : public ast::WithDeclsToAdd {
    197198        unordered_set<const StructDecl *> & actorStructDecls;
    198         unordered_set<const StructDecl *>  & messageStructDecls;
    199         const StructDecl ** requestDecl;
    200         const EnumDecl ** allocationDecl;
    201         const StructDecl ** actorDecl;
    202         const StructDecl ** msgDecl;
     199        unordered_set<const StructDecl *> & messageStructDecls;
     200        const StructDecl *& requestDecl;
     201        const EnumDecl *& allocationDecl;
     202        const StructDecl *& actorDecl;
     203        const StructDecl *& msgDecl;
    203204        FwdDeclTable & forwardDecls;
    204205
     
    279280                                                decl->location,
    280281                                                "base_actor",
    281                                                 new PointerType( new PointerType( new StructInstType( *actorDecl ) ) )
     282                                                new PointerType( new PointerType( new StructInstType( actorDecl ) ) )
    282283                                        ),
    283284                                        new ObjectDecl(
    284285                                                decl->location,
    285286                                                "base_msg",
    286                                                 new PointerType( new PointerType( new StructInstType( *msgDecl ) ) )
     287                                                new PointerType( new PointerType( new StructInstType( msgDecl ) ) )
    287288                                        )
    288289                                },                      // params
     
    291292                                                decl->location,
    292293                                                "__CFA_receive_wrap_ret",
    293                                                 new EnumInstType( *allocationDecl )
     294                                                new EnumInstType( allocationDecl )
    294295                                        )
    295296                                },
     
    323324                                        decl->location,
    324325                                        "new_req",
    325                                         new StructInstType( *requestDecl )
     326                                        new StructInstType( requestDecl )
    326327                                )
    327328                        ));
     
    331332                        derivedReceive->params.push_back( ast::deepCopy( derivedActorRef ) );
    332333                        derivedReceive->params.push_back( ast::deepCopy( derivedMsgRef ) );
    333                         derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *actorDecl ) ) ) );
    334                         derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *msgDecl ) ) ) );
    335                         derivedReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
     334                        derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( actorDecl ) ) ) );
     335                        derivedReceive->params.push_back( new PointerType( new PointerType( new StructInstType( msgDecl ) ) ) );
     336                        derivedReceive->returns.push_back( new EnumInstType( allocationDecl ) );
    336337
    337338                        // Generates: allocation (*my_work_fn)( derived_actor &, derived_msg &, actor **, message ** ) = receive;
     
    348349                        // Function type is: allocation (*)( actor &, message & )
    349350                        FunctionType * genericReceive = new FunctionType();
    350                         genericReceive->params.push_back( new ReferenceType( new StructInstType( *actorDecl ) ) );
    351                         genericReceive->params.push_back( new ReferenceType( new StructInstType( *msgDecl ) ) );
    352                         genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *actorDecl ) ) ) );
    353                         genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( *msgDecl ) ) ) );
    354                         genericReceive->returns.push_back( new EnumInstType( *allocationDecl ) );
     351                        genericReceive->params.push_back( new ReferenceType( new StructInstType( actorDecl ) ) );
     352                        genericReceive->params.push_back( new ReferenceType( new StructInstType( msgDecl ) ) );
     353                        genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( actorDecl ) ) ) );
     354                        genericReceive->params.push_back( new PointerType( new PointerType( new StructInstType( msgDecl ) ) ) );
     355                        genericReceive->returns.push_back( new EnumInstType( allocationDecl ) );
    355356
    356357                        // Generates: allocation (*fn)( actor &, message & ) = (allocation (*)( actor &, message & ))my_work_fn;
     
    378379                                        {
    379380                                                new NameExpr( decl->location, "new_req" ),
    380                                                 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "receiver" ) ), new PointerType( new StructInstType( *actorDecl ) ), ExplicitCast ),
    381                                                 new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "msg" ) ), new PointerType( new StructInstType( *msgDecl ) ), ExplicitCast ),
     381                                                new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "receiver" ) ), new PointerType( new StructInstType( actorDecl ) ), ExplicitCast ),
     382                                                new CastExpr( decl->location, new AddressExpr( new NameExpr( decl->location, "msg" ) ), new PointerType( new StructInstType( msgDecl ) ), ExplicitCast ),
    382383                                                new NameExpr( decl->location, "fn" )
    383384                                        }
     
    443444  public:
    444445        GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    445                 const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl,
     446                const StructDecl *& requestDecl, const EnumDecl *& allocationDecl, const StructDecl *& actorDecl, const StructDecl *& msgDecl,
    446447                FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
    447448                requestDecl(requestDecl), allocationDecl(allocationDecl), actorDecl(actorDecl), msgDecl(msgDecl), forwardDecls(forwardDecls) {}
     
    453454struct FwdDeclOperator : public ast::WithDeclsToAdd {
    454455        unordered_set<const StructDecl *> & actorStructDecls;
    455         unordered_set<const StructDecl *>  & messageStructDecls;
     456        unordered_set<const StructDecl *> & messageStructDecls;
    456457        FwdDeclTable & forwardDecls;
    457458
     
    495496        // for storing through the passes
    496497        // these are populated with various important struct decls
    497         const StructDecl * requestDeclPtr = nullptr;
    498         const EnumDecl * allocationDeclPtr = nullptr;
    499         const StructDecl * actorDeclPtr = nullptr;
    500         const StructDecl * msgDeclPtr = nullptr;
    501 
    502         // double pointer to modify local ptrs above
    503         const StructDecl ** requestDecl = &requestDeclPtr;
    504         const EnumDecl ** allocationDecl = &allocationDeclPtr;
    505         const StructDecl ** actorDecl = &actorDeclPtr;
    506         const StructDecl ** msgDecl = &msgDeclPtr;
     498        const StructDecl * requestDecl = nullptr;
     499        const EnumDecl * allocationDecl = nullptr;
     500        const StructDecl * actorDecl = nullptr;
     501        const StructDecl * msgDecl = nullptr;
    507502
    508503        // first pass collects ptrs to allocation enum, request type, and generic receive fn typedef
    509504        // also populates maps of all derived actors and messages
    510         Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    511                 allocationDecl, actorDecl, msgDecl );
     505        Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls,
     506                requestDecl, allocationDecl, actorDecl, msgDecl );
    512507
    513508        // check that we have found all the decls we need from <actor.hfa>, if not no need to run the rest of this pass
    514         if ( !allocationDeclPtr || !requestDeclPtr || !actorDeclPtr || !msgDeclPtr )
     509        if ( !allocationDecl || !requestDecl || !actorDecl || !msgDecl )
    515510                return;
    516511
    517512        // second pass locates all receive() routines that overload the generic receive fn
    518513        // it then generates the appropriate operator '|' send routines for the receive routines
    519         Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    520                 allocationDecl, actorDecl, msgDecl, forwardDecls );
     514        Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls,
     515                requestDecl, allocationDecl, actorDecl, msgDecl, forwardDecls );
    521516
    522517        // The third pass forward declares operator '|' send routines
Note: See TracChangeset for help on using the changeset viewer.