Index: src/CodeGen/CodeGenerator.cc
===================================================================
--- src/CodeGen/CodeGenerator.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/CodeGen/CodeGenerator.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -455,5 +455,5 @@
 
 	void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) {
-		assert( false );
+		assert( false && "UntypedOffsetofExpr should not reach code generation" );
 	}
 
@@ -464,4 +464,8 @@
 		output << ", " << mangleName( offsetofExpr->get_member() );
 		output << ")";
+	}
+
+	void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) {
+		assert( false && "OffsetPackExpr should not reach code generation" );
 	}
   
Index: src/CodeGen/CodeGenerator.h
===================================================================
--- src/CodeGen/CodeGenerator.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/CodeGen/CodeGenerator.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -65,4 +65,5 @@
 		virtual void visit( UntypedOffsetofExpr *offsetofExpr );
 		virtual void visit( OffsetofExpr *offsetofExpr );
+		virtual void visit( OffsetPackExpr *offsetPackExpr );
 		virtual void visit( LogicalExpr *logicalExpr );
 		virtual void visit( ConditionalExpr *conditionalExpr );
Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/GenPoly/Box.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -214,6 +214,4 @@
 		};
 
-		class OffsetPackExpr;  // forward declaration so that it can be mutated by Pass2
-
 		/// * Moves polymorphic returns in function types to pointer-type parameters
 		/// * adds type size and assertion parameters to parameter lists
@@ -232,5 +230,5 @@
 			virtual Expression *mutate( AlignofExpr *alignofExpr );
 			virtual Expression *mutate( OffsetofExpr *offsetofExpr );
-			        Expression *mutate( OffsetPackExpr *offsetPackExpr );
+			virtual Expression *mutate( OffsetPackExpr *offsetPackExpr );
 
 			virtual void doBeginScope();
@@ -248,45 +246,4 @@
 			ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
 			ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
-		};
-
-		/// Special internal expression for offset arrays inserted by Pass1 and replaced by Pass2
-		class OffsetPackExpr : public Expression {
-		public:
-			OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 ) : Expression( aname_ ), type( type_ ) {
-					add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
-			}
-			
-			OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
-			virtual ~OffsetPackExpr() { delete type; }
-
-			StructInstType *get_type() const { return type; }
-			void set_type( StructInstType *newValue ) { type = newValue; }
-
-			virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
-			virtual void accept( Visitor &v ) { /* do nothing */ }
-			virtual Expression *acceptMutator( Mutator &m ) {
-				// only act if the mutator is a Pass2, which knows about this class
-				if ( Pass2 *m2 = dynamic_cast< Pass2* >( &m ) ) {
-					return m2->mutate( this );
-				} else {
-					return this;
-				}
-			}
-
-			virtual void print( std::ostream &os, int indent = 0 ) const {
-				os << std::string( indent, ' ' ) << "Offset pack expression on ";
-
-				if ( type ) {
-					type->print(os, indent + 2);
-				} else {
-					os << "<NULL>";
-				}
-
-				os << std::endl;
-				Expression::print( os, indent );
-			}
-			
-		private:
-			StructInstType *type;
 		};
 
Index: src/GenPoly/ScopedSet.h
===================================================================
--- src/GenPoly/ScopedSet.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
+++ src/GenPoly/ScopedSet.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -0,0 +1,221 @@
+//
+// 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.
+//
+// ScopedSet.h --
+//
+// Author           : Aaron B. Moss
+// Created On       : Thu Dec 3 11:51:00 2015
+// Last Modified By : Aaron B. Moss
+// Last Modified On : Thu Dec 3 11:51:00 2015
+// Update Count     : 1
+//
+
+#ifndef _SCOPEDSET_H
+#define _SCOPEDSET_H
+
+#include <iterator>
+#include <set>
+#include <vector>
+
+namespace GenPoly {
+	/// A set where the items are placed into nested scopes;
+	/// inserted items are placed into the innermost scope, lookup looks from the innermost scope outward
+	template<typename Value>
+	class ScopedSet {
+		typedef std::set< Value > Scope;
+		typedef std::vector< Scope > ScopeList;
+
+		ScopeList scopes; ///< scoped list of sets
+	public:
+		typedef typename Scope::key_type key_type;
+		typedef typename Scope::value_type value_type;
+		typedef typename ScopeList::size_type size_type;
+		typedef typename ScopeList::difference_type difference_type;
+		typedef typename Scope::reference reference;
+		typedef typename Scope::const_reference const_reference;
+		typedef typename Scope::pointer pointer;
+		typedef typename Scope::const_pointer const_pointer;
+		
+		class iterator : public std::iterator< std::bidirectional_iterator_tag,
+		                                       value_type > {
+		friend class ScopedSet;
+		friend class const_iterator;
+			typedef typename std::set< Value >::iterator wrapped_iterator;
+			typedef typename std::vector< std::set< Value > > scope_list;
+			typedef typename scope_list::size_type size_type;
+
+			iterator(scope_list const &_scopes, const wrapped_iterator &_it, size_type _i)
+				: scopes(&_scopes), it(_it), i(_i) {}
+		public:
+			iterator(const iterator &that) : scopes(that.scopes), it(that.it), i(that.i) {}
+			iterator& operator= (const iterator &that) {
+				scopes = that.scopes; i = that.i; it = that.it;
+				return *this;
+			}
+			
+			reference operator* () { return *it; }
+			pointer operator-> () { return it.operator->(); }
+
+			iterator& operator++ () {
+				if ( it == (*scopes)[i].end() ) {
+					if ( i == 0 ) return *this;
+					--i;
+					it = (*scopes)[i].begin();
+					return *this;
+				}
+				++it;
+				return *this;
+			}
+			iterator& operator++ (int) { iterator tmp = *this; ++(*this); return tmp; }
+
+			iterator& operator-- () {
+				// may fail if this is the begin iterator; allowed by STL spec
+				if ( it == (*scopes)[i].begin() ) {
+					++i;
+					it = (*scopes)[i].end();
+				}
+				--it;
+				return *this;
+			}
+			iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
+
+			bool operator== (const iterator &that) {
+				return scopes == that.scopes && i == that.i && it == that.it;
+			}
+			bool operator!= (const iterator &that) { return !( *this == that ); }
+
+		private:
+			scope_list const *scopes;
+			wrapped_iterator it;
+			size_type i;
+		};
+
+		class const_iterator : public std::iterator< std::bidirectional_iterator_tag,
+		                                             value_type > {
+		friend class ScopedSet;
+			typedef typename std::set< Value >::iterator wrapped_iterator;
+			typedef typename std::set< Value >::const_iterator wrapped_const_iterator;
+			typedef typename std::vector< std::set< Value > > scope_list;
+			typedef typename scope_list::size_type size_type;
+
+			const_iterator(scope_list const &_scopes, const wrapped_const_iterator &_it, size_type _i)
+				: scopes(&_scopes), it(_it), i(_i) {}
+		public:
+			const_iterator(const iterator &that) : scopes(that.scopes), it(that.it), i(that.i) {}
+			const_iterator(const const_iterator &that) : scopes(that.scopes), it(that.it), i(that.i) {}
+			const_iterator& operator= (const iterator &that) {
+				scopes = that.scopes; i = that.i; it = that.it;
+				return *this;
+			}
+			const_iterator& operator= (const const_iterator &that) {
+				scopes = that.scopes; i = that.i; it = that.it;
+				return *this;
+			}
+
+			const_reference operator* () { return *it; }
+			const_pointer operator-> () { return it.operator->(); }
+
+			const_iterator& operator++ () {
+				if ( it == (*scopes)[i].end() ) {
+					if ( i == 0 ) return *this;
+					--i;
+					it = (*scopes)[i].begin();
+					return *this;
+				}
+				++it;
+				return *this;
+			}
+			const_iterator& operator++ (int) { const_iterator tmp = *this; ++(*this); return tmp; }
+
+			const_iterator& operator-- () {
+				// may fail if this is the begin iterator; allowed by STL spec
+				if ( it == (*scopes)[i].begin() ) {
+					++i;
+					it = (*scopes)[i].end();
+				}
+				--it;
+				return *this;
+			}
+			const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
+
+			bool operator== (const const_iterator &that) {
+				return scopes == that.scopes && i == that.i && it == that.it;
+			}
+			bool operator!= (const const_iterator &that) { return !( *this == that ); }
+
+		private:
+			scope_list const *scopes;
+			wrapped_const_iterator it;
+			size_type i;
+		};
+		
+		/// Starts a new scope
+		void beginScope() {
+			Scope scope;
+			scopes.push_back(scope);
+		}
+
+		/// Ends a scope; invalidates any iterators pointing to elements of that scope
+		void endScope() {
+			scopes.pop_back();
+		}
+
+		/// Default constructor initializes with one scope
+		ScopedSet() { beginScope(); }
+
+		iterator begin() { return iterator(scopes, scopes.back().begin(), scopes.size()-1); }
+		const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
+		const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1); }
+		iterator end() { return iterator(scopes, scopes[0].end(), 0); }
+		const_iterator end() const { return const_iterator(scopes, scopes[0].end(), 0); }
+		const_iterator cend() const { return const_iterator(scopes, scopes[0].end(), 0); }
+
+		/// Gets the index of the current scope (counted from 1)
+		size_type currentScope() const { return scopes.size(); }
+
+		/// Finds the given key in the outermost scope it occurs; returns end() for none such
+		iterator find( const Value &key ) {
+			for ( size_type i = scopes.size() - 1; ; --i ) {
+				typename Scope::iterator val = scopes[i].find( key );
+				if ( val != scopes[i].end() ) return iterator( scopes, val, i );
+				if ( i == 0 ) break;
+			}
+			return end();
+		}
+		const_iterator find( const Value &key ) const {
+			return const_iterator( const_cast< ScopedSet< Value >* >(this)->find( key ) );
+		}
+		
+		/// Finds the given key in the outermost scope inside the given scope where it occurs
+		iterator findNext( const_iterator &it, const Value &key ) {
+			if ( it.i == 0 ) return end();
+			for ( size_type i = it.i - 1; ; --i ) {
+				typename Scope::iterator val = scopes[i].find( key );
+				if ( val != scopes[i].end() ) return iterator( scopes, val, i );
+				if ( i == 0 ) break;
+			}
+			return end();
+		}
+		const_iterator findNext( const_iterator &it, const Value &key ) const {
+			return const_iterator( const_cast< ScopedSet< Value >* >(this)->findNext( it, key ) );
+		}
+
+		/// Inserts the given value into the outermost scope
+		std::pair< iterator, bool > insert( const value_type &value ) {
+			std::pair< typename Scope::iterator, bool > res = scopes.back().insert( value );
+			return std::make_pair( iterator(scopes, res.first, scopes.size()-1), res.second );
+		}
+		
+	};
+} // namespace GenPoly
+
+#endif // _SCOPEDSET_H
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/InitTweak/InitModel.h
===================================================================
--- src/InitTweak/InitModel.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/InitTweak/InitModel.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -75,4 +75,5 @@
 			void visit( UntypedOffsetofExpr * ) { throw 0; }
 			void visit( OffsetofExpr * ) { throw 0; }
+			void visit( OffsetPackExpr * ) { throw 0; }
 			void visit( AttrExpr * ) { throw 0; }
 			void visit( LogicalExpr * ) { throw 0; }
Index: src/ResolvExpr/AlternativeFinder.cc
===================================================================
--- src/ResolvExpr/AlternativeFinder.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/ResolvExpr/AlternativeFinder.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -848,4 +848,8 @@
 	}
 
+	void AlternativeFinder::visit( OffsetPackExpr *offsetPackExpr ) {
+		alternatives.push_back( Alternative( offsetPackExpr->clone(), env, Cost::zero ) );
+	}
+
 	void AlternativeFinder::resolveAttr( DeclarationWithType *funcDecl, FunctionType *function, Type *argType, const TypeEnvironment &env ) {
 		// assume no polymorphism
Index: src/ResolvExpr/AlternativeFinder.h
===================================================================
--- src/ResolvExpr/AlternativeFinder.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/ResolvExpr/AlternativeFinder.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -59,4 +59,5 @@
 		virtual void visit( UntypedOffsetofExpr *offsetofExpr );
 		virtual void visit( OffsetofExpr *offsetofExpr );
+		virtual void visit( OffsetPackExpr *offsetPackExpr );
 		virtual void visit( AttrExpr *attrExpr );
 		virtual void visit( LogicalExpr *logicalExpr );
Index: src/SymTab/Indexer.cc
===================================================================
--- src/SymTab/Indexer.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SymTab/Indexer.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -344,4 +344,9 @@
 		maybeAccept( offsetofExpr->get_type(), *this );
 		maybeAccept( offsetofExpr->get_member(), *this );
+	}
+
+	void Indexer::visit( OffsetPackExpr *offsetPackExpr ) {
+		acceptAllNewScope( offsetPackExpr->get_results(), *this );
+		maybeAccept( offsetPackExpr->get_type(), *this );
 	}
 
Index: src/SymTab/Indexer.h
===================================================================
--- src/SymTab/Indexer.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SymTab/Indexer.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -59,4 +59,5 @@
 		virtual void visit( UntypedOffsetofExpr *offsetofExpr );
 		virtual void visit( OffsetofExpr *offsetofExpr );
+		virtual void visit( OffsetPackExpr *offsetPackExpr );
 		virtual void visit( AttrExpr *attrExpr );
 		virtual void visit( LogicalExpr *logicalExpr );
Index: src/SynTree/Expression.cc
===================================================================
--- src/SynTree/Expression.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SynTree/Expression.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -222,4 +222,25 @@
 }
 
+OffsetPackExpr::OffsetPackExpr( StructInstType *type_, Expression *aname_ ) : Expression( aname_ ), type( type_ ) {
+	add_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) );
+}
+
+OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {}
+
+OffsetPackExpr::~OffsetPackExpr() { delete type; }
+
+void OffsetPackExpr::print( std::ostream &os, int indent ) const {
+	os << std::string( indent, ' ' ) << "Offset pack expression on ";
+
+	if ( type ) {
+		type->print(os, indent + 2);
+	} else {
+		os << "<NULL>";
+	}
+
+	os << std::endl;
+	Expression::print( os, indent );
+}
+
 AttrExpr::AttrExpr( Expression *attr, Expression *expr_, Expression *_aname ) :
 		Expression( _aname ), attr( attr ), expr(expr_), type(0), isType(false) {
Index: src/SynTree/Expression.h
===================================================================
--- src/SynTree/Expression.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SynTree/Expression.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -362,4 +362,24 @@
 };
 
+/// Expression representing a pack of field-offsets for a generic type
+class OffsetPackExpr : public Expression {
+public:
+	OffsetPackExpr( StructInstType *type_, Expression *aname_ = 0 );
+	OffsetPackExpr( const OffsetPackExpr &other );
+	virtual ~OffsetPackExpr();
+
+	StructInstType *get_type() const { return type; }
+	void set_type( StructInstType *newValue ) { type = newValue; }
+
+	virtual OffsetPackExpr *clone() const { return new OffsetPackExpr( *this ); }
+	virtual void accept( Visitor &v ) { v.visit( this ); }
+	virtual Expression *acceptMutator( Mutator &m ) { return m.mutate( this ); }
+
+	virtual void print( std::ostream &os, int indent = 0 ) const;
+
+private:
+	StructInstType *type;
+};
+
 /// AttrExpr represents an @attribute expression (like sizeof, but user-defined)
 class AttrExpr : public Expression {
Index: src/SynTree/Mutator.cc
===================================================================
--- src/SynTree/Mutator.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SynTree/Mutator.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -274,4 +274,10 @@
 }
 
+Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) {
+	mutateAll( offsetPackExpr->get_results(), *this );
+	offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) );
+	return offsetPackExpr;
+}
+
 Expression *Mutator::mutate( AttrExpr *attrExpr ) {
 	mutateAll( attrExpr->get_results(), *this );
Index: src/SynTree/Mutator.h
===================================================================
--- src/SynTree/Mutator.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SynTree/Mutator.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -67,4 +67,5 @@
 	virtual Expression* mutate( UntypedOffsetofExpr *offsetofExpr );
 	virtual Expression* mutate( OffsetofExpr *offsetofExpr );
+	virtual Expression* mutate( OffsetPackExpr *offsetPackExpr );
 	virtual Expression* mutate( AttrExpr *attrExpr );
 	virtual Expression* mutate( LogicalExpr *logicalExpr );
Index: src/SynTree/SynTree.h
===================================================================
--- src/SynTree/SynTree.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SynTree/SynTree.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -72,4 +72,5 @@
 class UntypedOffsetofExpr;
 class OffsetofExpr;
+class OffsetPackExpr;
 class AttrExpr;
 class LogicalExpr;
Index: src/SynTree/Visitor.cc
===================================================================
--- src/SynTree/Visitor.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SynTree/Visitor.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -230,4 +230,9 @@
 }
 
+void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
+	acceptAll( offsetPackExpr->get_results(), *this );
+	maybeAccept( offsetPackExpr->get_type(), *this );
+}
+
 void Visitor::visit( AttrExpr *attrExpr ) {
 	acceptAll( attrExpr->get_results(), *this );
Index: src/SynTree/Visitor.h
===================================================================
--- src/SynTree/Visitor.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/SynTree/Visitor.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -67,4 +67,5 @@
 	virtual void visit( UntypedOffsetofExpr *offsetofExpr );
 	virtual void visit( OffsetofExpr *offsetofExpr );
+	virtual void visit( OffsetPackExpr *offsetPackExpr );
 	virtual void visit( AttrExpr *attrExpr );
 	virtual void visit( LogicalExpr *logicalExpr );
Index: src/Tuples/FlattenTuple.cc
===================================================================
--- src/Tuples/FlattenTuple.cc	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/Tuples/FlattenTuple.cc	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -49,4 +49,5 @@
 	void FlattenTuple::CollectArgs::visit( UntypedOffsetofExpr *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
 	void FlattenTuple::CollectArgs::visit( OffsetofExpr        *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
+	void FlattenTuple::CollectArgs::visit( OffsetPackExpr      *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
 	void FlattenTuple::CollectArgs::visit( AttrExpr            *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
 	void FlattenTuple::CollectArgs::visit( LogicalExpr         *expr )  {  currentArgs.insert( currentArgs.end(), expr );  }
Index: src/Tuples/FlattenTuple.h
===================================================================
--- src/Tuples/FlattenTuple.h	(revision b3f9a0cb9de9429c2209a03c9f8cc182f8609da3)
+++ src/Tuples/FlattenTuple.h	(revision afc1045a9ddab4e6d7c524844fc6895bf4ef52ec)
@@ -45,4 +45,5 @@
 			virtual void visit( UntypedOffsetofExpr * );
 			virtual void visit( OffsetofExpr * );
+			virtual void visit( OffsetPackExpr * );
 			virtual void visit( AttrExpr * );
 			virtual void visit( LogicalExpr * );
