Changeset fcd0b9d7


Ignore:
Timestamp:
Jan 18, 2021, 3:34:57 PM (8 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
4b1c8da
Parents:
e35a32b
Message:

PolyCost? calculation result becomes 0 or 1 per type, avoiding double-couting. Fixes #235?

PolyCost? calculation is documented as "Count of parameters and return values bound to some poly type." Before this fix, the cost calculation, looking inside one parameter or return, counted each occurrence of a poly type that it found there. This caused an incorrect increase in PolyCost? on cases like #235 where several type variables are used in the declaration of one parameter.

libcfa/src/concurrency/thread.cfa: Changing a decl-use pattern to keep resolution consistent (no behaviour is changed). The management of defaultResumptionHandler in the thread constructor was benefitting from bug #235 to disambiguate assignment to local variable vs assignment to declared function (due to #234). After this change, the code works around that false ambiguity by using a different name for the local variable.

tests/avl*: Adding a missing assertion on the custom destructor definition. Previously, the destructor definition was benefiting from bug #235 to avoid the missing-assertion-on-custom-dtor problem described in #227.

Files:
6 edited

Legend:

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

    re35a32b rfcd0b9d7  
    8383forall(dtype T | is_thread(T) | IS_EXCEPTION(ThreadCancelled, (T)))
    8484void ?{}( thread_dtor_guard_t & this,
    85                 T & thrd, void(*defaultResumptionHandler)(ThreadCancelled(T) &)) {
    86         $monitor * m = get_monitor(thrd);
     85                T & thrd, void(*cancelHandler)(ThreadCancelled(T) &)) {
     86        $monitor * m = get_monitor(thrd);
    8787        $thread * desc = get_thread(thrd);
    8888
    8989        // Setup the monitor guard
    9090        void (*dtor)(T& mutex this) = ^?{};
    91         bool join = defaultResumptionHandler != (void(*)(ThreadCancelled(T)&))0;
     91        bool join = cancelHandler != (void(*)(ThreadCancelled(T)&))0;
    9292        (this.mg){&m, (void(*)())dtor, join};
    9393
     
    103103        }
    104104        desc->state = Cancelled;
    105         if (!join) {
    106                 defaultResumptionHandler = default_thread_cancel_handler;
    107         }
     105        void(*defaultResumptionHandler)(ThreadCancelled(T) &) =
     106                join ? cancelHandler : default_thread_cancel_handler;
    108107
    109108        ThreadCancelled(T) except;
  • src/ResolvExpr/PolyCost.cc

    re35a32b rfcd0b9d7  
    3535                PassVisitor<PolyCost> coster( env, indexer );
    3636                type->accept( coster );
    37                 return coster.pass.result;
     37                return (coster.pass.result > 0) ? 1 : 0;
    3838        }
    3939
     
    8787        ast::Pass<PolyCost_new> costing( symtab, env );
    8888        type->accept( costing );
    89         return costing.core.result;
     89        return (costing.core.result > 0) ? 1 : 0;
    9090}
    9191
  • tests/.expect/poly-selection.txt

    re35a32b rfcd0b9d7  
    11friending generically
    22friending specifically
     3-
     4f-generic
     5f-specific
  • tests/avltree/avl.h

    re35a32b rfcd0b9d7  
    5757void ?{}(tree(K, V) &t, K key, V value);
    5858
    59 forall(otype K, otype V)
     59forall(otype K | Comparable(K), otype V)
    6060void ^?{}(tree(K, V) & t);
    6161
  • tests/avltree/avl1.cfa

    re35a32b rfcd0b9d7  
    1313}
    1414
    15 forall(otype K, otype V)
     15forall(otype K| Comparable(K), otype V)
    1616void ^?{}(tree(K, V) & t){
    1717  delete(t.left);
  • tests/poly-selection.cfa

    re35a32b rfcd0b9d7  
    3535}
    3636
     37void testSpecializationFromGenericAccessibleWithExtraTyvars() {
     38
     39    forall( dtype T, dtype U )
     40    struct map {};
     41
     42    forall( dtype T )
     43    void f( T & ) {
     44        printf("f-generic\n");
     45    }
     46
     47    forall( dtype T )
     48    void f( map(T, T) & ) {
     49        printf("f-specific\n");
     50    }
     51
     52    float one;
     53    map(float, float) two;
     54    f(one);
     55    f(two);
     56}
    3757
    3858int main() {
    3959    testSpecializationFromGenericOverBareTyvar();
     60    printf("-\n");
     61    testSpecializationFromGenericAccessibleWithExtraTyvars();
    4062}
Note: See TracChangeset for help on using the changeset viewer.