Commit a79385d6 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Improve tear-down process slightly

Since we are putting more things in the IC gc references,
call GC again after clearing them.
parent 3d9a8393
...@@ -1435,8 +1435,7 @@ void Rewriter::commit() { ...@@ -1435,8 +1435,7 @@ void Rewriter::commit() {
for (auto p : gc_references) { for (auto p : gc_references) {
if (Py_REFCNT(p) == 1) { if (Py_REFCNT(p) == 1) {
// we hold the only ref to this object // we hold the only ref to this object, there's no way this could succeed in the future
assert(0 && "untested");
this->abort(); this->abort();
return; return;
......
...@@ -3955,6 +3955,10 @@ static int type_traverse(PyTypeObject* type, visitproc visit, void* arg) { ...@@ -3955,6 +3955,10 @@ static int type_traverse(PyTypeObject* type, visitproc visit, void* arg) {
Py_VISIT(type->tp_bases); Py_VISIT(type->tp_bases);
Py_VISIT(type->tp_base); Py_VISIT(type->tp_base);
// TODO: should have something like this to traverse GC references in the type runtime ICs:
// if (type->hasnext_ic)
// Py_TRAVERSE(*type->hasnext_ic);
/* There's no need to visit type->tp_subclasses or /* There's no need to visit type->tp_subclasses or
((PyHeapTypeObject *)type)->ht_slots, because they can't be involved ((PyHeapTypeObject *)type)->ht_slots, because they can't be involved
in cycles; tp_subclasses is a list of weak references, in cycles; tp_subclasses is a list of weak references,
...@@ -4719,6 +4723,8 @@ extern "C" void Py_Finalize() noexcept { ...@@ -4719,6 +4723,8 @@ extern "C" void Py_Finalize() noexcept {
// May need to run multiple collections to collect everything: // May need to run multiple collections to collect everything:
while (true) { while (true) {
clearAllICs();
int freed = 0; int freed = 0;
freed += PyGC_Collect(); freed += PyGC_Collect();
...@@ -4738,7 +4744,6 @@ extern "C" void Py_Finalize() noexcept { ...@@ -4738,7 +4744,6 @@ extern "C" void Py_Finalize() noexcept {
} }
constant_locations.clear(); constant_locations.clear();
clearAllICs();
PyType_ClearCache(); PyType_ClearCache();
PyOS_FiniInterrupts(); PyOS_FiniInterrupts();
_PyCodecRegistry_Deinit(); _PyCodecRegistry_Deinit();
...@@ -4752,6 +4757,7 @@ extern "C" void Py_Finalize() noexcept { ...@@ -4752,6 +4757,7 @@ extern "C" void Py_Finalize() noexcept {
constants.clear(); constants.clear();
clearAllICs(); clearAllICs();
PyGC_Collect();
for (auto b : late_constants) { for (auto b : late_constants) {
Py_DECREF(b); Py_DECREF(b);
......
...@@ -251,7 +251,7 @@ extern "C" void dumpEx(void* p, int levels) { ...@@ -251,7 +251,7 @@ extern "C" void dumpEx(void* p, int levels) {
FunctionMetadata* md = f->md; FunctionMetadata* md = f->md;
if (md->source) { if (md->source) {
printf("User-defined function '%s'\n", md->source->getName()->c_str()); printf("User-defined function '%s'\n", md->source->getName()->c_str());
printf("Defined at %s:%d\n", md->source->getFn()->c_str(), md->source->getBody()[0]->lineno); printf("Defined at %s:%d\n", md->source->getFn()->c_str(), md->source->ast->lineno);
if (md->source->cfg && levels > 0) { if (md->source->cfg && levels > 0) {
md->source->cfg->print(); md->source->cfg->print();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment