Commit ce9232aa authored by Marius Wachtler's avatar Marius Wachtler

fix deopt

parent c38f6248
...@@ -191,11 +191,15 @@ public: ...@@ -191,11 +191,15 @@ public:
friend struct pyston::ASTInterpreterJitInterface; friend struct pyston::ASTInterpreterJitInterface;
}; };
void ASTInterpreter::addSymbol(InternedString name, Box* value, bool allow_duplicates) { void ASTInterpreter::addSymbol(InternedString name, Box* new_value, bool allow_duplicates) {
assert(getSymVRegMap().count(name)); assert(getSymVRegMap().count(name));
if (!allow_duplicates) Box*& value = vregs[getSymVRegMap()[name]];
assert(vregs[getSymVRegMap()[name]] == NULL); Box* old_value = value;
vregs[getSymVRegMap()[name]] = value; value = incref(new_value);
if (allow_duplicates)
Py_XDECREF(old_value);
else
assert(old_value == NULL);
} }
void ASTInterpreter::setGenerator(Box* gen) { void ASTInterpreter::setGenerator(Box* gen) {
...@@ -223,8 +227,10 @@ void ASTInterpreter::setBoxedLocals(Box* boxedLocals) { ...@@ -223,8 +227,10 @@ void ASTInterpreter::setBoxedLocals(Box* boxedLocals) {
void ASTInterpreter::setFrameInfo(const FrameInfo* frame_info) { void ASTInterpreter::setFrameInfo(const FrameInfo* frame_info) {
Box** vregs = this->frame_info.vregs; Box** vregs = this->frame_info.vregs;
int num_vregs = this->frame_info.num_vregs;
this->frame_info = *frame_info; this->frame_info = *frame_info;
this->frame_info.vregs = vregs; this->frame_info.vregs = vregs;
this->frame_info.num_vregs = num_vregs;
} }
void ASTInterpreter::setGlobals(Box* globals) { void ASTInterpreter::setGlobals(Box* globals) {
...@@ -402,6 +408,7 @@ Box* ASTInterpreter::executeInner(ASTInterpreter& interpreter, CFGBlock* start_b ...@@ -402,6 +408,7 @@ Box* ASTInterpreter::executeInner(ASTInterpreter& interpreter, CFGBlock* start_b
// it will confuse our unwinder! // it will confuse our unwinder!
rtn = interpreter.doOSR(cur_stmt); rtn = interpreter.doOSR(cur_stmt);
} }
Py_XDECREF(v.o);
return rtn; return rtn;
} }
} }
...@@ -857,6 +864,7 @@ Value ASTInterpreter::visit_invoke(AST_Invoke* node) { ...@@ -857,6 +864,7 @@ Value ASTInterpreter::visit_invoke(AST_Invoke* node) {
Value ASTInterpreter::visit_clsAttribute(AST_ClsAttribute* node) { Value ASTInterpreter::visit_clsAttribute(AST_ClsAttribute* node) {
Value obj = visit_expr(node->value); Value obj = visit_expr(node->value);
BoxedString* attr = node->attr.getBox(); BoxedString* attr = node->attr.getBox();
AUTO_DECREF(obj.o);
return Value(getclsattr(obj.o, attr), jit ? jit->emitGetClsAttr(obj, attr) : NULL); return Value(getclsattr(obj.o, attr), jit ? jit->emitGetClsAttr(obj, attr) : NULL);
} }
...@@ -891,8 +899,7 @@ Value ASTInterpreter::visit_langPrimitive(AST_LangPrimitive* node) { ...@@ -891,8 +899,7 @@ Value ASTInterpreter::visit_langPrimitive(AST_LangPrimitive* node) {
assert(ast_str->str_type == AST_Str::STR); assert(ast_str->str_type == AST_Str::STR);
const std::string& name = ast_str->str_data; const std::string& name = ast_str->str_data;
assert(name.size()); assert(name.size());
BoxedString* name_boxed = source_info->parent_module->getStringConstant(name, true); BORROWED(BoxedString*) name_boxed = source_info->parent_module->getStringConstant(name, true);
AUTO_DECREF(name_boxed);
if (jit) if (jit)
v.var = jit->emitImportFrom(module, name_boxed); v.var = jit->emitImportFrom(module, name_boxed);
...@@ -2020,6 +2027,7 @@ extern "C" Box* astInterpretDeoptFromASM(FunctionMetadata* md, AST_expr* after_e ...@@ -2020,6 +2027,7 @@ extern "C" Box* astInterpretDeoptFromASM(FunctionMetadata* md, AST_expr* after_e
auto expr = ast_cast<AST_Expr>(enclosing_stmt); auto expr = ast_cast<AST_Expr>(enclosing_stmt);
RELEASE_ASSERT(expr->value == after_expr, "%p %p", expr->value, after_expr); RELEASE_ASSERT(expr->value == after_expr, "%p %p", expr->value, after_expr);
assert(expr->value == after_expr); assert(expr->value == after_expr);
assert(0 && "check refcounting");
break; break;
} else if (enclosing_stmt->type == AST_TYPE::Invoke) { } else if (enclosing_stmt->type == AST_TYPE::Invoke) {
auto invoke = ast_cast<AST_Invoke>(enclosing_stmt); auto invoke = ast_cast<AST_Invoke>(enclosing_stmt);
...@@ -2059,7 +2067,7 @@ extern "C" Box* astInterpretDeoptFromASM(FunctionMetadata* md, AST_expr* after_e ...@@ -2059,7 +2067,7 @@ extern "C" Box* astInterpretDeoptFromASM(FunctionMetadata* md, AST_expr* after_e
cur_thread_state.frame_info = frame_state.frame_info->back; cur_thread_state.frame_info = frame_state.frame_info->back;
Box* v = ASTInterpreter::execute(interpreter, start_block, starting_statement); Box* v = ASTInterpreter::execute(interpreter, start_block, starting_statement);
return v ? v : None; return v ? v : incref(None);
} }
extern "C" void printExprHelper(Box* obj) { extern "C" void printExprHelper(Box* obj) {
......
...@@ -289,6 +289,7 @@ public: ...@@ -289,6 +289,7 @@ public:
= emitter.getBuilder()->CreateConstInBoundsGEP2_32(var->getValue(), 0, offsetof(Box, cls) / sizeof(void*)); = emitter.getBuilder()->CreateConstInBoundsGEP2_32(var->getValue(), 0, offsetof(Box, cls) / sizeof(void*));
llvm::Value* cls_value = emitter.getBuilder()->CreateLoad(cls_ptr); llvm::Value* cls_value = emitter.getBuilder()->CreateLoad(cls_ptr);
emitter.setType(cls_value, RefType::BORROWED);
assert(cls_value->getType() == g.llvm_class_type_ptr); assert(cls_value->getType() == g.llvm_class_type_ptr);
llvm::Value* rtn = emitter.getBuilder()->CreateICmpEQ( llvm::Value* rtn = emitter.getBuilder()->CreateICmpEQ(
cls_value, emitter.setType(embedRelocatablePtr(cls, g.llvm_class_type_ptr), RefType::BORROWED)); cls_value, emitter.setType(embedRelocatablePtr(cls, g.llvm_class_type_ptr), RefType::BORROWED));
......
...@@ -623,7 +623,9 @@ public: ...@@ -623,7 +623,9 @@ public:
llvm::Value* v llvm::Value* v
= createIC(pp, (void*)pyston::deopt, { embedRelocatablePtr(node, g.llvm_astexpr_type_ptr), node_value }, = createIC(pp, (void*)pyston::deopt, { embedRelocatablePtr(node, g.llvm_astexpr_type_ptr), node_value },
UnwindInfo(current_stmt, NULL)); UnwindInfo(current_stmt, NULL));
return getBuilder()->CreateIntToPtr(v, g.llvm_value_type_ptr); llvm::Value* rtn = getBuilder()->CreateIntToPtr(v, g.llvm_value_type_ptr);
setType(rtn, RefType::OWNED);
return rtn;
} }
void checkAndPropagateCapiException(const UnwindInfo& unw_info, llvm::Value* returned_val, llvm::Value* exc_val, void checkAndPropagateCapiException(const UnwindInfo& unw_info, llvm::Value* returned_val, llvm::Value* exc_val,
...@@ -808,7 +810,8 @@ private: ...@@ -808,7 +810,8 @@ private:
curblock = deopt_bb; curblock = deopt_bb;
emitter.getBuilder()->SetInsertPoint(curblock); emitter.getBuilder()->SetInsertPoint(curblock);
llvm::Value* v = emitter.createDeopt(current_statement, (AST_expr*)node, node_value); llvm::Value* v = emitter.createDeopt(current_statement, (AST_expr*)node, node_value);
emitter.getBuilder()->CreateRet(v); llvm::Instruction* ret_inst = emitter.getBuilder()->CreateRet(v);
irstate->getRefcounts()->refConsumed(v, ret_inst);
curblock = success_bb; curblock = success_bb;
emitter.getBuilder()->SetInsertPoint(curblock); emitter.getBuilder()->SetInsertPoint(curblock);
...@@ -891,7 +894,7 @@ private: ...@@ -891,7 +894,7 @@ private:
// local symbols will not throw. // local symbols will not throw.
emitter.getBuilder()->CreateUnreachable(); emitter.getBuilder()->CreateUnreachable();
exc_type = exc_value = exc_tb = emitter.getNone(); exc_type = exc_value = exc_tb = emitter.getNone();
endBlock(DEAD); // endBlock(DEAD);
} }
// clear this out to signal that we consumed them: // clear this out to signal that we consumed them:
......
...@@ -778,10 +778,8 @@ DeoptState getDeoptState() { ...@@ -778,10 +778,8 @@ DeoptState getDeoptState() {
bool found = false; bool found = false;
unwindPythonStack([&](PythonFrameIteratorImpl* frame_iter) { unwindPythonStack([&](PythonFrameIteratorImpl* frame_iter) {
BoxedDict* d; BoxedDict* d;
BoxedClosure* closure;
CompiledFunction* cf; CompiledFunction* cf;
if (frame_iter->getId().type == PythonFrameId::COMPILED) { if (frame_iter->getId().type == PythonFrameId::COMPILED) {
assert(0 && "check refcounting");
d = new BoxedDict(); d = new BoxedDict();
cf = frame_iter->getCF(); cf = frame_iter->getCF();
...@@ -826,7 +824,7 @@ DeoptState getDeoptState() { ...@@ -826,7 +824,7 @@ DeoptState getDeoptState() {
if (!v) if (!v)
continue; continue;
d->d[p.first.getBox()] = v; d->d[incref(p.first.getBox())] = v;
} }
for (const auto& p : cf->location_map->names) { for (const auto& p : cf->location_map->names) {
......
...@@ -231,9 +231,9 @@ extern "C" void deinitFrame(FrameInfo* frame_info) { ...@@ -231,9 +231,9 @@ extern "C" void deinitFrame(FrameInfo* frame_info) {
} }
assert(frame_info->vregs || frame_info->num_vregs == 0); assert(frame_info->vregs || frame_info->num_vregs == 0);
int num_user_visible_vregs = frame_info->num_vregs; int num_vregs = frame_info->num_vregs;
decrefArray<true>(frame_info->vregs, num_user_visible_vregs); decrefArray<true>(frame_info->vregs, num_vregs);
Py_CLEAR(frame_info->boxedLocals); Py_CLEAR(frame_info->boxedLocals);
...@@ -248,8 +248,8 @@ int frameinfo_traverse(FrameInfo* frame_info, visitproc visit, void* arg) noexce ...@@ -248,8 +248,8 @@ int frameinfo_traverse(FrameInfo* frame_info, visitproc visit, void* arg) noexce
Py_VISIT(frame_info->frame_obj); Py_VISIT(frame_info->frame_obj);
if (frame_info->vregs) { if (frame_info->vregs) {
int num_user_visible_vregs = frame_info->num_vregs; int num_vregs = frame_info->num_vregs;
for (int i = 0; i < num_user_visible_vregs; i++) { for (int i = 0; i < num_vregs; i++) {
Py_VISIT(frame_info->vregs[i]); Py_VISIT(frame_info->vregs[i]);
} }
} }
......
...@@ -136,9 +136,7 @@ extern "C" Box* deopt(AST_expr* expr, Box* value) { ...@@ -136,9 +136,7 @@ extern "C" Box* deopt(AST_expr* expr, Box* value) {
deopt_state.frame_state.frame_info->exc.value = NULL; deopt_state.frame_state.frame_info->exc.value = NULL;
} }
assert(0 && "check refcounting");
AUTO_DECREF(deopt_state.frame_state.locals); AUTO_DECREF(deopt_state.frame_state.locals);
return astInterpretDeopt(deopt_state.cf->md, expr, deopt_state.current_stmt, value, deopt_state.frame_state); return astInterpretDeopt(deopt_state.cf->md, expr, deopt_state.current_stmt, value, deopt_state.frame_state);
} }
......
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