Commit 584f94a8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Lots more annotations

parent d3c92a78
...@@ -513,6 +513,12 @@ void RewriterVar::xdecref() { ...@@ -513,6 +513,12 @@ void RewriterVar::xdecref() {
} }
void Rewriter::_incref(RewriterVar* var) { void Rewriter::_incref(RewriterVar* var) {
// Small optimization: skip any time we want to do xincref(NULL)
if (var->isConstant() && var->constant_value == 0) {
assert(var->nullable);
return;
}
assert(!var->nullable); assert(!var->nullable);
//assembler->trap(); //assembler->trap();
//auto reg = var->getInReg(); //auto reg = var->getInReg();
......
...@@ -314,6 +314,7 @@ public: ...@@ -314,6 +314,7 @@ public:
#ifndef NDEBUG #ifndef NDEBUG
// XXX: for testing, reset these on deallocation so that we will see the next time they get set. // XXX: for testing, reset these on deallocation so that we will see the next time they get set.
~RewriterVar() { ~RewriterVar() {
rewriter = (Rewriter*)-1;
reftype = (RefType)-1; reftype = (RefType)-1;
num_refs_consumed = -11; num_refs_consumed = -11;
} }
......
...@@ -256,6 +256,7 @@ public: ...@@ -256,6 +256,7 @@ public:
void delattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr) override { void delattr(IREmitter& emitter, const OpInfo& info, ConcreteCompilerVariable* var, BoxedString* attr) override {
llvm::Constant* ptr = embedRelocatablePtr(attr, g.llvm_boxedstring_type_ptr); llvm::Constant* ptr = embedRelocatablePtr(attr, g.llvm_boxedstring_type_ptr);
emitter.setType(ptr, RefType::BORROWED);
// TODO // TODO
// bool do_patchpoint = ENABLE_ICDELATTRS; // bool do_patchpoint = ENABLE_ICDELATTRS;
...@@ -283,8 +284,8 @@ public: ...@@ -283,8 +284,8 @@ public:
llvm::Value* cls_value = emitter.getBuilder()->CreateLoad(cls_ptr); llvm::Value* cls_value = emitter.getBuilder()->CreateLoad(cls_ptr);
assert(cls_value->getType() == g.llvm_class_type_ptr); assert(cls_value->getType() == g.llvm_class_type_ptr);
llvm::Value* rtn llvm::Value* rtn = emitter.getBuilder()->CreateICmpEQ(
= emitter.getBuilder()->CreateICmpEQ(cls_value, embedRelocatablePtr(cls, g.llvm_class_type_ptr)); cls_value, emitter.setType(embedRelocatablePtr(cls, g.llvm_class_type_ptr), RefType::BORROWED));
return rtn; return rtn;
} }
...@@ -1604,12 +1605,14 @@ CompilerVariable* makeUnboxedFloat(IREmitter& emitter, llvm::Value* v) { ...@@ -1604,12 +1605,14 @@ CompilerVariable* makeUnboxedFloat(IREmitter& emitter, llvm::Value* v) {
} }
ConcreteCompilerVariable* makeLong(Box* v) { ConcreteCompilerVariable* makeLong(IREmitter& emitter, Box* v) {
return new ConcreteCompilerVariable(LONG, embedRelocatablePtr(v, g.llvm_value_type_ptr)); return new ConcreteCompilerVariable(
LONG, emitter.setType(embedRelocatablePtr(v, g.llvm_value_type_ptr), RefType::BORROWED));
} }
ConcreteCompilerVariable* makePureImaginary(Box* v) { ConcreteCompilerVariable* makePureImaginary(IREmitter& emitter, Box* v) {
return new ConcreteCompilerVariable(BOXED_COMPLEX, embedRelocatablePtr(v, g.llvm_value_type_ptr)); return new ConcreteCompilerVariable(
BOXED_COMPLEX, emitter.setType(embedRelocatablePtr(v, g.llvm_value_type_ptr), RefType::BORROWED));
} }
class KnownClassobjType : public ValuedCompilerType<BoxedClass*> { class KnownClassobjType : public ValuedCompilerType<BoxedClass*> {
...@@ -1742,11 +1745,13 @@ public: ...@@ -1742,11 +1745,13 @@ public:
ASSERT(rtattr, "%s.%s", debugName().c_str(), attr->data()); ASSERT(rtattr, "%s.%s", debugName().c_str(), attr->data());
if (rtattr->cls == function_cls) { if (rtattr->cls == function_cls) {
CompilerVariable* clattr = new ConcreteCompilerVariable( CompilerVariable* clattr = new ConcreteCompilerVariable(
typeFromClass(function_cls), embedRelocatablePtr(rtattr, g.llvm_value_type_ptr)); typeFromClass(function_cls),
emitter.setType(embedRelocatablePtr(rtattr, g.llvm_value_type_ptr), RefType::BORROWED));
return InstanceMethodType::makeIM( return InstanceMethodType::makeIM(
var, clattr, var, clattr,
new ConcreteCompilerVariable(UNKNOWN, embedRelocatablePtr(cls, g.llvm_value_type_ptr))); new ConcreteCompilerVariable(
UNKNOWN, emitter.setType(embedRelocatablePtr(cls, g.llvm_value_type_ptr), RefType::BORROWED)));
} }
} }
...@@ -1895,6 +1900,7 @@ public: ...@@ -1895,6 +1900,7 @@ public:
llvm_value = embedRelocatablePtr(value, g.llvm_value_type_ptr); llvm_value = embedRelocatablePtr(value, g.llvm_value_type_ptr);
else else
llvm_value = getNullPtr(g.llvm_value_type_ptr); llvm_value = getNullPtr(g.llvm_value_type_ptr);
emitter.setType(llvm_value, RefType::BORROWED);
new_args.push_back(new ConcreteCompilerVariable(UNKNOWN, llvm_value)); new_args.push_back(new ConcreteCompilerVariable(UNKNOWN, llvm_value));
} }
...@@ -2465,6 +2471,7 @@ public: ...@@ -2465,6 +2471,7 @@ public:
} }
llvm::Value* rtn = emitter.getBuilder()->CreateCall2(g.funcs.createTuple, nelts, scratch); llvm::Value* rtn = emitter.getBuilder()->CreateCall2(g.funcs.createTuple, nelts, scratch);
emitter.setType(rtn, RefType::OWNED);
return new ConcreteCompilerVariable(other_type, rtn); return new ConcreteCompilerVariable(other_type, rtn);
} }
......
...@@ -353,8 +353,8 @@ CompilerVariable* makeUnboxedFloat(IREmitter&, ConcreteCompilerVariable*); ...@@ -353,8 +353,8 @@ CompilerVariable* makeUnboxedFloat(IREmitter&, ConcreteCompilerVariable*);
CompilerVariable* makeUnboxedFloat(IREmitter&, llvm::Value*); CompilerVariable* makeUnboxedFloat(IREmitter&, llvm::Value*);
ConcreteCompilerVariable* makeBool(bool); ConcreteCompilerVariable* makeBool(bool);
ConcreteCompilerVariable* makeLong(Box*); ConcreteCompilerVariable* makeLong(IREmitter&, Box*);
ConcreteCompilerVariable* makePureImaginary(Box*); ConcreteCompilerVariable* makePureImaginary(IREmitter&, Box*);
CompilerVariable* makeStr(BoxedString*); CompilerVariable* makeStr(BoxedString*);
CompilerVariable* makeUnicode(Box*); CompilerVariable* makeUnicode(Box*);
......
...@@ -218,6 +218,7 @@ llvm::Value* IRGenState::getFrameInfoVar() { ...@@ -218,6 +218,7 @@ llvm::Value* IRGenState::getFrameInfoVar() {
// frame_info.boxedLocals = createDict() // frame_info.boxedLocals = createDict()
// (Since this can call into the GC, we have to initialize it to NULL first as we did above.) // (Since this can call into the GC, we have to initialize it to NULL first as we did above.)
this->boxed_locals = builder.CreateCall(g.funcs.createDict); this->boxed_locals = builder.CreateCall(g.funcs.createDict);
getRefcounts()->setType(this->boxed_locals, RefType::OWNED);
builder.CreateStore(this->boxed_locals, boxed_locals_gep); builder.CreateStore(this->boxed_locals, boxed_locals_gep);
} }
...@@ -782,6 +783,7 @@ private: ...@@ -782,6 +783,7 @@ private:
llvm::Value* name_arg llvm::Value* name_arg
= embedRelocatablePtr(irstate->getSourceInfo()->parent_module->getStringConstant(name, true), = embedRelocatablePtr(irstate->getSourceInfo()->parent_module->getStringConstant(name, true),
g.llvm_boxedstring_type_ptr); g.llvm_boxedstring_type_ptr);
emitter.setType(name_arg, RefType::BORROWED);
llvm::Value* r llvm::Value* r
= emitter.createCall2(unw_info, g.funcs.importFrom, converted_module->getValue(), name_arg); = emitter.createCall2(unw_info, g.funcs.importFrom, converted_module->getValue(), name_arg);
...@@ -819,10 +821,11 @@ private: ...@@ -819,10 +821,11 @@ private:
assert(ast_str->str_type == AST_Str::STR); assert(ast_str->str_type == AST_Str::STR);
const std::string& module_name = ast_str->str_data; const std::string& module_name = ast_str->str_data;
llvm::Value* imported = emitter.createCall(unw_info, g.funcs.import, llvm::Value* imported = emitter.createCall(
{ getConstantInt(level, g.i32), converted_froms->getValue(), unw_info, g.funcs.import,
embedRelocatablePtr(module_name.c_str(), g.i8_ptr), { getConstantInt(level, g.i32), converted_froms->getValue(),
getConstantInt(module_name.size(), g.i64) }); emitter.setType(embedRelocatablePtr(module_name.c_str(), g.i8_ptr), RefType::BORROWED),
getConstantInt(module_name.size(), g.i64) });
ConcreteCompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, imported); ConcreteCompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, imported);
return v; return v;
} }
...@@ -1085,8 +1088,8 @@ private: ...@@ -1085,8 +1088,8 @@ private:
ConcreteCompilerVariable* getEllipsis() { ConcreteCompilerVariable* getEllipsis() {
llvm::Constant* ellipsis = embedRelocatablePtr(Ellipsis, g.llvm_value_type_ptr, "cEllipsis"); llvm::Constant* ellipsis = embedRelocatablePtr(Ellipsis, g.llvm_value_type_ptr, "cEllipsis");
auto ellipsis_cls = Ellipsis->cls;
emitter.setType(ellipsis, RefType::BORROWED); emitter.setType(ellipsis, RefType::BORROWED);
auto ellipsis_cls = Ellipsis->cls;
return new ConcreteCompilerVariable(typeFromClass(ellipsis_cls), ellipsis); return new ConcreteCompilerVariable(typeFromClass(ellipsis_cls), ellipsis);
} }
...@@ -1185,6 +1188,7 @@ private: ...@@ -1185,6 +1188,7 @@ private:
} else if (vst == ScopeInfo::VarScopeType::NAME) { } else if (vst == ScopeInfo::VarScopeType::NAME) {
llvm::Value* boxedLocals = irstate->getBoxedLocalsVar(); llvm::Value* boxedLocals = irstate->getBoxedLocalsVar();
llvm::Value* attr = embedRelocatablePtr(node->id.getBox(), g.llvm_boxedstring_type_ptr); llvm::Value* attr = embedRelocatablePtr(node->id.getBox(), g.llvm_boxedstring_type_ptr);
emitter.setType(attr, RefType::BORROWED);
llvm::Value* module = irstate->getGlobals(); llvm::Value* module = irstate->getGlobals();
llvm::Value* r = emitter.createCall3(unw_info, g.funcs.boxedLocalsGet, boxedLocals, attr, module); llvm::Value* r = emitter.createCall3(unw_info, g.funcs.boxedLocalsGet, boxedLocals, attr, module);
return new ConcreteCompilerVariable(UNKNOWN, r); return new ConcreteCompilerVariable(UNKNOWN, r);
...@@ -1196,7 +1200,8 @@ private: ...@@ -1196,7 +1200,8 @@ private:
llvm::CallSite call = emitter.createCall( llvm::CallSite call = emitter.createCall(
unw_info, g.funcs.assertNameDefined, unw_info, g.funcs.assertNameDefined,
{ getConstantInt(0, g.i1), embedRelocatablePtr(node->id.c_str(), g.i8_ptr), { getConstantInt(0, g.i1), embedRelocatablePtr(node->id.c_str(), g.i8_ptr),
embedRelocatablePtr(UnboundLocalError, g.llvm_class_type_ptr), getConstantInt(true, g.i1) }); emitter.setType(embedRelocatablePtr(UnboundLocalError, g.llvm_class_type_ptr), RefType::BORROWED),
getConstantInt(true, g.i1) });
call.setDoesNotReturn(); call.setDoesNotReturn();
return undefVariable(); return undefVariable();
} }
...@@ -1209,7 +1214,8 @@ private: ...@@ -1209,7 +1214,8 @@ private:
emitter.createCall( emitter.createCall(
unw_info, g.funcs.assertNameDefined, unw_info, g.funcs.assertNameDefined,
{ i1FromBool(emitter, is_defined_var), embedRelocatablePtr(node->id.c_str(), g.i8_ptr), { i1FromBool(emitter, is_defined_var), embedRelocatablePtr(node->id.c_str(), g.i8_ptr),
embedRelocatablePtr(UnboundLocalError, g.llvm_class_type_ptr), getConstantInt(true, g.i1) }); emitter.setType(embedRelocatablePtr(UnboundLocalError, g.llvm_class_type_ptr), RefType::BORROWED),
getConstantInt(true, g.i1) });
// At this point we know the name must be defined (otherwise the assert would have fired): // At this point we know the name must be defined (otherwise the assert would have fired):
_popFake(defined_name); _popFake(defined_name);
...@@ -1230,9 +1236,10 @@ private: ...@@ -1230,9 +1236,10 @@ private:
} else if (node->num_type == AST_Num::FLOAT) { } else if (node->num_type == AST_Num::FLOAT) {
return makeFloat(node->n_float); return makeFloat(node->n_float);
} else if (node->num_type == AST_Num::COMPLEX) { } else if (node->num_type == AST_Num::COMPLEX) {
return makePureImaginary(irstate->getSourceInfo()->parent_module->getPureImaginaryConstant(node->n_float)); return makePureImaginary(emitter,
irstate->getSourceInfo()->parent_module->getPureImaginaryConstant(node->n_float));
} else { } else {
return makeLong(irstate->getSourceInfo()->parent_module->getLongConstant(node->n_long)); return makeLong(emitter, irstate->getSourceInfo()->parent_module->getLongConstant(node->n_long));
} }
} }
...@@ -1299,6 +1306,7 @@ private: ...@@ -1299,6 +1306,7 @@ private:
} else if (node->str_type == AST_Str::UNICODE) { } else if (node->str_type == AST_Str::UNICODE) {
llvm::Value* rtn = embedRelocatablePtr( llvm::Value* rtn = embedRelocatablePtr(
irstate->getSourceInfo()->parent_module->getUnicodeConstant(node->str_data), g.llvm_value_type_ptr); irstate->getSourceInfo()->parent_module->getUnicodeConstant(node->str_data), g.llvm_value_type_ptr);
emitter.setType(rtn, RefType::BORROWED);
return new ConcreteCompilerVariable(typeFromClass(unicode_cls), rtn); return new ConcreteCompilerVariable(typeFromClass(unicode_cls), rtn);
} else { } else {
...@@ -1404,8 +1412,10 @@ private: ...@@ -1404,8 +1412,10 @@ private:
ConcreteCompilerVariable* converted_attr_dict = attr_dict->makeConverted(emitter, attr_dict->getBoxType()); ConcreteCompilerVariable* converted_attr_dict = attr_dict->makeConverted(emitter, attr_dict->getBoxType());
llvm::Value* classobj = emitter.createCall3( llvm::Value* classobj = emitter.createCall3(
unw_info, g.funcs.createUserClass, embedRelocatablePtr(node->name.getBox(), g.llvm_boxedstring_type_ptr), unw_info, g.funcs.createUserClass,
emitter.setType(embedRelocatablePtr(node->name.getBox(), g.llvm_boxedstring_type_ptr), RefType::BORROWED),
bases_tuple->getValue(), converted_attr_dict->getValue()); bases_tuple->getValue(), converted_attr_dict->getValue());
emitter.setType(classobj, RefType::OWNED);
// Note: createuserClass is free to manufacture non-class objects // Note: createuserClass is free to manufacture non-class objects
CompilerVariable* cls = new ConcreteCompilerVariable(UNKNOWN, classobj); CompilerVariable* cls = new ConcreteCompilerVariable(UNKNOWN, classobj);
...@@ -1703,6 +1713,7 @@ private: ...@@ -1703,6 +1713,7 @@ private:
// TODO inefficient // TODO inefficient
llvm::Value* boxedLocals = irstate->getBoxedLocalsVar(); llvm::Value* boxedLocals = irstate->getBoxedLocalsVar();
llvm::Value* attr = embedRelocatablePtr(name.getBox(), g.llvm_boxedstring_type_ptr); llvm::Value* attr = embedRelocatablePtr(name.getBox(), g.llvm_boxedstring_type_ptr);
emitter.setType(attr, RefType::BORROWED);
emitter.createCall3(unw_info, g.funcs.boxedLocalsSet, boxedLocals, attr, emitter.createCall3(unw_info, g.funcs.boxedLocalsSet, boxedLocals, attr,
val->makeConverted(emitter, UNKNOWN)->getValue()); val->makeConverted(emitter, UNKNOWN)->getValue());
} else { } else {
...@@ -1888,13 +1899,15 @@ private: ...@@ -1888,13 +1899,15 @@ private:
if (vst == ScopeInfo::VarScopeType::GLOBAL) { if (vst == ScopeInfo::VarScopeType::GLOBAL) {
// Can't use delattr since the errors are different: // Can't use delattr since the errors are different:
emitter.createCall2(unw_info, g.funcs.delGlobal, irstate->getGlobals(), emitter.createCall2(unw_info, g.funcs.delGlobal, irstate->getGlobals(),
embedRelocatablePtr(target->id.getBox(), g.llvm_boxedstring_type_ptr)); emitter.setType(embedRelocatablePtr(target->id.getBox(), g.llvm_boxedstring_type_ptr),
RefType::BORROWED));
return; return;
} }
if (vst == ScopeInfo::VarScopeType::NAME) { if (vst == ScopeInfo::VarScopeType::NAME) {
llvm::Value* boxedLocals = irstate->getBoxedLocalsVar(); llvm::Value* boxedLocals = irstate->getBoxedLocalsVar();
llvm::Value* attr = embedRelocatablePtr(target->id.getBox(), g.llvm_boxedstring_type_ptr); llvm::Value* attr = embedRelocatablePtr(target->id.getBox(), g.llvm_boxedstring_type_ptr);
emitter.setType(attr, RefType::BORROWED);
emitter.createCall2(unw_info, g.funcs.boxedLocalsDel, boxedLocals, attr); emitter.createCall2(unw_info, g.funcs.boxedLocalsDel, boxedLocals, attr);
return; return;
} }
...@@ -1904,11 +1917,11 @@ private: ...@@ -1904,11 +1917,11 @@ private:
assert(vst == ScopeInfo::VarScopeType::FAST); assert(vst == ScopeInfo::VarScopeType::FAST);
if (symbol_table.count(target->id) == 0) { if (symbol_table.count(target->id) == 0) {
llvm::CallSite call llvm::CallSite call = emitter.createCall(
= emitter.createCall(unw_info, g.funcs.assertNameDefined, unw_info, g.funcs.assertNameDefined,
{ getConstantInt(0, g.i1), embedConstantPtr(target->id.c_str(), g.i8_ptr), { getConstantInt(0, g.i1), embedConstantPtr(target->id.c_str(), g.i8_ptr),
embedRelocatablePtr(NameError, g.llvm_class_type_ptr), emitter.setType(embedRelocatablePtr(NameError, g.llvm_class_type_ptr), RefType::BORROWED),
getConstantInt(true /*local_error_msg*/, g.i1) }); getConstantInt(true /*local_error_msg*/, g.i1) });
call.setDoesNotReturn(); call.setDoesNotReturn();
return; return;
} }
...@@ -1917,10 +1930,11 @@ private: ...@@ -1917,10 +1930,11 @@ private:
ConcreteCompilerVariable* is_defined_var = static_cast<ConcreteCompilerVariable*>(_getFake(defined_name, true)); ConcreteCompilerVariable* is_defined_var = static_cast<ConcreteCompilerVariable*>(_getFake(defined_name, true));
if (is_defined_var) { if (is_defined_var) {
emitter.createCall(unw_info, g.funcs.assertNameDefined, emitter.createCall(
{ i1FromBool(emitter, is_defined_var), embedConstantPtr(target->id.c_str(), g.i8_ptr), unw_info, g.funcs.assertNameDefined,
embedRelocatablePtr(NameError, g.llvm_class_type_ptr), { i1FromBool(emitter, is_defined_var), embedConstantPtr(target->id.c_str(), g.i8_ptr),
getConstantInt(true /*local_error_msg*/, g.i1) }); emitter.setType(embedRelocatablePtr(NameError, g.llvm_class_type_ptr), RefType::BORROWED),
getConstantInt(true /*local_error_msg*/, g.i1) });
_popFake(defined_name); _popFake(defined_name);
} }
...@@ -2244,7 +2258,7 @@ private: ...@@ -2244,7 +2258,7 @@ private:
ConcreteCompilerVariable* converted = v->makeConverted(emitter, v->getBoxType()); ConcreteCompilerVariable* converted = v->makeConverted(emitter, v->getBoxType());
args.push_back(converted->getValue()); args.push_back(converted->getValue());
} else { } else {
args.push_back(embedRelocatablePtr(None, g.llvm_value_type_ptr, "cNone")); args.push_back(emitter.getNone()->getValue());
} }
} }
......
...@@ -104,6 +104,11 @@ void addIncrefs(llvm::Value* v, bool nullable, int num_refs, llvm::Instruction* ...@@ -104,6 +104,11 @@ void addIncrefs(llvm::Value* v, bool nullable, int num_refs, llvm::Instruction*
llvm::IRBuilder<true> builder(incref_pt); llvm::IRBuilder<true> builder(incref_pt);
// Deal with subtypes of Box:
while (v->getType() != g.llvm_value_type_ptr) {
v = builder.CreateConstInBoundsGEP2_32(v, 0, 0);
}
if (nullable) { if (nullable) {
cur_block = incref_pt->getParent(); cur_block = incref_pt->getParent();
continue_block = cur_block->splitBasicBlock(incref_pt); continue_block = cur_block->splitBasicBlock(incref_pt);
...@@ -148,6 +153,12 @@ void addDecrefs(llvm::Value* v, bool nullable, int num_refs, llvm::Instruction* ...@@ -148,6 +153,12 @@ void addDecrefs(llvm::Value* v, bool nullable, int num_refs, llvm::Instruction*
assert(num_refs > 0); assert(num_refs > 0);
llvm::IRBuilder<true> builder(decref_pt); llvm::IRBuilder<true> builder(decref_pt);
// Deal with subtypes of Box:
while (v->getType() != g.llvm_value_type_ptr) {
v = builder.CreateConstInBoundsGEP2_32(v, 0, 0);
}
#ifdef Py_REF_DEBUG #ifdef Py_REF_DEBUG
auto reftotal_gv = g.cur_module->getOrInsertGlobal("_Py_RefTotal", g.i64); auto reftotal_gv = g.cur_module->getOrInsertGlobal("_Py_RefTotal", g.i64);
auto reftotal = new llvm::LoadInst(reftotal_gv, "", decref_pt); auto reftotal = new llvm::LoadInst(reftotal_gv, "", decref_pt);
...@@ -671,8 +682,7 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) { ...@@ -671,8 +682,7 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
if (VERBOSITY()) { if (VERBOSITY()) {
fprintf(stderr, "After refcounts:\n"); fprintf(stderr, "After refcounts:\n");
fprintf(stderr, "\033[35m"); fprintf(stderr, "\033[35m");
f->dump(); dumpPrettyIR(f);
//dumpPrettyIR(f);
fprintf(stderr, "\033[0m"); fprintf(stderr, "\033[0m");
} }
} }
......
...@@ -79,7 +79,7 @@ enum class RefType { ...@@ -79,7 +79,7 @@ enum class RefType {
UNKNOWN UNKNOWN
#ifndef NDEBUG #ifndef NDEBUG
// Set this to non-zero to make it possible for the debugger to // Set this to non-zero to make it possible for the debugger to
= 0 = 1
#endif #endif
, ,
OWNED, OWNED,
......
...@@ -1868,34 +1868,40 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa ...@@ -1868,34 +1868,40 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa
if (flags == METH_VARARGS) { if (flags == METH_VARARGS) {
rtn = (Box*)func(self->passthrough, arg1); rtn = (Box*)func(self->passthrough, arg1);
if (rewrite_args) if (rewrite_args)
rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1); rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1)
->setType(RefType::OWNED);
} else if (flags == (METH_VARARGS | METH_KEYWORDS)) { } else if (flags == (METH_VARARGS | METH_KEYWORDS)) {
rtn = (Box*)((PyCFunctionWithKeywords)func)(self->passthrough, arg1, arg2); rtn = (Box*)((PyCFunctionWithKeywords)func)(self->passthrough, arg1, arg2);
if (rewrite_args) if (rewrite_args)
rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1, rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1,
rewrite_args->arg2); rewrite_args->arg2)->setType(RefType::OWNED);
} else if (flags == METH_NOARGS) { } else if (flags == METH_NOARGS) {
rtn = (Box*)func(self->passthrough, NULL); rtn = (Box*)func(self->passthrough, NULL);
if (rewrite_args) if (rewrite_args)
rewrite_args->out_rtn = rewrite_args->rewriter->call( rewrite_args->out_rtn
true, (void*)func, r_passthrough, rewrite_args->rewriter->loadConst(0, Location::forArg(1))); = rewrite_args->rewriter->call(true, (void*)func, r_passthrough,
rewrite_args->rewriter->loadConst(0, Location::forArg(1)))
->setType(RefType::OWNED);
} else if (flags == METH_O) { } else if (flags == METH_O) {
rtn = (Box*)func(self->passthrough, arg1); rtn = (Box*)func(self->passthrough, arg1);
if (rewrite_args) if (rewrite_args)
rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1); rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1)
->setType(RefType::OWNED);
} else if ((flags & ~(METH_O3 | METH_D3)) == 0) { } else if ((flags & ~(METH_O3 | METH_D3)) == 0) {
assert(paramspec.totalReceived() <= 3); // would need to pass through oargs assert(paramspec.totalReceived() <= 3); // would need to pass through oargs
rtn = ((Box * (*)(Box*, Box*, Box*, Box*))func)(self->passthrough, arg1, arg2, arg3); rtn = ((Box * (*)(Box*, Box*, Box*, Box*))func)(self->passthrough, arg1, arg2, arg3);
if (rewrite_args) { if (rewrite_args) {
if (paramspec.totalReceived() == 1) if (paramspec.totalReceived() == 1)
rewrite_args->out_rtn
= rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1);
else if (paramspec.totalReceived() == 2)
rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->out_rtn = rewrite_args->rewriter->call(true, (void*)func, r_passthrough,
rewrite_args->arg1, rewrite_args->arg2); rewrite_args->arg1)->setType(RefType::OWNED);
else if (paramspec.totalReceived() == 2)
rewrite_args->out_rtn
= rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1,
rewrite_args->arg2)->setType(RefType::OWNED);
else if (paramspec.totalReceived() == 3) else if (paramspec.totalReceived() == 3)
rewrite_args->out_rtn = rewrite_args->rewriter->call( rewrite_args->out_rtn
true, (void*)func, r_passthrough, rewrite_args->arg1, rewrite_args->arg2, rewrite_args->arg3); = rewrite_args->rewriter->call(true, (void*)func, r_passthrough, rewrite_args->arg1,
rewrite_args->arg2, rewrite_args->arg3)->setType(RefType::OWNED);
else else
abort(); abort();
} }
......
...@@ -1248,9 +1248,9 @@ void Box::setattr(BoxedString* attr, BORROWED(Box*) val, SetattrRewriteArgs* rew ...@@ -1248,9 +1248,9 @@ void Box::setattr(BoxedString* attr, BORROWED(Box*) val, SetattrRewriteArgs* rew
// will tell the auto-refcount system to decref it. // will tell the auto-refcount system to decref it.
r_hattrs->getAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs)) r_hattrs->getAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs))
->setType(RefType::OWNED); ->setType(RefType::OWNED);
// TODO make this stealing
r_hattrs->setAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs), r_hattrs->setAttr(offset * sizeof(Box*) + offsetof(HCAttrs::AttrList, attrs),
rewrite_args->attrval); rewrite_args->attrval);
rewrite_args->attrval->refConsumed();
rewrite_args->out_success = true; rewrite_args->out_success = true;
} }
...@@ -2591,7 +2591,9 @@ template <ExceptionStyle S> Box* _getattrEntry(Box* obj, BoxedString* attr, void ...@@ -2591,7 +2591,9 @@ template <ExceptionStyle S> Box* _getattrEntry(Box* obj, BoxedString* attr, void
if (attr->interned_state == SSTATE_INTERNED_IMMORTAL) { if (attr->interned_state == SSTATE_INTERNED_IMMORTAL) {
if (return_convention == ReturnConvention::NO_RETURN) { if (return_convention == ReturnConvention::NO_RETURN) {
assert(!rtn); assert(!rtn);
rtn = rewriter->loadConst(0, Location::forArg(1)); rtn = rewriter->loadConst(0, Location::forArg(1))
->setType(RefType::BORROWED)
->setNullable(true);
} }
rewriter->call(true, (void*)NoexcHelper::call, rtn, rewriter->getArg(0), rewriter->call(true, (void*)NoexcHelper::call, rtn, rewriter->getArg(0),
rewriter->loadConst((intptr_t)attr, Location::forArg(2))); rewriter->loadConst((intptr_t)attr, Location::forArg(2)));
...@@ -2770,10 +2772,8 @@ void setattrGeneric(Box* obj, BoxedString* attr, STOLEN(Box*) val, SetattrRewrit ...@@ -2770,10 +2772,8 @@ void setattrGeneric(Box* obj, BoxedString* attr, STOLEN(Box*) val, SetattrRewrit
raiseAttributeError(obj, attr->s()); raiseAttributeError(obj, attr->s());
} }
// TODO: make setattr() stealing // TODO: make Box::setattr() stealing
obj->setattr(attr, val, rewrite_args); obj->setattr(attr, val, rewrite_args);
if (rewrite_args)
rewrite_args->attrval->refConsumed();
Py_DECREF(val); Py_DECREF(val);
} }
...@@ -3798,7 +3798,7 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa ...@@ -3798,7 +3798,7 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
for (int i = 0; i < num_output_args - 3; i++) { for (int i = 0; i < num_output_args - 3; i++) {
rewrite_args->args->getAttr(i * sizeof(Box*)) rewrite_args->args->getAttr(i * sizeof(Box*))
->setType(RefType::BORROWED) ->setType(RefType::BORROWED)
->setNullable(true) ->setNullable(argspec.has_kwargs)
->refConsumed(); ->refConsumed();
} }
} }
...@@ -6782,6 +6782,7 @@ extern "C" void setGlobal(Box* globals, BoxedString* name, STOLEN(Box*) value) { ...@@ -6782,6 +6782,7 @@ extern "C" void setGlobal(Box* globals, BoxedString* name, STOLEN(Box*) value) {
setattr(static_cast<BoxedModule*>(globals), name, value); setattr(static_cast<BoxedModule*>(globals), name, value);
} else { } else {
RELEASE_ASSERT(globals->cls == dict_cls, "%s", globals->cls->tp_name); RELEASE_ASSERT(globals->cls == dict_cls, "%s", globals->cls->tp_name);
assert(0 && "check refcounting");
static_cast<BoxedDict*>(globals)->d[name] = value; static_cast<BoxedDict*>(globals)->d[name] = value;
} }
} }
......
...@@ -1108,6 +1108,10 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo ...@@ -1108,6 +1108,10 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
throw e; throw e;
} }
AUTO_XDECREF(made);
AUTO_XDECREF(arg2);
AUTO_XDECREF(arg3);
if (!rewrite_success) if (!rewrite_success)
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