Index: examples/hashtable2.cfa
===================================================================
--- examples/hashtable2.cfa	(revision df733edff0cd4f9cb81110b8ad0882cb1feebeaf)
+++ examples/hashtable2.cfa	(revision df733edff0cd4f9cb81110b8ad0882cb1feebeaf)
@@ -0,0 +1,257 @@
+
+#include <containers/list.hfa>
+
+typedef unsigned int K;
+
+// workaround type for trac#185; used here as the ticket's examples use a spontaneous float
+typedef struct {} t_unused;
+
+struct request {
+
+    unsigned int src_id;
+    unsigned int tgt_id;
+
+    DLISTED_MGD_EXPL_IN(request, ht_by_src)
+    DLISTED_MGD_EXPL_IN(request, ht_by_tgt)
+};
+DLISTED_MGD_EXPL_OUT(request, ht_by_src)
+DLISTED_MGD_EXPL_OUT(request, ht_by_tgt)
+
+size_t hash( unsigned int k ) {
+    // not really a hash function, not really the point
+    return k;
+}
+
+unsigned int key( request_in_ht_by_src & v ) {
+    return v.src_id;
+}
+
+
+#include <exception.hfa>
+TRIVIAL_EXCEPTION(ht_fill_limit_crossed);
+
+
+
+void defaultResumptionHandler(ht_fill_limit_crossed &) {
+    printf("default resumption ht_fill_limit_crossed\n");
+}
+
+void defaultTerminationHandler(ht_fill_limit_crossed &) = void;
+
+trait pretendsToMatter( dtype TTT ) {
+    void actsmart(TTT &);
+};
+
+forall( dtype TTTx )
+void actsmart(TTTx &) {}
+
+// probable bug, wrt otype Tt_unused...
+//   1. changing to dtype Tt_unused crashes GenPoly
+//   2. declaring function check_ff_warning as concrete, i.e. operating on type hashtable_rbs(t_unused) makes cfa-cc generate bad C
+// in both cases, it's on the throwResume call
+// where it implicitly uses this.defaultResumptionHandler as a throwResume argument
+// whereas that, of course, has to be surrounded in a cast
+// at GenPoly breakpoint, type of said cast appears as CFA generic struct, even as the "this" parameter appears as C struct; casted type ...
+//   1. is hashtable_rbs(Tt_unused); assertion complains you don't need a type arg here
+//   2. shows up in -CFA output as hashtable_rbs(), which is bad C; expecting hashtable_rbs*
+
+forall( otype Tt_unused | pretendsToMatter(Tt_unused) ) {
+
+    // hashtable of request by source
+    struct hashtable_rbs {
+
+        size_t n_buckets;
+        dlist(request_in_ht_by_src, request) *buckets;
+        
+        size_t item_count;
+        float ff_next_warn_up;
+
+        void (*defaultResumptionHandler) (ht_fill_limit_crossed &);
+    };
+
+    void ?{}( hashtable_rbs(Tt_unused) & this ) = void;
+}
+
+forall( otype Tt_unused | pretendsToMatter(Tt_unused) | { void defaultResumptionHandler(ht_fill_limit_crossed &); } ) {
+
+    void ?{}( hashtable_rbs(Tt_unused) & this, size_t n_buckets, dlist(request_in_ht_by_src, request) *buckets ) {
+
+        this.n_buckets = n_buckets;
+        this.buckets = buckets;
+
+        this.item_count = 0;
+        this.ff_next_warn_up = 0.5;
+
+        this.defaultResumptionHandler = defaultResumptionHandler;
+
+        for ( i; n_buckets ) {
+            ?{}( this.buckets[i] );
+        }
+    }
+}
+
+forall( otype Tt_unused | pretendsToMatter(Tt_unused) ) {
+
+    float fill_frac( hashtable_rbs(Tt_unused) & this ) with(this) {
+        return ((float)item_count) / n_buckets;
+    }
+
+    size_t bucket_of( hashtable_rbs(Tt_unused) & this, K k ) {
+        return hash(k) % this.n_buckets;
+    }
+
+    request & get( hashtable_rbs(Tt_unused) & this, K k ) with (this) {
+
+        dlist(request_in_ht_by_src, request) & bucket = buckets[ bucket_of(this, k) ];
+
+        for ( request_in_ht_by_src * item = & $tempcv_e2n(bucket`first);  item != 0p;  item = & $tempcv_e2n((*item)`next) ) {
+            if ( key(*item) == k ) {
+                return *item;
+            }
+        }
+
+        return *0p;
+    }
+
+    void check_ff_warning( hashtable_rbs(Tt_unused) & this ) with (this) {
+        if (fill_frac(this) > ff_next_warn_up) {
+            throwResume (ht_fill_limit_crossed){};
+            ff_next_warn_up *= 2;
+        }
+    }
+
+    void put( hashtable_rbs(Tt_unused) & this, request & v ) with (this) {
+
+        check_ff_warning(this);
+
+        K k = key( $tempcv_e2n(v) );
+        dlist(request_in_ht_by_src, request) & bucket = buckets[ bucket_of(this, k) ];
+
+        for ( request_in_ht_by_src * item = & $tempcv_e2n(bucket`first);  item != 0p;  item = & $tempcv_e2n((*item)`next) ) {
+            if ( key(*item) == k ) {
+                remove(*item);
+                break;
+            }
+        }
+
+        insert_first(bucket, v);
+        this.item_count ++;
+    }
+}
+
+// tactical usage:
+// HASHTABLE_RBS_STATIC(n, ht)
+//
+// intended equivalent:
+// hashtable_rbs_static(Z(n)) ht;
+#define HASHTABLE_RBS_STATIC(n_buckets, obj) \
+    struct __hashtable_static_ ## obj { \
+        inline hashtable_rbs(t_unused); \
+        dlist(request_in_ht_by_src, request) $items[n_buckets]; \
+    }; \
+    void ?{}( __hashtable_static_ ## obj & this )  { \
+        ((hashtable_rbs(t_unused) &)this){ n_buckets, this.$items }; \
+    } \
+    __hashtable_static_ ## obj obj;
+
+
+
+trait heaped(dtype T) {
+    T * alloc( size_t );
+    void free( void * ); 
+};
+
+void __dynamic_defaultResumptionHandler(ht_fill_limit_crossed & ex) {
+    printf("dynamic limit crossed\n");
+}
+
+forall( | heaped( dlist(request_in_ht_by_src, request) ) ) {
+
+    struct hashtable_rbs_dynamic { 
+        inline hashtable_rbs(t_unused); 
+    };
+    void ?{}( hashtable_rbs_dynamic(t_unused) & this, size_t n_buckets )  {
+        void (*defaultResumptionHandler) (ht_fill_limit_crossed &) = __dynamic_defaultResumptionHandler;
+        dlist(request_in_ht_by_src, request) *buckets = alloc(n_buckets);
+        ((hashtable_rbs(t_unused) &)this){ n_buckets, buckets };
+    }
+    void ^?{}( hashtable_rbs_dynamic(t_unused) & this ) {
+        free(this.buckets);
+    }
+}
+
+
+
+
+
+
+#include <stdlib.hfa>
+
+int main() {
+
+
+    HASHTABLE_RBS_STATIC(67, h_src)
+
+    request & wasnt_found = get(h_src, 17);
+    assert( &wasnt_found == 0p );
+
+    request r;
+    r.src_id = 117;
+    r.tgt_id = 998;
+
+    put(h_src, r);
+
+    request & found = get(h_src, 117);
+    assert( &found == &r );
+
+    & wasnt_found = & get(h_src, 998);
+    assert( &wasnt_found == 0p );
+
+    printf( "%f\n", fill_frac(h_src) );
+
+
+    request rs[500];
+    try {
+        for (i; 500) {
+            rs[i].src_id = 8000 * i;
+            put(h_src, rs[i]);
+        }
+    } catchResume(ht_fill_limit_crossed*) {
+        printf("fill limit tripped with h_src filled at %f\n", fill_frac(h_src));
+        throwResume;
+    }
+
+    assert(  & get(h_src, 117      ) );
+    assert(  & get(h_src, 8000*25  ) );
+    assert(! & get(h_src, 8000*25+1) );
+
+
+
+    dlist(request_in_ht_by_src, request) * (*old_alloc)( size_t ) = alloc;
+    dlist(request_in_ht_by_src, request) * alloc( size_t n ) {
+        dlist(request_in_ht_by_src, request) * ret = old_alloc(n);
+        printf("alloc'ed at %p\n", ret);
+        return ret;
+    }
+
+    void (*old_free)( void * ) = free;
+    void free( void * o ) {
+        printf("free'ing at %p\n", o);
+        old_free(o);
+    }
+
+    hashtable_rbs_dynamic(t_unused) ht2 = { 113 };
+    request rs2[500];
+    try {
+        for (i; 500) {
+            if (i % 10 == 0) {printf("%d(%f),", i, fill_frac(ht2));}
+            rs2[i].src_id = 8000 * i;
+            put(ht2, rs2[i]);
+        }
+    } catchResume(ht_fill_limit_crossed*) {
+        printf("fill limit tripped with ht2 filled at %f\n", fill_frac(ht2));
+        throwResume;
+    }
+
+
+}
