Index: src/Common/PassVisitor.h
===================================================================
--- src/Common/PassVisitor.h	(revision 84733c19dd0d0f3c4aeef31fc4394f9705b51415)
+++ src/Common/PassVisitor.h	(revision 447c35601995880f86baa595fb0755c65564b620)
@@ -238,4 +238,6 @@
 	virtual Attribute * mutate( Attribute * attribute ) override final;
 
+	virtual TypeSubstitution * mutate( TypeSubstitution * sub ) final;
+
 private:
 	template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
Index: src/Common/PassVisitor.impl.h
===================================================================
--- src/Common/PassVisitor.impl.h	(revision 84733c19dd0d0f3c4aeef31fc4394f9705b51415)
+++ src/Common/PassVisitor.impl.h	(revision 447c35601995880f86baa595fb0755c65564b620)
@@ -2127,2 +2127,16 @@
 	MUTATE_BODY( Attribute, node );
 }
+
+template< typename pass_type >
+TypeSubstitution * PassVisitor< pass_type >::mutate( TypeSubstitution * node ) {
+	MUTATE_START( node );
+
+	for ( auto & p : node->typeEnv ) {
+		indexerScopedMutate( p.second, *this );
+	}
+	for ( auto & p : node->varEnv ) {
+		indexerScopedMutate( p.second, *this );
+	}
+
+	MUTATE_END( TypeSubstitution, node );
+}
Index: src/SynTree/Mutator.cc
===================================================================
--- src/SynTree/Mutator.cc	(revision 84733c19dd0d0f3c4aeef31fc4394f9705b51415)
+++ src/SynTree/Mutator.cc	(revision 447c35601995880f86baa595fb0755c65564b620)
@@ -626,4 +626,14 @@
 }
 
+TypeSubstitution * Mutator::mutate( TypeSubstitution * sub ) {
+	for ( auto & p : sub->typeEnv ) {
+		p.second = maybeMutate( p.second, *this );
+	}
+	for ( auto & p : sub->varEnv ) {
+		p.second = maybeMutate( p.second, *this );
+	}
+	return sub;
+}
+
 // Local Variables: //
 // tab-width: 4 //
Index: src/SynTree/Mutator.h
===================================================================
--- src/SynTree/Mutator.h	(revision 84733c19dd0d0f3c4aeef31fc4394f9705b51415)
+++ src/SynTree/Mutator.h	(revision 447c35601995880f86baa595fb0755c65564b620)
@@ -117,4 +117,6 @@
 
 	virtual Attribute * mutate( Attribute * attribute );
+
+	virtual TypeSubstitution * mutate( TypeSubstitution * sub );
   private:
 	virtual Declaration * handleAggregateDecl(AggregateDecl * aggregateDecl );
Index: src/SynTree/TypeSubstitution.cc
===================================================================
--- src/SynTree/TypeSubstitution.cc	(revision 84733c19dd0d0f3c4aeef31fc4394f9705b51415)
+++ src/SynTree/TypeSubstitution.cc	(revision 447c35601995880f86baa595fb0755c65564b620)
@@ -148,5 +148,5 @@
 template< typename TypeClass >
 Type *TypeSubstitution::handleType( TypeClass *type ) {
-	BoundVarsType oldBoundVars( boundVars );
+	ValueGuard<BoundVarsType> oldBoundVars( boundVars );
 	// bind type variables from forall-qualifiers
 	if ( freeOnly ) {
@@ -156,5 +156,4 @@
 	} // if
 	Type *ret = Mutator::mutate( type );
-	boundVars = oldBoundVars;
 	return ret;
 }
@@ -162,5 +161,5 @@
 template< typename TypeClass >
 Type *TypeSubstitution::handleAggregateType( TypeClass *type ) {
-	BoundVarsType oldBoundVars( boundVars );
+	ValueGuard<BoundVarsType> oldBoundVars( boundVars );
 	// bind type variables from forall-qualifiers
 	if ( freeOnly ) {
@@ -177,5 +176,4 @@
 	} // if
 	Type *ret = Mutator::mutate( type );
-	boundVars = oldBoundVars;
 	return ret;
 }
@@ -231,14 +229,4 @@
 Type * TypeSubstitution::mutate( OneType *oneType ) {
 	return handleType( oneType );
-}
-
-TypeSubstitution * TypeSubstitution::acceptMutator( Mutator & mutator ) {
-	for ( auto & p : typeEnv ) {
-		p.second = maybeMutate( p.second, mutator );
-	}
-	for ( auto & p : varEnv ) {
-		p.second = maybeMutate( p.second, mutator );
-	}
-	return this;
 }
 
Index: src/SynTree/TypeSubstitution.h
===================================================================
--- src/SynTree/TypeSubstitution.h	(revision 84733c19dd0d0f3c4aeef31fc4394f9705b51415)
+++ src/SynTree/TypeSubstitution.h	(revision 447c35601995880f86baa595fb0755c65564b620)
@@ -59,5 +59,5 @@
 	void normalize();
 
-	TypeSubstitution * acceptMutator( Mutator & mutator );
+	TypeSubstitution * acceptMutator( Mutator & m ) { return m.mutate( this ); }
 
 	void print( std::ostream &os, Indenter indent = {} ) const;
@@ -89,4 +89,9 @@
 
 	void initialize( const TypeSubstitution &src, TypeSubstitution &dest );
+
+	friend class Mutator;
+
+	template<typename pass_type>
+	friend class PassVisitor;
 
 	typedef std::map< std::string, Type* > TypeEnvType;
