Changeset f229fc2
- Timestamp:
- Apr 13, 2018, 12:25:33 PM (7 years ago)
- Branches:
- new-env, with_gc
- Children:
- b5aa3d8
- Parents:
- 09a1ae6
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/GC.cc
r09a1ae6 rf229fc2 23 23 #include <cassert> 24 24 25 // #include <csignal>26 27 25 GC& GC::get() { 28 26 static GC gc; … … 47 45 if( obj ) 48 46 { 49 bool isMarked = obj->mark == this->mark; 50 if( !isMarked ) { 47 if( obj->mark != this->mark ) { 51 48 obj->mark = this->mark; 52 49 obj->trace( *this ); … … 57 54 58 55 void GC::register_object(GC_Object* obj) { 59 // if ( obj == (GC_Object*)0x60f00000e410ul ) std::raise( SIGTRAP );60 56 (using_young ? young : old).push_back(obj); 61 obj->mark = ! 57 obj->mark = !this->mark; // initialize as un-marked 62 58 } 63 59 … … 67 63 68 64 void GC::new_generation() { 69 using_young = true; 65 assert(!using_young && "Cannot start new generation when young generation already in use"); 66 67 using_young = true; // mark young generation as in-use 68 mark = !mark; // switch mark so aged young objects will still be unmarked in old 70 69 } 71 70 … … 78 77 79 78 void GC::collect_young() { 80 // check young generation, just reset mark if not using81 if ( ! using_young ) {82 mark = !mark;83 return;84 }85 86 79 // collect young gen 87 80 for ( GC_Object*& obj : young ) { … … 100 93 young.clear(); 101 94 102 // reset mark for next collection95 // reset mark to return to old generation mark 103 96 mark = !mark; 104 97 } 105 98 106 99 void GC::collect() { 100 // ensure not called when young gen is active 101 assert(!using_young && "Cannot do old collection when young generation is active"); 102 107 103 // collect old gen 108 104 for ( GC_Object*& obj : old ) { 109 105 if ( obj->mark != mark ) { 110 // if ( obj == (GC_Object*)0x60f00000e410ul ) std::raise( SIGTRAP );111 106 delete obj; 112 107 obj = nullptr; … … 117 112 old.erase( std::remove( old.begin(), old.end(), nullptr ), old.end() ); 118 113 119 // collect young gen (also resets mark)120 collect_young();114 // reset mark 115 mark = !mark; 121 116 } 122 117 -
src/Common/GC.h
r09a1ae6 rf229fc2 48 48 void collect_young(); 49 49 50 /// Collects all memory; use old generation afterward. 50 /// Collects old generation; use old generation afterward. 51 /// Error if currently using young generation 51 52 void collect(); 52 53 -
src/ResolvExpr/Alternative.cc
r09a1ae6 rf229fc2 20 20 #include <utility> // for move 21 21 22 #include "Common/GC.h" 23 #include "Common/PassVisitor.h" 22 24 #include "Common/utility.h" // for maybeClone 23 25 #include "ResolvExpr/Cost.h" // for Cost, Cost::zero, operator<< 24 26 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 25 27 #include "SynTree/Expression.h" // for Expression 28 #include "SynTree/GcTracer.h" 26 29 #include "SynTree/Type.h" // for Type 27 30 … … 64 67 } 65 68 69 const GC& operator<< ( const GC& gc, const Alternative& alt ) { 70 PassVisitor<GcTracer> tracer{ gc }; 71 maybeAccept( alt.expr, tracer ); 72 tracer << alt.env; 73 return gc; 74 } 75 66 76 } // namespace ResolvExpr 67 77 -
src/ResolvExpr/Alternative.h
r09a1ae6 rf229fc2 23 23 24 24 class Expression; 25 26 class GC; 25 27 26 28 namespace ResolvExpr { … … 52 54 return os; 53 55 } 56 57 const GC& operator<< ( const GC&, const Alternative& ); 54 58 } // namespace ResolvExpr 55 59 -
src/ResolvExpr/Resolver.cc
r09a1ae6 rf229fc2 22 22 #include "Alternative.h" // for Alternative, AltList 23 23 #include "AlternativeFinder.h" // for AlternativeFinder, resolveIn... 24 #include "Common/GC.h" // for new_generation, collect_young 24 25 #include "Common/PassVisitor.h" // for PassVisitor 25 26 #include "Common/SemanticError.h" // for SemanticError … … 146 147 void findUnfinishedKindExpression(Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) { 147 148 assertf( untyped, "expected a non-null expression." ); 149 150 new_generation(); // set up GC young generation for this top-level expression 151 148 152 TypeEnvironment env; 149 153 AlternativeFinder finder( indexer, env ); … … 173 177 findMinCost( candidates.begin(), candidates.end(), back_inserter( winners ) ); 174 178 if ( winners.size() == 0 ) { 175 SemanticError( untyped, toString( "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), "expression: ") ); 179 collect_young(); 180 SemanticError( untyped, toString( 181 "No reasonable alternatives for ", kindStr, (kindStr != "" ? " " : ""), 182 "expression: ") ); 176 183 } else if ( winners.size() != 1 ) { 177 184 std::ostringstream stream; 178 stream << "Cannot choose between " << winners.size() << " alternatives for " << kindStr << (kindStr != "" ? " " : "") << "expression\n"; 185 stream << "Cannot choose between " << winners.size() << " alternatives for " 186 << kindStr << (kindStr != "" ? " " : "") << "expression\n"; 179 187 untyped->print( stream ); 180 188 stream << " Alternatives are:\n"; 181 189 printAlts( winners, stream, 1 ); 190 191 collect_young(); 182 192 SemanticError( untyped->location, stream.str() ); 183 193 } … … 186 196 Alternative & choice = winners.front(); 187 197 if ( findDeletedExpr( choice.expr ) ) { 188 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " ); 198 collect_young( choice.expr ); 199 SemanticError( choice.expr, 200 "Unique best alternative includes deleted identifier in " ); 189 201 } 190 202 alt = std::move( choice ); 203 collect_young( alt ); 191 204 } 192 205 -
src/ResolvExpr/TypeEnvironment.cc
r09a1ae6 rf229fc2 19 19 #include <utility> // for pair 20 20 21 #include "Common/PassVisitor.h" // for PassVisitor<GcTracer> 21 22 #include "Common/utility.h" // for maybeClone 23 #include "SynTree/GcTracer.h" // for PassVisitor<GcTracer> 22 24 #include "SynTree/Type.h" // for Type, FunctionType, Type::Fora... 23 25 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution … … 222 224 return out; 223 225 } 226 227 PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ) { 228 for ( const EqvClass & c : env ) { 229 maybeAccept( c.type, gc ); 230 } 231 return gc; 232 } 224 233 } // namespace ResolvExpr 225 234 -
src/ResolvExpr/TypeEnvironment.h
r09a1ae6 rf229fc2 26 26 #include "SynTree/Type.h" // for Type, Type::ForallList 27 27 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 28 29 template< typename Pass > 30 class PassVisitor; 31 class GcTracer; 28 32 29 33 namespace ResolvExpr { … … 116 120 117 121 std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env ); 122 123 PassVisitor<GcTracer> & operator<<( PassVisitor<GcTracer> & gc, const TypeEnvironment & env ); 118 124 } // namespace ResolvExpr 119 125
Note: See TracChangeset
for help on using the changeset viewer.