Changeset b583113


Ignore:
Timestamp:
Apr 21, 2021, 3:44:58 PM (3 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
578c09a
Parents:
7711064
Message:

Recovered the polymorphic CoroutineCancelled? exception. The interface might need a bit of polish.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/coroutine.cfa

    r7711064 rb583113  
    4646
    4747//-----------------------------------------------------------------------------
    48 EHM_VIRTUAL_TABLE(SomeCoroutineCancelled, std_coroutine_cancelled);
    49 
    5048forall(T &)
    5149void copy(CoroutineCancelled(T) * dst, CoroutineCancelled(T) * src) {
     
    6260// This code should not be inlined. It is the error path on resume.
    6361forall(T & | is_coroutine(T))
    64 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc ) {
     62void __cfaehm_cancelled_coroutine(
     63                T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable ) {
    6564        verify( desc->cancellation );
    6665        desc->state = Cancelled;
     
    6867
    6968        // TODO: Remove explitate vtable set once trac#186 is fixed.
    70         SomeCoroutineCancelled except;
    71         except.virtual_table = &std_coroutine_cancelled;
     69        CoroutineCancelled(T) except;
     70        except.virtual_table = &_default_vtable;
    7271        except.the_coroutine = &cor;
    7372        except.the_exception = except;
    7473        // Why does this need a cast?
    75         throwResume (SomeCoroutineCancelled &)except;
     74        throwResume (CoroutineCancelled(T) &)except;
    7675
    7776        except->virtual_table->free( except );
     
    146145// Part of the Public API
    147146// Not inline since only ever called once per coroutine
    148 forall(T & | is_coroutine(T))
     147forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    149148void prime(T& cor) {
    150149        $coroutine* this = get_coroutine(cor);
  • libcfa/src/concurrency/coroutine.hfa

    r7711064 rb583113  
    2222//-----------------------------------------------------------------------------
    2323// Exception thrown from resume when a coroutine stack is cancelled.
    24 EHM_EXCEPTION(SomeCoroutineCancelled)(
    25         void * the_coroutine;
    26         exception_t * the_exception;
    27 );
    28 
    29 EHM_EXTERN_VTABLE(SomeCoroutineCancelled, std_coroutine_cancelled);
    30 
    3124EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) (
    3225        coroutine_t * the_coroutine;
     
    4437// Anything that implements this trait can be resumed.
    4538// Anything that is resumed is a coroutine.
    46 trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(SomeCoroutineCancelled)) {
     39trait is_coroutine(T & | IS_RESUMPTION_EXCEPTION(CoroutineCancelled, (T))) {
    4740        void main(T & this);
    4841        $coroutine * get_coroutine(T & this);
     
    6760//-----------------------------------------------------------------------------
    6861// Public coroutine API
    69 forall(T & | is_coroutine(T))
     62forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    7063void prime(T & cor);
    7164
     
    137130
    138131forall(T & | is_coroutine(T))
    139 void __cfaehm_cancelled_coroutine( T & cor, $coroutine * desc );
     132void __cfaehm_cancelled_coroutine(
     133        T & cor, $coroutine * desc, _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable );
    140134
    141135// Resume implementation inlined for performance
    142 forall(T & | is_coroutine(T))
     136forall(T & | is_coroutine(T) | { _EHM_VTABLE_TYPE(CoroutineCancelled)(T) & const _default_vtable; })
    143137static inline T & resume(T & cor) {
    144138        // optimization : read TLS once and reuse it
     
    170164        $ctx_switch( src, dst );
    171165        if ( unlikely(dst->cancellation) ) {
    172                 __cfaehm_cancelled_coroutine( cor, dst );
     166                __cfaehm_cancelled_coroutine( cor, dst, _default_vtable );
    173167        }
    174168
  • libcfa/src/exception.hfa

    r7711064 rb583113  
    142142                _EHM_VTABLE_TYPE(exception_name) parameters const &) {} \
    143143
    144 #define _EHM_TRAIT_FUNCTION2(exception_name, forall_clause, parameters) \
    145         forall_clause _EHM_VTABLE_TYPE(exception_name) parameters const & \
    146                         get_exception_vtable(exception_name parameters const & this)
    147 
    148144#define __EHM_TRAIT_FUNCTION(exception_name, forall_clause, parameters) \
    149145        forall_clause inline _EHM_VTABLE_TYPE(exception_name) parameters const & \
  • src/Concurrency/Keywords.cc

    r7711064 rb583113  
    414414                if ( type_decl && isDestructorFor( decl, type_decl ) )
    415415                        dtor_decl = decl;
    416                 else if ( vtable_name.empty() )
    417                         ;
    418                 else if( !decl->has_body() )
     416                else if ( vtable_name.empty() || !decl->has_body() )
    419417                        ;
    420418                else if ( auto param = isMainFor( decl, cast_target ) ) {
     
    428426                        std::list< Expression * > poly_args = { new TypeExpr( struct_type->clone() ) };
    429427                        ObjectDecl * vtable_object = Virtual::makeVtableInstance(
     428                                "_default_vtable_object_declaration",
    430429                                vtable_decl->makeInst( poly_args ), struct_type, nullptr );
    431430                        declsToAddAfter.push_back( vtable_object );
     431                        declsToAddAfter.push_back(
     432                                new ObjectDecl(
     433                                        Virtual::concurrentDefaultVTableName(),
     434                                        Type::Const,
     435                                        LinkageSpec::Cforall,
     436                                        /* bitfieldWidth */ nullptr,
     437                                        new ReferenceType( Type::Const, vtable_object->type->clone() ),
     438                                        new SingleInit( new VariableExpr( vtable_object ) )
     439                                )
     440                        );
    432441                        declsToAddAfter.push_back( Virtual::makeGetExceptionFunction(
    433442                                vtable_object, except_decl->makeInst( std::move( poly_args ) )
     
    488497                        except_decl->makeInst( poly_args )
    489498                ) );
    490                 declsToAddBefore.push_back( Virtual::makeVtableForward(
    491                         vtable_decl->makeInst( move( poly_args ) ) ) );
     499                ObjectDecl * vtable_object = Virtual::makeVtableForward(
     500                        "_default_vtable_object_declaration",
     501                        vtable_decl->makeInst( move( poly_args ) ) );
     502                declsToAddBefore.push_back( vtable_object );
     503                declsToAddAfter.push_back(
     504                        new ObjectDecl(
     505                                Virtual::concurrentDefaultVTableName(),
     506                                Type::Const,
     507                                LinkageSpec::Cforall,
     508                                /* bitfieldWidth */ nullptr,
     509                                new ReferenceType( Type::Const, vtable_object->type->clone() ),
     510                                /* init */ nullptr
     511                        )
     512                );
    492513        }
    493514
  • src/Virtual/Tables.cc

    r7711064 rb583113  
    1010// Created On       : Mon Aug 31 11:11:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Apr  8 15:51:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Wed Apr 21 15:36:00 2021
     13// Update Count     : 2
    1414//
    1515
     
    5050}
    5151
     52std::string concurrentDefaultVTableName() {
     53        return "_default_vtable";
     54}
     55
    5256bool isVTableInstanceName( std::string const & name ) {
    5357        // There are some delicate length calculations here.
     
    5761
    5862static ObjectDecl * makeVtableDeclaration(
     63                std::string const & name,
    5964                StructInstType * type, Initializer * init ) {
    60         std::string const & name = instanceName( type->name );
    6165        Type::StorageClasses storage = noStorageClasses;
    6266        if ( nullptr == init ) {
     
    7377}
    7478
    75 ObjectDecl * makeVtableForward( StructInstType * type ) {
     79ObjectDecl * makeVtableForward( std::string const & name, StructInstType * type ) {
    7680        assert( type );
    77         return makeVtableDeclaration( type, nullptr );
     81        return makeVtableDeclaration( name, type, nullptr );
    7882}
    7983
    8084ObjectDecl * makeVtableInstance(
    81                 StructInstType * vtableType, Type * objectType, Initializer * init ) {
     85                std::string const & name, StructInstType * vtableType,
     86                Type * objectType, Initializer * init ) {
    8287        assert( vtableType );
    8388        assert( objectType );
     
    115120                assert(false);
    116121        }
    117         return makeVtableDeclaration( vtableType, init );
     122        return makeVtableDeclaration( name, vtableType, init );
    118123}
    119124
     
    167172}
    168173
    169 ObjectDecl * makeTypeIdForward() {
    170         return nullptr;
    171 }
    172 
    173174Attribute * linkonce( const std::string & subsection ) {
    174175        const std::string section = ".gnu.linkonce." + subsection;
  • src/Virtual/Tables.h

    r7711064 rb583113  
    1010// Created On       : Mon Aug 31 11:07:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Apr  8 15:55:00 2021
    13 // Update Count     : 1
     12// Last Modified On : Wed Apr 21 10:30:00 2021
     13// Update Count     : 2
    1414//
    1515
     
    2727std::string instanceName( std::string const & vtable_name );
    2828std::string vtableInstanceName( std::string const & type_name );
     29std::string concurrentDefaultVTableName();
    2930bool isVTableInstanceName( std::string const & name );
    3031
    31 ObjectDecl * makeVtableForward( StructInstType * vtableType );
     32ObjectDecl * makeVtableForward(
     33        std::string const & name, StructInstType * vtableType );
    3234/* Create a forward declaration of a vtable of the given type.
    3335 * vtableType node is consumed.
    3436 */
    3537
    36 ObjectDecl * makeVtableInstance( StructInstType * vtableType, Type * objectType,
     38ObjectDecl * makeVtableInstance(
     39        std::string const & name,
     40        StructInstType * vtableType, Type * objectType,
    3741        Initializer * init = nullptr );
    3842/* Create an initialized definition of a vtable.
  • tests/exceptions/cancel/coroutine.cfa

    r7711064 rb583113  
    2525                resume(cancel);
    2626                printf("4");
    27         } catchResume (SomeCoroutineCancelled * error) {
     27        } catchResume (CoroutineCancelled(WillCancel) * error) {
    2828                printf("2");
    2929                if ((virtual internal_error *)error->the_exception) {
Note: See TracChangeset for help on using the changeset viewer.