Commit c4ace2f9 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Kill off the old vref system. This is much easier now

parent a68bb9e6
...@@ -238,19 +238,6 @@ public: ...@@ -238,19 +238,6 @@ public:
RewriterVar* setType(RefType type); RewriterVar* setType(RefType type);
// XXX convert callers back to setType
RewriterVar* asBorrowed() {
return setType(RefType::BORROWED);
}
RewriterVar* incvref() {
assert(0 && "don't call incvref anymore");
}
RewriterVar* decvref() {
assert(0 && "don't call decvref anymore");
}
// Call this to let the automatic refcount machinery know that a refcount // Call this to let the automatic refcount machinery know that a refcount
// got "consumed", ie passed off. Such as to a function that steals a reference, // got "consumed", ie passed off. Such as to a function that steals a reference,
// or when stored into a memory location that is an owned reference, etc. // or when stored into a memory location that is an owned reference, etc.
...@@ -259,10 +246,6 @@ public: ...@@ -259,10 +246,6 @@ public:
// r_val->refConsumed() // r_val->refConsumed()
void refConsumed(); void refConsumed();
RewriterVar* stealRef() {
assert(0 && "don't call stealref anymore");
}
template <typename Src, typename Dst> inline RewriterVar* getAttrCast(int offset, Location loc = Location::any()); template <typename Src, typename Dst> inline RewriterVar* getAttrCast(int offset, Location loc = Location::any());
...@@ -700,30 +683,6 @@ public: ...@@ -700,30 +683,6 @@ public:
friend class RewriterVar; friend class RewriterVar;
}; };
struct AutoDecvref {
private:
RewriterVar* var;
public:
AutoDecvref(RewriterVar* var) : var(var) {}
~AutoDecvref() {
if (var)
var->decvref();
}
operator RewriterVar*() {
return var;
}
RewriterVar* operator->() {
return var;
}
void operator=(RewriterVar* new_var) {
assert(!var);
var = new_var;
}
};
void setSlowpathFunc(uint8_t* pp_addr, void* func); void setSlowpathFunc(uint8_t* pp_addr, void* func);
struct GRCompare { struct GRCompare {
......
...@@ -1493,7 +1493,7 @@ Value ASTInterpreter::visit_num(AST_Num* node) { ...@@ -1493,7 +1493,7 @@ Value ASTInterpreter::visit_num(AST_Num* node) {
Py_INCREF(o); Py_INCREF(o);
RewriterVar* v = NULL; RewriterVar* v = NULL;
if (jit) { if (jit) {
v = jit->imm(o)->asBorrowed(); v = jit->imm(o)->setType(RefType::BORROWED);
} }
return Value(o, v); return Value(o, v);
} }
......
...@@ -521,8 +521,8 @@ void JitFragmentWriter::emitReturn(RewriterVar* v) { ...@@ -521,8 +521,8 @@ void JitFragmentWriter::emitReturn(RewriterVar* v) {
} }
void JitFragmentWriter::emitSetAttr(AST_expr* node, RewriterVar* obj, BoxedString* s, STOLEN(RewriterVar*) attr) { void JitFragmentWriter::emitSetAttr(AST_expr* node, RewriterVar* obj, BoxedString* s, STOLEN(RewriterVar*) attr) {
attr->stealRef();
emitPPCall((void*)setattr, { obj, imm(s), attr }, 2, 512, node); emitPPCall((void*)setattr, { obj, imm(s), attr }, 2, 512, node);
attr->refConsumed();
} }
void JitFragmentWriter::emitSetBlockLocal(InternedString s, STOLEN(RewriterVar*) v) { void JitFragmentWriter::emitSetBlockLocal(InternedString s, STOLEN(RewriterVar*) v) {
......
...@@ -1176,7 +1176,7 @@ int assign_version_tag(PyTypeObject* type) noexcept { ...@@ -1176,7 +1176,7 @@ int assign_version_tag(PyTypeObject* type) noexcept {
return 1; return 1;
} }
template <Rewritable rewritable> Box* typeLookup(BoxedClass* cls, BoxedString* attr, GetattrRewriteArgs* rewrite_args) { template <Rewritable rewritable> BORROWED(Box*) typeLookup(BoxedClass* cls, BoxedString* attr, GetattrRewriteArgs* rewrite_args) {
if (rewritable == NOT_REWRITABLE) { if (rewritable == NOT_REWRITABLE) {
assert(!rewrite_args); assert(!rewrite_args);
rewrite_args = NULL; rewrite_args = NULL;
...@@ -2098,7 +2098,6 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew ...@@ -2098,7 +2098,6 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
Box* val; Box* val;
if (rewrite_args) { if (rewrite_args) {
RELEASE_ASSERT(0, "need to check the refcounting for this");
GetattrRewriteArgs hrewrite_args(rewrite_args->rewriter, rewrite_args->obj, rewrite_args->destination); GetattrRewriteArgs hrewrite_args(rewrite_args->rewriter, rewrite_args->obj, rewrite_args->destination);
val = obj->getattr(attr, &hrewrite_args); val = obj->getattr(attr, &hrewrite_args);
...@@ -3597,11 +3596,11 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa ...@@ -3597,11 +3596,11 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
getArg(idx, oarg1, oarg2, oarg3, NULL) = NULL; // pass NULL for kwargs getArg(idx, oarg1, oarg2, oarg3, NULL) = NULL; // pass NULL for kwargs
if (rewrite_args) { if (rewrite_args) {
if (idx == 0) if (idx == 0)
rewrite_args->arg1 = rewrite_args->rewriter->loadConst(0)->asBorrowed(); rewrite_args->arg1 = rewrite_args->rewriter->loadConst(0)->setType(RefType::BORROWED);
else if (idx == 1) else if (idx == 1)
rewrite_args->arg2 = rewrite_args->rewriter->loadConst(0)->asBorrowed(); rewrite_args->arg2 = rewrite_args->rewriter->loadConst(0)->setType(RefType::BORROWED);
else if (idx == 2) else if (idx == 2)
rewrite_args->arg3 = rewrite_args->rewriter->loadConst(0)->asBorrowed(); rewrite_args->arg3 = rewrite_args->rewriter->loadConst(0)->setType(RefType::BORROWED);
else else
abort(); abort();
} }
...@@ -3693,10 +3692,7 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa ...@@ -3693,10 +3692,7 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
getArg(i, oarg1, oarg2, oarg3, oargs) = incref(getArg(i, arg1, arg2, arg3, args)); getArg(i, oarg1, oarg2, oarg3, oargs) = incref(getArg(i, arg1, arg2, arg3, args));
} }
if (rewrite_args) { if (rewrite_args) {
for (int i = 0; i < positional_to_positional; i++) { assert(positional_to_positional < 3 && "figure this out");
assert(i < 3 && "figure this out");
getArg(i, rewrite_args)->incvref();
}
} }
int varargs_to_positional = std::min((int)varargs_size, paramspec.num_args - positional_to_positional); int varargs_to_positional = std::min((int)varargs_size, paramspec.num_args - positional_to_positional);
...@@ -3962,13 +3958,13 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa ...@@ -3962,13 +3958,13 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
if (rewrite_args) { if (rewrite_args) {
if (arg_idx == 0) if (arg_idx == 0)
rewrite_args->arg1 rewrite_args->arg1
= rewrite_args->rewriter->loadConst((intptr_t)default_obj, Location::forArg(0))->asBorrowed(); = rewrite_args->rewriter->loadConst((intptr_t)default_obj, Location::forArg(0))->setType(RefType::BORROWED);
else if (arg_idx == 1) else if (arg_idx == 1)
rewrite_args->arg2 rewrite_args->arg2
= rewrite_args->rewriter->loadConst((intptr_t)default_obj, Location::forArg(1))->asBorrowed(); = rewrite_args->rewriter->loadConst((intptr_t)default_obj, Location::forArg(1))->setType(RefType::BORROWED);
else if (arg_idx == 2) else if (arg_idx == 2)
rewrite_args->arg3 rewrite_args->arg3
= rewrite_args->rewriter->loadConst((intptr_t)default_obj, Location::forArg(2))->asBorrowed(); = rewrite_args->rewriter->loadConst((intptr_t)default_obj, Location::forArg(2))->setType(RefType::BORROWED);
else { else {
assert(0 && "check refcounting"); assert(0 && "check refcounting");
rewrite_args->args->setAttr((arg_idx - 3) * sizeof(Box*), rewrite_args->args->setAttr((arg_idx - 3) * sizeof(Box*),
......
...@@ -795,6 +795,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo ...@@ -795,6 +795,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
RewriterVar* r_ccls = NULL; RewriterVar* r_ccls = NULL;
RewriterVar* r_new = NULL; RewriterVar* r_new = NULL;
RewriterVar* r_init = NULL; RewriterVar* r_init = NULL;
// TODO: is this ok? what if new causes init to get freed?
BORROWED(Box*) init_attr = NULL; BORROWED(Box*) init_attr = NULL;
if (rewrite_args) { if (rewrite_args) {
assert(!argspec.has_starargs); assert(!argspec.has_starargs);
...@@ -830,10 +831,9 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo ...@@ -830,10 +831,9 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
DecrefHandle<Box, true> new_attr(nullptr); DecrefHandle<Box, true> new_attr(nullptr);
static BoxedString* new_str = getStaticString("__new__"); static BoxedString* new_str = getStaticString("__new__");
if (rewrite_args) { if (rewrite_args) {
assert(0 && "check refcounting");
GetattrRewriteArgs grewrite_args(rewrite_args->rewriter, r_ccls, rewrite_args->destination); GetattrRewriteArgs grewrite_args(rewrite_args->rewriter, r_ccls, rewrite_args->destination);
// TODO: if tp_new != Py_CallPythonNew, call that instead? // TODO: if tp_new != Py_CallPythonNew, call that instead?
new_attr = typeLookup(cls, new_str, &grewrite_args); new_attr = incref(typeLookup(cls, new_str, &grewrite_args));
assert(new_attr); assert(new_attr);
if (!grewrite_args.isSuccessful()) if (!grewrite_args.isSuccessful())
...@@ -847,6 +847,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo ...@@ -847,6 +847,7 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
if (new_attr->cls != function_cls) { if (new_attr->cls != function_cls) {
try { try {
Box* descr_r = processDescriptorOrNull(new_attr, None, cls); Box* descr_r = processDescriptorOrNull(new_attr, None, cls);
// TODO do we need to guard here on the class of new_attr (or that it's a class that can't change classes?)
if (descr_r) { if (descr_r) {
new_attr = descr_r; new_attr = descr_r;
rewrite_args = NULL; rewrite_args = NULL;
......
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