Changeset 24de7b1


Ignore:
Timestamp:
Apr 16, 2018, 3:21:17 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
fb97252f
Parents:
6f81db3
Message:

Fix more missing visits in GcTracer?, add cycle detection back in, ensure mark isn't broken by defaulted GC_Object copy and assign

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Common/GC.cc

    r6f81db3 r24de7b1  
    4040}
    4141
    42 const GC& GC::operator<< (const GC_Traceable* obj) const {
     42const GC& GC::operator<< (const GC_Object* obj) const {
    4343        if( obj )
    4444        {
     
    119119}
    120120
     121GC_Object::GC_Object( const GC_Object& ) {
     122        GC::get().register_object( this );
     123}
     124
     125GC_Object::GC_Object( GC_Object&& ) {
     126        GC::get().register_object( this );
     127}
     128
    121129// Local Variables: //
    122130// tab-width: 4 //
  • src/Common/GC.h

    r6f81db3 r24de7b1  
    1818#include <vector>
    1919
    20 class GC_Traceable;
    2120class GC_Object;
    2221class BaseSyntaxNode;
     
    3029
    3130        /// Traces a traceable object
    32         const GC& operator<< (const GC_Traceable*) const;
     31        const GC& operator<< (const GC_Object*) const;
    3332
    3433        /// Adds a new object to garbage collection
     
    111110}
    112111
    113 /// Class that is traced by the GC, but not managed by it
    114 class GC_Traceable {
     112/// Class that is managed by the GC
     113class GC_Object {
    115114        friend class GC;
    116115protected:
    117116        mutable bool mark;
    118117
     118        // Override default constructors to ensure clones are registered and properly marked
     119        GC_Object();
     120
     121        GC_Object(const GC_Object&);
     122
     123        GC_Object(GC_Object&&);
     124
     125        GC_Object& operator= (const GC_Object&) { /* do not assign mark */ return *this; }
     126
     127        GC_Object& operator= (GC_Object&&) { /* do not assign mark */ return *this; }
     128
     129        // Ensure subclasses can be deleted by garbage collector
     130        virtual ~GC_Object() {}
     131
    119132        /// override to trace any child objects
    120133        virtual void trace(const GC&) const {}
    121 };
    122 
    123 /// Class that is managed by the GC
    124 class GC_Object : public GC_Traceable {
    125         friend class GC;
    126 protected:
    127         virtual ~GC_Object() {}
    128 public:
    129         GC_Object();
    130134};
    131135
  • src/SynTree/GcTracer.h

    r6f81db3 r24de7b1  
    3838        void previsit( BaseSyntaxNode * node ) {
    3939                // skip tree if already seen
    40                 // xxx - this should be uncommented (it breaks object cycles), but at the moment it seems
    41                 // like the object cycles don't happen and other bugs do
    42                 // if ( node->mark == gc.mark ) {
    43                 //      visit_children = false;
    44                 //      return;
    45                 // }
     40                if ( node->mark == gc.mark ) {
     41                        visit_children = false;
     42                        return;
     43                }
    4644
    4745                // mark node
     
    5048
    5149        // add visits left out by PassVisitor
     50
     51        void postvisit( Constant* con ) {
     52                maybeAccept( con->get_type(), *visitor );
     53        }
    5254
    5355        void postvisit( Expression* expr ) {
     
    5860                postvisit( static_cast<Expression*>(expr) );
    5961                maybeAccept( expr->function, *visitor );
     62        }
     63
     64        void postvisit( VariableExpr* expr ) {
     65                postvisit( static_cast<Expression*>(expr) );
     66                maybeAccept( expr->var, *visitor );  // not in PassVisitor because it causes cycle
    6067        }
    6168
Note: See TracChangeset for help on using the changeset viewer.