Ignore:
Timestamp:
Jul 18, 2018, 5:18:29 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env
Children:
eff03a94
Parents:
5c14030
Message:

Fix assorted memory bugs with persistent-array environment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/GcTracer.h

    r5c14030 rd318a18  
    2525#include "Common/GC.h"
    2626#include "Common/PassVisitor.h"
    27 
    28 class Expression;
     27#include "ResolvExpr/TypeEnvironment.h"
    2928
    3029/// Implements `trace` method for syntax nodes
     
    3433public:
    3534        GcTracer( const GC& gc ) : gc(gc) {}
     35
     36        template<typename... Args>
     37        void traceAll(Args&... args) { ::traceAll(gc, args...); }
    3638
    3739        // mark node and children
     
    151153                maybeAccept( type->baseUnion, *visitor );
    152154        }
     155
     156private:
     157        void visit( const ResolvExpr::TypeEnvironment::Classes* c ) {
     158                typedef ResolvExpr::TypeEnvironment::Classes C;
     159                // trace all parent classes, short-circuiting at one traced
     160                while ( gc.notrace_mark( c ) && c->get_mode() != C::BASE ) { c = c->get_base(); }
     161        }
     162
     163        void visit( const ResolvExpr::TypeEnvironment::Bindings* b ) {
     164                typedef ResolvExpr::TypeEnvironment::Bindings B;
     165
     166                while ( true ) {
     167                        if ( ! gc.notrace_mark( b ) ) return;  // short-circuit if already traced
     168
     169                        if ( b->get_mode() == B::BASE ) break; // break if this is a base map
     170                       
     171                        if ( b->get_mode() != B::REM ) { // trace bound intermediate elements
     172                                maybeAccept( b->get_val().type, *visitor );
     173                        }
     174
     175                        b = b->get_base();
     176                }
     177
     178                // trace bound elements in base binding
     179                b->for_each( [&](interned_string, const ResolvExpr::BoundType& bound) {
     180                        maybeAccept( bound.type, *visitor );  // trace bound elements
     181                } );
     182        }
     183
     184public:
     185        void visit( const ResolvExpr::TypeEnvironment& env ) {
     186                visit( env.classes );
     187                visit( env.bindings );
     188        }
    153189};
    154190
Note: See TracChangeset for help on using the changeset viewer.