Commit edd43ed5 authored by Kevin Modzelewski's avatar Kevin Modzelewski

More refcounting

parent ecaf782b
......@@ -460,10 +460,10 @@ void ASTInterpreter::doStore(AST_Name* node, STOLEN(Value) value) {
InternedString name = node->id;
ScopeInfo::VarScopeType vst = node->lookup_type;
if (vst == ScopeInfo::VarScopeType::GLOBAL) {
assert(0 && "check refcounting");
if (jit)
jit->emitSetGlobal(globals, name.getBox(), value);
setGlobal(globals, name.getBox(), value.o);
Py_DECREF(value.o);
} else if (vst == ScopeInfo::VarScopeType::NAME) {
assert(0 && "check refcounting");
if (jit)
......@@ -1430,17 +1430,19 @@ Value ASTInterpreter::visit_call(AST_Call* node) {
v.o = callattr(func.o, attr.getBox(), callattr_flags, args.size() > 0 ? args[0] : 0,
args.size() > 1 ? args[1] : 0, args.size() > 2 ? args[2] : 0, args.size() > 3 ? &args[3] : 0,
keyword_names);
return v;
} else {
Value v;
if (jit)
v.var = jit->emitRuntimeCall(node, func, argspec, args_vars, keyword_names);
v.o = runtimeCall(func.o, argspec, args.size() > 0 ? args[0] : 0, args.size() > 1 ? args[1] : 0,
args.size() > 2 ? args[2] : 0, args.size() > 3 ? &args[3] : 0, keyword_names);
return v;
}
Py_DECREF(func.o);
for (auto e : args)
Py_DECREF(e);
return v;
}
......@@ -1536,7 +1538,6 @@ Value ASTInterpreter::visit_name(AST_Name* node) {
if (jit)
v.var = jit->emitGetGlobal(globals, node->id.getBox());
assert(0 && "check refcounting");
v.o = getGlobal(globals, node->id.getBox());
return v;
}
......@@ -1596,12 +1597,12 @@ Value ASTInterpreter::visit_subscript(AST_Subscript* node) {
Value ASTInterpreter::visit_list(AST_List* node) {
llvm::SmallVector<RewriterVar*, 8> items;
BoxedList* list = new BoxedList;
BoxedList* list = new BoxedList();
list->ensure(node->elts.size());
for (AST_expr* e : node->elts) {
Value v = visit_expr(e);
items.push_back(v);
listAppendInternal(list, v.o);
listAppendInternalStolen(list, v.o);
}
return Value(list, jit ? jit->emitCreateList(items) : NULL);
......
......@@ -410,12 +410,12 @@ Box* range(Box* start, Box* stop, Box* step) {
if (istep > 0) {
for (i64 i = istart; i < istop; i += istep) {
Box* bi = boxInt(i);
listAppendInternal(rtn, bi);
listAppendInternalStolen(rtn, bi);
}
} else {
for (i64 i = istart; i > istop; i += istep) {
Box* bi = boxInt(i);
listAppendInternal(rtn, bi);
listAppendInternalStolen(rtn, bi);
}
}
return rtn;
......
......@@ -42,7 +42,7 @@ inline void BoxedList::ensure(int min_free) {
}
// TODO the inliner doesn't want to inline these; is there any point to having them in the inline section?
extern "C" inline void listAppendInternal(Box* s, Box* v) {
extern "C" inline void listAppendInternalStolen(Box* s, Box* v) {
// Lock must be held!
assert(PyList_Check(s));
......@@ -52,10 +52,14 @@ extern "C" inline void listAppendInternal(Box* s, Box* v) {
self->ensure(1);
assert(self->size < self->capacity);
Py_INCREF(v);
self->elts->elts[self->size] = v;
self->size++;
}
extern "C" inline void listAppendInternal(Box* s, Box* v) {
Py_INCREF(v);
listAppendInternalStolen(s, v);
}
}
#endif
......@@ -3925,7 +3925,7 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
rewrite_args->rewriter->loadConst((intptr_t)default_obj));
}
getArg(arg_idx, oarg1, oarg2, oarg3, oargs) = incref(default_obj);
getArg(arg_idx, oarg1, oarg2, oarg3, oargs) = default_obj;
}
}
......@@ -6335,6 +6335,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
if (globals->cls == module_cls) {
BoxedModule* m = static_cast<BoxedModule*>(globals);
if (rewriter.get()) {
assert(0 && "check refcounting");
RewriterVar* r_mod = rewriter->getArg(0);
// Guard on it being a module rather than a dict
......@@ -6359,6 +6360,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
r = m->getattr(name);
nopatch_getglobal.log();
if (r) {
Py_INCREF(r);
return r;
}
}
......@@ -6371,6 +6373,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
auto it = d->d.find(name);
if (it != d->d.end()) {
Py_INCREF(it->second);
return it->second;
}
}
......@@ -6380,6 +6383,7 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
Box* rtn;
if (rewriter.get()) {
assert(0 && "check refcounting");
RewriterVar* builtins = rewriter->loadConst((intptr_t)builtins_module, Location::any());
GetattrRewriteArgs rewrite_args(rewriter.get(), builtins, rewriter->getReturnDestination());
rewrite_args.obj_shape_guarded = true; // always builtin module
......@@ -6398,8 +6402,10 @@ extern "C" Box* getGlobal(Box* globals, BoxedString* name) {
rtn = builtins_module->getattr(name);
}
if (rtn)
if (rtn) {
Py_INCREF(rtn);
return rtn;
}
}
assert(name->data()[name->size()] == '\0');
......
......@@ -151,6 +151,7 @@ BoxedString* boxStringTwine(const llvm::Twine& s);
extern "C" Box* decodeUTF8StringPtr(llvm::StringRef s);
extern "C" inline void listAppendInternal(Box* self, Box* v) __attribute__((visibility("default")));
extern "C" inline void listAppendInternalStolen(Box* self, Box* v) __attribute__((visibility("default")));
extern "C" void listAppendArrayInternal(Box* self, Box** v, int nelts);
extern "C" Box* createFunctionFromMetadata(FunctionMetadata* f, BoxedClosure* closure, Box* globals,
std::initializer_list<Box*> defaults) noexcept;
......
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