Index: src/GenPoly/Box.cpp
===================================================================
--- src/GenPoly/Box.cpp	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ src/GenPoly/Box.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -14,5 +14,5 @@
 //
 
-#include "Box.h"
+#include "Box.hpp"
 
 #include "AST/Decl.hpp"                // for Decl, FunctionDecl, ...
@@ -24,16 +24,16 @@
 #include "AST/Vector.hpp"              // for vector
 #include "AST/GenericSubstitution.hpp" // for genericSubstitution
-#include "CodeGen/OperatorTable.h"     // for isAssignment
+#include "CodeGen/OperatorTable.hpp"   // for isAssignment
 #include "Common/Iterate.hpp"          // for group_iterate
-#include "Common/ScopedMap.h"          // for ScopedMap
+#include "Common/ScopedMap.hpp"        // for ScopedMap
 #include "Common/ToString.hpp"         // for toCString
-#include "Common/UniqueName.h"         // for UniqueName
-#include "GenPoly/FindFunction.h"      // for findFunction
-#include "GenPoly/GenPoly.h"           // for getFunctionType, ...
-#include "GenPoly/Lvalue.h"            // for generalizedLvalue
-#include "GenPoly/ScopedSet.h"         // for ScopedSet
+#include "Common/UniqueName.hpp"       // for UniqueName
+#include "GenPoly/FindFunction.hpp"    // for findFunction
+#include "GenPoly/GenPoly.hpp"         // for getFunctionType, ...
+#include "GenPoly/Lvalue.hpp"          // for generalizedLvalue
+#include "GenPoly/ScopedSet.hpp"       // for ScopedSet
 #include "GenPoly/ScrubTypeVars.hpp"   // for scrubTypeVars, scrubAllTypeVars
-#include "ResolvExpr/Unify.h"          // for typesCompatible
-#include "SymTab/Mangler.h"            // for mangle, mangleType
+#include "ResolvExpr/Unify.hpp"        // for typesCompatible
+#include "SymTab/Mangler.hpp"          // for mangle, mangleType
 
 namespace GenPoly {
Index: src/GenPoly/Box.h
===================================================================
--- src/GenPoly/Box.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,32 +1,0 @@
-//
-// 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.
-//
-// Box.h -- Implement polymorphic function calls and types.
-//
-// Author           : Richard C. Bilson
-// Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Thr Oct  6 13:37:00 2022
-// Update Count     : 7
-//
-
-#pragma once
-
-namespace ast {
-	class TranslationUnit;
-}
-
-namespace GenPoly {
-
-void box( ast::TranslationUnit & translationUnit );
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/Box.hpp
===================================================================
--- src/GenPoly/Box.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/Box.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,32 @@
+//
+// 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.
+//
+// Box.hpp -- Implement polymorphic function calls and types.
+//
+// Author           : Richard C. Bilson
+// Created On       : Mon May 18 07:44:20 2015
+// Last Modified By : Andrew Beach
+// Last Modified On : Thr Oct  6 13:37:00 2022
+// Update Count     : 7
+//
+
+#pragma once
+
+namespace ast {
+	class TranslationUnit;
+}
+
+namespace GenPoly {
+
+void box( ast::TranslationUnit & translationUnit );
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/ErasableScopedMap.h
===================================================================
--- src/GenPoly/ErasableScopedMap.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,297 +1,0 @@
-//
-// 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.
-//
-// ErasableScopedMap.h -- A map that supports scoping and erasing elements.
-//
-// Author           : Aaron B. Moss
-// Created On       : Wed Dec 2 11:37:00 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 22 09:23:24 2017
-// Update Count     : 2
-//
-
-#pragma once
-
-#include <cassert>
-#include <iterator>
-#include <map>
-#include <utility>
-#include <vector>
-
-namespace GenPoly {
-
-/// A map where the items are placed into nested scopes.
-/// Inserted items are placed into the innermost scope, lookup looks from the
-/// innermost scope outward. Erasing a key means that find() will no longer
-/// report any instance of the key in a scope further out, but the erasure
-/// itself is scoped. Key erasure works by inserting a sentinal value into
-/// the value field, and thus only works for Value types where a meaningful
-/// sentinal can be chosen.
-template<typename Key, typename Value>
-class ErasableScopedMap {
-	typedef std::map< Key, Value > Scope;
-	typedef std::vector< Scope > ScopeList;
-
-	/// Scoped list of maps.
-	ScopeList scopes;
-	/// Sentinal value for erased keys.
-	Value erased;
-public:
-	typedef typename Scope::key_type key_type;
-	typedef typename Scope::mapped_type mapped_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;
-
-	// Both iterator types are complete bidirectional iterators, see below.
-	class iterator;
-	class const_iterator;
-
-	/// Starts a new scope
-	void beginScope() {
-		scopes.emplace_back();
-	}
-
-	/// Ends a scope; invalidates any iterators pointing to elements of that scope
-	void endScope() {
-		scopes.pop_back();
-		assert( ! scopes.empty() );
-	}
-
-	/// Default constructor initializes with one scope
-	ErasableScopedMap( const Value &erased_ ) : erased( erased_ ) { beginScope(); }
-
-	iterator begin() { return iterator(*this, scopes.back().begin(), scopes.size()-1).next_valid(); }
-	const_iterator begin() const { return const_iterator(*this, scopes.back().begin(), scopes.size()-1).next_valid(); }
-	const_iterator cbegin() const { return const_iterator(*this, scopes.back().begin(), scopes.size()-1).next_valid(); }
-	iterator end() { return iterator(*this, scopes[0].end(), 0); }
-	const_iterator end() const { return const_iterator(*this, scopes[0].end(), 0); }
-	const_iterator cend() const { return const_iterator(*this, 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 Key &key ) {
-		for ( size_type i = scopes.size() - 1; ; --i ) {
-			typename Scope::iterator val = scopes[i].find( key );
-			if ( val != scopes[i].end() ) {
-				return val->second == erased ? end() : iterator( *this, val, i );
-			}
-			if ( i == 0 ) break;
-		}
-		return end();
-	}
-	const_iterator find( const Key &key ) const {
-		return const_iterator( const_cast< ErasableScopedMap< Key, 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 Key &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 val->second == erased ? end() : iterator( *this, val, i );
-			}
-			if ( i == 0 ) break;
-		}
-		return end();
-	}
-	const_iterator findNext( const_iterator &it, const Key &key ) const {
-		return const_iterator( const_cast< ErasableScopedMap< Key, Value >* >(this)->findNext( it, key ) );
-	}
-
-	/// Inserts the given key-value pair 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(*this, res.first, scopes.size()-1), res.second );
-	}
-	std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); }
-
-	Value& operator[] ( const Key &key ) {
-		iterator slot = find( key );
-		if ( slot != end() ) return slot->second;
-		return insert( key, Value() ).first->second;
-	}
-
-	/// Marks the given element as erased from this scope inward; returns 1 for erased an element, 0 otherwise
-	size_type erase( const Key &key ) {
-		typename Scope::iterator val = scopes.back().find( key );
-		if ( val != scopes.back().end() ) {
-			val->second = erased;
-			return 1;
-		} else {
-			scopes.back().insert( val, std::make_pair( key, erased ) );
-			return 0;
-		}
-	}
-
-	bool contains( const Key & key ) const {
-		return find( key ) != cend();
-	}
-};
-
-template<typename Key, typename Value>
-class ErasableScopedMap<Key, Value>::iterator :
-		public std::iterator< std::bidirectional_iterator_tag, value_type > {
-	friend class ErasableScopedMap;
-	typedef typename Scope::iterator wrapped_iterator;
-	typedef typename ScopeList::size_type size_type;
-
-	/// Checks if this iterator points to a valid item
-	bool is_valid() const {
-		return it != map->scopes[i].end() && it->second != map->erased;
-	}
-
-	/// Increments on invalid
-	iterator& next_valid() {
-		if ( ! is_valid() ) { ++(*this); }
-		return *this;
-	}
-
-	/// Decrements on invalid
-	iterator& prev_valid() {
-		if ( ! is_valid() ) { --(*this); }
-		return *this;
-	}
-
-	iterator(ErasableScopedMap< Key, Value > const &_map, const wrapped_iterator &_it, size_type _i)
-			: map(&_map), it(_it), i(_i) {}
-
-public:
-	iterator(const iterator &that) : map(that.map), it(that.it), i(that.i) {}
-	iterator& operator= (const iterator &that) {
-		map = that.map; i = that.i; it = that.it;
-		return *this;
-	}
-
-	reference operator* () { return *it; }
-	pointer operator-> () { return it.operator->(); }
-
-	iterator& operator++ () {
-		if ( it == map->scopes[i].end() ) {
-			if ( i == 0 ) return *this;
-			--i;
-			it = map->scopes[i].begin();
-		} else {
-			++it;
-		}
-		return next_valid();
-	}
-
-	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 == map->scopes[i].begin() ) {
-			++i;
-			it = map->scopes[i].end();
-		}
-		--it;
-		return prev_valid();
-	}
-	iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
-
-	bool operator== (const iterator &that) {
-		return map == that.map && i == that.i && it == that.it;
-	}
-	bool operator!= (const iterator &that) { return !( *this == that ); }
-
-private:
-	ErasableScopedMap< Key, Value > const *map;
-	wrapped_iterator it;
-	size_type i;
-};
-
-template<typename Key, typename Value>
-class ErasableScopedMap<Key, Value>::const_iterator :
-		public std::iterator< std::bidirectional_iterator_tag, value_type > {
-	friend class ErasableScopedMap;
-	typedef typename std::map< Key, Value >::iterator wrapped_iterator;
-	typedef typename std::map< Key, Value >::const_iterator wrapped_const_iterator;
-	typedef typename std::vector< std::map< Key, Value > > scope_list;
-	typedef typename scope_list::size_type size_type;
-
-	/// Checks if this iterator points to a valid item
-	bool is_valid() const {
-		return it != map->scopes[i].end() && it->second != map->erased;
-	}
-
-	/// Increments on invalid
-	const_iterator& next_valid() {
-		if ( ! is_valid() ) { ++(*this); }
-		return *this;
-	}
-
-	/// Decrements on invalid
-	const_iterator& prev_valid() {
-		if ( ! is_valid() ) { --(*this); }
-		return *this;
-	}
-
-	const_iterator(ErasableScopedMap< Key, Value > const &_map, const wrapped_const_iterator &_it, size_type _i)
-			: map(&_map), it(_it), i(_i) {}
-public:
-	const_iterator(const iterator &that) : map(that.map), it(that.it), i(that.i) {}
-	const_iterator(const const_iterator &that) : map(that.map), it(that.it), i(that.i) {}
-	const_iterator& operator= (const iterator &that) {
-		map = that.map; i = that.i; it = that.it;
-		return *this;
-	}
-	const_iterator& operator= (const const_iterator &that) {
-		map = that.map; i = that.i; it = that.it;
-		return *this;
-	}
-
-	const_reference operator* () { return *it; }
-	const_pointer operator-> () { return it.operator->(); }
-
-	const_iterator& operator++ () {
-		if ( it == map->scopes[i].end() ) {
-			if ( i == 0 ) return *this;
-			--i;
-			it = map->scopes[i].begin();
-		} else {
-			++it;
-		}
-		return next_valid();
-	}
-	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 == map->scopes[i].begin() ) {
-			++i;
-			it = map->scopes[i].end();
-		}
-		--it;
-		return prev_valid();
-	}
-	const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
-
-	bool operator== (const const_iterator &that) {
-		return map == that.map && i == that.i && it == that.it;
-	}
-	bool operator!= (const const_iterator &that) { return !( *this == that ); }
-
-private:
-	ErasableScopedMap< Key, Value > const *map;
-	wrapped_const_iterator it;
-	size_type i;
-};
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/ErasableScopedMap.hpp
===================================================================
--- src/GenPoly/ErasableScopedMap.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/ErasableScopedMap.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,297 @@
+//
+// 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.
+//
+// ErasableScopedMap.h -- A map that supports scoping and erasing elements.
+//
+// Author           : Aaron B. Moss
+// Created On       : Wed Dec 2 11:37:00 2015
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Jul 22 09:23:24 2017
+// Update Count     : 2
+//
+
+#pragma once
+
+#include <cassert>
+#include <iterator>
+#include <map>
+#include <utility>
+#include <vector>
+
+namespace GenPoly {
+
+/// A map where the items are placed into nested scopes.
+/// Inserted items are placed into the innermost scope, lookup looks from the
+/// innermost scope outward. Erasing a key means that find() will no longer
+/// report any instance of the key in a scope further out, but the erasure
+/// itself is scoped. Key erasure works by inserting a sentinal value into
+/// the value field, and thus only works for Value types where a meaningful
+/// sentinal can be chosen.
+template<typename Key, typename Value>
+class ErasableScopedMap {
+	typedef std::map< Key, Value > Scope;
+	typedef std::vector< Scope > ScopeList;
+
+	/// Scoped list of maps.
+	ScopeList scopes;
+	/// Sentinal value for erased keys.
+	Value erased;
+public:
+	typedef typename Scope::key_type key_type;
+	typedef typename Scope::mapped_type mapped_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;
+
+	// Both iterator types are complete bidirectional iterators, see below.
+	class iterator;
+	class const_iterator;
+
+	/// Starts a new scope
+	void beginScope() {
+		scopes.emplace_back();
+	}
+
+	/// Ends a scope; invalidates any iterators pointing to elements of that scope
+	void endScope() {
+		scopes.pop_back();
+		assert( ! scopes.empty() );
+	}
+
+	/// Default constructor initializes with one scope
+	ErasableScopedMap( const Value &erased_ ) : erased( erased_ ) { beginScope(); }
+
+	iterator begin() { return iterator(*this, scopes.back().begin(), scopes.size()-1).next_valid(); }
+	const_iterator begin() const { return const_iterator(*this, scopes.back().begin(), scopes.size()-1).next_valid(); }
+	const_iterator cbegin() const { return const_iterator(*this, scopes.back().begin(), scopes.size()-1).next_valid(); }
+	iterator end() { return iterator(*this, scopes[0].end(), 0); }
+	const_iterator end() const { return const_iterator(*this, scopes[0].end(), 0); }
+	const_iterator cend() const { return const_iterator(*this, 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 Key &key ) {
+		for ( size_type i = scopes.size() - 1; ; --i ) {
+			typename Scope::iterator val = scopes[i].find( key );
+			if ( val != scopes[i].end() ) {
+				return val->second == erased ? end() : iterator( *this, val, i );
+			}
+			if ( i == 0 ) break;
+		}
+		return end();
+	}
+	const_iterator find( const Key &key ) const {
+		return const_iterator( const_cast< ErasableScopedMap< Key, 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 Key &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 val->second == erased ? end() : iterator( *this, val, i );
+			}
+			if ( i == 0 ) break;
+		}
+		return end();
+	}
+	const_iterator findNext( const_iterator &it, const Key &key ) const {
+		return const_iterator( const_cast< ErasableScopedMap< Key, Value >* >(this)->findNext( it, key ) );
+	}
+
+	/// Inserts the given key-value pair 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(*this, res.first, scopes.size()-1), res.second );
+	}
+	std::pair< iterator, bool > insert( const Key &key, const Value &value ) { return insert( std::make_pair( key, value ) ); }
+
+	Value& operator[] ( const Key &key ) {
+		iterator slot = find( key );
+		if ( slot != end() ) return slot->second;
+		return insert( key, Value() ).first->second;
+	}
+
+	/// Marks the given element as erased from this scope inward; returns 1 for erased an element, 0 otherwise
+	size_type erase( const Key &key ) {
+		typename Scope::iterator val = scopes.back().find( key );
+		if ( val != scopes.back().end() ) {
+			val->second = erased;
+			return 1;
+		} else {
+			scopes.back().insert( val, std::make_pair( key, erased ) );
+			return 0;
+		}
+	}
+
+	bool contains( const Key & key ) const {
+		return find( key ) != cend();
+	}
+};
+
+template<typename Key, typename Value>
+class ErasableScopedMap<Key, Value>::iterator :
+		public std::iterator< std::bidirectional_iterator_tag, value_type > {
+	friend class ErasableScopedMap;
+	typedef typename Scope::iterator wrapped_iterator;
+	typedef typename ScopeList::size_type size_type;
+
+	/// Checks if this iterator points to a valid item
+	bool is_valid() const {
+		return it != map->scopes[i].end() && it->second != map->erased;
+	}
+
+	/// Increments on invalid
+	iterator& next_valid() {
+		if ( ! is_valid() ) { ++(*this); }
+		return *this;
+	}
+
+	/// Decrements on invalid
+	iterator& prev_valid() {
+		if ( ! is_valid() ) { --(*this); }
+		return *this;
+	}
+
+	iterator(ErasableScopedMap< Key, Value > const &_map, const wrapped_iterator &_it, size_type _i)
+			: map(&_map), it(_it), i(_i) {}
+
+public:
+	iterator(const iterator &that) : map(that.map), it(that.it), i(that.i) {}
+	iterator& operator= (const iterator &that) {
+		map = that.map; i = that.i; it = that.it;
+		return *this;
+	}
+
+	reference operator* () { return *it; }
+	pointer operator-> () { return it.operator->(); }
+
+	iterator& operator++ () {
+		if ( it == map->scopes[i].end() ) {
+			if ( i == 0 ) return *this;
+			--i;
+			it = map->scopes[i].begin();
+		} else {
+			++it;
+		}
+		return next_valid();
+	}
+
+	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 == map->scopes[i].begin() ) {
+			++i;
+			it = map->scopes[i].end();
+		}
+		--it;
+		return prev_valid();
+	}
+	iterator& operator-- (int) { iterator tmp = *this; --(*this); return tmp; }
+
+	bool operator== (const iterator &that) {
+		return map == that.map && i == that.i && it == that.it;
+	}
+	bool operator!= (const iterator &that) { return !( *this == that ); }
+
+private:
+	ErasableScopedMap< Key, Value > const *map;
+	wrapped_iterator it;
+	size_type i;
+};
+
+template<typename Key, typename Value>
+class ErasableScopedMap<Key, Value>::const_iterator :
+		public std::iterator< std::bidirectional_iterator_tag, value_type > {
+	friend class ErasableScopedMap;
+	typedef typename std::map< Key, Value >::iterator wrapped_iterator;
+	typedef typename std::map< Key, Value >::const_iterator wrapped_const_iterator;
+	typedef typename std::vector< std::map< Key, Value > > scope_list;
+	typedef typename scope_list::size_type size_type;
+
+	/// Checks if this iterator points to a valid item
+	bool is_valid() const {
+		return it != map->scopes[i].end() && it->second != map->erased;
+	}
+
+	/// Increments on invalid
+	const_iterator& next_valid() {
+		if ( ! is_valid() ) { ++(*this); }
+		return *this;
+	}
+
+	/// Decrements on invalid
+	const_iterator& prev_valid() {
+		if ( ! is_valid() ) { --(*this); }
+		return *this;
+	}
+
+	const_iterator(ErasableScopedMap< Key, Value > const &_map, const wrapped_const_iterator &_it, size_type _i)
+			: map(&_map), it(_it), i(_i) {}
+public:
+	const_iterator(const iterator &that) : map(that.map), it(that.it), i(that.i) {}
+	const_iterator(const const_iterator &that) : map(that.map), it(that.it), i(that.i) {}
+	const_iterator& operator= (const iterator &that) {
+		map = that.map; i = that.i; it = that.it;
+		return *this;
+	}
+	const_iterator& operator= (const const_iterator &that) {
+		map = that.map; i = that.i; it = that.it;
+		return *this;
+	}
+
+	const_reference operator* () { return *it; }
+	const_pointer operator-> () { return it.operator->(); }
+
+	const_iterator& operator++ () {
+		if ( it == map->scopes[i].end() ) {
+			if ( i == 0 ) return *this;
+			--i;
+			it = map->scopes[i].begin();
+		} else {
+			++it;
+		}
+		return next_valid();
+	}
+	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 == map->scopes[i].begin() ) {
+			++i;
+			it = map->scopes[i].end();
+		}
+		--it;
+		return prev_valid();
+	}
+	const_iterator& operator-- (int) { const_iterator tmp = *this; --(*this); return tmp; }
+
+	bool operator== (const const_iterator &that) {
+		return map == that.map && i == that.i && it == that.it;
+	}
+	bool operator!= (const const_iterator &that) { return !( *this == that ); }
+
+private:
+	ErasableScopedMap< Key, Value > const *map;
+	wrapped_const_iterator it;
+	size_type i;
+};
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/FindFunction.cc
===================================================================
--- src/GenPoly/FindFunction.cc	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,112 +1,0 @@
-//
-// 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.
-//
-// FindFunction.cc -- Find function types in a larger type.
-//
-// Author           : Richard C. Bilson
-// Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Fri Oct  7 17:05:20 2022
-// Update Count     : 7
-//
-
-#include "FindFunction.h"
-
-#include <utility>                      // for pair
-
-#include "AST/Pass.hpp"                 // for Pass
-#include "AST/Type.hpp"
-#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::iterator
-#include "GenPoly/GenPoly.h"            // for TyVarMap
-#include "ScrubTypeVars.hpp"            // for scrubTypeVars
-
-namespace GenPoly {
-
-namespace {
-
-struct FindFunctionCore :
-		public ast::WithGuards,
-		public ast::WithShortCircuiting,
-		public ast::WithVisitorRef<FindFunctionCore> {
-	FindFunctionCore(
-		std::vector<ast::ptr<ast::FunctionType>> & functions,
-		const TypeVarMap & typeVars, FindFunctionPred predicate,
-		bool replaceMode );
-
-	void previsit( ast::FunctionType const * type );
-	ast::Type const * postvisit( ast::FunctionType const * type );
-	void previsit( ast::PointerType const * type );
-private:
-	void handleForall( const ast::FunctionType::ForallList & forall );
-
-	std::vector<ast::ptr<ast::FunctionType>> &functions;
-	TypeVarMap typeVars;
-	FindFunctionPred predicate;
-	bool replaceMode;
-};
-
-FindFunctionCore::FindFunctionCore(
-		std::vector<ast::ptr<ast::FunctionType>> & functions,
-		const TypeVarMap &typeVars, FindFunctionPred predicate,
-		bool replaceMode ) :
-	functions( functions ), typeVars( typeVars ),
-	predicate( predicate ), replaceMode( replaceMode ) {}
-
-void FindFunctionCore::handleForall( const ast::FunctionType::ForallList & forall ) {
-	for ( const ast::ptr<ast::TypeInstType> & td : forall ) {
-		TypeVarMap::iterator var = typeVars.find( *td );
-		if ( var != typeVars.end() ) {
-			typeVars.erase( var->first );
-		} // if
-	} // for
-}
-
-void FindFunctionCore::previsit( ast::FunctionType const * type ) {
-	visit_children = false;
-	GuardScope( typeVars );
-	handleForall( type->forall );
-	ast::accept_each( type->returns, *visitor );
-}
-
-ast::Type const * FindFunctionCore::postvisit( ast::FunctionType const * type ) {
-	ast::Type const * ret = type;
-	if ( predicate( type, typeVars ) ) {
-		functions.push_back( type );
-		if ( replaceMode ) {
-			// Replace type parameters in function type with void *.
-			ret = scrubTypeVars( ast::deepCopy( type ), typeVars );
-		} // if
-	} // if
-	return ret;
-}
-
-void FindFunctionCore::previsit( ast::PointerType const * /*type*/ ) {
-	GuardScope( typeVars );
-}
-
-} // namespace
-
-void findFunction( const ast::Type * type,
-		std::vector<ast::ptr<ast::FunctionType>> & functions,
-		const TypeVarMap & typeVars, FindFunctionPred predicate ) {
-	ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, false );
-	type->accept( pass );
-}
-
-const ast::Type * findAndReplaceFunction( const ast::Type * type,
-		std::vector<ast::ptr<ast::FunctionType>> & functions,
-		const TypeVarMap & typeVars, FindFunctionPred predicate ) {
-	ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, true );
-	return type->accept( pass );
-}
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/FindFunction.cpp
===================================================================
--- src/GenPoly/FindFunction.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/FindFunction.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,112 @@
+//
+// 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.
+//
+// FindFunction.cpp -- Find function types in a larger type.
+//
+// Author           : Richard C. Bilson
+// Created On       : Mon May 18 07:44:20 2015
+// Last Modified By : Andrew Beach
+// Last Modified On : Fri Oct  7 17:05:20 2022
+// Update Count     : 7
+//
+
+#include "FindFunction.hpp"
+
+#include <utility>                        // for pair
+
+#include "AST/Pass.hpp"                   // for Pass
+#include "AST/Type.hpp"
+#include "GenPoly/ErasableScopedMap.hpp"  // for ErasableScopedMap<>::iterator
+#include "GenPoly/GenPoly.hpp"            // for TyVarMap
+#include "ScrubTypeVars.hpp"              // for scrubTypeVars
+
+namespace GenPoly {
+
+namespace {
+
+struct FindFunctionCore :
+		public ast::WithGuards,
+		public ast::WithShortCircuiting,
+		public ast::WithVisitorRef<FindFunctionCore> {
+	FindFunctionCore(
+		std::vector<ast::ptr<ast::FunctionType>> & functions,
+		const TypeVarMap & typeVars, FindFunctionPred predicate,
+		bool replaceMode );
+
+	void previsit( ast::FunctionType const * type );
+	ast::Type const * postvisit( ast::FunctionType const * type );
+	void previsit( ast::PointerType const * type );
+private:
+	void handleForall( const ast::FunctionType::ForallList & forall );
+
+	std::vector<ast::ptr<ast::FunctionType>> &functions;
+	TypeVarMap typeVars;
+	FindFunctionPred predicate;
+	bool replaceMode;
+};
+
+FindFunctionCore::FindFunctionCore(
+		std::vector<ast::ptr<ast::FunctionType>> & functions,
+		const TypeVarMap &typeVars, FindFunctionPred predicate,
+		bool replaceMode ) :
+	functions( functions ), typeVars( typeVars ),
+	predicate( predicate ), replaceMode( replaceMode ) {}
+
+void FindFunctionCore::handleForall( const ast::FunctionType::ForallList & forall ) {
+	for ( const ast::ptr<ast::TypeInstType> & td : forall ) {
+		TypeVarMap::iterator var = typeVars.find( *td );
+		if ( var != typeVars.end() ) {
+			typeVars.erase( var->first );
+		} // if
+	} // for
+}
+
+void FindFunctionCore::previsit( ast::FunctionType const * type ) {
+	visit_children = false;
+	GuardScope( typeVars );
+	handleForall( type->forall );
+	ast::accept_each( type->returns, *visitor );
+}
+
+ast::Type const * FindFunctionCore::postvisit( ast::FunctionType const * type ) {
+	ast::Type const * ret = type;
+	if ( predicate( type, typeVars ) ) {
+		functions.push_back( type );
+		if ( replaceMode ) {
+			// Replace type parameters in function type with void *.
+			ret = scrubTypeVars( ast::deepCopy( type ), typeVars );
+		} // if
+	} // if
+	return ret;
+}
+
+void FindFunctionCore::previsit( ast::PointerType const * /*type*/ ) {
+	GuardScope( typeVars );
+}
+
+} // namespace
+
+void findFunction( const ast::Type * type,
+		std::vector<ast::ptr<ast::FunctionType>> & functions,
+		const TypeVarMap & typeVars, FindFunctionPred predicate ) {
+	ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, false );
+	type->accept( pass );
+}
+
+const ast::Type * findAndReplaceFunction( const ast::Type * type,
+		std::vector<ast::ptr<ast::FunctionType>> & functions,
+		const TypeVarMap & typeVars, FindFunctionPred predicate ) {
+	ast::Pass<FindFunctionCore> pass( functions, typeVars, predicate, true );
+	return type->accept( pass );
+}
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/FindFunction.h
===================================================================
--- src/GenPoly/FindFunction.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,40 +1,0 @@
-//
-// 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.
-//
-// FindFunction.h -- Find function types in a larger type.
-//
-// Author           : Richard C. Bilson
-// Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Fri Oct  7 10:30:00 2022
-// Update Count     : 3
-//
-
-#pragma once
-
-#include "GenPoly.h"            // for TypeVarMap
-
-namespace GenPoly {
-
-typedef bool (*FindFunctionPred)( const ast::FunctionType *, const TypeVarMap & );
-
-/// Recursively walks `type`, placing all functions that match `predicate`
-/// under `typeVars` into `functions`.
-void findFunction( const ast::Type * type,
-		std::vector<ast::ptr<ast::FunctionType>> & functions,
-		const TypeVarMap & typeVars, FindFunctionPred predicate );
-/// Like findFunction, but also replaces the function type with `void ()(void)`.
-const ast::Type * findAndReplaceFunction( const ast::Type * type,
-		std::vector<ast::ptr<ast::FunctionType>> & functions,
-		const TypeVarMap & typeVars, FindFunctionPred predicate );
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/FindFunction.hpp
===================================================================
--- src/GenPoly/FindFunction.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/FindFunction.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,40 @@
+//
+// 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.
+//
+// FindFunction.hpp -- Find function types in a larger type.
+//
+// Author           : Richard C. Bilson
+// Created On       : Mon May 18 07:44:20 2015
+// Last Modified By : Andrew Beach
+// Last Modified On : Fri Oct  7 10:30:00 2022
+// Update Count     : 3
+//
+
+#pragma once
+
+#include "GenPoly.hpp"            // for TypeVarMap
+
+namespace GenPoly {
+
+typedef bool (*FindFunctionPred)( const ast::FunctionType *, const TypeVarMap & );
+
+/// Recursively walks `type`, placing all functions that match `predicate`
+/// under `typeVars` into `functions`.
+void findFunction( const ast::Type * type,
+		std::vector<ast::ptr<ast::FunctionType>> & functions,
+		const TypeVarMap & typeVars, FindFunctionPred predicate );
+/// Like findFunction, but also replaces the function type with `void ()(void)`.
+const ast::Type * findAndReplaceFunction( const ast::Type * type,
+		std::vector<ast::ptr<ast::FunctionType>> & functions,
+		const TypeVarMap & typeVars, FindFunctionPred predicate );
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/GenPoly.cc
===================================================================
--- src/GenPoly/GenPoly.cc	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,414 +1,0 @@
-//
-// 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.
-//
-// GenPoly.cc -- General GenPoly utilities.
-//
-// Author           : Richard C. Bilson
-// Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Mon Oct 24 15:19:00 2022
-// Update Count     : 17
-//
-
-#include "GenPoly.h"
-
-#include <cassert>                      // for assertf, assert
-#include <iostream>                     // for operator<<, ostream, basic_os...
-#include <iterator>                     // for back_insert_iterator, back_in...
-#include <list>                         // for list, _List_iterator, list<>:...
-#include <typeindex>                    // for type_index
-#include <utility>                      // for pair
-#include <vector>                       // for vector
-
-#include "AST/Expr.hpp"
-#include "AST/Type.hpp"
-#include "AST/TypeSubstitution.hpp"
-#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it...
-#include "ResolvExpr/typeops.h"         // for flatten
-
-using namespace std;
-
-namespace GenPoly {
-
-namespace {
-	/// Checks a parameter list for polymorphic parameters; will substitute according to env if present.
-	bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env ) {
-		for ( auto & param : params ) {
-			auto paramType = param.as<ast::TypeExpr>();
-			assertf( paramType, "Aggregate parameters should be type expressions" );
-			if ( isPolyType( paramType->type, env ) ) return true;
-		}
-		return false;
-	}
-
-	/// Checks a parameter list for polymorphic parameters from typeVars; will substitute according to env if present.
-	bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const TypeVarMap & typeVars, const ast::TypeSubstitution * env ) {
-		for ( auto & param : params ) {
-			auto paramType = param.as<ast::TypeExpr>();
-			assertf( paramType, "Aggregate parameters should be type expressions" );
-			if ( isPolyType( paramType->type, typeVars, env ) ) return true;
-		}
-		return false;
-	}
-
-	/// Checks a parameter list for dynamic-layout parameters from tyVars; will substitute according to env if present.
-	bool hasDynParams(
-			const std::vector<ast::ptr<ast::Expr>> & params,
-			const TypeVarMap & typeVars,
-			const ast::TypeSubstitution * subst ) {
-		for ( ast::ptr<ast::Expr> const & paramExpr : params ) {
-			auto param = paramExpr.as<ast::TypeExpr>();
-			assertf( param, "Aggregate parameters should be type expressions." );
-			if ( isDynType( param->type.get(), typeVars, subst ) ) {
-				return true;
-			}
-		}
-		return false;
-	}
-} // namespace
-
-const ast::Type * replaceTypeInst( const ast::Type * type, const ast::TypeSubstitution * env ) {
-	if ( !env ) return type;
-	if ( auto typeInst = dynamic_cast<const ast::TypeInstType*>( type ) ) {
-		if ( auto newType = env->lookup( typeInst ) ) return newType;
-	}
-	return type;
-}
-
-const ast::Type * isPolyType( const ast::Type * type, const ast::TypeSubstitution * subst ) {
-	type = replaceTypeInst( type, subst );
-
-	if ( dynamic_cast< const ast::TypeInstType * >( type ) ) {
-		// This case is where the two variants of isPolyType differ.
-		return type;
-	} else if ( auto arrayType = dynamic_cast< const ast::ArrayType * >( type ) ) {
-		return isPolyType( arrayType->base, subst );
-	} else if ( auto structType = dynamic_cast< const ast::StructInstType* >( type ) ) {
-		if ( hasPolyParams( structType->params, subst ) ) return type;
-	} else if ( auto unionType = dynamic_cast< const ast::UnionInstType* >( type ) ) {
-		if ( hasPolyParams( unionType->params, subst ) ) return type;
-	}
-	return nullptr;
-}
-
-const ast::Type * isPolyType( const ast::Type * type,
-		const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) {
-	type = replaceTypeInst( type, subst );
-
-	if ( auto inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
-		if ( typeVars.contains( *inst ) ) return type;
-	} else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) {
-		return isPolyType( array->base, typeVars, subst );
-	} else if ( auto sue = dynamic_cast< const ast::StructInstType * >( type ) ) {
-		if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
-	} else if ( auto sue = dynamic_cast< const ast::UnionInstType * >( type ) ) {
-		if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
-	}
-	return nullptr;
-}
-
-const ast::BaseInstType * isDynType(
-		const ast::Type * type, const TypeVarMap & typeVars,
-		const ast::TypeSubstitution * subst ) {
-	type = replaceTypeInst( type, subst );
-
-	if ( auto inst = dynamic_cast<ast::TypeInstType const *>( type ) ) {
-		auto var = typeVars.find( *inst );
-		if ( var != typeVars.end() && var->second.isComplete ) {
-			return inst;
-		}
-	} else if ( auto inst = dynamic_cast<ast::StructInstType const *>( type ) ) {
-		if ( hasDynParams( inst->params, typeVars, subst ) ) return inst;
-	} else if ( auto inst = dynamic_cast<ast::UnionInstType const *>( type ) ) {
-		if ( hasDynParams( inst->params, typeVars, subst ) ) return inst;
-	}
-	return nullptr;
-}
-
-const ast::BaseInstType *isDynRet(
-		const ast::FunctionType * type, const TypeVarMap & typeVars ) {
-	if ( type->returns.empty() ) return nullptr;
-
-	return isDynType( type->returns.front(), typeVars );
-}
-
-const ast::BaseInstType *isDynRet( const ast::FunctionType * func ) {
-	if ( func->returns.empty() ) return nullptr;
-
-	TypeVarMap forallTypes;
-	makeTypeVarMap( func, forallTypes );
-	return isDynType( func->returns.front(), forallTypes );
-}
-
-bool needsAdapter(
-		ast::FunctionType const * adaptee, const TypeVarMap & typeVars ) {
-	if ( isDynRet( adaptee, typeVars ) ) return true;
-
-	for ( auto param : adaptee->params ) {
-		if ( isDynType( param, typeVars ) ) {
-			return true;
-		}
-	}
-	return false;
-}
-
-const ast::Type * isPolyPtr(
-		const ast::Type * type, const TypeVarMap & typeVars,
-		const ast::TypeSubstitution * typeSubs ) {
-	type = replaceTypeInst( type, typeSubs );
-
-	if ( auto * ptr = dynamic_cast<ast::PointerType const *>( type ) ) {
-		return isPolyType( ptr->base, typeVars, typeSubs );
-	}
-	return nullptr;
-}
-
-ast::Type const * hasPolyBase(
-		ast::Type const * type, const TypeVarMap & typeVars,
-		int * levels, const ast::TypeSubstitution * subst ) {
-	int level_count = 0;
-
-	while ( true ) {
-		type = replaceTypeInst( type, subst );
-
-		if ( auto ptr = dynamic_cast<ast::PointerType const *>( type ) ) {
-			type = ptr->base;
-			++level_count;
-		} else {
-			break;
-		}
-	}
-
-	if ( nullptr != levels ) { *levels = level_count; }
-	return isPolyType( type, typeVars, subst );
-}
-
-const ast::FunctionType * getFunctionType( const ast::Type * ty ) {
-	if ( auto pty = dynamic_cast< const ast::PointerType * >( ty ) ) {
-		return pty->base.as< ast::FunctionType >();
-	} else {
-		return dynamic_cast< const ast::FunctionType * >( ty );
-	}
-}
-
-namespace {
-	/// Checks if is a pointer to D
-	template<typename D, typename B>
-	bool is( const B* p ) { return type_index{typeid(D)} == type_index{typeid(*p)}; }
-
-	/// Converts to a pointer to D without checking for safety
-	template<typename D, typename B>
-	inline D* as( B* p ) { return reinterpret_cast<D*>(p); }
-
-	template<typename D, typename B>
-	inline D const * as( B const * p ) {
-		return reinterpret_cast<D const *>( p );
-	}
-
-	/// Flattens a list of types.
-	void flattenList( vector<ast::ptr<ast::Type>> const & src,
-			vector<ast::ptr<ast::Type>> & out ) {
-		for ( auto const & type : src ) {
-			ResolvExpr::flatten( type, out );
-		}
-	}
-
-	bool paramListsPolyCompatible(
-			std::vector<ast::ptr<ast::Expr>> const & lparams,
-			std::vector<ast::ptr<ast::Expr>> const & rparams ) {
-		if ( lparams.size() != rparams.size() ) {
-			return false;
-		}
-
-		for ( auto lparam = lparams.begin(), rparam = rparams.begin() ;
-				lparam != lparams.end() ; ++lparam, ++rparam ) {
-			ast::TypeExpr const * lexpr = lparam->as<ast::TypeExpr>();
-			assertf( lexpr, "Aggregate parameters should be type expressions" );
-			ast::TypeExpr const * rexpr = rparam->as<ast::TypeExpr>();
-			assertf( rexpr, "Aggregate parameters should be type expressions" );
-
-			// xxx - might need to let VoidType be a wildcard here too; could have some voids
-			// stuffed in for dtype-statics.
-			// if ( is<VoidType>( lexpr->type() ) || is<VoidType>( bparam->get_type() ) ) continue;
-			if ( !typesPolyCompatible( lexpr->type, rexpr->type ) ) {
-				return false;
-			}
-		}
-
-		return true;
-	}
-} // namespace
-
-bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs ) {
-	type_index const lid = typeid(*lhs);
-
-	// Polymorphic types always match:
-	if ( type_index(typeid(ast::TypeInstType)) == lid ) return true;
-
-	type_index const rid = typeid(*rhs);
-	if ( type_index(typeid(ast::TypeInstType)) == rid ) return true;
-
-	// All other types only match if they are the same type:
-	if ( lid != rid ) return false;
-
-	// So remaining types can be examined case by case.
-	// Recurse through type structure (conditions borrowed from Unify.cc).
-
-	if ( type_index(typeid(ast::BasicType)) == lid ) {
-		return as<ast::BasicType>(lhs)->kind == as<ast::BasicType>(rhs)->kind;
-	} else if ( type_index(typeid(ast::PointerType)) == lid ) {
-		ast::PointerType const * l = as<ast::PointerType>(lhs);
-		ast::PointerType const * r = as<ast::PointerType>(rhs);
-
-		// void pointers should match any other pointer type.
-		return is<ast::VoidType>( l->base.get() )
-			|| is<ast::VoidType>( r->base.get() )
-			|| typesPolyCompatible( l->base.get(), r->base.get() );
-	} else if ( type_index(typeid(ast::ReferenceType)) == lid ) {
-		ast::ReferenceType const * l = as<ast::ReferenceType>(lhs);
-		ast::ReferenceType const * r = as<ast::ReferenceType>(rhs);
-
-		// void references should match any other reference type.
-		return is<ast::VoidType>( l->base.get() )
-			|| is<ast::VoidType>( r->base.get() )
-			|| typesPolyCompatible( l->base.get(), r->base.get() );
-	} else if ( type_index(typeid(ast::ArrayType)) == lid ) {
-		ast::ArrayType const * l = as<ast::ArrayType>(lhs);
-		ast::ArrayType const * r = as<ast::ArrayType>(rhs);
-
-		if ( l->isVarLen ) {
-			if ( !r->isVarLen ) return false;
-		} else {
-			if ( r->isVarLen ) return false;
-
-			auto lc = l->dimension.as<ast::ConstantExpr>();
-			auto rc = r->dimension.as<ast::ConstantExpr>();
-			if ( lc && rc && lc->intValue() != rc->intValue() ) {
-				return false;
-			}
-		}
-
-		return typesPolyCompatible( l->base.get(), r->base.get() );
-	} else if ( type_index(typeid(ast::FunctionType)) == lid ) {
-		ast::FunctionType const * l = as<ast::FunctionType>(lhs);
-		ast::FunctionType const * r = as<ast::FunctionType>(rhs);
-
-		std::vector<ast::ptr<ast::Type>> lparams, rparams;
-		flattenList( l->params, lparams );
-		flattenList( r->params, rparams );
-		if ( lparams.size() != rparams.size() ) return false;
-		for ( unsigned i = 0; i < lparams.size(); ++i ) {
-			if ( !typesPolyCompatible( lparams[i], rparams[i] ) ) return false;
-		}
-
-		std::vector<ast::ptr<ast::Type>> lrets, rrets;
-		flattenList( l->returns, lrets );
-		flattenList( r->returns, rrets );
-		if ( lrets.size() != rrets.size() ) return false;
-		for ( unsigned i = 0; i < lrets.size(); ++i ) {
-			if ( !typesPolyCompatible( lrets[i], rrets[i] ) ) return false;
-		}
-		return true;
-	} else if ( type_index(typeid(ast::StructInstType)) == lid ) {
-		ast::StructInstType const * l = as<ast::StructInstType>(lhs);
-		ast::StructInstType const * r = as<ast::StructInstType>(rhs);
-
-		if ( l->name != r->name ) return false;
-		return paramListsPolyCompatible( l->params, r->params );
-	} else if ( type_index(typeid(ast::UnionInstType)) == lid ) {
-		ast::UnionInstType const * l = as<ast::UnionInstType>(lhs);
-		ast::UnionInstType const * r = as<ast::UnionInstType>(rhs);
-
-		if ( l->name != r->name ) return false;
-		return paramListsPolyCompatible( l->params, r->params );
-	} else if ( type_index(typeid(ast::EnumInstType)) == lid ) {
-		ast::EnumInstType const * l = as<ast::EnumInstType>(lhs);
-		ast::EnumInstType const * r = as<ast::EnumInstType>(rhs);
-
-		return l->name == r->name;
-	} else if ( type_index(typeid(ast::TraitInstType)) == lid ) {
-		ast::TraitInstType const * l = as<ast::TraitInstType>(lhs);
-		ast::TraitInstType const * r = as<ast::TraitInstType>(rhs);
-
-		return l->name == r->name;
-	} else if ( type_index(typeid(ast::TupleType)) == lid ) {
-		ast::TupleType const * l = as<ast::TupleType>(lhs);
-		ast::TupleType const * r = as<ast::TupleType>(rhs);
-
-		std::vector<ast::ptr<ast::Type>> ltypes, rtypes;
-		flattenList( l->types, ( ltypes ) );
-		flattenList( r->types, ( rtypes ) );
-		if ( ltypes.size() != rtypes.size() ) return false;
-
-		for ( unsigned i = 0 ; i < ltypes.size() ; ++i ) {
-			if ( !typesPolyCompatible( ltypes[i], rtypes[i] ) ) return false;
-		}
-		return true;
-	// The remaining types (VoidType, VarArgsType, ZeroType & OneType)
-	// have no variation so will always be equal.
-	} else {
-		return true;
-	}
-}
-
-bool needsBoxing( const ast::Type * param, const ast::Type * arg,
-		const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) {
-	// Don't need to box if the parameter is not polymorphic.
-	if ( !isPolyType( param, typeVars ) ) return false;
-
-	ast::ptr<ast::Type> newType = arg;
-	if ( subst ) {
-		int count = subst->apply( newType );
-		(void)count;
-	}
-	// Only need to box if the argument is not also polymorphic.
-	return !isPolyType( newType );
-}
-
-bool needsBoxing(
-		const ast::Type * param, const ast::Type * arg,
-		const ast::ApplicationExpr * expr,
-		const ast::TypeSubstitution * subst ) {
-	const ast::FunctionType * function = getFunctionType( expr->func->result );
-	assertf( function, "ApplicationExpr has non-function type: %s", toCString( expr->func->result ) );
-	TypeVarMap exprTyVars;
-	makeTypeVarMap( function, exprTyVars );
-	return needsBoxing( param, arg, exprTyVars, subst );
-}
-
-void addToTypeVarMap( const ast::TypeDecl * decl, TypeVarMap & typeVars ) {
-	typeVars.insert( ast::TypeEnvKey( decl, 0, 0 ), ast::TypeData( decl ) );
-}
-
-void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars ) {
-	typeVars.insert( ast::TypeEnvKey( *type ), ast::TypeData( type->base ) );
-}
-
-void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars ) {
-	if ( auto func = dynamic_cast<ast::FunctionType const *>( type ) ) {
-		for ( auto & typeVar : func->forall ) {
-			assert( typeVar );
-			addToTypeVarMap( typeVar, typeVars );
-		}
-	}
-	if ( auto pointer = dynamic_cast<ast::PointerType const *>( type ) ) {
-		makeTypeVarMap( pointer->base, typeVars );
-	}
-}
-
-void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars ) {
-	for ( auto & typeDecl : decl->type_params ) {
-		addToTypeVarMap( typeDecl, typeVars );
-	}
-}
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/GenPoly.cpp
===================================================================
--- src/GenPoly/GenPoly.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/GenPoly.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,414 @@
+//
+// 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.
+//
+// GenPoly.cpp -- General GenPoly utilities.
+//
+// Author           : Richard C. Bilson
+// Created On       : Mon May 18 07:44:20 2015
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Oct 24 15:19:00 2022
+// Update Count     : 17
+//
+
+#include "GenPoly.hpp"
+
+#include <cassert>                        // for assertf, assert
+#include <iostream>                       // for operator<<, ostream, basic_...
+#include <iterator>                       // for back_insert_iterator, back_...
+#include <list>                           // for list, _List_iterator, list<...
+#include <typeindex>                      // for type_index
+#include <utility>                        // for pair
+#include <vector>                         // for vector
+
+#include "AST/Expr.hpp"
+#include "AST/Type.hpp"
+#include "AST/TypeSubstitution.hpp"
+#include "GenPoly/ErasableScopedMap.hpp"  // for ErasableScopedMap<>::const_...
+#include "ResolvExpr/Typeops.hpp"         // for flatten
+
+using namespace std;
+
+namespace GenPoly {
+
+namespace {
+	/// Checks a parameter list for polymorphic parameters; will substitute according to env if present.
+	bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const ast::TypeSubstitution * env ) {
+		for ( auto & param : params ) {
+			auto paramType = param.as<ast::TypeExpr>();
+			assertf( paramType, "Aggregate parameters should be type expressions" );
+			if ( isPolyType( paramType->type, env ) ) return true;
+		}
+		return false;
+	}
+
+	/// Checks a parameter list for polymorphic parameters from typeVars; will substitute according to env if present.
+	bool hasPolyParams( const std::vector<ast::ptr<ast::Expr>> & params, const TypeVarMap & typeVars, const ast::TypeSubstitution * env ) {
+		for ( auto & param : params ) {
+			auto paramType = param.as<ast::TypeExpr>();
+			assertf( paramType, "Aggregate parameters should be type expressions" );
+			if ( isPolyType( paramType->type, typeVars, env ) ) return true;
+		}
+		return false;
+	}
+
+	/// Checks a parameter list for dynamic-layout parameters from tyVars; will substitute according to env if present.
+	bool hasDynParams(
+			const std::vector<ast::ptr<ast::Expr>> & params,
+			const TypeVarMap & typeVars,
+			const ast::TypeSubstitution * subst ) {
+		for ( ast::ptr<ast::Expr> const & paramExpr : params ) {
+			auto param = paramExpr.as<ast::TypeExpr>();
+			assertf( param, "Aggregate parameters should be type expressions." );
+			if ( isDynType( param->type.get(), typeVars, subst ) ) {
+				return true;
+			}
+		}
+		return false;
+	}
+} // namespace
+
+const ast::Type * replaceTypeInst( const ast::Type * type, const ast::TypeSubstitution * env ) {
+	if ( !env ) return type;
+	if ( auto typeInst = dynamic_cast<const ast::TypeInstType*>( type ) ) {
+		if ( auto newType = env->lookup( typeInst ) ) return newType;
+	}
+	return type;
+}
+
+const ast::Type * isPolyType( const ast::Type * type, const ast::TypeSubstitution * subst ) {
+	type = replaceTypeInst( type, subst );
+
+	if ( dynamic_cast< const ast::TypeInstType * >( type ) ) {
+		// This case is where the two variants of isPolyType differ.
+		return type;
+	} else if ( auto arrayType = dynamic_cast< const ast::ArrayType * >( type ) ) {
+		return isPolyType( arrayType->base, subst );
+	} else if ( auto structType = dynamic_cast< const ast::StructInstType* >( type ) ) {
+		if ( hasPolyParams( structType->params, subst ) ) return type;
+	} else if ( auto unionType = dynamic_cast< const ast::UnionInstType* >( type ) ) {
+		if ( hasPolyParams( unionType->params, subst ) ) return type;
+	}
+	return nullptr;
+}
+
+const ast::Type * isPolyType( const ast::Type * type,
+		const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) {
+	type = replaceTypeInst( type, subst );
+
+	if ( auto inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
+		if ( typeVars.contains( *inst ) ) return type;
+	} else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) {
+		return isPolyType( array->base, typeVars, subst );
+	} else if ( auto sue = dynamic_cast< const ast::StructInstType * >( type ) ) {
+		if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
+	} else if ( auto sue = dynamic_cast< const ast::UnionInstType * >( type ) ) {
+		if ( hasPolyParams( sue->params, typeVars, subst ) ) return type;
+	}
+	return nullptr;
+}
+
+const ast::BaseInstType * isDynType(
+		const ast::Type * type, const TypeVarMap & typeVars,
+		const ast::TypeSubstitution * subst ) {
+	type = replaceTypeInst( type, subst );
+
+	if ( auto inst = dynamic_cast<ast::TypeInstType const *>( type ) ) {
+		auto var = typeVars.find( *inst );
+		if ( var != typeVars.end() && var->second.isComplete ) {
+			return inst;
+		}
+	} else if ( auto inst = dynamic_cast<ast::StructInstType const *>( type ) ) {
+		if ( hasDynParams( inst->params, typeVars, subst ) ) return inst;
+	} else if ( auto inst = dynamic_cast<ast::UnionInstType const *>( type ) ) {
+		if ( hasDynParams( inst->params, typeVars, subst ) ) return inst;
+	}
+	return nullptr;
+}
+
+const ast::BaseInstType *isDynRet(
+		const ast::FunctionType * type, const TypeVarMap & typeVars ) {
+	if ( type->returns.empty() ) return nullptr;
+
+	return isDynType( type->returns.front(), typeVars );
+}
+
+const ast::BaseInstType *isDynRet( const ast::FunctionType * func ) {
+	if ( func->returns.empty() ) return nullptr;
+
+	TypeVarMap forallTypes;
+	makeTypeVarMap( func, forallTypes );
+	return isDynType( func->returns.front(), forallTypes );
+}
+
+bool needsAdapter(
+		ast::FunctionType const * adaptee, const TypeVarMap & typeVars ) {
+	if ( isDynRet( adaptee, typeVars ) ) return true;
+
+	for ( auto param : adaptee->params ) {
+		if ( isDynType( param, typeVars ) ) {
+			return true;
+		}
+	}
+	return false;
+}
+
+const ast::Type * isPolyPtr(
+		const ast::Type * type, const TypeVarMap & typeVars,
+		const ast::TypeSubstitution * typeSubs ) {
+	type = replaceTypeInst( type, typeSubs );
+
+	if ( auto * ptr = dynamic_cast<ast::PointerType const *>( type ) ) {
+		return isPolyType( ptr->base, typeVars, typeSubs );
+	}
+	return nullptr;
+}
+
+ast::Type const * hasPolyBase(
+		ast::Type const * type, const TypeVarMap & typeVars,
+		int * levels, const ast::TypeSubstitution * subst ) {
+	int level_count = 0;
+
+	while ( true ) {
+		type = replaceTypeInst( type, subst );
+
+		if ( auto ptr = dynamic_cast<ast::PointerType const *>( type ) ) {
+			type = ptr->base;
+			++level_count;
+		} else {
+			break;
+		}
+	}
+
+	if ( nullptr != levels ) { *levels = level_count; }
+	return isPolyType( type, typeVars, subst );
+}
+
+const ast::FunctionType * getFunctionType( const ast::Type * ty ) {
+	if ( auto pty = dynamic_cast< const ast::PointerType * >( ty ) ) {
+		return pty->base.as< ast::FunctionType >();
+	} else {
+		return dynamic_cast< const ast::FunctionType * >( ty );
+	}
+}
+
+namespace {
+	/// Checks if is a pointer to D
+	template<typename D, typename B>
+	bool is( const B* p ) { return type_index{typeid(D)} == type_index{typeid(*p)}; }
+
+	/// Converts to a pointer to D without checking for safety
+	template<typename D, typename B>
+	inline D* as( B* p ) { return reinterpret_cast<D*>(p); }
+
+	template<typename D, typename B>
+	inline D const * as( B const * p ) {
+		return reinterpret_cast<D const *>( p );
+	}
+
+	/// Flattens a list of types.
+	void flattenList( vector<ast::ptr<ast::Type>> const & src,
+			vector<ast::ptr<ast::Type>> & out ) {
+		for ( auto const & type : src ) {
+			ResolvExpr::flatten( type, out );
+		}
+	}
+
+	bool paramListsPolyCompatible(
+			std::vector<ast::ptr<ast::Expr>> const & lparams,
+			std::vector<ast::ptr<ast::Expr>> const & rparams ) {
+		if ( lparams.size() != rparams.size() ) {
+			return false;
+		}
+
+		for ( auto lparam = lparams.begin(), rparam = rparams.begin() ;
+				lparam != lparams.end() ; ++lparam, ++rparam ) {
+			ast::TypeExpr const * lexpr = lparam->as<ast::TypeExpr>();
+			assertf( lexpr, "Aggregate parameters should be type expressions" );
+			ast::TypeExpr const * rexpr = rparam->as<ast::TypeExpr>();
+			assertf( rexpr, "Aggregate parameters should be type expressions" );
+
+			// xxx - might need to let VoidType be a wildcard here too; could have some voids
+			// stuffed in for dtype-statics.
+			// if ( is<VoidType>( lexpr->type() ) || is<VoidType>( bparam->get_type() ) ) continue;
+			if ( !typesPolyCompatible( lexpr->type, rexpr->type ) ) {
+				return false;
+			}
+		}
+
+		return true;
+	}
+} // namespace
+
+bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs ) {
+	type_index const lid = typeid(*lhs);
+
+	// Polymorphic types always match:
+	if ( type_index(typeid(ast::TypeInstType)) == lid ) return true;
+
+	type_index const rid = typeid(*rhs);
+	if ( type_index(typeid(ast::TypeInstType)) == rid ) return true;
+
+	// All other types only match if they are the same type:
+	if ( lid != rid ) return false;
+
+	// So remaining types can be examined case by case.
+	// Recurse through type structure (conditions borrowed from Unify.cc).
+
+	if ( type_index(typeid(ast::BasicType)) == lid ) {
+		return as<ast::BasicType>(lhs)->kind == as<ast::BasicType>(rhs)->kind;
+	} else if ( type_index(typeid(ast::PointerType)) == lid ) {
+		ast::PointerType const * l = as<ast::PointerType>(lhs);
+		ast::PointerType const * r = as<ast::PointerType>(rhs);
+
+		// void pointers should match any other pointer type.
+		return is<ast::VoidType>( l->base.get() )
+			|| is<ast::VoidType>( r->base.get() )
+			|| typesPolyCompatible( l->base.get(), r->base.get() );
+	} else if ( type_index(typeid(ast::ReferenceType)) == lid ) {
+		ast::ReferenceType const * l = as<ast::ReferenceType>(lhs);
+		ast::ReferenceType const * r = as<ast::ReferenceType>(rhs);
+
+		// void references should match any other reference type.
+		return is<ast::VoidType>( l->base.get() )
+			|| is<ast::VoidType>( r->base.get() )
+			|| typesPolyCompatible( l->base.get(), r->base.get() );
+	} else if ( type_index(typeid(ast::ArrayType)) == lid ) {
+		ast::ArrayType const * l = as<ast::ArrayType>(lhs);
+		ast::ArrayType const * r = as<ast::ArrayType>(rhs);
+
+		if ( l->isVarLen ) {
+			if ( !r->isVarLen ) return false;
+		} else {
+			if ( r->isVarLen ) return false;
+
+			auto lc = l->dimension.as<ast::ConstantExpr>();
+			auto rc = r->dimension.as<ast::ConstantExpr>();
+			if ( lc && rc && lc->intValue() != rc->intValue() ) {
+				return false;
+			}
+		}
+
+		return typesPolyCompatible( l->base.get(), r->base.get() );
+	} else if ( type_index(typeid(ast::FunctionType)) == lid ) {
+		ast::FunctionType const * l = as<ast::FunctionType>(lhs);
+		ast::FunctionType const * r = as<ast::FunctionType>(rhs);
+
+		std::vector<ast::ptr<ast::Type>> lparams, rparams;
+		flattenList( l->params, lparams );
+		flattenList( r->params, rparams );
+		if ( lparams.size() != rparams.size() ) return false;
+		for ( unsigned i = 0; i < lparams.size(); ++i ) {
+			if ( !typesPolyCompatible( lparams[i], rparams[i] ) ) return false;
+		}
+
+		std::vector<ast::ptr<ast::Type>> lrets, rrets;
+		flattenList( l->returns, lrets );
+		flattenList( r->returns, rrets );
+		if ( lrets.size() != rrets.size() ) return false;
+		for ( unsigned i = 0; i < lrets.size(); ++i ) {
+			if ( !typesPolyCompatible( lrets[i], rrets[i] ) ) return false;
+		}
+		return true;
+	} else if ( type_index(typeid(ast::StructInstType)) == lid ) {
+		ast::StructInstType const * l = as<ast::StructInstType>(lhs);
+		ast::StructInstType const * r = as<ast::StructInstType>(rhs);
+
+		if ( l->name != r->name ) return false;
+		return paramListsPolyCompatible( l->params, r->params );
+	} else if ( type_index(typeid(ast::UnionInstType)) == lid ) {
+		ast::UnionInstType const * l = as<ast::UnionInstType>(lhs);
+		ast::UnionInstType const * r = as<ast::UnionInstType>(rhs);
+
+		if ( l->name != r->name ) return false;
+		return paramListsPolyCompatible( l->params, r->params );
+	} else if ( type_index(typeid(ast::EnumInstType)) == lid ) {
+		ast::EnumInstType const * l = as<ast::EnumInstType>(lhs);
+		ast::EnumInstType const * r = as<ast::EnumInstType>(rhs);
+
+		return l->name == r->name;
+	} else if ( type_index(typeid(ast::TraitInstType)) == lid ) {
+		ast::TraitInstType const * l = as<ast::TraitInstType>(lhs);
+		ast::TraitInstType const * r = as<ast::TraitInstType>(rhs);
+
+		return l->name == r->name;
+	} else if ( type_index(typeid(ast::TupleType)) == lid ) {
+		ast::TupleType const * l = as<ast::TupleType>(lhs);
+		ast::TupleType const * r = as<ast::TupleType>(rhs);
+
+		std::vector<ast::ptr<ast::Type>> ltypes, rtypes;
+		flattenList( l->types, ( ltypes ) );
+		flattenList( r->types, ( rtypes ) );
+		if ( ltypes.size() != rtypes.size() ) return false;
+
+		for ( unsigned i = 0 ; i < ltypes.size() ; ++i ) {
+			if ( !typesPolyCompatible( ltypes[i], rtypes[i] ) ) return false;
+		}
+		return true;
+	// The remaining types (VoidType, VarArgsType, ZeroType & OneType)
+	// have no variation so will always be equal.
+	} else {
+		return true;
+	}
+}
+
+bool needsBoxing( const ast::Type * param, const ast::Type * arg,
+		const TypeVarMap & typeVars, const ast::TypeSubstitution * subst ) {
+	// Don't need to box if the parameter is not polymorphic.
+	if ( !isPolyType( param, typeVars ) ) return false;
+
+	ast::ptr<ast::Type> newType = arg;
+	if ( subst ) {
+		int count = subst->apply( newType );
+		(void)count;
+	}
+	// Only need to box if the argument is not also polymorphic.
+	return !isPolyType( newType );
+}
+
+bool needsBoxing(
+		const ast::Type * param, const ast::Type * arg,
+		const ast::ApplicationExpr * expr,
+		const ast::TypeSubstitution * subst ) {
+	const ast::FunctionType * function = getFunctionType( expr->func->result );
+	assertf( function, "ApplicationExpr has non-function type: %s", toCString( expr->func->result ) );
+	TypeVarMap exprTyVars;
+	makeTypeVarMap( function, exprTyVars );
+	return needsBoxing( param, arg, exprTyVars, subst );
+}
+
+void addToTypeVarMap( const ast::TypeDecl * decl, TypeVarMap & typeVars ) {
+	typeVars.insert( ast::TypeEnvKey( decl, 0, 0 ), ast::TypeData( decl ) );
+}
+
+void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars ) {
+	typeVars.insert( ast::TypeEnvKey( *type ), ast::TypeData( type->base ) );
+}
+
+void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars ) {
+	if ( auto func = dynamic_cast<ast::FunctionType const *>( type ) ) {
+		for ( auto & typeVar : func->forall ) {
+			assert( typeVar );
+			addToTypeVarMap( typeVar, typeVars );
+		}
+	}
+	if ( auto pointer = dynamic_cast<ast::PointerType const *>( type ) ) {
+		makeTypeVarMap( pointer->base, typeVars );
+	}
+}
+
+void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars ) {
+	for ( auto & typeDecl : decl->type_params ) {
+		addToTypeVarMap( typeDecl, typeVars );
+	}
+}
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/GenPoly.h
===================================================================
--- src/GenPoly/GenPoly.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,104 +1,0 @@
-//
-// 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.
-//
-// GenPoly.h -- General GenPoly utilities.
-//
-// Author           : Richard C. Bilson
-// Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Mon Oct 24 15:18:00 2022
-// Update Count     : 11
-//
-
-#pragma once
-
-#include <iostream>               // for ostream
-#include <string>                 // for string, allocator, operator+, basic...
-
-#include "ErasableScopedMap.h"    // for ErasableScopedMap
-#include "AST/Decl.hpp"           // for AggregateDecl
-#include "AST/Fwd.hpp"            // for ApplicationExpr, BaseInstType, Func...
-#include "SymTab/Mangler.h"       // for Mangler
-
-namespace ast {
-	struct TypeEnvKey;
-}
-
-namespace GenPoly {
-
-struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> {
-	TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {}
-};
-
-/// Replaces a TypeInstType by its referrent in the environment, if applicable.
-const ast::Type * replaceTypeInst( const ast::Type *, const ast::TypeSubstitution * );
-
-/// Returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided.
-const ast::Type * isPolyType( const ast::Type * type, const ast::TypeSubstitution * subst = nullptr );
-
-/// Returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided.
-const ast::Type * isPolyType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = nullptr );
-
-/// Returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided.
-const ast::BaseInstType *isDynType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = 0 );
-
-/// Returns true iff function has dynamic-layout return type under the given type variable map.
-const ast::BaseInstType *isDynRet( const ast::FunctionType * type, const TypeVarMap & typeVars );
-
-/// Returns true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters.
-const ast::BaseInstType *isDynRet( const ast::FunctionType * func );
-
-/// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type.
-bool needsAdapter( ast::FunctionType const * adaptee, const TypeVarMap & typeVars );
-
-/// Returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided.
-const ast::Type * isPolyPtr( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * env = 0 );
-
-/// If the base type (after dereferencing N >= 0 pointers) is a polymorphic type in tyVars, returns the base type, NULL otherwise;
-/// N will be stored in levels, if provided, will look up substitution in env if provided.
-const ast::Type * hasPolyBase( const ast::Type * type, const TypeVarMap & typeVars, int * levels = 0, const ast::TypeSubstitution * env = 0 );
-
-/// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise.
-const ast::FunctionType * getFunctionType( const ast::Type * ty );
-
-/// Returns true iff types are structurally identical, where TypeInstType's match any type.
-bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs );
-
-/// Returns true if arg requires boxing given typeVars.
-bool needsBoxing( const ast::Type * param, const ast::Type * arg, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst );
-
-/// Returns true if arg requires boxing in the call to appExpr.
-bool needsBoxing( const ast::Type * param, const ast::Type * arg, const ast::ApplicationExpr * expr, const ast::TypeSubstitution * subst );
-
-/// Adds the type variable `type` to `typeVars`.
-void addToTypeVarMap( const ast::TypeDecl * type, TypeVarMap & typeVars );
-void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars );
-
-/// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `typeVars`.
-void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars );
-void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars );
-
-/// Gets the name of the sizeof parameter for the type, given its mangled name.
-inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
-
-/// Gets the name of the alignof parameter for the type, given its mangled name.
-inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
-
-/// Gets the name of the offsetof parameter for the type, given its mangled name.
-inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
-
-/// Gets the name of the layout function for a given aggregate type, given its declaration.
-inline std::string layoutofName( ast::AggregateDecl const * decl ) {
-	return std::string( "_layoutof_" ) + decl->name;
-}
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/GenPoly.hpp
===================================================================
--- src/GenPoly/GenPoly.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/GenPoly.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,104 @@
+//
+// 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.
+//
+// GenPoly.hpp -- General GenPoly utilities.
+//
+// Author           : Richard C. Bilson
+// Created On       : Mon May 18 07:44:20 2015
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Oct 24 15:18:00 2022
+// Update Count     : 11
+//
+
+#pragma once
+
+#include <iostream>               // for ostream
+#include <string>                 // for string, allocator, operator+, basic...
+
+#include "ErasableScopedMap.hpp"  // for ErasableScopedMap
+#include "AST/Decl.hpp"           // for AggregateDecl
+#include "AST/Fwd.hpp"            // for ApplicationExpr, BaseInstType, Func...
+#include "SymTab/Mangler.hpp"     // for Mangler
+
+namespace ast {
+	struct TypeEnvKey;
+}
+
+namespace GenPoly {
+
+struct TypeVarMap : public ErasableScopedMap<ast::TypeEnvKey, ast::TypeData> {
+	TypeVarMap() : ErasableScopedMap( ast::TypeData() ) {}
+};
+
+/// Replaces a TypeInstType by its referrent in the environment, if applicable.
+const ast::Type * replaceTypeInst( const ast::Type *, const ast::TypeSubstitution * );
+
+/// Returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided.
+const ast::Type * isPolyType( const ast::Type * type, const ast::TypeSubstitution * subst = nullptr );
+
+/// Returns polymorphic type if is polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided.
+const ast::Type * isPolyType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = nullptr );
+
+/// Returns dynamic-layout type if is dynamic-layout type in tyVars, NULL otherwise; will look up substitution in env if provided.
+const ast::BaseInstType *isDynType( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst = 0 );
+
+/// Returns true iff function has dynamic-layout return type under the given type variable map.
+const ast::BaseInstType *isDynRet( const ast::FunctionType * type, const TypeVarMap & typeVars );
+
+/// Returns true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters.
+const ast::BaseInstType *isDynRet( const ast::FunctionType * func );
+
+/// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type.
+bool needsAdapter( ast::FunctionType const * adaptee, const TypeVarMap & typeVars );
+
+/// Returns polymorphic type if is pointer to polymorphic type in tyVars, NULL otherwise; will look up substitution in env if provided.
+const ast::Type * isPolyPtr( const ast::Type * type, const TypeVarMap & typeVars, const ast::TypeSubstitution * env = 0 );
+
+/// If the base type (after dereferencing N >= 0 pointers) is a polymorphic type in tyVars, returns the base type, NULL otherwise;
+/// N will be stored in levels, if provided, will look up substitution in env if provided.
+const ast::Type * hasPolyBase( const ast::Type * type, const TypeVarMap & typeVars, int * levels = 0, const ast::TypeSubstitution * env = 0 );
+
+/// Returns a pointer to the base FunctionType if ty is the type of a function (or pointer to one), NULL otherwise.
+const ast::FunctionType * getFunctionType( const ast::Type * ty );
+
+/// Returns true iff types are structurally identical, where TypeInstType's match any type.
+bool typesPolyCompatible( ast::Type const * lhs, ast::Type const * rhs );
+
+/// Returns true if arg requires boxing given typeVars.
+bool needsBoxing( const ast::Type * param, const ast::Type * arg, const TypeVarMap & typeVars, const ast::TypeSubstitution * subst );
+
+/// Returns true if arg requires boxing in the call to appExpr.
+bool needsBoxing( const ast::Type * param, const ast::Type * arg, const ast::ApplicationExpr * expr, const ast::TypeSubstitution * subst );
+
+/// Adds the type variable `type` to `typeVars`.
+void addToTypeVarMap( const ast::TypeDecl * type, TypeVarMap & typeVars );
+void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars );
+
+/// Adds the declarations in the forall list of type (and its pointed-to type if it's a pointer type) to `typeVars`.
+void makeTypeVarMap( const ast::Type * type, TypeVarMap & typeVars );
+void makeTypeVarMap( const ast::FunctionDecl * decl, TypeVarMap & typeVars );
+
+/// Gets the name of the sizeof parameter for the type, given its mangled name.
+inline std::string sizeofName( const std::string &name ) { return std::string( "_sizeof_" ) + name; }
+
+/// Gets the name of the alignof parameter for the type, given its mangled name.
+inline std::string alignofName( const std::string &name ) { return std::string( "_alignof_" ) + name; }
+
+/// Gets the name of the offsetof parameter for the type, given its mangled name.
+inline std::string offsetofName( const std::string &name ) { return std::string( "_offsetof_" ) + name; }
+
+/// Gets the name of the layout function for a given aggregate type, given its declaration.
+inline std::string layoutofName( ast::AggregateDecl const * decl ) {
+	return std::string( "_layoutof_" ) + decl->name;
+}
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/InstantiateGeneric.cpp
===================================================================
--- src/GenPoly/InstantiateGeneric.cpp	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ src/GenPoly/InstantiateGeneric.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -14,5 +14,5 @@
 //
 
-#include "InstantiateGeneric.h"
+#include "InstantiateGeneric.hpp"
 
 #include <cassert>                     // for assertf, assert
@@ -27,11 +27,11 @@
 #include "AST/TranslationUnit.hpp"     // for TranslationUnit
 #include "AST/Vector.hpp"              // for vector
-#include "CodeGen/OperatorTable.h"     // for isAssignment
-#include "Common/ScopedMap.h"          // for ScopedMap
-#include "Common/UniqueName.h"         // for UniqueName
-#include "GenPoly/GenPoly.h"           // for isPolyType, typesPolyCompatible
+#include "CodeGen/OperatorTable.hpp"   // for isAssignment
+#include "Common/ScopedMap.hpp"        // for ScopedMap
+#include "Common/UniqueName.hpp"       // for UniqueName
+#include "GenPoly/GenPoly.hpp"         // for isPolyType, typesPolyCompatible
 #include "GenPoly/ScrubTypeVars.hpp"   // for scrubAllTypeVars
 #include "ResolvExpr/AdjustExprType.hpp"  // for adjustExprType
-#include "ResolvExpr/Unify.h"          // for typesCompatible
+#include "ResolvExpr/Unify.hpp"        // for typesCompatible
 
 namespace GenPoly {
Index: src/GenPoly/InstantiateGeneric.h
===================================================================
--- src/GenPoly/InstantiateGeneric.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,36 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// InstantiateGeneric.h -- Create concrete instances of generic types.
-//
-// Author           : Aaron B. Moss
-// Created On       : Thu Aug 04 18:33:00 2016
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 22 09:22:42 2017
-// Update Count     : 2
-//
-
-#pragma once
-
-namespace ast {
-	class TranslationUnit;
-}
-
-namespace GenPoly {
-
-void instantiateGeneric( ast::TranslationUnit & translationUnit );
-/// Replaces all generic types that have static layout with concrete
-/// instantiations. Sized types are replaced with the concrete argument types
-/// while unsized types are erased to a void type.
-/// This pass can cause designators to ignore the pretty print option.
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/InstantiateGeneric.hpp
===================================================================
--- src/GenPoly/InstantiateGeneric.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/InstantiateGeneric.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,36 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// InstantiateGeneric.hpp -- Create concrete instances of generic types.
+//
+// Author           : Aaron B. Moss
+// Created On       : Thu Aug 04 18:33:00 2016
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Jul 22 09:22:42 2017
+// Update Count     : 2
+//
+
+#pragma once
+
+namespace ast {
+	class TranslationUnit;
+}
+
+namespace GenPoly {
+
+void instantiateGeneric( ast::TranslationUnit & translationUnit );
+/// Replaces all generic types that have static layout with concrete
+/// instantiations. Sized types are replaced with the concrete argument types
+/// while unsized types are erased to a void type.
+/// This pass can cause designators to ignore the pretty print option.
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/Lvalue.cpp
===================================================================
--- src/GenPoly/Lvalue.cpp	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ src/GenPoly/Lvalue.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -14,5 +14,5 @@
 //
 
-#include "Lvalue.h"
+#include "Lvalue.hpp"
 
 #include <set>
@@ -24,10 +24,10 @@
 #include "AST/LinkageSpec.hpp"         // for Linkage
 #include "AST/Pass.hpp"
-#include "Common/SemanticError.h"      // for SemanticWarning
+#include "Common/SemanticError.hpp"    // for SemanticWarning
 #include "Common/ToString.hpp"         // for toCString
-#include "Common/UniqueName.h"         // for UniqueName
-#include "GenPoly/GenPoly.h"           // for genFunctionType
-#include "ResolvExpr/typeops.h"        // for typesCompatible
-#include "ResolvExpr/Unify.h"          // for unify
+#include "Common/UniqueName.hpp"       // for UniqueName
+#include "GenPoly/GenPoly.hpp"         // for genFunctionType
+#include "ResolvExpr/Typeops.hpp"      // for typesCompatible
+#include "ResolvExpr/Unify.hpp"        // for unify
 
 #if 0
Index: src/GenPoly/Lvalue.h
===================================================================
--- src/GenPoly/Lvalue.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,40 +1,0 @@
-//
-// 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.
-//
-// Lvalue.h -- Clean up lvalues and remove references.
-//
-// Author           : Richard C. Bilson
-// Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Thu Sep 15 14:13:00 2022
-// Update Count     : 3
-//
-
-#pragma once
-
-namespace ast {
-	class Expr;
-	class TranslationUnit;
-}
-
-namespace GenPoly {
-
-/// Replaces return type of `T&` with `T*`, along with appropriate address-of and dereference operators.
-void convertLvalue( ast::TranslationUnit & translationUnit );
-
-/// Returns true until reference types have been eliminated from the source code. After this point, reference types should not be added to the AST.
-bool referencesPermissable();
-
-/// Applies transformations that allow GCC to accept more complicated lvalue expressions, e.g. &(a, b).
-ast::Expr const * generalizedLvalue( ast::Expr const * expr );
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/Lvalue.hpp
===================================================================
--- src/GenPoly/Lvalue.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/Lvalue.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,40 @@
+//
+// 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.
+//
+// Lvalue.h -- Clean up lvalues and remove references.
+//
+// Author           : Richard C. Bilson
+// Created On       : Mon May 18 07:44:20 2015
+// Last Modified By : Andrew Beach
+// Last Modified On : Thu Sep 15 14:13:00 2022
+// Update Count     : 3
+//
+
+#pragma once
+
+namespace ast {
+	class Expr;
+	class TranslationUnit;
+}
+
+namespace GenPoly {
+
+/// Replaces return type of `T&` with `T*`, along with appropriate address-of and dereference operators.
+void convertLvalue( ast::TranslationUnit & translationUnit );
+
+/// Returns true until reference types have been eliminated from the source code. After this point, reference types should not be added to the AST.
+bool referencesPermissable();
+
+/// Applies transformations that allow GCC to accept more complicated lvalue expressions, e.g. &(a, b).
+ast::Expr const * generalizedLvalue( ast::Expr const * expr );
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/Lvalue2.cc
===================================================================
--- src/GenPoly/Lvalue2.cc	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,25 +1,0 @@
-//
-// 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.
-//
-// Lvalue2.cc -- Seperate Lvalue module for linking.
-//
-// Author           : Andrew Beach
-// Created On       : Mon May 16 14:05:00 2022
-// Last Modified By : Andrew Beach
-// Last Modified On : Mon May 16 14:05:00 2022
-// Update Count     : 0
-//
-
-namespace GenPoly {
-
-bool referencesEliminated = false;
-
-/// Are reference types still allowed in the AST?
-bool referencesPermissable() {
-	return !referencesEliminated;
-}
-
-}
Index: src/GenPoly/Lvalue2.cpp
===================================================================
--- src/GenPoly/Lvalue2.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/Lvalue2.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,25 @@
+//
+// 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.
+//
+// Lvalue2.cc -- Seperate Lvalue module for linking.
+//
+// Author           : Andrew Beach
+// Created On       : Mon May 16 14:05:00 2022
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon May 16 14:05:00 2022
+// Update Count     : 0
+//
+
+namespace GenPoly {
+
+bool referencesEliminated = false;
+
+/// Are reference types still allowed in the AST?
+bool referencesPermissable() {
+	return !referencesEliminated;
+}
+
+}
Index: src/GenPoly/ScopedSet.h
===================================================================
--- src/GenPoly/ScopedSet.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,265 +1,0 @@
-//
-// 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 -- A set that supports save/restore scoping.
-//
-// Author           : Aaron B. Moss
-// Created On       : Thu Dec 3 11:51:00 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 22 09:22:17 2017
-// Update Count     : 2
-//
-
-#pragma once
-
-#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;
-
-	/// Scoped list of sets.
-	ScopeList scopes;
-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;
-
-	// Both iterator types are complete bidirectional iterators, see below.
-	class iterator;
-	class const_iterator;
-
-	/// Starts a new scope
-	void beginScope() {
-		scopes.emplace_back();
-	}
-
-	/// 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).next_valid(); }
-	const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
-	const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
-	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 );
-	}
-
-	bool contains( const Value & key ) const {
-		return find( key ) != cend();
-	}
-};
-
-template<typename Value>
-class ScopedSet<Value>::iterator :
-		public std::iterator< std::bidirectional_iterator_tag, value_type > {
-	friend class ScopedSet;
-	friend class const_iterator;
-	typedef typename Scope::iterator wrapped_iterator;
-	typedef typename ScopeList::size_type size_type;
-
-	/// Checks if this iterator points to a valid item
-	bool is_valid() const {
-		return it != (*scopes)[i].end();
-	}
-
-	/// Increments on invalid
-	iterator& next_valid() {
-		if ( ! is_valid() ) { ++(*this); }
-		return *this;
-	}
-
-	/// Decrements on invalid
-	iterator& prev_valid() {
-		if ( ! is_valid() ) { --(*this); }
-		return *this;
-	}
-
-	iterator(ScopeList 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();
-		} else {
-			++it;
-		}
-		return next_valid();
-	}
-	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 prev_valid();
-	}
-	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 ); }
-
-	size_type get_level() const { return i; }
-
-private:
-	ScopeList const *scopes;
-	wrapped_iterator it;
-	size_type i;
-};
-
-template<typename Value>
-class ScopedSet<Value>::const_iterator :
-		public std::iterator< std::bidirectional_iterator_tag, value_type > {
-	friend class ScopedSet;
-	typedef typename Scope::iterator wrapped_iterator;
-	typedef typename Scope::const_iterator wrapped_const_iterator;
-	typedef typename ScopeList::size_type size_type;
-
-	/// Checks if this iterator points to a valid item
-	bool is_valid() const {
-		return it != (*scopes)[i].end();
-	}
-
-	/// Increments on invalid
-	const_iterator& next_valid() {
-		if ( ! is_valid() ) { ++(*this); }
-		return *this;
-	}
-
-	/// Decrements on invalid
-	const_iterator& prev_valid() {
-		if ( ! is_valid() ) { --(*this); }
-		return *this;
-	}
-
-	const_iterator(ScopeList 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();
-		} else {
-			++it;
-		}
-		return next_valid();
-	}
-	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 prev_valid();
-	}
-	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 ); }
-
-	size_type get_level() const { return i; }
-
-private:
-	ScopeList const *scopes;
-	wrapped_const_iterator it;
-	size_type i;
-};
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/ScopedSet.hpp
===================================================================
--- src/GenPoly/ScopedSet.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/ScopedSet.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,265 @@
+//
+// 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 -- A set that supports save/restore scoping.
+//
+// Author           : Aaron B. Moss
+// Created On       : Thu Dec 3 11:51:00 2015
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Jul 22 09:22:17 2017
+// Update Count     : 2
+//
+
+#pragma once
+
+#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;
+
+	/// Scoped list of sets.
+	ScopeList scopes;
+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;
+
+	// Both iterator types are complete bidirectional iterators, see below.
+	class iterator;
+	class const_iterator;
+
+	/// Starts a new scope
+	void beginScope() {
+		scopes.emplace_back();
+	}
+
+	/// 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).next_valid(); }
+	const_iterator begin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
+	const_iterator cbegin() const { return const_iterator(scopes, scopes.back().begin(), scopes.size()-1).next_valid(); }
+	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 );
+	}
+
+	bool contains( const Value & key ) const {
+		return find( key ) != cend();
+	}
+};
+
+template<typename Value>
+class ScopedSet<Value>::iterator :
+		public std::iterator< std::bidirectional_iterator_tag, value_type > {
+	friend class ScopedSet;
+	friend class const_iterator;
+	typedef typename Scope::iterator wrapped_iterator;
+	typedef typename ScopeList::size_type size_type;
+
+	/// Checks if this iterator points to a valid item
+	bool is_valid() const {
+		return it != (*scopes)[i].end();
+	}
+
+	/// Increments on invalid
+	iterator& next_valid() {
+		if ( ! is_valid() ) { ++(*this); }
+		return *this;
+	}
+
+	/// Decrements on invalid
+	iterator& prev_valid() {
+		if ( ! is_valid() ) { --(*this); }
+		return *this;
+	}
+
+	iterator(ScopeList 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();
+		} else {
+			++it;
+		}
+		return next_valid();
+	}
+	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 prev_valid();
+	}
+	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 ); }
+
+	size_type get_level() const { return i; }
+
+private:
+	ScopeList const *scopes;
+	wrapped_iterator it;
+	size_type i;
+};
+
+template<typename Value>
+class ScopedSet<Value>::const_iterator :
+		public std::iterator< std::bidirectional_iterator_tag, value_type > {
+	friend class ScopedSet;
+	typedef typename Scope::iterator wrapped_iterator;
+	typedef typename Scope::const_iterator wrapped_const_iterator;
+	typedef typename ScopeList::size_type size_type;
+
+	/// Checks if this iterator points to a valid item
+	bool is_valid() const {
+		return it != (*scopes)[i].end();
+	}
+
+	/// Increments on invalid
+	const_iterator& next_valid() {
+		if ( ! is_valid() ) { ++(*this); }
+		return *this;
+	}
+
+	/// Decrements on invalid
+	const_iterator& prev_valid() {
+		if ( ! is_valid() ) { --(*this); }
+		return *this;
+	}
+
+	const_iterator(ScopeList 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();
+		} else {
+			++it;
+		}
+		return next_valid();
+	}
+	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 prev_valid();
+	}
+	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 ); }
+
+	size_type get_level() const { return i; }
+
+private:
+	ScopeList const *scopes;
+	wrapped_const_iterator it;
+	size_type i;
+};
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/ScrubTypeVars.cpp
===================================================================
--- src/GenPoly/ScrubTypeVars.cpp	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ src/GenPoly/ScrubTypeVars.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -16,10 +16,10 @@
 #include "ScrubTypeVars.hpp"
 
-#include <utility>                      // for pair
+#include <utility>                        // for pair
 
 #include "AST/Pass.hpp"
-#include "GenPoly.h"                    // for mangleType, TyVarMap, alignof...
-#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it...
-#include "SymTab/Mangler.h"             // for mangleType
+#include "GenPoly.hpp"                    // for mangleType, TyVarMap, align...
+#include "GenPoly/ErasableScopedMap.hpp"  // for ErasableScopedMap<>::const_...
+#include "SymTab/Mangler.hpp"             // for mangleType
 
 namespace GenPoly {
Index: src/GenPoly/ScrubTypeVars.hpp
===================================================================
--- src/GenPoly/ScrubTypeVars.hpp	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ src/GenPoly/ScrubTypeVars.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -19,5 +19,5 @@
 
 #include "AST/Fwd.hpp"        // for Node
-#include "GenPoly.h"          // for TypeVarMap
+#include "GenPoly.hpp"        // for TypeVarMap
 
 namespace GenPoly {
Index: src/GenPoly/Specialize.cpp
===================================================================
--- src/GenPoly/Specialize.cpp	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ src/GenPoly/Specialize.cpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -14,5 +14,5 @@
 //
 
-#include "Specialize.h"
+#include "Specialize.hpp"
 
 #include "AST/Copy.hpp"                  // for deepCopy
@@ -20,7 +20,7 @@
 #include "AST/Pass.hpp"                  // for Pass
 #include "AST/TypeEnvironment.hpp"       // for OpenVarSet, AssertionSet
-#include "Common/UniqueName.h"           // for UniqueName
-#include "GenPoly/GenPoly.h"             // for getFunctionType
-#include "ResolvExpr/FindOpenVars.h"     // for findOpenVars
+#include "Common/UniqueName.hpp"         // for UniqueName
+#include "GenPoly/GenPoly.hpp"           // for getFunctionType
+#include "ResolvExpr/FindOpenVars.hpp"   // for findOpenVars
 
 namespace GenPoly {
Index: src/GenPoly/Specialize.h
===================================================================
--- src/GenPoly/Specialize.h	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ 	(revision )
@@ -1,32 +1,0 @@
-//
-// 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.
-//
-// Specialize.h -- Generate thunks to specialize polymorphic functions.
-//
-// Author           : Richard C. Bilson
-// Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 22 09:22:31 2017
-// Update Count     : 2
-//
-
-#pragma once
-
-namespace ast {
-	class TranslationUnit;
-}
-
-namespace GenPoly {
-
-void convertSpecializations( ast::TranslationUnit & translationUnit );
-
-} // namespace GenPoly
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/GenPoly/Specialize.hpp
===================================================================
--- src/GenPoly/Specialize.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
+++ src/GenPoly/Specialize.hpp	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -0,0 +1,32 @@
+//
+// 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.
+//
+// Specialize.h -- Generate thunks to specialize polymorphic functions.
+//
+// Author           : Richard C. Bilson
+// Created On       : Mon May 18 07:44:20 2015
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Sat Jul 22 09:22:31 2017
+// Update Count     : 2
+//
+
+#pragma once
+
+namespace ast {
+	class TranslationUnit;
+}
+
+namespace GenPoly {
+
+void convertSpecializations( ast::TranslationUnit & translationUnit );
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/module.mk
===================================================================
--- src/GenPoly/module.mk	(revision 7a780ad23506507b6a1feccc46d18e12da183ceb)
+++ src/GenPoly/module.mk	(revision c92bdcc6ef9bc5c1b005f67d1c9f428bb8bd2b4c)
@@ -16,23 +16,23 @@
 
 SRC_GENPOLY = \
-	GenPoly/GenPoly.cc \
-	GenPoly/GenPoly.h \
-	GenPoly/Lvalue2.cc \
-	GenPoly/Lvalue.h
+	GenPoly/GenPoly.cpp \
+	GenPoly/GenPoly.hpp \
+	GenPoly/Lvalue2.cpp \
+	GenPoly/Lvalue.hpp
 
 SRC += $(SRC_GENPOLY) \
 	GenPoly/Box.cpp \
-	GenPoly/Box.h \
-	GenPoly/ErasableScopedMap.h \
-	GenPoly/FindFunction.cc \
-	GenPoly/FindFunction.h \
+	GenPoly/Box.hpp \
+	GenPoly/ErasableScopedMap.hpp \
+	GenPoly/FindFunction.cpp \
+	GenPoly/FindFunction.hpp \
 	GenPoly/InstantiateGeneric.cpp \
-	GenPoly/InstantiateGeneric.h \
+	GenPoly/InstantiateGeneric.hpp \
 	GenPoly/Lvalue.cpp \
-	GenPoly/ScopedSet.h \
+	GenPoly/ScopedSet.hpp \
 	GenPoly/ScrubTypeVars.cpp \
 	GenPoly/ScrubTypeVars.hpp \
 	GenPoly/Specialize.cpp \
-	GenPoly/Specialize.h
+	GenPoly/Specialize.hpp
 
 SRCDEMANGLE += $(SRC_GENPOLY)
