Index: libcfa/src/Makefile.am
===================================================================
--- libcfa/src/Makefile.am	(revision b6f39aaa8453307a222b815da992331e550aaa6a)
+++ libcfa/src/Makefile.am	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -61,4 +61,5 @@
 	containers/queueLockFree.hfa \
 	containers/stackLockFree.hfa \
+	containers/vector2.hfa \
 	vec/vec.hfa \
 	vec/vec2.hfa \
Index: libcfa/src/containers/vector2.hfa
===================================================================
--- libcfa/src/containers/vector2.hfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ libcfa/src/containers/vector2.hfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,355 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// vector -- A growable array, with full-service iterators
+//
+// Author           : Michael Brooks
+// Created On       : Thu Jun 23 22:00:00 2021
+// Last Modified By : Michael Brooks
+// Last Modified On : Thu Jun 23 22:00:00 2021
+// Update Count     : 1
+//
+
+#include <stdlib.hfa>
+#include "list.hfa"
+
+forall( T ) {
+    struct vector;
+    
+    struct vector_transit {
+        vector(T) * col_$;
+        ptrdiff_t idx_$;
+    };
+
+    struct vector_exit {
+        vector(T) * invec_$;
+        T * item_$;
+    };
+
+    struct vector_permit {
+        vector(T) * invec_$;
+        T * item_$;
+        inline dlink(vector_permit(T));
+    };
+    P9_EMBEDDED(vector_permit(T), dlink(vector_permit(T)))
+
+    struct vector {
+        T * buffer_first_$;
+        T * buffer_end_$;
+        T * elems_first_$;
+        T * elems_end_$; // wrapped before storing, never == buffer_end_$
+        size_t exit_refcount_$;
+        dlist(vector_permit(T)) live_iters_$;
+    };
+}
+
+static inline
+forall( T ) {
+    
+    // vector
+
+    void ?{}( vector( T ) &, size_t capacity );
+    void ^?{}( vector( T ) & );
+
+    void ?{}( vector( T ) & ) = void;
+    void ?{}( vector( T ) &, vector( T ) & ) = void;
+    vector( T ) & ?=?( vector( T ) &, vector( T ) & ) = void;
+
+    // transit
+
+    void ?{}( vector_transit(T) & ) = void;
+    void ?{}( vector_transit(T) &, vector_transit(T) & );
+    void ^?{}( vector_transit(T) & );
+
+    T ?`val( vector_transit(T) & src );
+    void ?=?( vector_transit(T) & dst, T val );
+
+    // exit
+
+    void ?{}( vector_exit(T) & ) = void;
+    void ?{}( vector_exit(T) &, vector(T) * ) = void;
+
+    void ^?{}( vector_exit(T) & );
+    void ?{}( vector_exit(T) &, vector_transit(T) & );
+    void ?{}( vector_exit(T) &, vector_exit(T) & );
+
+    T ?`val( vector_exit(T) & src );
+    void ?=?( vector_exit(T) & dst, T val );
+    T & ?=?( T & dst, vector_exit(T) & src );
+    void ?*=?( T & dst, vector_exit(T) & src );
+
+    bool ?`moveNext( vector_exit(T) & it );
+
+    // permit
+
+    void ?{}( vector_permit(T) & ) = void;
+
+    void ^?{}( vector_permit(T) & );
+    void ?{}( vector_permit(T) &, vector_transit(T) & );
+    void ?{}( vector_permit(T) &, vector_exit(T) & );
+    void ?{}( vector_permit(T) &, vector_permit(T) & ) = void;
+
+    T ?`val( vector_permit(T) & src );
+
+    // api
+
+    vector_transit(T) push_last( vector( T ) & col, T val );
+    vector_transit(T) ?[?]( vector( T ) &, ptrdiff_t );
+    vector_exit(T) ?`origin( vector( T ) & );
+    size_t ?`capacity( vector(T) & );
+    size_t ?`length( vector(T) & );
+
+    void insert_before( vector( T ) & col, ptrdiff_t idx, T val );
+
+}
+
+static inline
+forall( T ) {
+
+    // vector
+
+    void ?{}( vector( T ) & this, size_t capacity ) {
+        (this.buffer_first_$){ aalloc( capacity ) };
+        (this.buffer_end_$){ this.buffer_first_$ + capacity};
+        (this.elems_first_$){ 0p };
+        (this.elems_end_$){ this.buffer_first_$ };
+        (this.exit_refcount_$){ 0 };
+        (this.live_iters_$){};
+    }
+
+    void ^?{}( vector( T ) & this ) {
+        assert( this.exit_refcount_$ == 0 );
+        free( this.buffer_first_$ );
+        this.buffer_first_$ = 0p;
+        this.buffer_end_$ = 0p;
+        this.elems_first_$ = 0p;
+        this.elems_end_$ = 0p;
+    }
+
+    // transit 
+
+    void ?{}( vector_transit(T) & this, vector_transit(T) & other ) {
+        // call autogen constructor deleted at end of hfa
+        (this){ other.col_$, other.idx_$ };
+    }
+
+    void ^?{}( vector_transit(T) & ) {}
+
+
+    vector_transit(T) ?[?]( vector( T ) & vec, ptrdiff_t idx ) {
+        // call autogen constructor deleted at end of hfa
+        vector_transit(T) ret = { & vec, idx };
+        return ret;
+    }
+
+    T & findElemMem_$( vector(T) & v, ptrdiff_t idx ) {
+        size_t len = v`length;
+        while (idx > len) idx -= len;
+        while (idx < 0  ) idx += len;
+        T * ret = v.elems_first_$ + idx;
+        if (ret < v.buffer_end_$) return *ret;
+        ret -= (v.buffer_end_$ - v.buffer_first_$);
+        assert( v.buffer_first_$ <= ret && ret < v.elems_end_$ );
+        return *ret;
+    }
+
+    T ?`val( vector_transit(T) & src ) {
+        T ret = findElemMem_$( *src.col_$, src.idx_$ );
+        return ret;
+    }
+
+    void ?=?( vector_transit(T) & src, T val ) {
+        findElemMem_$( *src.col_$, src.idx_$ ) = val;
+    }
+
+    // exit
+
+    void ?{}( vector_exit(T) & this, vector_transit(T) & src ) {
+        ( this.invec_$ ){ src.col_$ };
+        ( this.item_$ ){ & findElemMem_$( *src.col_$, src.idx_$ ) };
+
+        this.invec_$->exit_refcount_$ ++;
+    }
+    void ?{}( vector_exit(T) & this, vector_exit(T) & src ){
+        ( this.invec_$ ){ src.invec_$ };
+        ( this.item_$ ){ src.item_$ };
+
+        this.invec_$->exit_refcount_$ ++;
+    }
+
+    void ^?{}( vector_exit(T) & it ) {
+        it.invec_$->exit_refcount_$ --;
+    }
+
+    T ?`val( vector_exit(T) & src ) {
+        return *src.item_$;
+    }
+
+    void ?*=?( T & dst, vector_exit(T) & src ) {
+        dst = *src.item_$;
+    }
+
+    bool ?`moveNext( vector_exit(T) & it ) {
+        if (it.invec_$->elems_first_$ == 0p) {
+            // vector is empty
+            assert ( it.item_$ == 0p ); // it was at origin
+            return false;
+        }
+        assert( it.invec_$->elems_first_$ < it.invec_$->elems_end_$ && "can't handle wraparound yet" ); // temporary: must implement
+        if( it.item_$ == 0p ) {
+            // moving from origin
+            it.item_$ = it.invec_$->elems_first_$;
+        } else {
+            it.item_$ += 1;
+            if( it.item_$ > it.invec_$->buffer_end_$ )
+                it.item_$ = it.invec_$->buffer_first_$;
+        }
+        if ( it.item_$ >= it.invec_$->elems_end_$ ) {
+            // moving to origin
+            it.item_$ = 0p;
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    // permit
+
+    void ^?{}( vector_permit(T) & this ) {
+        remove(this);
+    }
+
+    void ?{}( vector_permit(T) & this, vector_transit(T) & src ) {
+        ( this.invec_$ ){ src.col_$ };
+        ( this.item_$ ){ & findElemMem_$( *src.col_$, src.idx_$ ) };
+        insert_first( src.col_$->live_iters_$, this );
+    }
+
+    void ?{}( vector_permit(T) & this, vector_exit(T) & src ) {
+        ( this.invec_$ ){ src.invec_$ };
+        ( this.item_$ ){ src.item_$ };
+        insert_first( src.invec_$->live_iters_$, this );
+    }
+
+    T ?`val( vector_permit(T) & src ){
+        return *src.item_$;
+    }
+
+    // vec internals
+
+    void grow( vector( T ) & this ) {
+        size_t newCapacity = 2 * (this.buffer_end_$ - this.buffer_first_$);
+        T * newItems = aalloc( newCapacity );
+        size_t elemCount = this`length;
+        for ( ptrdiff_t pos = 0; pos < elemCount; pos += 1 ) {
+            newItems[pos] = findElemMem_$(this, pos);
+        }
+
+        while ( vector_permit(T) & liveIter = this.live_iters_$`elems; liveIter`moveNext ) {
+            liveIter.item_$ += (newItems - this.buffer_first_$);
+        }
+
+        free( this.buffer_first_$ );
+        this.buffer_first_$ = newItems;
+        this.buffer_end_$ = newItems + newCapacity;
+        this.elems_first_$ = this.buffer_first_$;
+        this.elems_end_$ = this.buffer_first_$ + elemCount;
+        assert (this.elems_end_$ < this.buffer_end_$);
+    }
+
+    // vec api
+
+    vector_transit(T) push_last( vector( T ) & col, T val ) {
+        assert (col.exit_refcount_$ == 0);
+        if (col`length >= col`capacity) {
+            assert (col`length == col`capacity);
+            grow(col);
+        }
+        // call autogen constructor deleted at end of hfa
+        vector_transit(T) ret = { & col, col`length };
+        *col.elems_end_$ = val;
+        if (col.elems_first_$ == 0p) col.elems_first_$ = col.elems_end_$;
+        col.elems_end_$ += 1;
+        if (col.elems_end_$ >= col.buffer_end_$) col.elems_end_$ = col.buffer_first_$;
+        return ret;
+    }
+
+    vector_exit(T) ?`origin( vector( T ) & vec ) {
+
+        // private memberwise constructor, deleted from global namespace at end
+        // autogen constructor would not do the raii
+        void ?{}( vector_exit(T) & this, vector(T) * invec_$, T * item_$ ) {
+            ( this.invec_$ ){ invec_$ };
+            ( this.item_$ ){ item_$ };
+            this.invec_$->exit_refcount_$ ++;
+        }
+
+        vector_exit(T) ret = { &vec, 0p };
+        return ret;
+    }
+
+    bool inRange_$( T * query, T * from, T * to) {
+        if (from == to) return false;
+        if (from < to) return from <= query && query < to;
+        return query < to || from <= query;
+    }
+
+    void insert_before( vector( T ) & col, ptrdiff_t idx, T val ) {
+        assert (col.exit_refcount_$ == 0);
+        if (col`length >= col`capacity) {
+            assert (col`length == col`capacity);
+            grow(col);
+        }
+        
+        T & insertTargetR = findElemMem_$( col, idx );
+        T * insertTarget = & insertTargetR; // doesn't work in one line; must be a bug
+
+        // bubble toward back
+        if ( col.elems_end_$ < insertTarget ) {
+            // two phases of bubbling, to wrap around
+            for (T * tgt = col.elems_end_$; tgt > col.buffer_first_$; tgt--) {
+                *tgt = *(tgt-1);
+            }
+            *col.buffer_first_$ = *(col.buffer_end_$ - 1);
+            for (T * tgt = col.buffer_end_$ - 1; tgt > insertTarget; tgt--) {
+                *tgt = *(tgt-1);
+            }
+        } else {
+            for (T * tgt = col.elems_end_$; tgt > insertTarget; tgt--) {
+                *tgt = *(tgt-1);
+            }
+        }
+
+        col.elems_end_$ += 1;
+        if (col.elems_end_$ == col.buffer_end_$) col.elems_end_$ = col.buffer_first_$;
+
+        *insertTarget = val;
+
+        while ( vector_permit(T) & liveIter = col.live_iters_$`elems; liveIter`moveNext ) {
+            if ( inRange_$(liveIter.item_$, insertTarget, col.elems_end_$) ) {
+                liveIter.item_$ += 1;
+                if (liveIter.item_$ >= col.buffer_end_$) liveIter.item_$ = col.buffer_first_$;
+            }
+        }
+    }
+
+    size_t ?`capacity( vector(T) & v ) {
+        return v.buffer_end_$ - v.buffer_first_$;
+    }
+
+    size_t ?`length( vector(T) & v ) {
+        if (v.elems_first_$ == 0p) return 0;
+        if (v.elems_first_$ < v.elems_end_$ ) return v.elems_end_$ - v.elems_first_$;
+        return v.buffer_end_$ - v.elems_first_$ + v.elems_end_$ - v.buffer_first_$;
+    }
+
+
+} // forall T
+
+forall( T ) {
+    void ?{}( vector_exit(T) &, vector(T) *, T * ) = void;
+    void ?{}( vector_transit(T) & this, vector( T ) * col, ptrdiff_t idx ) = void;
+}
Index: tests/collections/.expect/vector-demo.txt
===================================================================
--- tests/collections/.expect/vector-demo.txt	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/collections/.expect/vector-demo.txt	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,21 @@
+raiiTests=================
+Having pushed, length is 1
+by transit, got pos0 = 1.000000
+by exit, got pos0 = 1.000000
+Having pushed, length is 2
+helperE sees 2.000000
+producerE gave 1.000000
+producerE again gave 1.000000
+helperT sees 2.000000
+producerT gave 1.000000
+by permit, got pos0 = 1.000000
+Having pushed, length is 3
+into permit from call, got ofH = 1.000000
+stayValidTests============
+before 0.100000
+after, logical: 0.100000
+after, physical: -0.100000
+loopTests=================
+loop sees 0.000000
+loop sees 0.100000
+loop sees 0.200000
Index: tests/collections/.expect/vector-err-pass-perm-it-byval.txt
===================================================================
--- tests/collections/.expect/vector-err-pass-perm-it-byval.txt	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/collections/.expect/vector-err-pass-perm-it-byval.txt	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,270 @@
+error: Unique best alternative includes deleted identifier in Generated Cast of:
+  Application of
+    Deleted Expression
+      Variable Expression: ?{}: static inline forall
+        instance of type T (not function type)
+        with assertions
+        Variable Expression: ?=?: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning
+          instance of type T (not function type)
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning
+            instance of type T (not function type)
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ^?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        function
+      ... with parameters
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+      ... returning nothing
+
+      ... with resolved type:
+        forall
+          instance of type T (not function type)
+          with assertions
+          Variable Expression: ?=?: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning
+            instance of type T (not function type)
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+              instance of type T (not function type)
+            ... returning
+              instance of type T (not function type)
+
+          Variable Expression: ?{}: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+            ... returning nothing
+
+          Variable Expression: ?{}: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning nothing
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+              instance of type T (not function type)
+            ... returning nothing
+
+          Variable Expression: ^?{}: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+            ... returning nothing
+
+          function
+        ... with parameters
+          reference to instance of struct vector_permit with body
+          ... with parameters
+            instance of type T (not function type)
+
+          reference to instance of struct vector_permit with body
+          ... with parameters
+            instance of type T (not function type)
+
+        ... returning nothing
+
+      ... deleted by: ?{}: static inline forall
+        instance of type T (not function type)
+        with assertions
+        Variable Expression: ?=?: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning
+          instance of type T (not function type)
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning
+            instance of type T (not function type)
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ^?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        function
+      ... with parameters
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+      ... returning nothing
+
+    ... to arguments
+    Generated Cast of:
+      Variable Expression: __tmp: instance of struct vector_permit with body
+      ... with parameters
+        float
+
+      ... with resolved type:
+        instance of struct vector_permit with body
+        ... with parameters
+          float
+
+    ... to:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+    ... with resolved type:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+    Generated Cast of:
+      Variable Expression: it: instance of struct vector_permit with body
+      ... with parameters
+        float
+
+      ... with resolved type:
+        instance of struct vector_permit with body
+        ... with parameters
+          float
+
+    ... to:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+    ... with resolved type:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+  with inferred parameters 0:
+    ?=?: function
+    ... with parameters
+      reference to float
+      float
+    ... returning
+      float
+
+    ?{}: function
+    ... with parameters
+      reference to float
+    ... returning nothing
+
+    ?{}: function
+    ... with parameters
+      reference to float
+      float
+    ... returning nothing
+
+    ^?{}: function
+    ... with parameters
+      reference to float
+    ... returning nothing
+
+
+  ... with resolved type:
+    void
+... to: nothing
+... with resolved type:
+  void
Index: tests/collections/.expect/vector-err-retn-perm-it-byval.txt
===================================================================
--- tests/collections/.expect/vector-err-retn-perm-it-byval.txt	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/collections/.expect/vector-err-retn-perm-it-byval.txt	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,314 @@
+collections/vector-demo.cfa:105:1 error: Unique best alternative includes deleted identifier in Generated Cast of:
+  Application of
+    Deleted Expression
+      Variable Expression: ?{}: static inline forall
+        instance of type T (not function type)
+        with assertions
+        Variable Expression: ?=?: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning
+          instance of type T (not function type)
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning
+            instance of type T (not function type)
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ^?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        function
+      ... with parameters
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+      ... returning nothing
+
+      ... with resolved type:
+        forall
+          instance of type T (not function type)
+          with assertions
+          Variable Expression: ?=?: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning
+            instance of type T (not function type)
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+              instance of type T (not function type)
+            ... returning
+              instance of type T (not function type)
+
+          Variable Expression: ?{}: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+            ... returning nothing
+
+          Variable Expression: ?{}: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning nothing
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+              instance of type T (not function type)
+            ... returning nothing
+
+          Variable Expression: ^?{}: pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+          ... with resolved type:
+            pointer to function
+            ... with parameters
+              reference to instance of type T (not function type)
+            ... returning nothing
+
+          function
+        ... with parameters
+          reference to instance of struct vector_permit with body
+          ... with parameters
+            instance of type T (not function type)
+
+          reference to instance of struct vector_permit with body
+          ... with parameters
+            instance of type T (not function type)
+
+        ... returning nothing
+
+      ... deleted by: ?{}: static inline forall
+        instance of type T (not function type)
+        with assertions
+        Variable Expression: ?=?: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning
+          instance of type T (not function type)
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning
+            instance of type T (not function type)
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+          instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+            instance of type T (not function type)
+          ... returning nothing
+
+        Variable Expression: ^?{}: pointer to function
+        ... with parameters
+          reference to instance of type T (not function type)
+        ... returning nothing
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of type T (not function type)
+          ... returning nothing
+
+        function
+      ... with parameters
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+        reference to instance of struct vector_permit with body
+        ... with parameters
+          instance of type T (not function type)
+
+      ... returning nothing
+
+    ... to arguments
+    Generated Cast of:
+      Variable Expression: ofG: instance of struct vector_permit with body
+      ... with parameters
+        float
+
+      ... with resolved type:
+        instance of struct vector_permit with body
+        ... with parameters
+          float
+
+    ... to:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+    ... with resolved type:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+    Generated Cast of:
+      Application of
+        Variable Expression: g: function
+        ... with parameters
+          reference to instance of struct vector with body
+          ... with parameters
+            float
+
+        ... returning
+          instance of struct vector_permit with body
+          ... with parameters
+            float
+
+
+        ... with resolved type:
+          pointer to function
+          ... with parameters
+            reference to instance of struct vector with body
+            ... with parameters
+              float
+
+          ... returning
+            instance of struct vector_permit with body
+            ... with parameters
+              float
+
+
+        ... to arguments
+        Generated Cast of:
+          Variable Expression: v: instance of struct vector with body
+          ... with parameters
+            float
+
+          ... with resolved type:
+            instance of struct vector with body
+            ... with parameters
+              float
+
+        ... to:
+          reference to instance of struct vector with body
+          ... with parameters
+            float
+
+        ... with resolved type:
+          reference to instance of struct vector with body
+          ... with parameters
+            float
+
+
+      ... with resolved type:
+        instance of struct vector_permit with body
+        ... with parameters
+          float
+
+    ... to:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+    ... with resolved type:
+      reference to instance of struct vector_permit with body
+      ... with parameters
+        float
+
+  with inferred parameters 0:
+    ?=?: function
+    ... with parameters
+      reference to float
+      float
+    ... returning
+      float
+
+    ?{}: function
+    ... with parameters
+      reference to float
+    ... returning nothing
+
+    ?{}: function
+    ... with parameters
+      reference to float
+      float
+    ... returning nothing
+
+    ^?{}: function
+    ... with parameters
+      reference to float
+    ... returning nothing
+
+
+  ... with resolved type:
+    void
+... to: nothing
+... with resolved type:
+  void
Index: tests/collections/vector-demo.cfa
===================================================================
--- tests/collections/vector-demo.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/collections/vector-demo.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,169 @@
+#include <containers/vector2.hfa>
+
+void raiiTests() {
+    printf("raiiTests=================\n");
+
+    vector( float ) v = { 25 };
+
+    push_last( v, 1 );
+    printf( "Having pushed, length is %ld\n", v`length );
+
+    float y = v[0]`val;
+    printf( "by transit, got pos0 = %f\n", y );
+
+    {
+        vector_exit(float) it = v[0];
+
+        float z = it`val;
+        printf( "by exit, got pos0 = %f\n", z );
+
+        // forbid modification while locked
+      #ifdef TRY_MOD_WHILE_LOCKED_1
+        push_last( v, 1 );   // runtime assertion failure
+        printf( "Having pushed, length is %ld\n", v`length );
+      #endif
+    }
+
+    push_last( v, 2 );
+    printf( "Having pushed, length is %ld\n", v`length );
+
+    // deletion scope for some exits
+    // point is the function decls and calls, though
+    {
+        void helperE(vector_exit(float) it) {
+            float q = it`val;
+            printf( "helperE sees %f\n", q );
+        }
+
+        vector_exit(float) it2 = v[1];
+        helperE(it2);
+
+        // can't call with implied exit (wish I could, low priority)
+      #ifdef TRY_IMPLIED_EXIT_1
+        helperE( v[1] ); // Invalid application of existing declaration(s)
+      #endif
+
+        //------
+
+        vector_exit(float) producerE( vector( float ) & theVec ) {
+          return theVec[0];
+        }
+
+        vector_exit(float) it3 = producerE( v );
+        float z = it3`val;
+        printf( "producerE gave %f\n", z );
+
+        float zzzz = producerE( v )`val;
+        printf( "producerE again gave %f\n", zzzz );
+
+        //------
+
+        void helperT(vector_transit(float) it) {
+            float q = it`val;
+            printf( "helperT sees %f\n", q );
+        }
+
+        helperT( v[1] );
+
+        //------
+
+        vector_transit(float) producerT( vector( float ) & theVec ) {
+            return theVec[0];
+        }
+
+        float zz = producerT( v )`val;
+        printf( "producerT gave %f\n", zz );
+    }
+
+    //=======
+
+    {
+        vector_permit(float) it = v[0];
+
+        float z = it`val;
+        printf( "by permit, got pos0 = %f\n", z );
+
+        // allow modification while permits exist
+        push_last( v, 1 );
+        printf( "Having pushed, length is %ld\n", v`length );
+
+        // forbid passing permit by value
+      #ifdef TRY_PASS_PERMIT_BYVAL_1
+        void f( vector_permit(float) xx ) {
+            printf("can't get here\n");
+        }
+        f( it ); // Unique best alternative includes deleted identifier
+      #endif
+
+        // can declare function that returns permit (wish to forbid)
+        vector_permit(float) g( vector( float ) & theVec ) {
+            return theVec[0]; // want to forbid
+        }
+
+        // forbid calling a function that returns permit by value
+      #ifdef TRY_RETURN_PERMIT_BYVAL_1
+        vector_permit(float) ofG = g( v ); // Unique best alternative includes deleted identifier
+      #endif
+        
+        // allow declaration of permit, populating from exit
+        vector_exit(float) h( vector( float ) & theVec ) {
+            return theVec[0];
+        }
+
+        vector_permit(float) ofH = h( v );
+        float zh = ofH`val;
+        printf( "into permit from call, got ofH = %f\n", zh );
+    }
+}
+
+void stayValidTests() {
+    printf("stayValidTests============\n");
+    vector( float ) v = { 4 };
+    push_last(v, 0.0f);
+    push_last(v, 0.1f);
+    push_last(v, 0.2f);
+    // v is [0.0, 0.1, 0.2]
+
+    vector_permit(float) iter = v[1];  // iter at 0.1
+
+    float val1 = iter`val;
+    printf("before %f\n", val1);
+
+    insert_before( v, 1, 98.6f );  // v is [0.0, 98.6, 0.1, 0.2]; iter at 0.1
+
+    float val2 = iter`val;
+    printf("after, logical: %f\n", val2);
+
+    // we had filled it to the brim
+    assert( v`capacity == 4 && v`length == 4 );
+
+    push_last(v, -100); // v is [0.0, 98.6, 0.1, 0.2, 0.3]; iter at 0.1, but RTP it's not looking at the old memory's 0.1
+
+    // that made it bigger
+    assert( v`capacity >  5 && v`length == 5 );
+
+    v[2] = -0.1;  // v is [0.0, 98.6, -0.1, 0.2, 0.3]; iter at -0.1, where only the new memory had that change
+
+    float val3 = iter`val;
+    printf("after, physical: %f\n", val3);
+}
+
+void loopTests() {
+    printf("loopTests=================\n");
+    vector(float) v = { 4 };
+    push_last(v, 0.0f);
+    push_last(v, 0.1f);
+    push_last(v, 0.2f);
+    float toPrint;
+
+    while( vector_exit(float) it = v`origin; it`moveNext ) {
+        toPrint *= it;
+        printf("loop sees %f\n", toPrint);
+    }
+}
+
+int main() {
+    raiiTests();
+    stayValidTests();
+    loopTests();
+}
Index: tests/collections/vector-err-mod-with-excl-it.cfa
===================================================================
--- tests/collections/vector-err-mod-with-excl-it.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/collections/vector-err-mod-with-excl-it.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,8 @@
+/*
+Temporarily: no associated .expect file, not runnable with test.py.
+For human acceptance: Should compile, but crash with an assertion failure when run.
+Detail of this error reporting is work in progress.
+*/
+
+#define TRY_MOD_WHILE_LOCKED_1
+#include "vector-demo.cfa"
Index: tests/collections/vector-err-pass-perm-it-byval.cfa
===================================================================
--- tests/collections/vector-err-pass-perm-it-byval.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/collections/vector-err-pass-perm-it-byval.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,2 @@
+#define TRY_PASS_PERMIT_BYVAL_1
+#include "vector-demo.cfa"
Index: tests/collections/vector-err-retn-perm-it-byval.cfa
===================================================================
--- tests/collections/vector-err-retn-perm-it-byval.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/collections/vector-err-retn-perm-it-byval.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,2 @@
+#define TRY_RETURN_PERMIT_BYVAL_1
+#include "vector-demo.cfa"
Index: tests/zombies/vector-perf/iteration-perf.cfa
===================================================================
--- tests/zombies/vector-perf/iteration-perf.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/zombies/vector-perf/iteration-perf.cfa	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,32 @@
+#include "vector2.hfa"
+
+#include <time.h>
+
+enum { NumElements = 10000, NumReps = 50000 };
+
+// A layer of indirection to improve performance (naturally!)
+// Works around trac #248.
+// This test keeps a vector of notfloat, instead of a vector of float.  The optimizer removes this added indirection.
+// Furthermore, by passing notfloat's static-inline constructors, defined in this compile unit, to vector, the vector's element's constructors become eligible for inlining.
+// Skipping this optimization costs about a 25% slowdown.
+struct notfloat{ inline float; };
+
+int main() {
+    clock_t start, end;
+    vector(notfloat) x = { 4 };
+    for (i; NumElements) {
+        push_last(x, (notfloat){0.1f * i});
+    }
+    float total;
+    start = clock();
+    for (rep; NumReps) {
+        total = 0;
+        while( vector_exit(notfloat) it = x`origin; it`moveNext ) {
+            total += it`val;
+        }
+    }
+    end = clock();
+    printf("last total was %f\n", total);
+    double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; \
+    printf("iterating duration was %f\n", elapsed);
+}
Index: tests/zombies/vector-perf/iteration-perf.cpp
===================================================================
--- tests/zombies/vector-perf/iteration-perf.cpp	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
+++ tests/zombies/vector-perf/iteration-perf.cpp	(revision 44856edf2e65daf51c0bc39fe8f674cd056b4fce)
@@ -0,0 +1,25 @@
+#include <vector>
+#include <iostream>
+#include <time.h>
+
+enum { NumElements = 10000, NumReps = 50000 };
+
+int main() {
+    clock_t start, end;
+    std::vector<float> x;
+    for (int i = 0; i < NumElements; i++) {
+        x.push_back(0.1f * i);
+    }
+    float total;
+    start = clock();
+    for (int rep = 0; rep < NumReps; rep++) {
+        total = 0;
+        for( std::vector<float>::iterator it = x.begin(); it < x.end(); it ++ ) {
+            total += *it;
+        }
+    }
+    end = clock();
+    std::cout << "last total was " << total << std::endl;
+    double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC; \
+    std::cout << "iterating duration was " << elapsed << std::endl;
+}
