Index: src/AST/Create.cpp
===================================================================
--- src/AST/Create.cpp	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
+++ src/AST/Create.cpp	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
@@ -0,0 +1,63 @@
+//
+// 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.
+//
+// Create.cpp -- Helpers to create pieces of the AST.
+//
+// Author           : Andrew Beach
+// Created On       : Tue Sep 20 13:28:00 2022
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue Sep 20 14:55:00 2022
+// Update Count     : 0
+//
+
+#include "AST/Create.hpp"
+
+#include "AST/Attribute.hpp"
+#include "AST/Copy.hpp"
+#include "AST/Decl.hpp"
+
+namespace ast {
+
+namespace {
+
+	template<typename node_t>
+	std::vector<ast::ptr<node_t>> vectorCopy(
+			std::vector<ast::ptr<node_t>> const & nodes ) {
+		return map_range<std::vector<ast::ptr<node_t>>>( nodes,
+			[]( ptr<node_t> const & node ){
+				return deepCopy<node_t>( node );
+			}
+		);
+	}
+
+} // namespace
+
+StructDecl * asForward( StructDecl const * decl ) {
+	if ( !decl->body ) {
+		return nullptr;
+	}
+	StructDecl * fwd = new StructDecl( decl->location,
+		decl->name,
+		decl->kind,
+		vectorCopy<ast::Attribute>( decl->attributes ),
+		decl->linkage );
+	fwd->params = vectorCopy( decl->params );
+	return fwd;
+}
+
+UnionDecl * asForward( UnionDecl const * decl ) {
+	if ( !decl->body ) {
+		return nullptr;
+	}
+	UnionDecl * fwd = new UnionDecl( decl->location,
+		decl->name,
+		vectorCopy( decl->attributes ),
+		decl->linkage );
+	fwd->params = vectorCopy( decl->params );
+	return fwd;
+}
+
+}
Index: src/AST/Create.hpp
===================================================================
--- src/AST/Create.hpp	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
+++ src/AST/Create.hpp	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
@@ -0,0 +1,26 @@
+//
+// 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.
+//
+// Create.hpp -- Helpers to create pieces of the AST.
+//
+// Author           : Andrew Beach
+// Created On       : Tue Sep 20 13:25:00 2022
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue Sep 20 14:38:00 2022
+// Update Count     : 0
+//
+
+#include "AST/Fwd.hpp"
+
+namespace ast {
+
+/// Create a forward declaration of the existing declaration.
+/// If the argument is already a forward declaration, return nullptr instead.
+/// More efficient than the deepCopy and clear pattern.
+StructDecl * asForward( StructDecl const * );
+UnionDecl * asForward( UnionDecl const * );
+
+}
Index: src/AST/Print.cpp
===================================================================
--- src/AST/Print.cpp	(revision 4520b77e192c372763501afd950a0f1452141b3b)
+++ src/AST/Print.cpp	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
@@ -90,5 +90,5 @@
 
 		static constexpr auto Qualifiers = make_array<const char*>(
-			"const", "restrict", "volatile", "lvalue", "mutex", "_Atomic"
+			"const", "restrict", "volatile", "mutex", "_Atomic"
 		);
 	};
@@ -1635,4 +1635,4 @@
 constexpr array<const char*, 3> Printer::Names::FuncSpecifiers;
 constexpr array<const char*, 6> Printer::Names::StorageClasses;
-constexpr array<const char*, 6> Printer::Names::Qualifiers;
+constexpr array<const char*, 5> Printer::Names::Qualifiers;
 }
Index: src/AST/Type.hpp
===================================================================
--- src/AST/Type.hpp	(revision 4520b77e192c372763501afd950a0f1452141b3b)
+++ src/AST/Type.hpp	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
@@ -412,5 +412,4 @@
 		std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; }
 		bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
-
 	};
 
Index: src/AST/TypeEnvironment.hpp
===================================================================
--- src/AST/TypeEnvironment.hpp	(revision 4520b77e192c372763501afd950a0f1452141b3b)
+++ src/AST/TypeEnvironment.hpp	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
@@ -56,4 +56,10 @@
 struct AssertCompare {
 	bool operator()( const VariableExpr * d1, const VariableExpr * d2 ) const {
+		auto kind1 = ast::SymbolTable::getSpecialFunctionKind(d1->var->name);
+		auto kind2 = ast::SymbolTable::getSpecialFunctionKind(d2->var->name);
+		// heuristics optimization: force special functions to go last
+		if (kind1 > kind2) return true;
+		else if (kind1 < kind2) return false;
+
 		int cmp = d1->var->name.compare( d2->var->name );
 		return cmp < 0 || ( cmp == 0 && d1->result < d2->result );
Index: src/AST/module.mk
===================================================================
--- src/AST/module.mk	(revision 4520b77e192c372763501afd950a0f1452141b3b)
+++ src/AST/module.mk	(revision a065f1ffe843ea0a3ceecdf36a1210abe07a2441)
@@ -24,4 +24,6 @@
 	AST/Copy.cpp \
 	AST/Copy.hpp \
+	AST/Create.cpp \
+	AST/Create.hpp \
 	AST/CVQualifiers.hpp \
 	AST/Decl.cpp \
