Index: doc/proposals/vtable.md
===================================================================
--- doc/proposals/vtable.md	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ doc/proposals/vtable.md	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -8,11 +8,11 @@
 
 The basic concept of a virtual table (vtable) is the same here as in most
-other languages. They will mostly contain function pointers although they
-should be able to store anything that goes into a trait.
-
-I also include notes on a sample implementation, which primarly exists to show
-there is a resonable implementation. The code samples for that are in a slight
-psudo-code to help avoid name mangling and keeps some CFA features while they
-would actually be writen in C.
+other languages that use them. They will mostly contain function pointers
+although they should be able to store anything that goes into a trait.
+
+I also include notes on a sample implementation, which primarily exists to show
+there is a reasonable implementation. The code samples for that are in a slight
+pseudo-code to help avoid name mangling and keeps some CFA features while they
+would actually be written in C.
 
 Trait Instances
@@ -20,26 +20,28 @@
 
 Currently traits are completely abstract. Data types might implement a trait
-but traits are not themselves data types. This will change that and allow
-instances of traits to be created from instances of data types that implement
-the trait.
+but traits are not themselves data types. Which is to say you cannot have an
+instance of a trait. This proposal will change that and allow instances of
+traits to be created from instances of data types that implement the trait.
+
+For example:
 
     trait combiner(otype T) {
-		void combine(T&, int);
-	};
+        void combine(T&, int);
+    };
 
     struct summation {
-		int sum;
-	};
-
-	void ?{}( struct summation & this ) {
-		this.sum = 0;
-	}
+        int sum;
+    };
+
+    void ?{}( struct summation & this ) {
+        this.sum = 0;
+    }
 
     void combine( struct summation & this, int num ) {
-		this.sum = this.sum + num;
-	}
-
-	trait combiner obj = struct summation{};
-	combine(obj, 5);
+        this.sum = this.sum + num;
+    }
+
+    trait combiner obj = struct summation{};
+    combine(obj, 5);
 
 As with `struct` (and `union` and `enum`), `trait` might be optional when
@@ -49,16 +51,30 @@
 For traits to be used this way they should meet two requirements. First they
 should only have a single polymorphic type and each assertion should use that
-type once as a parameter. Extentions may later loosen these requirements.
-
-If a trait object is used it should generate a series of implicate functions
-each of which implements one of the functions required by the trait. So for
-combiner there is an implicate:
-
-    void combine(trait combiner & this, int);
-
-This function is the one actually called at the end
+type once as a parameter. Extensions may later loosen these requirements.
+
+Also note this applies to the final expanded list of assertions. Consider:
+
+    trait foo(otype T, otype U) {
+        ... functions that use T once ...
+    }
+
+    trait bar(otype S | foo(S, char)) {
+        ... functions that use S once ...
+    }
+
+In this example `bar` may be used as a type but `foo` may not.
+
+When a trait is used as a type it creates a generic object which combines
+the base structure (an instance of `summation` in this case) and the vtable,
+which is currently created and provided by a hidden mechanism.
+
+The generic object type for each trait also implements that trait. This is
+actually the only means by which it can be used. The type of these functions
+look something like this:
+
+    void combine(trait combiner & this, int num);
 
 The main use case for trait objects is that they can be stored. They can be
-passed into functions, but using the trait directly is prefred in this case.
+passed into functions, but using the trait directly is preferred in this case.
 
     trait drawable(otype T) {
@@ -78,19 +94,70 @@
     }
 
-Currently these traits are limited to 1 trait parameter and functions should
-have exactly 1 parameter. We cannot abstract away pairs of types and still
-pass them into normal functions, which take them seperately.
-
-The second is required the because we need to get the vtable from somewhere.
-If there are 0 trait objects than no vtable is avalible, if we have more than
-1 than the vtables give conflicting answers on what underlying function to
-call. And even then the underlying type assumes a concrete type.
-
-This loop can sort of be broken by using the trait object directly in the
-signature. This has well defined meaning, but might not be useful.
+The trait types can also be used in the types of assertions on traits as well.
+In this usage they passed as the underlying object and vtable pair as they
+are stored. The trait types can also be used in that trait's definition, which
+means you can pass two instances of a trait to a single function. However the
+look-up of the one that is not used to look up any functions, until another
+function that uses that object in the generic/look-up location is called.
 
     trait example(otype T) {
         bool test(T & this, trait example & that);
     }
+
+### Explanation Of Restrictions
+
+The two restrictions on traits that can be used as trait objects are:
+
+1.  Only one generic parameter may be defined in the trait's header.
+2.  Each function assertion must have one parameter with the type of the
+    generic parameter. They may or may not return a value of that type.
+
+Elsewhere in this proposal I suggest ways to broaden these requirements.
+A simple example would be if a trait meets requirement 1 but not 2, then
+the assertions that do not satisfy the exactly one parameter requirement can
+be ignored.
+
+However I would like to talk about why these two rules are in place in the
+first place and the problems that any exceptions to these rules must avoid.
+
+The problems appear when the dispatcher function which operates on the
+generic object.
+
+    trait combiner(otype T, otype U) {
+        void combine(T&, U);
+    }
+
+This one is so strange I don't have proper syntax for it but let us say that
+the concrete dispatcher would be typed as
+`void combine(combiner(T) &, combiner(U));`. Does the function that combine
+the two underlying types exist to dispatch too?
+
+Maybe not. If `combiner(T)` works with ints and `combiner(U)` is a char then
+they could not be. It would have to enforce that all pairs of any types
+that are wrapped in this way. Which would pretty much destroy any chance of
+separate compilation.
+
+Even then it would be more expensive as the wrappers would have to carry ids
+that you use to look up on an <number of types>+1 dimensional table.
+
+The second restriction has a similar issue but makes a bit more sense to
+write out.
+
+    trait Series(otype T) {
+        ... size, iterators, getters ...
+        T join(T const &, T const &);
+    }
+
+With the dispatcher typed as:
+
+    Series join(Series const &, Series const &);
+
+Because these instances are generic and hide the underlying implementation we
+do not know what that implementation is. Unfortunately this also means the
+implementation for the two parameters might not be the same. Once we have
+two different types involved this devolves into the first case.
+
+We could check at run-time that the have the same underlying type, but this
+would likely time and space overhead and there is no clear recovery path.
 
 #### Sample Implementation
@@ -116,115 +183,96 @@
 
 There may have to be special cases for things like copy construction, that
-might require a more sigificant wrapper. On the other hand moving could be
+might require a more significant wrapper. On the other hand moving could be
 implemented by moving the pointers without any need to refer to the base
 object.
 
-### Extention: Multiple Trait Parameters
-Currently, this gives traits two independent uses. They use the same syntax,
-except for limits boxable traits have, and yet don't really mix. The most
-natural way to do this is to allow trait instances to pick one parameter
-that they are generic over, the others they choose types to implement.
-
-The two ways to do the selection, the first is do it at the trait definition.
-Each trait picks out a single parameter which it can box (here the `virtual`
-qualifier). When you create an instance of a trait object you provide
-arguments like for a generic structure, but skip over the marked parameter.
-
-    trait combiner(virtual otype T, otype Combined) {
-        void combine(T &, Combined &);
-    }
-
-    trait combiner(int) int_combiner;
-
-The second is to do it at the instaniation point. A placeholder (here the
-keyword `virtual`) is used to explicately skip over the parameter that will be
-abstracted away, with the same rules as above if it was the marked parameter.
-
-    trait combiner(otype T, otype Combined) {
-        void combine(T &, Combined &);
-    };
-
-    trait combiner(virtual, int) int_combiner;
-
-Using both (first to set the default, second as a local override) would also
-work, although might be exessively complicated.
-
-This is useful in cases where you want to use a generic type, but leave part
-of it open and store partially generic result. As a simple example
-
-    trait folder(otype T, otype In, otype Out) {
-        void fold(T & this, In);
-        Out fold_result(T & this);
-    }
-
-Which allows you to fold values without putting them in a container. If they
-are already in a container this is exessive, but if they are generated over
-time this gives you a simple interface. This could for instance be used in
-a profile, where T changes for each profiling statistic and you can plug in
-multiple profilers for any run by adding them to an array.
+### Extension: Multiple Trait Parameters
+The base proposal in effect creates another use for the trait syntax that is
+related to the ones currently in the language but is also separate from them.
+The current uses generic functions and generic types, this new use could be
+described as generic objects.
+
+A generic object is of a concrete type and has concrete functions that work on
+it. It is generic in that it is a wrapper for an unknown type. Traits serve
+a similar role here as in generic functions as they limit what the function
+can be generic over.
+
+This combines the use allowing to have a generic type that is a generic
+object. All but one of the trait's parameters is given a concrete type,
+conceptually currying the trait to create a trait with on generic parameter
+that fits the original restrictions. The resulting concrete generic object
+type is different with each set of provided parameters and their values.
+
+Then it just becomes a question of where this is done. Again both examples use
+a basic syntax to show the idea.
+
+    trait iterator(virtual otype T, otype Item) {
+        bool has_next(T const &);
+        Item get_next(T const *);
+    }
+
+    iterator(int) int_it = begin(container_of_ints);
+
+The first option is to do it at the definition of the trait. One parameter
+is selected (here with the `virtual` keyword, but other rules like "the first"
+could also be used) and when an instance of the trait is created all the
+other parameters must be provided.
+
+    trait iterator(otype T, otype Item) {
+        bool has_next(T const &);
+        Item get_next(T const *);
+    }
+
+    iterator(virtual, int) int_it = begin(container_of_ints);
+
+The second option is to skip a parameter as part of the type instance
+definition. One parameter is explicitly skipped (again with the `virtual`
+keyword) and the others have concrete types. The skipped one is the one we
+are generic on.
+
+Incidentally in both examples `container_of_ints` may itself be a generic
+object and `begin` returns a generic iterator with unknown implementation.
+
+These options are not exclusive. Defining a default on the trait allows for
+an object to be created as in the first example. However, whether the
+default is provided or not, the second syntax can be used to pick a
+parameter on instantiation.
 
 Hierarchy
 ---------
 
-Virtual tables by them selves are not quite enough to implement the planned
-hierarchy system. An addition of type ids, implemented as pointers which
-point to your parent's type id, is required to actually create the shape of
-the hierarchy. However vtables would allow behaviour to be carried with the
-tree.
-
-The hierarchy would be a tree of types, of traits and structs. Currently we do
-not support structural extension, so traits form the internal nodes and
-structures the leaf nodes.
-
-The syntax is undecided but it will include a clause like `virtual (PARENT)`
-on trait and struct definitions. It marks out all types in a hierarchy.
-PARENT may be omitted, if it is this type is the root of a hierarchy. Otherwise
-it is the name of the type that is this type's parent in the hierarchy.
-
-Traits define a trait instance type that implements all assertions in this
-trait and its parents up until the root of the hierarchy. Each trait then
-defines a vtable type. Structures will also have a vtable type but it should
-be the same as their parent's.
-
-Trait objects within the tree can be statically cast to a parent type. Casts
-from a parent type to a child type are conditional, they check to make sure
-the underlying instance is an instance of the child type, or an instance of
-one of its children. The type then is recoverable at run-time.
-
-As with regular trait objects, calling a function on a trait object will cause
-a look-up on the the virtual table. The casting rules make sure anything that
-can be cast to a trait type will have all the function implementations for
-that trait.
-
-Converting from a concrete type (structures at the edge of the hierarchy) to
-an abstract type works the same as with normal trait objects, the underlying
-object is packaged with a virtual table pointer. Converting back to an abstract
-type requires confirming the underlying type matches, but then simply extracts
-the pointer to it.
-
-Exception Example:
+We would also like to implement hierarchical relations between types.
+
+    AstNode
+    |-ParseNode
+    | |-Declaration
+    | | |-DeclarationWithType
+    | | |-StructureDeclaration
+    | |-Statement
+    | | |-CompoundStatement
+    | |-Expression
+    |-Type
+
+Virtual tables by themselves are not quite enough to implement this system.
+A vtable is just a list of functions and there is no way to check at run-time
+what these functions, we carry that knowledge with the table.
+
+This proposal adds type ids to check for position in the hierarchy and an
+explicate syntax for establishing a hierarchical relation between traits and
+their implementing types. The ids should uniquely identify each type and
+allow retrieval of the type's parent if one exists. By recursion this allows
+the ancestor relation between any two hierarchical types can be checked.
+
+The hierarchy is created with traits as the internal nodes and structures
+as the leaf nodes. The structures may be used normally and the traits can
+be used to create generic objects as in the first section (the same
+restrictions apply). However these type objects store their type id which can
+be recovered to figure out which type they are or at least check to see if
+they fall into a given sub-tree at run-time.
+
+Here is an example of part of a hierarchy. The `virtual(PARENT)` syntax is
+just an example. But when used it give the name of the parent type or if
+empty it shows that this type is the root of its hierarchy.
 (Also I'm not sure where I got these casing rules.)
-
-    trait exception(otype T) virtual() {
-        char const * what(T & this);
-    }
-
-    trait io_error(otype T) virtual(exception) {
-        FILE * which_file(T & this);
-    }
-
-    struct eof_error(otype T) virtual(io_error) {
-        FILE * file;
-    }
-
-    char const * what(eof_error &) {
-        return "Tried to read from an empty file.";
-    }
-
-    FILE * which_file(eof_error & this) {
-        return eof_error.file;
-    }
-
-Ast Example:
 
     trait ast_node(otype T) virtual() {
@@ -267,4 +315,25 @@
     }
 
+### Extension: Structural Inheritance
+An extension would be allow structures to be used as internal nodes on the
+inheritance tree. Its child types would have to implement the same fields.
+
+The weaker restriction would be to convert the fields into field assertions
+(Not implemented yet: `U T.x` means there is a field of type you on the type
+T. Offset unknown and passed in/stored with function pointers.)
+A concrete child would have to declare the same set of fields with the same
+types. This is of a more functional style.
+
+The stronger restriction is that the fields of the parent are a prefix of the
+child's fields. Possibly automatically inserted. This the imperative view and
+may also have less overhead.
+
+### Extension: Unions and Enumerations
+Currently there is no reason unions and enumerations, in the cases they
+do implement the trait, could not be in the hierarchy as leaf nodes.
+
+It does not work with structural induction, but that could just be a compile
+time check that all ancestors are traits or do not add field assertions.
+
 #### Sample Implementation
 The type id may be as little as:
@@ -275,5 +344,5 @@
 
 Some linker magic would have to be used to ensure exactly one copy of each
-structure for each type exists in memory. There seem to be spectial once
+structure for each type exists in memory. There seem to be special once
 sections that support this and it should be easier than generating unique
 ids across compilation units.
@@ -300,18 +369,61 @@
 
 ### Virtual Casts
-To convert from a pointer to a type higher on the hierarchy to one lower on
-the hierarchy a check is used to make sure that the underlying type is also
-of that lower type.
-
-The proposed syntax for this is:
+The generic objects may be cast up and down the hierarchy.
+
+Casting to an ancestor type always succeeds. From one generic type to another
+is just a reinterpretation and could be implicate. Wrapping and unwrapping
+a concrete type will probably use the same syntax as in the first section.
+
+Casting from an ancestor to a descendent requires a check. The underlying
+type may or may not belong to the sub-tree headed by that descendent. For this
+we introduce a new cast operator, which returns the pointer unchanged if the
+check succeeds and null otherwise.
 
     trait SubType * new_value = (virtual trait SubType *)super_type;
 
-It will return the same pointer if it does point to the subtype and null if
-it does not, doing the check and conversion in one operation.
-
-### Inline vtables
+For the following example I am using the as of yet finished exception system.
+
+    trait exception(otype T) virtual() {
+        char const * what(T & this);
+    }
+
+    trait io_error(otype T) virtual(exception) {
+        FILE * which_file(T & this);
+    }
+
+    struct eof_error(otype T) virtual(io_error) {
+        FILE * file;
+    }
+
+    char const * what(eof_error &) {
+        return "Tried to read from an empty file.";
+    }
+
+    FILE * which_file(eof_error & this) {
+        return eof_error.file;
+    }
+
+    bool handleIoError(exception * exc) {
+        io_error * error = (virtual io_error *)exc;
+        if (NULL == error) {
+            return false;
+        }
+        ...
+        return true;
+    }
+
+### Extension: Implicate Virtual Cast Target
+This is a small extension, even in the example above `io_error *` is repeated
+in the cast and the variable being assigned to. Using return type inference
+would allow the second type to be skipped in cases it is clear what type is
+being checked against.
+
+The line then becomes:
+
+    io_error * error = (virtual)exc;
+
+### Extension: Inline vtables
 Since the structures here are usually made to be turned into trait objects
-it might be worth it to have fields on them to store the virtual table
+it might be worth it to have fields in them to store the virtual table
 pointer. This would have to be declared on the trait as an assertion (example:
 `vtable;` or `T.vtable;`), but if it is the trait object could be a single
@@ -320,5 +432,5 @@
 There are also three options for where the pointer to the vtable. It could be
 anywhere, a fixed location for each trait or always at the front. For the per-
-trait solution an extention to specify what it is (example `vtable[0];`) which
+trait solution an extension to specify what it is (example `vtable[0];`) which
 could also be used to combine it with others. So these options can be combined
 to allow access to all three options.
@@ -344,6 +456,5 @@
 the type declaration, including the functions that satisfy the trait, are
 all defined. Currently there are many points where this can happen, not all
-of them will have the same definitions and no way to select one over the
-other.
+of them have the same definitions and no way to select one over the other.
 
 Some syntax would have to be added to specify the resolution point. To ensure
@@ -395,7 +506,7 @@
 
 These could also be placed inside functions. In which case both the name and
-the default keyword might be optional. If the name is ommited in an assignment
-the closest vtable is choosen (returning to the global default rule if no
-approprate local vtable is in scope).
+the default keyword might be optional. If the name is omitted in an assignment
+the closest vtable is chosen (returning to the global default rule if no
+appropriate local vtable is in scope).
 
 ### Site Based Resolution:
Index: src/AST/Attribute.hpp
===================================================================
--- src/AST/Attribute.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Attribute.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -47,4 +47,13 @@
 };
 
+
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Attribute * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Attribute * node, Node::ref_type ref ) { node->decrement( ref ); }
 }
 
Index: src/AST/Bitfield.hpp
===================================================================
--- src/AST/Bitfield.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Bitfield.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -22,44 +22,53 @@
 /// does not allow it. Requires type to have `unsigned val` field
 /// @param BFType  Name of containing type
-#define MakeBitfield( BFType )                                         \
-	constexpr BFType() : val( 0 ) {}                                   \
-	constexpr BFType( unsigned int v ) : val( v ) {}                   \
-	bool operator[]( unsigned int i ) const { return val & (1 << i); } \
-	bool any() const { return val != 0; }                              \
-	void reset() { val = 0; }                                          \
-	int ffs() { return ::ffs( val ) - 1; }                             \
-	BFType operator&=( BFType other ) {                                \
-		val &= other.val; return *this;                                \
-	}                                                                  \
-	BFType operator&( BFType other ) const {                           \
-		BFType q = other;                                              \
-		q &= *this;                                                    \
-		return q;                                                      \
-	}                                                                  \
-	BFType operator|=( BFType other ) {                                \
-		val |= other.val; return *this;                                \
-	}                                                                  \
-	BFType operator|( BFType other ) const {                           \
-		BFType q = other;                                              \
-		q |= *this;                                                    \
-		return q;                                                      \
-	}                                                                  \
-	BFType operator-=( BFType other ) {                                \
-		val &= ~other.val; return *this;                               \
+template<typename T>
+struct bitfield : public T {
+	static_assert(sizeof(T) == sizeof(unsigned int), "Type has incorrect size");
+	using T::val;
+	using val_t = decltype(val);
+
+	constexpr bitfield() : T( 0 ) {}
+	constexpr bitfield( val_t v ) : T( v ) {}
+
+	bool operator[]( val_t i ) const { return val & (1 << i); }
+	bool any() const { return val != 0; }
+	void reset() { val = 0; }
+	int ffs() { return ::ffs( val ) - 1; }
+
+	bitfield operator&=( bitfield other ) {
+		val &= other.val; return *this;
 	}
+	bitfield operator&( bitfield other ) const {
+		bitfield q = other;
+		q &= *this;
+		return q;
+	}
+	bitfield operator|=( bitfield other ) {
+		val |= other.val; return *this;
+	}
+	bitfield operator|( bitfield other ) const {
+		bitfield q = other;
+		q |= *this;
+		return q;
+	}
+	bitfield operator-=( bitfield other ) {
+		val &= ~other.val; return *this;
+	}
+};
 
 /// Adds default printing operator to a bitfield type.
 /// Include in definition to add print function, requires other bitfield operators.
 /// @param N  Number of bits in bitfield
-#define MakeBitfieldPrint( N )                                         \
-	static const char* Names[];                                        \
-	void print( std::ostream & os ) const {                            \
-		if ( (*this).any() ) {                                         \
-			for ( unsigned int i = 0; i < N; i += 1 ) {                \
-				if ( (*this)[i] ) {                                    \
-					os << Names[i] << ' ';                             \
-				}                                                      \
-			}                                                          \
-		}                                                              \
+#define MakeBitfieldPrint( N ) \
+	static const char* Names[]; \
+ \
+	void print( std::ostream & os ) const { \
+		if ( (*this).any() ) { \
+			for ( unsigned int i = 0; i < N; i += 1 ) { \
+				if ( (*this)[i] ) { \
+					os << Names[i] << ' '; \
+				} \
+			} \
+		} \
 	}
 
Index: src/AST/Decl.hpp
===================================================================
--- src/AST/Decl.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Decl.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -122,5 +122,5 @@
 	std::vector<ptr<DeclWithType>> assertions;
 
-	NamedTypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, 
+	NamedTypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage,
 		Type* b, Linkage::Spec spec = Linkage::Cforall )
 	: Decl( loc, name, storage, spec ), base( b ), parameters(), assertions() {}
@@ -149,5 +149,5 @@
 		Data( TypeDecl* d ) : kind( d->kind ), isComplete( d->sized ) {}
 		Data( Kind k, bool c ) : kind( k ), isComplete( c ) {}
-		Data( const Data& d1, const Data& d2 ) 
+		Data( const Data& d1, const Data& d2 )
 		: kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
 
@@ -158,5 +158,5 @@
 	};
 
-	TypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, Type* b, 
+	TypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, Type* b,
 		Kind k, bool s, Type* i = nullptr )
 	: NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == Ttype || s ), init( i ) {}
@@ -174,5 +174,5 @@
 class TypedefDecl final : public NamedTypeDecl {
 public:
-	TypedefDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, 
+	TypedefDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage,
 		Type* b, Linkage::Spec spec = Linkage::Cforall )
 	: NamedTypeDecl( loc, name, storage, b, spec ) {}
@@ -275,4 +275,43 @@
 };
 
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Decl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class Decl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class DeclWithType * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class DeclWithType * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class ObjectDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class ObjectDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class FunctionDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class FunctionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class AggregateDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class AggregateDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class StructDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class StructDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class UnionDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class UnionDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class EnumDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class EnumDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class TraitDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class TraitDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class NamedTypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class NamedTypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class TypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class TypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class FtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class FtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class DtypeDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class DtypeDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class TypedefDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class TypedefDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class AsmDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class AsmDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class StaticAssertDecl * node, Node::ref_type ref ) { node->increment(ref); }
+inline void decrement( const class StaticAssertDecl * node, Node::ref_type ref ) { node->decrement(ref); }
+
 }
 
Index: src/AST/Expr.hpp
===================================================================
--- src/AST/Expr.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
+++ src/AST/Expr.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -0,0 +1,134 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Expr.hpp --
+//
+// Author           : Aaron B. Moss
+// Created On       : Fri May 10 10:30:00 2019
+// Last Modified By : Aaron B. Moss
+// Created On       : Fri May 10 10:30:00 2019
+// Update Count     : 1
+//
+
+#pragma once
+
+#include <cassert>
+#include <map>
+#include <utility>        // for move
+#include <vector>
+
+#include "Fwd.hpp"        // for UniqueId
+#include "ParseNode.hpp"
+#include "Type.hpp"       // for ptr<Type>
+
+namespace ast {
+
+/// Contains the ID of a declaration and a type that is derived from that declaration, 
+/// but subject to decay-to-pointer and type parameter renaming
+struct ParamEntry {
+	UniqueId decl;
+	ptr<Type> actualType;
+	ptr<Type> formalType;
+	ptr<Expr> expr;
+
+	ParamEntry() : decl( 0 ), actualType( nullptr ), formalType( nullptr ), expr( nullptr ) {}
+	ParamEntry( UniqueId id, Type* actual, Type* formal, Expr* e )
+	: decl( id ), actualType( actual ), formalType( formal ), expr( e ) {}
+};
+
+/// Pre-resolution list of parameters to infer
+using ResnSlots = std::vector<UniqueId>;
+/// Post-resolution map of inferred parameters
+using InferredParams = std::map< UniqueId, ParamEntry >;
+
+/// Base node for expressions
+class Expr : public ParseNode {
+public:
+	/// Saves space (~16 bytes) by combining ResnSlots and InferredParams
+	struct InferUnion {
+		enum { Empty, Slots, Params } mode;
+		union data_t {
+			char def;
+			ResnSlots resnSlots;
+			InferredParams inferParams;
+
+			data_t() : def('\0') {}
+			~data_t() {}
+		} data;
+
+		/// initializes from other InferUnion
+		void init_from( const InferUnion& o ) {
+			switch ( o.mode ) {
+			case Empty:  return;
+			case Slots:  new(&data.resnSlots) ResnSlots{ o.data.resnSlots }; return;
+			case Params: new(&data.inferParams) InferredParams{ o.data.inferParams }; return;
+			}
+		}
+
+		/// initializes from other InferUnion (move semantics)
+		void init_from( InferUnion&& o ) {
+			switch ( o.mode ) {
+			case Empty:  return;
+			case Slots:  new(&data.resnSlots) ResnSlots{ std::move(o.data.resnSlots) }; return;
+			case Params: 
+				new(&data.inferParams) InferredParams{ std::move(o.data.inferParams) }; return;
+			}
+		}
+
+		/// clears variant fields
+		void reset() {
+			switch( mode ) {
+			case Empty:  return;
+			case Slots:  data.resnSlots.~ResnSlots(); return;
+			case Params: data.inferParams.~InferredParams(); return;
+			}
+		}
+
+		InferUnion() : mode(Empty), data() {}
+		InferUnion( const InferUnion& o ) : mode( o.mode ), data() { init_from( o ); }
+		InferUnion( InferUnion&& o ) : mode( o.mode ), data() { init_from( std::move(o) ); }
+		InferUnion& operator= ( const InferUnion& ) = delete;
+		InferUnion& operator= ( InferUnion&& ) = delete;
+		~InferUnion() { reset(); }
+
+		ResnSlots& resnSlots() {
+			switch (mode) {
+			case Empty: new(&data.resnSlots) ResnSlots{}; mode = Slots; // fallthrough
+			case Slots: return data.resnSlots;
+			case Params: assert(!"Cannot return to resnSlots from Params");
+			}
+		}
+
+		InferredParams& inferParams() {
+			switch (mode) {
+			case Slots: data.resnSlots.~ResnSlots(); // fallthrough
+			case Empty: new(&data.inferParams) InferredParams{}; mode = Params; // fallthrough
+			case Params: return data.inferParams;
+			}
+		}
+	};
+
+	ptr<Type> result;
+	ptr<TypeSubstitution> env;
+	InferUnion inferred;
+	bool extension = false;
+
+	Expr(const CodeLocation& loc ) : ParseNode( loc ), result(), env(), inferred() {}
+
+	Expr* set_extension( bool ex ) { extension = ex; return this; }
+
+	virtual Expr* accept( Visitor& v ) override = 0;
+private:
+	virtual Expr* clone() const override = 0;
+};
+
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/AST/FunctionSpec.hpp
===================================================================
--- src/AST/FunctionSpec.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/FunctionSpec.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -31,16 +31,20 @@
 
 	/// Bitflag type for storage classes
-	union Specs {
-		unsigned int val;
-		struct {
-			bool is_inline   : 1;
-			bool is_noreturn : 1;
-			bool is_fortran  : 1;
+	struct spec_flags {
+		union {
+			unsigned int val;
+			struct {
+				bool is_inline   : 1;
+				bool is_noreturn : 1;
+				bool is_fortran  : 1;
+			};
+
+			// MakeBitfieldPrint( NumSpecs )
 		};
 
-		MakeBitfield( Specs )
-		MakeBitfieldPrint( NumSpecs )
+		constexpr spec_flags( unsigned int val ) : val(val) {}
 	};
 
+	using Specs = bitfield<spec_flags>;
 }
 }
Index: src/AST/Fwd.hpp
===================================================================
--- src/AST/Fwd.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Fwd.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -16,7 +16,8 @@
 #pragma once
 
+#include "AST/Node.hpp"
+
 namespace ast {
 
-class Node;
 class ParseNode;
 
@@ -137,4 +138,228 @@
 class TypeSubstitution;
 
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void decrement( const class Node * node, Node::ref_type ref ) { node->decrement(ref); }
+inline void increment( const class Node * node, Node::ref_type ref ) { node->increment(ref); }
+inline void increment( const class ParseNode *, Node::ref_type );
+inline void decrement( const class ParseNode *, Node::ref_type );
+inline void increment( const class Decl *, Node::ref_type );
+inline void decrement( const class Decl *, Node::ref_type );
+inline void increment( const class DeclWithType *, Node::ref_type );
+inline void decrement( const class DeclWithType *, Node::ref_type );
+inline void increment( const class ObjectDecl *, Node::ref_type );
+inline void decrement( const class ObjectDecl *, Node::ref_type );
+inline void increment( const class FunctionDecl *, Node::ref_type );
+inline void decrement( const class FunctionDecl *, Node::ref_type );
+inline void increment( const class AggregateDecl *, Node::ref_type );
+inline void decrement( const class AggregateDecl *, Node::ref_type );
+inline void increment( const class StructDecl *, Node::ref_type );
+inline void decrement( const class StructDecl *, Node::ref_type );
+inline void increment( const class UnionDecl *, Node::ref_type );
+inline void decrement( const class UnionDecl *, Node::ref_type );
+inline void increment( const class EnumDecl *, Node::ref_type );
+inline void decrement( const class EnumDecl *, Node::ref_type );
+inline void increment( const class TraitDecl *, Node::ref_type );
+inline void decrement( const class TraitDecl *, Node::ref_type );
+inline void increment( const class NamedTypeDecl *, Node::ref_type );
+inline void decrement( const class NamedTypeDecl *, Node::ref_type );
+inline void increment( const class TypeDecl *, Node::ref_type );
+inline void decrement( const class TypeDecl *, Node::ref_type );
+inline void increment( const class FtypeDecl *, Node::ref_type );
+inline void decrement( const class FtypeDecl *, Node::ref_type );
+inline void increment( const class DtypeDecl *, Node::ref_type );
+inline void decrement( const class DtypeDecl *, Node::ref_type );
+inline void increment( const class TypedefDecl *, Node::ref_type );
+inline void decrement( const class TypedefDecl *, Node::ref_type );
+inline void increment( const class AsmDecl *, Node::ref_type );
+inline void decrement( const class AsmDecl *, Node::ref_type );
+inline void increment( const class StaticAssertDecl *, Node::ref_type );
+inline void decrement( const class StaticAssertDecl *, Node::ref_type );
+inline void increment( const class Stmt *, Node::ref_type );
+inline void decrement( const class Stmt *, Node::ref_type );
+inline void increment( const class CompoundStmt *, Node::ref_type );
+inline void decrement( const class CompoundStmt *, Node::ref_type );
+inline void increment( const class ExprStmt *, Node::ref_type );
+inline void decrement( const class ExprStmt *, Node::ref_type );
+inline void increment( const class AsmStmt *, Node::ref_type );
+inline void decrement( const class AsmStmt *, Node::ref_type );
+inline void increment( const class DirectiveStmt *, Node::ref_type );
+inline void decrement( const class DirectiveStmt *, Node::ref_type );
+inline void increment( const class IfStmt *, Node::ref_type );
+inline void decrement( const class IfStmt *, Node::ref_type );
+inline void increment( const class WhileStmt *, Node::ref_type );
+inline void decrement( const class WhileStmt *, Node::ref_type );
+inline void increment( const class ForStmt *, Node::ref_type );
+inline void decrement( const class ForStmt *, Node::ref_type );
+inline void increment( const class SwitchStmt *, Node::ref_type );
+inline void decrement( const class SwitchStmt *, Node::ref_type );
+inline void increment( const class CaseStmt *, Node::ref_type );
+inline void decrement( const class CaseStmt *, Node::ref_type );
+inline void increment( const class BranchStmt *, Node::ref_type );
+inline void decrement( const class BranchStmt *, Node::ref_type );
+inline void increment( const class ReturnStmt *, Node::ref_type );
+inline void decrement( const class ReturnStmt *, Node::ref_type );
+inline void increment( const class ThrowStmt *, Node::ref_type );
+inline void decrement( const class ThrowStmt *, Node::ref_type );
+inline void increment( const class TryStmt *, Node::ref_type );
+inline void decrement( const class TryStmt *, Node::ref_type );
+inline void increment( const class CatchStmt *, Node::ref_type );
+inline void decrement( const class CatchStmt *, Node::ref_type );
+inline void increment( const class FinallyStmt *, Node::ref_type );
+inline void decrement( const class FinallyStmt *, Node::ref_type );
+inline void increment( const class WaitForStmt *, Node::ref_type );
+inline void decrement( const class WaitForStmt *, Node::ref_type );
+inline void increment( const class WithStmt *, Node::ref_type );
+inline void decrement( const class WithStmt *, Node::ref_type );
+inline void increment( const class DeclStmt *, Node::ref_type );
+inline void decrement( const class DeclStmt *, Node::ref_type );
+inline void increment( const class NullStmt *, Node::ref_type );
+inline void decrement( const class NullStmt *, Node::ref_type );
+inline void increment( const class ImplicitCtorDtorStmt *, Node::ref_type );
+inline void decrement( const class ImplicitCtorDtorStmt *, Node::ref_type );
+inline void increment( const class Expr *, Node::ref_type );
+inline void decrement( const class Expr *, Node::ref_type );
+inline void increment( const class ApplicationExpr *, Node::ref_type );
+inline void decrement( const class ApplicationExpr *, Node::ref_type );
+inline void increment( const class UntypedExpr *, Node::ref_type );
+inline void decrement( const class UntypedExpr *, Node::ref_type );
+inline void increment( const class NameExpr *, Node::ref_type );
+inline void decrement( const class NameExpr *, Node::ref_type );
+inline void increment( const class AddressExpr *, Node::ref_type );
+inline void decrement( const class AddressExpr *, Node::ref_type );
+inline void increment( const class LabelAddressExpr *, Node::ref_type );
+inline void decrement( const class LabelAddressExpr *, Node::ref_type );
+inline void increment( const class CastExpr *, Node::ref_type );
+inline void decrement( const class CastExpr *, Node::ref_type );
+inline void increment( const class KeywordCastExpr *, Node::ref_type );
+inline void decrement( const class KeywordCastExpr *, Node::ref_type );
+inline void increment( const class VirtualCastExpr *, Node::ref_type );
+inline void decrement( const class VirtualCastExpr *, Node::ref_type );
+inline void increment( const class MemberExpr *, Node::ref_type );
+inline void decrement( const class MemberExpr *, Node::ref_type );
+inline void increment( const class UntypedMemberExpr *, Node::ref_type );
+inline void decrement( const class UntypedMemberExpr *, Node::ref_type );
+inline void increment( const class VariableExpr *, Node::ref_type );
+inline void decrement( const class VariableExpr *, Node::ref_type );
+inline void increment( const class ConstantExpr *, Node::ref_type );
+inline void decrement( const class ConstantExpr *, Node::ref_type );
+inline void increment( const class SizeofExpr *, Node::ref_type );
+inline void decrement( const class SizeofExpr *, Node::ref_type );
+inline void increment( const class AlignofExpr *, Node::ref_type );
+inline void decrement( const class AlignofExpr *, Node::ref_type );
+inline void increment( const class UntypedOffsetofExpr *, Node::ref_type );
+inline void decrement( const class UntypedOffsetofExpr *, Node::ref_type );
+inline void increment( const class OffsetofExpr *, Node::ref_type );
+inline void decrement( const class OffsetofExpr *, Node::ref_type );
+inline void increment( const class OffsetPackExpr *, Node::ref_type );
+inline void decrement( const class OffsetPackExpr *, Node::ref_type );
+inline void increment( const class AttrExpr *, Node::ref_type );
+inline void decrement( const class AttrExpr *, Node::ref_type );
+inline void increment( const class LogicalExpr *, Node::ref_type );
+inline void decrement( const class LogicalExpr *, Node::ref_type );
+inline void increment( const class ConditionalExpr *, Node::ref_type );
+inline void decrement( const class ConditionalExpr *, Node::ref_type );
+inline void increment( const class CommaExpr *, Node::ref_type );
+inline void decrement( const class CommaExpr *, Node::ref_type );
+inline void increment( const class TypeExpr *, Node::ref_type );
+inline void decrement( const class TypeExpr *, Node::ref_type );
+inline void increment( const class AsmExpr *, Node::ref_type );
+inline void decrement( const class AsmExpr *, Node::ref_type );
+inline void increment( const class ImplicitCopyCtorExpr *, Node::ref_type );
+inline void decrement( const class ImplicitCopyCtorExpr *, Node::ref_type );
+inline void increment( const class ConstructorExpr *, Node::ref_type );
+inline void decrement( const class ConstructorExpr *, Node::ref_type );
+inline void increment( const class CompoundLiteralExpr *, Node::ref_type );
+inline void decrement( const class CompoundLiteralExpr *, Node::ref_type );
+inline void increment( const class UntypedValofExpr *, Node::ref_type );
+inline void decrement( const class UntypedValofExpr *, Node::ref_type );
+inline void increment( const class RangeExpr *, Node::ref_type );
+inline void decrement( const class RangeExpr *, Node::ref_type );
+inline void increment( const class UntypedTupleExpr *, Node::ref_type );
+inline void decrement( const class UntypedTupleExpr *, Node::ref_type );
+inline void increment( const class TupleExpr *, Node::ref_type );
+inline void decrement( const class TupleExpr *, Node::ref_type );
+inline void increment( const class TupleIndexExpr *, Node::ref_type );
+inline void decrement( const class TupleIndexExpr *, Node::ref_type );
+inline void increment( const class TupleAssignExpr *, Node::ref_type );
+inline void decrement( const class TupleAssignExpr *, Node::ref_type );
+inline void increment( const class StmtExpr *, Node::ref_type );
+inline void decrement( const class StmtExpr *, Node::ref_type );
+inline void increment( const class UniqueExpr *, Node::ref_type );
+inline void decrement( const class UniqueExpr *, Node::ref_type );
+inline void increment( const class UntypedInitExpr *, Node::ref_type );
+inline void decrement( const class UntypedInitExpr *, Node::ref_type );
+inline void increment( const class InitExpr *, Node::ref_type );
+inline void decrement( const class InitExpr *, Node::ref_type );
+inline void increment( const class DeletedExpr *, Node::ref_type );
+inline void decrement( const class DeletedExpr *, Node::ref_type );
+inline void increment( const class DefaultArgExpr *, Node::ref_type );
+inline void decrement( const class DefaultArgExpr *, Node::ref_type );
+inline void increment( const class GenericExpr *, Node::ref_type );
+inline void decrement( const class GenericExpr *, Node::ref_type );
+inline void increment( const class Type *, Node::ref_type );
+inline void decrement( const class Type *, Node::ref_type );
+inline void increment( const class VoidType *, Node::ref_type );
+inline void decrement( const class VoidType *, Node::ref_type );
+inline void increment( const class BasicType *, Node::ref_type );
+inline void decrement( const class BasicType *, Node::ref_type );
+inline void increment( const class PointerType *, Node::ref_type );
+inline void decrement( const class PointerType *, Node::ref_type );
+inline void increment( const class ArrayType *, Node::ref_type );
+inline void decrement( const class ArrayType *, Node::ref_type );
+inline void increment( const class ReferenceType *, Node::ref_type );
+inline void decrement( const class ReferenceType *, Node::ref_type );
+inline void increment( const class QualifiedType *, Node::ref_type );
+inline void decrement( const class QualifiedType *, Node::ref_type );
+inline void increment( const class FunctionType *, Node::ref_type );
+inline void decrement( const class FunctionType *, Node::ref_type );
+inline void increment( const class ReferenceToType *, Node::ref_type );
+inline void decrement( const class ReferenceToType *, Node::ref_type );
+inline void increment( const class StructInstType *, Node::ref_type );
+inline void decrement( const class StructInstType *, Node::ref_type );
+inline void increment( const class UnionInstType *, Node::ref_type );
+inline void decrement( const class UnionInstType *, Node::ref_type );
+inline void increment( const class EnumInstType *, Node::ref_type );
+inline void decrement( const class EnumInstType *, Node::ref_type );
+inline void increment( const class TraitInstType *, Node::ref_type );
+inline void decrement( const class TraitInstType *, Node::ref_type );
+inline void increment( const class TypeInstType *, Node::ref_type );
+inline void decrement( const class TypeInstType *, Node::ref_type );
+inline void increment( const class TupleType *, Node::ref_type );
+inline void decrement( const class TupleType *, Node::ref_type );
+inline void increment( const class TypeofType *, Node::ref_type );
+inline void decrement( const class TypeofType *, Node::ref_type );
+inline void increment( const class AttrType *, Node::ref_type );
+inline void decrement( const class AttrType *, Node::ref_type );
+inline void increment( const class VarArgsType *, Node::ref_type );
+inline void decrement( const class VarArgsType *, Node::ref_type );
+inline void increment( const class ZeroType *, Node::ref_type );
+inline void decrement( const class ZeroType *, Node::ref_type );
+inline void increment( const class OneType *, Node::ref_type );
+inline void decrement( const class OneType *, Node::ref_type );
+inline void increment( const class GlobalScopeType *, Node::ref_type );
+inline void decrement( const class GlobalScopeType *, Node::ref_type );
+inline void increment( const class Designation *, Node::ref_type );
+inline void decrement( const class Designation *, Node::ref_type );
+inline void increment( const class Init *, Node::ref_type );
+inline void decrement( const class Init *, Node::ref_type );
+inline void increment( const class SingleInit *, Node::ref_type );
+inline void decrement( const class SingleInit *, Node::ref_type );
+inline void increment( const class ListInit *, Node::ref_type );
+inline void decrement( const class ListInit *, Node::ref_type );
+inline void increment( const class ConstructorInit *, Node::ref_type );
+inline void decrement( const class ConstructorInit *, Node::ref_type );
+inline void increment( const class Constant *, Node::ref_type );
+inline void decrement( const class Constant *, Node::ref_type );
+inline void increment( const class Label *, Node::ref_type );
+inline void decrement( const class Label *, Node::ref_type );
+inline void increment( const class Attribute *, Node::ref_type );
+inline void decrement( const class Attribute *, Node::ref_type );
+inline void increment( const class TypeSubstitution *, Node::ref_type );
+inline void decrement( const class TypeSubstitution *, Node::ref_type );
+
 typedef unsigned int UniqueId;
 
Index: src/AST/Init.hpp
===================================================================
--- src/AST/Init.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Init.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -28,5 +28,5 @@
 class Stmt;
 
-/// List of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an 
+/// List of designator (NameExpr, VariableExpr, and ConstantExpr) expressions that specify an
 /// object being initialized
 class Designation final : public ParseNode {
@@ -34,5 +34,5 @@
 	std::vector<ptr<Expr>> designators;
 
-	Designation( const CodeLocation& loc, std::vector<ptr<Expr>>&& ds = {} ) 
+	Designation( const CodeLocation& loc, std::vector<ptr<Expr>>&& ds = {} )
 	: ParseNode( loc ), designators( std::move(ds) ) {}
 
@@ -60,5 +60,5 @@
 	ptr<Expr> value;
 
-	SingleInit( const CodeLocation& loc, Expr* val, bool mc = false ) 
+	SingleInit( const CodeLocation& loc, Expr* val, bool mc = false )
 	: Init( loc, mc ), value( val ) {}
 
@@ -77,7 +77,7 @@
 	std::vector<ptr<Designation>> designations;
 
-	ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is, 
+	ListInit( const CodeLocation& loc, std::vector<ptr<Init>>&& is,
 		std::vector<ptr<Designation>>&& ds = {}, bool mc = false );
-	
+
 	using iterator = std::vector<ptr<Init>>::iterator;
 	using const_iterator = std::vector<ptr<Init>>::const_iterator;
@@ -93,5 +93,5 @@
 
 /// Either a constructor expression or a C-style initializer.
-/// Should not be necessary to create manually; instead set `maybeConstructed` true on `SingleInit` 
+/// Should not be necessary to create manually; instead set `maybeConstructed` true on `SingleInit`
 /// or `ListInit` if the object should be constructed.
 class ConstructorInit final : public Init {
@@ -99,5 +99,5 @@
 	ptr<Stmt> ctor;
 	ptr<Stmt> dtor;
-	/// C-style initializer made up of SingleInit/ListInit nodes to use as a fallback if an 
+	/// C-style initializer made up of SingleInit/ListInit nodes to use as a fallback if an
 	/// appropriate constructor definition is not found by the resolver.
 	ptr<Init> init;
@@ -111,4 +111,18 @@
 };
 
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Init * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Init * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class SingleInit * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class SingleInit * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ListInit * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ListInit * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ConstructorInit * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ConstructorInit * node, Node::ref_type ref ) { node->decrement( ref ); }
 }
 
Index: src/AST/Label.hpp
===================================================================
--- src/AST/Label.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Label.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -25,26 +25,35 @@
 namespace ast {
 
-	class Attribute;
+class Attribute;
 
-	/// Named labels for statements
-	class Label {
-	public:
-		CodeLocation location;
-		std::string name;
-		std::vector< ptr<Attribute> > attributes;
+/// Named labels for statements
+class Label {
+public:
+	CodeLocation location;
+	std::string name;
+	std::vector< ptr<Attribute> > attributes;
 
-		Label( CodeLocation loc, const std::string& name = "",
-			const std::vector<ptr<Attribute>>& attrs = std::vector<ptr<Attribute>>{} )
-		: location( loc ), name( name ), attributes( attrs ) {}
+	Label( CodeLocation loc, const std::string& name = "",
+		const std::vector<ptr<Attribute>>& attrs = std::vector<ptr<Attribute>>{} )
+	: location( loc ), name( name ), attributes( attrs ) {}
 
-		operator std::string () const { return name; }
-		bool empty() { return name.empty(); }
-	};
+	operator std::string () const { return name; }
+	bool empty() { return name.empty(); }
+};
 
-	inline bool operator== ( const Label& l1, const Label& l2 ) { return l1.name == l2.name; }
-	inline bool operator!= ( const Label& l1, const Label& l2 ) { return !(l1 == l2); }
-	inline bool operator<  ( const Label& l1, const Label& l2 ) { return l1.name < l2.name; }
+inline bool operator== ( const Label& l1, const Label& l2 ) { return l1.name == l2.name; }
+inline bool operator!= ( const Label& l1, const Label& l2 ) { return !(l1 == l2); }
+inline bool operator<  ( const Label& l1, const Label& l2 ) { return l1.name < l2.name; }
 
-	inline std::ostream& operator<< ( std::ostream& out, const Label& l ) { return out << l.name; }
+inline std::ostream& operator<< ( std::ostream& out, const Label& l ) { return out << l.name; }
+
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Label * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Label * node, Node::ref_type ref ) { node->decrement( ref ); }
 
 }
Index: src/AST/LinkageSpec.hpp
===================================================================
--- src/AST/LinkageSpec.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/LinkageSpec.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -35,16 +35,20 @@
 
 	/// Bitflag type for storage classes
-	union Spec {
-		unsigned int val;
-		struct {
-			bool is_mangled      : 1;
-			bool is_generatable  : 1;
-			bool is_overrideable : 1;
-			bool is_builtin      : 1;
-			bool is_gcc_builtin  : 1;
+	struct spec_flags {
+		union {
+			unsigned int val;
+			struct {
+				bool is_mangled      : 1;
+				bool is_generatable  : 1;
+				bool is_overrideable : 1;
+				bool is_builtin      : 1;
+				bool is_gcc_builtin  : 1;
+			};
 		};
 
-		MakeBitfield( Spec )
+		constexpr spec_flags( unsigned int val ) : val(val) {}
 	};
+
+	using Spec = bitfield<spec_flags>;
 
 	/// If `cmd` = "C" returns `spec` with `is_mangled = false`.
Index: src/AST/ParseNode.hpp
===================================================================
--- src/AST/ParseNode.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/ParseNode.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -22,18 +22,26 @@
 namespace ast {
 
-	/// AST node with an included source location
-	class ParseNode : public Node {
-	public:
-		CodeLocation location;
+/// AST node with an included source location
+class ParseNode : public Node {
+public:
+	CodeLocation location;
 
-		// Default constructor is deliberately omitted, all ParseNodes must have a location.
-		// Escape hatch if needed is to explicitly pass a default-constructed location, but
-		// this should be used sparingly.
+	// Default constructor is deliberately omitted, all ParseNodes must have a location.
+	// Escape hatch if needed is to explicitly pass a default-constructed location, but
+	// this should be used sparingly.
 
-		ParseNode( const CodeLocation& loc ) : Node(), location(loc) {}
+	ParseNode( const CodeLocation& loc ) : Node(), location(loc) {}
 
-		ParseNode( const ParseNode& o ) = default;
-	};
+	ParseNode( const ParseNode& o ) = default;
+};
 
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class ParseNode * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ParseNode * node, Node::ref_type ref ) { node->decrement( ref ); }
 }
 
Index: src/AST/Pass.hpp
===================================================================
--- src/AST/Pass.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Pass.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -1,4 +1,19 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Pass.hpp --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu May 09 15::37::05 2019
+// Last Modified By :
+// Last Modified On :
+// Update Count     :
+//
+
 #pragma once
-// IWYU pragma: private, include "Common/PassVisitor.h"
+// IWYU pragma: private, include "AST/Pass.hpp"
 
 #include <functional>
@@ -6,9 +21,13 @@
 #include <stack>
 
-#include "Fwd.hpp"
-#include "Node.hpp"
+#include "AST/Fwd.hpp"
+#include "AST/Node.hpp"
+#include "AST/Decl.hpp"
+#include "AST/Visitor.hpp"
+
+#include "SymTab/Indexer.h"
 
 // Private prelude header, needed for some of the magic tricks this class pulls off
-#include "Pass.proto.hpp"
+#include "AST/Pass.proto.hpp"
 
 namespace ast {
@@ -20,8 +39,12 @@
 //
 // Several additional features are available through inheritance
-// | WithTypeSubstitution - provides polymorphic TypeSubstitution * env for the current expression
+// | WithTypeSubstitution - provides polymorphic const TypeSubstitution * env for the
+//                          current expression
 // | WithStmtsToAdd       - provides the ability to insert statements before or after the current
 //                          statement by adding new statements into stmtsToAddBefore or
 //                          stmtsToAddAfter respectively.
+// | WithDeclsToAdd       - provides the ability to insert declarations before or after the current
+//                          declarations by adding new DeclStmt into declsToAddBefore or
+//                          declsToAddAfter respectively.
 // | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children
 //                          to false in pre{visit,visit} to skip visiting children
@@ -30,15 +53,19 @@
 //                          automatically be restored to its previous value after the corresponding
 //                          postvisit/postmutate teminates.
+// | WithVisitorRef       - provides an pointer to the templated visitor wrapper
+// | WithIndexer          - provides indexer functionality (i.e. up-to-date symbol table)
 //-------------------------------------------------------------------------------------------------
 template< typename pass_t >
 class Pass final : public ast::Visitor {
 public:
+	/// Forward any arguments to the pass constructor
+	/// Propagate 'this' if necessary
 	template< typename... Args >
 	Pass( Args &&... args)
-		: m_pass( std::forward<Args>( args )... )
+		: pass( std::forward<Args>( args )... )
 	{
 		// After the pass is constructed, check if it wants the have a pointer to the wrapping visitor
 		typedef Pass<pass_t> this_t;
-		this_t * const * visitor = __pass::visitor(m_pass, 0);
+		this_t * const * visitor = __pass::visitor(pass, 0);
 		if(visitor) {
 			*const_cast<this_t **>( visitor ) = this;
@@ -48,6 +75,8 @@
 	virtual ~Pass() = default;
 
-	pass_t m_pass;
-
+	/// Storage for the actual pass
+	pass_t pass;
+
+	/// Visit function declarations
 	virtual DeclWithType *     visit( const ObjectDecl           * ) override final;
 	virtual DeclWithType *     visit( const FunctionDecl         * ) override final;
@@ -145,128 +174,112 @@
 	virtual TypeSubstitution * visit( const TypeSubstitution     * ) override final;
 
+	friend void acceptAll( std::list< ptr<Decl> > & decls, Pass<pass_t>& visitor );
 private:
 
-	bool __visit_children() { __pass::bool_ref * ptr = __pass::visit_children(m_pass, 0); return ptr ? *ptr : true; }
+	bool __visit_children() { __pass::bool_ref * ptr = __pass::visit_children(pass, 0); return ptr ? *ptr : true; }
 
 private:
+	/// Logic to call the accept and mutate the parent if needed, delegates call to accept
 	template<typename parent_t, typename child_t>
 	void maybe_accept(parent_t * & , typename parent_t::child_t *);
 
-	ast::Statement  * call_accept( const ast::Statement  * );
-	ast::Expression * call_accept( const ast::Expression * );
+	Stmt * call_accept( const Stmt * );
+	Expr * call_accept( const Expr * );
 
 	template< template <class> class container_t >
-	container_t< ast::ptr<ast::Statement> > call_accept( const container_t< ast::ptr<ast::Statement> > & );
+	container_t< ptr<Stmt> > call_accept( const container_t< ptr<Stmt> > & );
 
 	template< template <class> class container_t, typename node_t >
-	container_t< ast::ptr<node_t> > call_accept( const container_t< ast::ptr<node_t> > & container );
+	container_t< ptr<node_t> > call_accept( const container_t< ptr<node_t> > & container );
 
 private:
-	struct indexer_guard {
+	/// Internal RAII guard for indexer features
+	struct guard_indexer {
+		guard_indexer( Pass<pass_t> & pass ): pass( pass ) { __pass::indexer::enter(pass, 0); }
+		~guard_indexer()                                   { __pass::indexer::leave(pass, 0); }
 		Pass<pass_t> & pass;
-
-		indexer_guard( Pass<pass_t> & pass ) : pass( pass ) { __pass::indexer::enter(pass, 0); }
-		~indexer_guard()                                    { __pass::indexer::leave(pass, 0); }
 	};
 
-	indexer_guard make_indexer_guard() { return { *this }; }
-
-private:
-	struct scope_guard {
+	/// Internal RAII guard for scope features
+	struct guard_scope {
+		guard_scope( Pass<pass_t> & pass ): pass( pass ) { __pass::scope::enter(pass, 0); }
+		~guard_scope()                                   { __pass::scope::leave(pass, 0); }
 		Pass<pass_t> & pass;
-
-		scope_guard( Pass<pass_t> & pass ) : pass( pass ) { __pass::scope::enter(pass, 0); }
-		~scope_guard()                                    { __pass::scope::leave(pass, 0); }
 	};
-
-	scope_guard make_scope_guard() { return { *this }; }
-};
-
-//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-// Guard value : RAII type to restore a value when the Pass finishes visiting this node
-template<typename pass_t, typename T>
-void GuardValue( pass_t * pass, T& val ) {
-	pass->at_cleanup( [ val ]( void * newVal ) {
-		* static_cast< T * >( newVal ) = val;
-	}, static_cast< void * >( & val ) );
-}
-
-//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+};
+
+template<typename pass_t>
+void acceptAll( std::list< ptr<Decl> >, Pass<pass_t>& visitor );
+
+//-------------------------------------------------------------------------------------------------
 // PASS ACCESSORIES
-//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-// Keep track of the type substitution
-struct WithConstTypeSubstitution {
-	const ast::TypeSubstitution * env = nullptr;
-};
+//-------------------------------------------------------------------------------------------------
 
 template<typename T>
 using std_list = std::list<T>;
 
-// Used if visitor requires added statements before or after the current node.
-// The Pass template handles what *before* and *after* means automatically
+/// Keep track of the polymorphic const TypeSubstitution * env for the current expression
+struct WithConstTypeSubstitution {
+	const TypeSubstitution * env = nullptr;
+};
+
+/// Used if visitor requires added statements before or after the current node.
+/// The Pass template handles what *before* and *after* means automatically
 template< template<class> class container_t = std_list >
 struct WithStmtsToAdd {
-	container_t< ast::ptr< ast::Statement > > stmtsToAddBefore;
-	container_t< ast::ptr< ast::Statement > > stmtsToAddAfter;
-};
-
-// Used if visitor requires added declarations before or after the current node.
-// The Pass template handles what *before* and *after* means automatically
+	container_t< ptr<Stmt> > stmtsToAddBefore;
+	container_t< ptr<Stmt> > stmtsToAddAfter;
+};
+
+/// Used if visitor requires added declarations before or after the current node.
+/// The Pass template handles what *before* and *after* means automatically
 template< template<class> class container_t = std_list >
 struct WithDeclsToAdd {
-	~WithDeclsToAdd() {
-		assert( declsToAddBefore.empty() );
-	}
-
-	container_t< ast::ptr< ast::Declaration > > declsToAddBefore;
-	container_t< ast::ptr< ast::Declaration > > declsToAddAfter;
-};
-
-// Use if visitation should stop at certain levels
-// set visit_children false of all child nodes should be ignored
+	container_t< ptr<Decl> > declsToAddBefore;
+	container_t< ptr<Decl> > declsToAddAfter;
+};
+
+/// Use if visitation should stop at certain levels
+/// set visit_children false of all child nodes should be ignored
 struct WithShortCircuiting {
 	__pass::bool_ref visit_children;
 };
 
-// class WithGuards {
-// protected:
-// 	WithGuards() = default;
-// 	~WithGuards() = default;
-
-// public:
-// 	at_cleanup_t at_cleanup;
-
-// 	template< typename T >
-// 	void GuardValue( T& val ) {
-// 		at_cleanup( [ val ]( void * newVal ) {
-// 			* static_cast< T * >( newVal ) = val;
-// 		}, static_cast< void * >( & val ) );
-// 	}
-
-// 	template< typename T >
-// 	void GuardScope( T& val ) {
-// 		val.beginScope();
-// 		at_cleanup( []( void * val ) {
-// 			static_cast< T * >( val )->endScope();
-// 		}, static_cast< void * >( & val ) );
-// 	}
-
-// 	template< typename Func >
-// 	void GuardAction( Func func ) {
-// 		at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr );
-// 	}
-// };
-
-// template<typename pass_type>
-// class WithVisitorRef {
-// protected:
-// 	WithVisitorRef() {}
-// 	~WithVisitorRef() {}
-
-// public:
-// 	PassVisitor<pass_type> * const visitor = nullptr;
-// };
-
+/// Used to restore values/functions/etc. when the Pass finishes visiting this node
+class WithGuards {
+	__pass::at_cleanup_t at_cleanup;
+
+public:
+	/// When this node is finished being visited, restore the value of a variable
+	template< typename T >
+	void GuardValue( T& val ) {
+		at_cleanup( [ val ]( void * newVal ) {
+			* static_cast< T * >( newVal ) = val;
+		}, static_cast< void * >( & val ) );
+	}
+
+	/// On the object, all beginScope now and endScope when the current node is finished being visited
+	template< typename T >
+	void GuardScope( T& val ) {
+		val.beginScope();
+		at_cleanup( []( void * val ) {
+			static_cast< T * >( val )->endScope();
+		}, static_cast< void * >( & val ) );
+	}
+
+	/// When this node is finished being visited, call a function
+	template< typename Func >
+	void GuardAction( Func func ) {
+		at_cleanup( [func](void *) { func(); }, nullptr );
+	}
+};
+
+/// Used to get a pointer to the pass with its wrapped type
+template<typename pass_t>
+struct WithVisitorRef {
+	Pass<pass_t> * const visitor = nullptr;
+};
+
+/// Use when the templated visitor should update the indexer
 struct WithIndexer {
 	SymTab::Indexer indexer;
Index: src/AST/Pass.impl.hpp
===================================================================
--- src/AST/Pass.impl.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Pass.impl.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -1,12 +1,28 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Pass.impl.hpp --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu May 09 15::37::05 2019
+// Last Modified By :
+// Last Modified On :
+// Update Count     :
+//
+
 #pragma once
-// IWYU pragma: private, include "Pass.hpp"
+// IWYU pragma: private, include "AST/Pass.hpp"
 
 #define VISIT_START( node ) \
+	using namespace ast; \
 	/* back-up the visit children */ \
-	__attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(m_pass, 0) ); \
+	__attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(pass, 0) ); \
 	/* setup the scope for passes that want to run code at exit */ \
-	__attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (m_pass, 0) ); \
+	__attribute__((unused)) ast::__pass::guard_value          guard2( ast::__pass::at_cleanup    (pass, 0) ); \
 	/* call the implementation of the previsit of this pass */ \
-	__pass::previsit( m_pass, node, 0 );
+	__pass::previsit( pass, node, 0 );
 
 #define VISIT( code ) \
@@ -98,9 +114,9 @@
 
 	template< typename pass_t >
-	ast::Expression * Pass< pass_t >::call_accept( const ast::Expression * expr ) {
+	ast::Expr * Pass< pass_t >::call_accept( const ast::Expr * expr ) {
 		__pedantic_pass_assert( __visit_children() );
 		__pedantic_pass_assert( expr );
 
-		const ast::TypeSubstitution ** env_ptr = __pass::env( m_pass, 0);
+		const ast::TypeSubstitution ** env_ptr = __pass::env( pass, 0);
 		if ( env_ptr && expr->env ) {
 			*env_ptr = expr->env;
@@ -111,64 +127,7 @@
 
 	template< typename pass_t >
-	ast::Statement * Pass< pass_t >::call_accept( const ast::Statement * stmt ) {
+	Stmt * Pass< pass_t >::call_accept( const Stmt * stmt ) {
 		__pedantic_pass_assert( __visit_children() );
 		__pedantic_pass_assert( stmt );
-
-		// add a few useful symbols to the scope
-		using __pass::empty;
-		using decls_t = typename std::remove_pointer< decltype(__decls_before()) >::type;
-		using stmts_t = typename std::remove_pointer< decltype(__stmts_before()) >::type;
-
-		// get the stmts/decls that will need to be spliced in
-		auto stmts_before = __pass::stmtsToAddBefore( m_pass, 0);
-		auto stmts_after  = __pass::stmtsToAddAfter ( m_pass, 0);
-		auto decls_before = __pass::declsToAddBefore( m_pass, 0);
-		auto decls_after  = __pass::declsToAddAfter ( m_pass, 0);
-
-		// These may be modified by subnode but most be restored once we exit this statemnet.
-		ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( m_pass, 0);  );
-		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
-		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
-		ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );
-		ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
-
-		// Now is the time to actually visit the node
-		ast::Statement * nstmt = stmt->accept( *this );
-
-		// If the pass doesn't want to add anything then we are done
-		if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
-			return nstmt;
-		}
-
-		// Make sure that it is either adding statements or declartions but not both
-		// this is because otherwise the order would be awkward to predict
-		assert(( empty( stmts_before ) && empty( stmts_after ))
-		    || ( empty( decls_before ) && empty( decls_after )) );
-
-		// Create a new Compound Statement to hold the new decls/stmts
-		ast::CompoundStmt * compound = new ast::CompoundStmt( parent->*child.location );
-
-		// Take all the declarations that go before
-		__pass::take_all( std::back_inserter( compound->kids ), decls_before );
-		__pass::take_all( std::back_inserter( compound->kids ), stmts_before );
-
-		// Insert the original declaration
-		compound->kids.push_back( nstmt );
-
-		// Insert all the declarations that go before
-		__pass::take_all( std::back_inserter( compound->kids ), decls_after );
-		__pass::take_all( std::back_inserter( compound->kids ), stmts_after );
-
-		return compound;
-	}
-
-	template< typename pass_t >
-	template< template <class> class container_t >
-	container_t< ast::ptr<ast::Statement> > Pass< pass_t >::call_accept( const container_t< ast::ptr<ast::Statement> > & statements ) {
-		__pedantic_pass_assert( __visit_children() );
-		if( statements.empty() ) return {};
-
-		// We are going to aggregate errors for all these statements
-		SemanticErrorException errors;
 
 		// add a few useful symbols to the scope
@@ -182,4 +141,5 @@
 
 		// These may be modified by subnode but most be restored once we exit this statemnet.
+		ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( pass, 0);  );
 		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
 		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
@@ -187,4 +147,58 @@
 		ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
 
+		// Now is the time to actually visit the node
+		ast::Statement * nstmt = stmt->accept( *this );
+
+		// If the pass doesn't want to add anything then we are done
+		if( empty(stmts_before) && empty(stmts_after) && empty(decls_before) && empty(decls_after) ) {
+			return nstmt;
+		}
+
+		// Make sure that it is either adding statements or declartions but not both
+		// this is because otherwise the order would be awkward to predict
+		assert(( empty( stmts_before ) && empty( stmts_after ))
+		    || ( empty( decls_before ) && empty( decls_after )) );
+
+		// Create a new Compound Statement to hold the new decls/stmts
+		ast::CompoundStmt * compound = new ast::CompoundStmt( parent->*child.location );
+
+		// Take all the declarations that go before
+		__pass::take_all( std::back_inserter( compound->kids ), decls_before );
+		__pass::take_all( std::back_inserter( compound->kids ), stmts_before );
+
+		// Insert the original declaration
+		compound->kids.push_back( nstmt );
+
+		// Insert all the declarations that go before
+		__pass::take_all( std::back_inserter( compound->kids ), decls_after );
+		__pass::take_all( std::back_inserter( compound->kids ), stmts_after );
+
+		return compound;
+	}
+
+	template< typename pass_t >
+	template< template <class> class container_t >
+	container_t< ptr<Stmt> > Pass< pass_t >::call_accept( const container_t< ptr<Stmt> > & statements ) {
+		__pedantic_pass_assert( __visit_children() );
+		if( statements.empty() ) return {};
+
+		// We are going to aggregate errors for all these statements
+		SemanticErrorException errors;
+
+		// add a few useful symbols to the scope
+		using __pass::empty;
+
+		// get the stmts/decls that will need to be spliced in
+		auto stmts_before = __pass::stmtsToAddBefore( pass, 0);
+		auto stmts_after  = __pass::stmtsToAddAfter ( pass, 0);
+		auto decls_before = __pass::declsToAddBefore( pass, 0);
+		auto decls_after  = __pass::declsToAddAfter ( pass, 0);
+
+		// These may be modified by subnode but most be restored once we exit this statemnet.
+		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) > __old_decls_before( stmts_before );
+		ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) > __old_decls_after ( stmts_after  );
+		ValueGuardPtr< typename std::remove_pointer< decltype(decls_before) > __old_stmts_before( decls_before );
+		ValueGuardPtr< typename std::remove_pointer< decltype(decls_after ) > __old_stmts_after ( decls_after  );
+
 		// update pass statitistics
 		pass_visitor_stats.depth++;
@@ -193,6 +207,6 @@
 
 		bool mutated = false;
-		container_t<ast::ptr< ast::Statement >> new_kids;
-		for( const ast::Statement * stmt : statements ) {
+		container_t< ptr<Stmt> > new_kids;
+		for( const Stmt * stmt : statements ) {
 			try {
 				__pedantic_pass_assert( stmt );
@@ -269,4 +283,44 @@
 //------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
+template< typename pass_t >
+inline void ast::acceptAll( std::list< ast::ptr<ast::Decl> > & decls, ast::Pass< pass_t > & visitor ) {
+	// We are going to aggregate errors for all these statements
+	SemanticErrorException errors;
+
+	// add a few useful symbols to the scope
+	using __pass::empty;
+
+	// get the stmts/decls that will need to be spliced in
+	auto decls_before = __pass::declsToAddBefore( pass, 0);
+	auto decls_after  = __pass::declsToAddAfter ( pass, 0);
+
+	// update pass statitistics
+	pass_visitor_stats.depth++;
+	pass_visitor_stats.max->push(pass_visitor_stats.depth);
+	pass_visitor_stats.avg->push(pass_visitor_stats.depth);
+
+	for ( std::list< ast::ptr<ast::Decl> >::iterator i = decls.begin(); ; ++i ) {
+		// splice in new declarations after previous decl
+		if ( !empty( decls_after ) ) { decls.splice( i, *decls_after ); }
+
+		if ( i == decls.end() ) break;
+
+		try {
+			// run visitor on declaration
+			ast::ptr<ast::Decl> & node = *i;
+			assert( node );
+			node = node->accept( visitor );
+		}
+		catch( SemanticErrorException &e ) {
+			errors.append( e );
+		}
+
+		// splice in new declarations before current decl
+		if ( !empty( decls_before ) ) { decls.splice( i, *decls_before ); }
+	}
+	pass_visitor_stats.depth--;
+	if ( !errors.isEmpty() ) { throw errors; }
+}
+
 // A NOTE ON THE ORDER OF TRAVERSAL
 //
@@ -289,20 +343,20 @@
 // ObjectDecl
 template< typename pass_t >
-ast::DeclarationWithType * Pass< pass_t >::mutate( ast::ObjectDecl * node ) {
+ast::DeclWithType * ast::Pass< pass_t >::visit( const ast::ObjectDecl * node ) {
 	VISIT_START( node );
 
 	VISIT(
 		{
-			auto guard = make_indexer_guard();
-			maybe_accept( node, ast::ObjectDecl::type );
-		}
-		maybe_accept( node, ast::ObjectDecl::init          );
-		maybe_accept( node, ast::ObjectDecl::bitfieldWidth );
-		maybe_accept( node, ast::ObjectDecl::attributes    );
+			indexer_guard guard { *this };
+			maybe_accept( node, ObjectDecl::type );
+		}
+		maybe_accept( node, ObjectDecl::init          );
+		maybe_accept( node, ObjectDecl::bitfieldWidth );
+		maybe_accept( node, ObjectDecl::attributes    );
 	)
 
-	__pass::indexer::AddId( m_pass, 0, node );
-
-	VISIT_END( DeclarationWithType, node );
+	__pass::indexer::AddId( pass, 0, node );
+
+	VISIT_END( DeclWithType, node );
 }
 
@@ -310,5 +364,5 @@
 // Attribute
 template< typename pass_type >
-ast::Attribute * ast::Pass< pass_type >::visit( ast::ptr<ast::Attribute> & node  )  {
+ast::Attribute * ast::Pass< pass_type >::visit( const ast::Attribute * node  )  {
 	VISIT_START(node);
 
@@ -323,5 +377,5 @@
 // TypeSubstitution
 template< typename pass_type >
-TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
+TypeSubstitution * PassVisitor< pass_type >::mutate( const TypeSubstitution * node ) {
 	MUTATE_START( node );
 
Index: src/AST/Pass.proto.hpp
===================================================================
--- src/AST/Pass.proto.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Pass.proto.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -1,274 +1,290 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// Pass.impl.hpp --
+//
+// Author           : Thierry Delisle
+// Created On       : Thu May 09 15::37::05 2019
+// Last Modified By :
+// Last Modified On :
+// Update Count     :
+//
+
 #pragma once
 // IWYU pragma: private, include "Pass.hpp"
 
 namespace ast {
-	template<typename pass_type>
-	class Pass;
-
-	namespace __pass {
-		typedef std::function<void( void * )> cleanup_func_t;
-		typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t;
-
-
-		// boolean reference that may be null
-		// either refers to a boolean value or is null and returns true
-		class bool_ref {
-		public:
-			bool_ref() = default;
-			~bool_ref() = default;
-
-			operator bool() { return m_ref ? *m_ref : true; }
-			bool operator=( bool val ) { assert(m_ref); return *m_ref = val; }
-
-		private:
-
-			friend class visit_children_guard;
-
-			bool * set( bool * val ) {
-				bool * prev = m_ref;
-				m_ref = val;
-				return prev;
+template<typename pass_type>
+class Pass;
+
+namespace __pass {
+	typedef std::function<void( void * )> cleanup_func_t;
+	typedef std::function<void( cleanup_func_t, void * )> at_cleanup_t;
+
+
+	// boolean reference that may be null
+	// either refers to a boolean value or is null and returns true
+	class bool_ref {
+	public:
+		bool_ref() = default;
+		~bool_ref() = default;
+
+		operator bool() { return m_ref ? *m_ref : true; }
+		bool operator=( bool val ) { assert(m_ref); return *m_ref = val; }
+
+	private:
+
+		friend class visit_children_guard;
+
+		bool * set( bool * val ) {
+			bool * prev = m_ref;
+			m_ref = val;
+			return prev;
+		}
+
+		bool * m_ref = nullptr;
+	};
+
+	// Implementation of the guard value
+	// Created inside the visit scope
+	class guard_value {
+	public:
+		/// Push onto the cleanup
+		guard_value( at_cleanup_t * at_cleanup ) {
+			if( at_cleanup ) {
+				*at_cleanup = [this]( cleanup_func_t && func, void* val ) {
+					push( std::move( func ), val );
+				};
 			}
-
-			bool * m_ref = nullptr;
+		}
+
+		~guard_value() {
+			while( !cleanups.empty() ) {
+				auto& cleanup = cleanups.top();
+				cleanup.func( cleanup.val );
+				cleanups.pop();
+			}
+		}
+
+		void push( cleanup_func_t && func, void* val ) {
+			cleanups.emplace( std::move(func), val );
+		}
+
+	private:
+		struct cleanup_t {
+			cleanup_func_t func;
+			void * val;
+
+			cleanup_t( cleanup_func_t&& func, void * val ) : func(func), val(val) {}
 		};
 
-		// Implementation of the guard value
-		// Created inside the visit scope
-		class guard_value {
-		public:
-			guard_value( at_cleanup_t * at_cleanup ) {
-				if( at_cleanup ) {
-					*at_cleanup = [this]( cleanup_func_t && func, void* val ) {
-						push( std::move( func ), val );
-					};
-				}
+		std::stack< cleanup_t > cleanups;
+	};
+
+	// Guard structure implementation for whether or not children should be visited
+	class visit_children_guard {
+	public:
+
+		visit_children_guard( bool_ref * ref )
+			: m_val ( true )
+			, m_prev( ref ? ref->set( &m_val ) : nullptr )
+			, m_ref ( ref )
+		{}
+
+		~visit_children_guard() {
+			if( m_ref ) {
+				m_ref->set( m_prev );
 			}
-
-			~guard_value() {
-				while( !cleanups.empty() ) {
-					auto& cleanup = cleanups.top();
-					cleanup.func( cleanup.val );
-					cleanups.pop();
-				}
-			}
-
-			void push( cleanup_func_t && func, void* val ) {
-				cleanups.emplace( std::move(func), val );
-			}
-
-		private:
-			struct cleanup_t {
-				cleanup_func_t func;
-				void * val;
-
-				cleanup_t( cleanup_func_t&& func, void * val ) : func(func), val(val) {}
-			};
-
-			std::stack< cleanup_t > cleanups;
-		};
-
-		// Guard structure implementation for whether or not children should be visited
-		class visit_children_guard {
-		public:
-
-			visit_children_guard( bool_ref * ref )
-				: m_val ( true )
-				, m_prev( ref ? ref->set( &m_val ) : nullptr )
-				, m_ref ( ref )
-			{}
-
-			~visit_children_guard() {
-				if( m_ref ) {
-					m_ref->set( m_prev );
-				}
-			}
-
-			operator bool() { return m_val; }
-
-		private:
-			bool       m_val;
-			bool     * m_prev;
-			bool_ref * m_ref;
-		};
-
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// Deep magic (a.k.a template meta programming) to make the templated visitor work
-		// Basically the goal is to make 2 previsit
-		// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
-		//     'pass.previsit( node )' that compiles will be used for that node for that type
-		//     This requires that this option only compile for passes that actually define an appropriate visit.
-		//     SFINAE will make sure the compilation errors in this function don't halt the build.
-		//     See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE
-		// 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing.
-		//     This is needed only to eliminate the need for passes to specify any kind of handlers.
-		//     The second implementation only works because it has a lower priority. This is due to the bogus last parameter.
-		//     The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0
-		//     the first implementation takes priority in regards to overloading.
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// PreVisit : may mutate the pointer passed in if the node is mutated in the previsit call
-		template<typename pass_t, typename node_t>
-		static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
-			node = pass.previsit( node );
-			assert(node);
-		}
-
-		template<typename pass_t, typename node_t>
-		static inline auto previsit( pass_t &, const node_t *, long ) {}
-
-		// PostVisit : never mutates the passed pointer but may return a different node
-		template<typename pass_t, typename node_t>
-		static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) {
-			return pass.postvisit( node );
-		}
-
-		template<typename pass_t, typename node_t>
-		static inline const node_t * postvisit( pass_t &, const node_t * node, long ) { return node; }
-
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// Deep magic (a.k.a template meta programming) continued
-		// To make the templated visitor be more expressive, we allow 'accessories' : classes/structs the implementation can inherit
-		// from in order to get extra functionallity for example
-		// class ErrorChecker : WithShortCircuiting { ... };
-		// Pass<ErrorChecker> checker;
-		// this would define a pass that uses the templated visitor with the additionnal feature that it has short circuiting
-		// Note that in all cases the accessories are not required but guarantee the requirements of the feature is matched
-		//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-		// For several accessories, the feature is enabled by detecting that a specific field is present
-		// Use a macro the encapsulate the logic of detecting a particular field
-		// The type is not strictly enforced but does match the accessory
-		#define FIELD_PTR( name, default_type ) \
-		template< typename pass_t > \
-		static inline auto name( pass_t & pass, int ) -> decltype( &pass.name ) { return &pass.name; } \
+		}
+
+		operator bool() { return m_val; }
+
+	private:
+		bool       m_val;
+		bool     * m_prev;
+		bool_ref * m_ref;
+	};
+
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// Deep magic (a.k.a template meta programming) to make the templated visitor work
+	// Basically the goal is to make 2 previsit
+	// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
+	//     'pass.previsit( node )' that compiles will be used for that node for that type
+	//     This requires that this option only compile for passes that actually define an appropriate visit.
+	//     SFINAE will make sure the compilation errors in this function don't halt the build.
+	//     See http://en.cppreference.com/w/cpp/language/sfinae for details on SFINAE
+	// 2 - Since the first implementation might not be specilizable, the second implementation exists and does nothing.
+	//     This is needed only to eliminate the need for passes to specify any kind of handlers.
+	//     The second implementation only works because it has a lower priority. This is due to the bogus last parameter.
+	//     The second implementation takes a long while the first takes an int. Since the caller always passes an literal 0
+	//     the first implementation takes priority in regards to overloading.
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// PreVisit : may mutate the pointer passed in if the node is mutated in the previsit call
+	template<typename pass_t, typename node_t>
+	static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
+		node = pass.previsit( node );
+		assert(node);
+	}
+
+	template<typename pass_t, typename node_t>
+	static inline auto previsit( pass_t &, const node_t *, long ) {}
+
+	// PostVisit : never mutates the passed pointer but may return a different node
+	template<typename pass_t, typename node_t>
+	static inline auto postvisit( pass_t & pass, const node_t * node, int ) -> decltype( pass.postvisit( node ), (const node_t *)nullptr ) {
+		return pass.postvisit( node );
+	}
+
+	template<typename pass_t, typename node_t>
+	static inline const node_t * postvisit( pass_t &, const node_t * node, long ) { return node; }
+
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// Deep magic (a.k.a template meta programming) continued
+	// To make the templated visitor be more expressive, we allow 'accessories' : classes/structs the implementation can inherit
+	// from in order to get extra functionallity for example
+	// class ErrorChecker : WithShortCircuiting { ... };
+	// Pass<ErrorChecker> checker;
+	// this would define a pass that uses the templated visitor with the additionnal feature that it has short circuiting
+	// Note that in all cases the accessories are not required but guarantee the requirements of the feature is matched
+	//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+	// For several accessories, the feature is enabled by detecting that a specific field is present
+	// Use a macro the encapsulate the logic of detecting a particular field
+	// The type is not strictly enforced but does match the accessory
+	#define FIELD_PTR( name, default_type ) \
+	template< typename pass_t > \
+	static inline auto name( pass_t & pass, int ) -> decltype( &pass.name ) { return &pass.name; } \
+	\
+	template< typename pass_t > \
+	static inline default_type * name( pass_t &, long ) { return nullptr; }
+
+	// List of fields and their expected types
+	FIELD_PTR( env, const ast::TypeSubstitution )
+	FIELD_PTR( stmtsToAddBefore, std::list< ast::ptr< ast::Stmt > > )
+	FIELD_PTR( stmtsToAddAfter , std::list< ast::ptr< ast::Stmt > > )
+	FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > )
+	FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > )
+	FIELD_PTR( visit_children, __pass::bool_ref )
+	FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
+	FIELD_PTR( visitor, ast::Pass<pass_t> * const )
+
+	// Remove the macro to make sure we don't clash
+	#undef FIELD_PTR
+
+	// Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
+	// All passes which have such functions are assumed desire this behaviour
+	// detect it using the same strategy
+	namespace scope {
+		template<typename pass_t>
+		static inline auto enter( pass_t & pass, int ) -> decltype( pass.beginScope(), void() ) {
+			pass.beginScope();
+		}
+
+		template<typename pass_t>
+		static inline void enter( pass_t &, long ) {}
+
+		template<typename pass_t>
+		static inline auto leave( pass_t & pass, int ) -> decltype( pass.endScope(), void() ) {
+			pass.endScope();
+		}
+
+		template<typename pass_t>
+		static inline void leave( pass_t &, long ) {}
+	};
+
+	// Finally certain pass desire an up to date indexer automatically
+	// detect the presence of a member name indexer and call all the members appropriately
+	namespace indexer {
+		// Some simple scoping rules
+		template<typename pass_t>
+		static inline auto enter( pass_t & pass, int ) -> decltype( pass.indexer.enterScope(), void() ) {
+			pass.indexer.enterScope();
+		}
+
+		template<typename pass_t>
+		static inline auto enter( pass_t &, long ) {}
+
+		template<typename pass_t>
+		static inline auto leave( pass_t & pass, int ) -> decltype( pass.indexer.leaveScope(), void() ) {
+			pass.indexer.leaveScope();
+		}
+
+		template<typename pass_t>
+		static inline auto leave( pass_t &, long ) {}
+
+		// The indexer has 2 kind of functions mostly, 1 argument and 2 arguments
+		// Create macro to condense these common patterns
+		#define INDEXER_FUNC1( func, type ) \
+		template<typename pass_t> \
+		static inline auto func( pass_t & pass, int, type arg ) -> decltype( pass.indexer.func( arg ), void() ) {\
+			pass.indexer.func( arg ); \
+		} \
 		\
-		template< typename pass_t > \
-		static inline default_type * name( pass_t &, long ) { return nullptr; }
-
-		// List of fields and their expected types
-		FIELD_PTR( env, const ast::TypeSubstitution )
-		FIELD_PTR( stmtsToAddBefore, std::list< ast::ptr< ast::Stmt > > )
-		FIELD_PTR( stmtsToAddAfter , std::list< ast::ptr< ast::Stmt > > )
-		FIELD_PTR( declsToAddBefore, std::list< ast::ptr< ast::Decl > > )
-		FIELD_PTR( declsToAddAfter , std::list< ast::ptr< ast::Decl > > )
-		FIELD_PTR( visit_children, __pass::bool_ref )
-		FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
-		FIELD_PTR( visitor, ast::Pass<pass_t> * const )
-
-		// Remove the macro to make sure we don't clash
-		#undef FIELD_PTR
-
-		// Another feature of the templated visitor is that it calls beginScope()/endScope() for compound statement.
-		// All passes which have such functions are assumed desire this behaviour
-		// detect it using the same strategy
-		namespace scope {
-			template<typename pass_t>
-			static inline auto enter( pass_t & pass, int ) -> decltype( pass.beginScope(), void() ) {
-				pass.beginScope();
-			}
-
-			template<typename pass_t>
-			static inline void enter( pass_t &, long ) {}
-
-			template<typename pass_t>
-			static inline auto leave( pass_t & pass, int ) -> decltype( pass.endScope(), void() ) {
-				pass.endScope();
-			}
-
-			template<typename pass_t>
-			static inline void leave( pass_t &, long ) {}
-		};
-
-		// Finally certain pass desire an up to date indexer automatically
-		// detect the presence of a member name indexer and call all the members appropriately
-		namespace indexer {
-			// Some simple scoping rules
-			template<typename pass_t>
-			static inline auto enter( pass_t & pass, int ) -> decltype( pass.indexer.enterScope(), void() ) {
-				pass.indexer.enterScope();
-			}
-
-			template<typename pass_t>
-			static inline auto enter( pass_t &, long ) {}
-
-			template<typename pass_t>
-			static inline auto leave( pass_t & pass, int ) -> decltype( pass.indexer.leaveScope(), void() ) {
-				pass.indexer.leaveScope();
-			}
-
-			template<typename pass_t>
-			static inline auto leave( pass_t &, long ) {}
-
-			// The indexer has 2 kind of functions mostly, 1 argument and 2 arguments
-			// Create macro to condense these common patterns
-			#define INDEXER_FUNC1( func, type ) \
-			template<typename pass_t> \
-			static inline auto func( pass_t & pass, int, type arg ) -> decltype( pass.indexer.func( arg ), void() ) {\
-				pass.indexer.func( arg ); \
-			} \
+		template<typename pass_t> \
+		static inline void func( pass_t &, long, type ) {}
+
+		#define INDEXER_FUNC2( func, type1, type2 ) \
+		template<typename pass_t> \
+		static inline auto func( pass_t & pass, int, type1 arg1, type2 arg2 ) -> decltype( pass.indexer.func( arg1, arg2 ), void () ) {\
+			pass.indexer.func( arg1, arg2 ); \
+		} \
 			\
-			template<typename pass_t> \
-			static inline void func( pass_t &, long, type ) {}
-
-			#define INDEXER_FUNC2( func, type1, type2 ) \
-			template<typename pass_t> \
-			static inline auto func( pass_t & pass, int, type1 arg1, type2 arg2 ) -> decltype( pass.indexer.func( arg1, arg2 ), void () ) {\
-				pass.indexer.func( arg1, arg2 ); \
-			} \
-			 \
-			template<typename pass_t> \
-			static inline void func( pass_t &, long, type1, type2 ) {}
-
-			INDEXER_FUNC1( addId     , DeclarationWithType *       );
-			INDEXER_FUNC1( addType   , NamedTypeDecl *             );
-			INDEXER_FUNC1( addStruct , StructDecl *                );
-			INDEXER_FUNC1( addEnum   , EnumDecl *                  );
-			INDEXER_FUNC1( addUnion  , UnionDecl *                 );
-			INDEXER_FUNC1( addTrait  , TraitDecl *                 );
-			INDEXER_FUNC2( addWith   , std::list< Expression * > &, BaseSyntaxNode * );
-
-			// A few extra functions have more complicated behaviour, they are hand written
-			template<typename pass_t>
-			static inline auto addStructFwd( pass_t & pass, int, ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {
-				ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
-				fwd->parameters = decl->parameters;
-				pass.indexer.addStruct( fwd );
-			}
-
-			template<typename pass_t>
-			static inline void addStructFwd( pass_t &, long, ast::StructDecl * ) {}
-
-			template<typename pass_t>
-			static inline auto addUnionFwd( pass_t & pass, int, ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {
-				UnionDecl * fwd = new UnionDecl( decl->name );
-				fwd->parameters = decl->parameters;
-				pass.indexer.addUnion( fwd );
-			}
-
-			template<typename pass_t>
-			static inline void addUnionFwd( pass_t &, long, ast::UnionDecl * ) {}
-
-			template<typename pass_t>
-			static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) {
-				if ( ! pass.indexer.lookupStruct( str ) ) {
-					pass.indexer.addStruct( str );
-				}
-			}
-
-			template<typename pass_t>
-			static inline void addStruct( pass_t &, long, const std::string & ) {}
-
-			template<typename pass_t>
-			static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {
-				if ( ! pass.indexer.lookupUnion( str ) ) {
-					pass.indexer.addUnion( str );
-				}
-			}
-
-			template<typename pass_t>
-			static inline void addUnion( pass_t &, long, const std::string & ) {}
-
-			#undef INDEXER_FUNC1
-			#undef INDEXER_FUNC2
-		};
+		template<typename pass_t> \
+		static inline void func( pass_t &, long, type1, type2 ) {}
+
+		INDEXER_FUNC1( addId     , DeclWithType *  );
+		INDEXER_FUNC1( addType   , NamedTypeDecl * );
+		INDEXER_FUNC1( addStruct , StructDecl *    );
+		INDEXER_FUNC1( addEnum   , EnumDecl *      );
+		INDEXER_FUNC1( addUnion  , UnionDecl *     );
+		INDEXER_FUNC1( addTrait  , TraitDecl *     );
+		INDEXER_FUNC2( addWith   , std::list< Expression * > &, Node * );
+
+		// A few extra functions have more complicated behaviour, they are hand written
+		// template<typename pass_t>
+		// static inline auto addStructFwd( pass_t & pass, int, ast::StructDecl * decl ) -> decltype( pass.indexer.addStruct( decl ), void() ) {
+		// 	ast::StructDecl * fwd = new ast::StructDecl( decl->location, decl->name );
+		// 	fwd->parameters = decl->parameters;
+		// 	pass.indexer.addStruct( fwd );
+		// }
+
+		// template<typename pass_t>
+		// static inline void addStructFwd( pass_t &, long, ast::StructDecl * ) {}
+
+		// template<typename pass_t>
+		// static inline auto addUnionFwd( pass_t & pass, int, ast::UnionDecl * decl ) -> decltype( pass.indexer.addUnion( decl ), void() ) {
+		// 	UnionDecl * fwd = new UnionDecl( decl->name );
+		// 	fwd->parameters = decl->parameters;
+		// 	pass.indexer.addUnion( fwd );
+		// }
+
+		// template<typename pass_t>
+		// static inline void addUnionFwd( pass_t &, long, ast::UnionDecl * ) {}
+
+		// template<typename pass_t>
+		// static inline auto addStruct( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addStruct( str ), void() ) {
+		// 	if ( ! pass.indexer.lookupStruct( str ) ) {
+		// 		pass.indexer.addStruct( str );
+		// 	}
+		// }
+
+		// template<typename pass_t>
+		// static inline void addStruct( pass_t &, long, const std::string & ) {}
+
+		// template<typename pass_t>
+		// static inline auto addUnion( pass_t & pass, int, const std::string & str ) -> decltype( pass.indexer.addUnion( str ), void() ) {
+		// 	if ( ! pass.indexer.lookupUnion( str ) ) {
+		// 		pass.indexer.addUnion( str );
+		// 	}
+		// }
+
+		// template<typename pass_t>
+		// static inline void addUnion( pass_t &, long, const std::string & ) {}
+
+		#undef INDEXER_FUNC1
+		#undef INDEXER_FUNC2
 	};
 };
+};
Index: src/AST/Stmt.hpp
===================================================================
--- src/AST/Stmt.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Stmt.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -89,4 +89,52 @@
 
 
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Stmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Stmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class CompoundStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class CompoundStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ExprStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ExprStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class AsmStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class AsmStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class DirectiveStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class DirectiveStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class IfStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class IfStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class WhileStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class WhileStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class SwitchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class SwitchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class CaseStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class CaseStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class BranchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class BranchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ReturnStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ReturnStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ThrowStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ThrowStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TryStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TryStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class CatchStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class CatchStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class FinallyStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class FinallyStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class WaitForStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class WaitForStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class WithStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class WithStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class DeclStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class DeclStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class NullStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class NullStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ImplicitCtorDtorStmt * node, Node::ref_type ref ) { node->decrement( ref ); }
+
 }
 
Index: src/AST/StorageClasses.hpp
===================================================================
--- src/AST/StorageClasses.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/StorageClasses.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -33,18 +33,22 @@
 
 	/// Bitflag type for storage classes
-	union Classes {
-		unsigned int val;
-		struct {
-			bool is_extern      : 1;
-			bool is_static      : 1;
-			bool is_auto        : 1;
-			bool is_register    : 1;
-			bool is_threadlocal : 1;
+	struct class_flags {
+		union {
+			unsigned int val;
+			struct {
+				bool is_extern      : 1;
+				bool is_static      : 1;
+				bool is_auto        : 1;
+				bool is_register    : 1;
+				bool is_threadlocal : 1;
+			};
+
+			// MakeBitfieldPrint( NumClasses )
 		};
 
-		MakeBitfield( Classes )
-		MakeBitfieldPrint( NumClasses )
+		constexpr class_flags( unsigned int val ) : val(val) {}
 	};
 
+	using Classes = bitfield<class_flags>;
 }
 }
Index: src/AST/Type.hpp
===================================================================
--- src/AST/Type.hpp	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/Type.hpp	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -24,4 +24,54 @@
 };
 
+
+
+//=================================================================================================
+/// This disgusting and giant piece of boiler-plate is here to solve a cyclic dependency
+/// remove only if there is a better solution
+/// The problem is that ast::ptr< ... > uses increment/decrement which won't work well with
+/// forward declarations
+inline void increment( const class Type * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class Type * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class VoidType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class VoidType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class BasicType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class BasicType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class PointerType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class PointerType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ArrayType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ArrayType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ReferenceType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ReferenceType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class QualifiedType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class QualifiedType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class FunctionType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class FunctionType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ReferenceToType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ReferenceToType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class StructInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class StructInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class UnionInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class UnionInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class EnumInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class EnumInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TraitInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TraitInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TypeInstType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TypeInstType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TupleType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TupleType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class TypeofType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class TypeofType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class AttrType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class AttrType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class VarArgsType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class VarArgsType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class ZeroType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class ZeroType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class OneType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class OneType * node, Node::ref_type ref ) { node->decrement( ref ); }
+inline void increment( const class GlobalScopeType * node, Node::ref_type ref ) { node->increment( ref ); }
+inline void decrement( const class GlobalScopeType * node, Node::ref_type ref ) { node->decrement( ref ); }
+
 }
 
Index: src/AST/porting.md
===================================================================
--- src/AST/porting.md	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/AST/porting.md	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -96,5 +96,6 @@
 
 `Expr`
-* Merged `inferParams`/`resnSlots` into union, as suggested by comment
+* Merged `inferParams`/`resnSlots` into union, as suggested by comment in old version
+  * does imply get_/set_ API, and some care about moving backward
 
 `Label`
Index: src/Common/PassVisitor.impl.h
===================================================================
--- src/Common/PassVisitor.impl.h	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/Common/PassVisitor.impl.h	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -168,4 +168,5 @@
 template< typename Container, typename pass_type >
 inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
+
 	if ( ! mutator.get_visit_children() ) return;
 	SemanticErrorException errors;
@@ -217,4 +218,5 @@
 		try {
 			func( *i );
+			assert( *i );
 			assert(( empty( beforeStmts ) && empty( afterStmts ))
 			    || ( empty( beforeDecls ) && empty( afterDecls )) );
Index: src/Common/PassVisitor.proto.h
===================================================================
--- src/Common/PassVisitor.proto.h	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/Common/PassVisitor.proto.h	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -222,4 +222,6 @@
 INDEXER_FUNC2( addWith   , std::list< Expression * > &, BaseSyntaxNode * );
 
+#undef INDEXER_FUNC1
+#undef INDEXER_FUNC2
 
 template<typename pass_type>
Index: src/SynTree/Declaration.h
===================================================================
--- src/SynTree/Declaration.h	(revision b78129a0ba9ecf9e12792c7395b10b702e4bec2c)
+++ src/SynTree/Declaration.h	(revision 768b3b4fc6eef10132c548773dc967965b9aeff5)
@@ -71,7 +71,7 @@
 	static Declaration *declFromId( UniqueId id );
 
-  private:
+	UniqueId uniqueId;
 	Type::StorageClasses storageClasses;
-	UniqueId uniqueId;
+  private:
 };
 
@@ -213,9 +213,9 @@
 		TypeDecl::Kind kind;
 		bool isComplete;
-		
+
 		Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {}
 		Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
 		Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {}
-		Data( const Data& d1, const Data& d2 ) 
+		Data( const Data& d1, const Data& d2 )
 		: kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {}
 
