Commit a9832bf5 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Lots more fixes

parent 30d4579b
...@@ -640,7 +640,6 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l ...@@ -640,7 +640,6 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l
assert(llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>(func->getType())->getElementType()) assert(llvm::cast<llvm::FunctionType>(llvm::cast<llvm::PointerType>(func->getType())->getElementType())
->getReturnType() == g.llvm_value_type_ptr); ->getReturnType() == g.llvm_value_type_ptr);
rtn = emitter.getBuilder()->CreateIntToPtr(uncasted, g.llvm_value_type_ptr); rtn = emitter.getBuilder()->CreateIntToPtr(uncasted, g.llvm_value_type_ptr);
emitter.setType(rtn, RefType::OWNED);
} else { } else {
// printf("\n"); // printf("\n");
// func->dump(); // func->dump();
...@@ -651,9 +650,10 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l ...@@ -651,9 +650,10 @@ static ConcreteCompilerVariable* _call(IREmitter& emitter, const OpInfo& info, l
// printf("%ld %ld\n", llvm_args.size(), args.size()); // printf("%ld %ld\n", llvm_args.size(), args.size());
// printf("\n"); // printf("\n");
rtn = emitter.createCall(info.unw_info, func, llvm_args, target_exception_style); rtn = emitter.createCall(info.unw_info, func, llvm_args, target_exception_style);
emitter.setType(rtn, RefType::OWNED);
} }
if (rtn_type->getBoxType() == rtn_type)
emitter.setType(rtn, RefType::OWNED);
assert(rtn->getType() == rtn_type->llvmType()); assert(rtn->getType() == rtn_type->llvmType());
if (target_exception_style == CAPI) { if (target_exception_style == CAPI) {
......
...@@ -523,6 +523,8 @@ public: ...@@ -523,6 +523,8 @@ public:
} }
llvm::Value* setType(llvm::Value* v, RefType reftype) { llvm::Value* setType(llvm::Value* v, RefType reftype) {
assert(llvm::isa<PointerType>(v->getType()));
irstate->getRefcounts()->setType(v, reftype); irstate->getRefcounts()->setType(v, reftype);
return v; return v;
} }
...@@ -731,10 +733,16 @@ private: ...@@ -731,10 +733,16 @@ private:
= emitter.getBuilder()->CreatePHI(g.llvm_value_type_ptr, incoming_exc_state.size()); = emitter.getBuilder()->CreatePHI(g.llvm_value_type_ptr, incoming_exc_state.size());
llvm::PHINode* phi_exc_tb llvm::PHINode* phi_exc_tb
= emitter.getBuilder()->CreatePHI(g.llvm_value_type_ptr, incoming_exc_state.size()); = emitter.getBuilder()->CreatePHI(g.llvm_value_type_ptr, incoming_exc_state.size());
emitter.setType(phi_exc_type, RefType::OWNED);
emitter.setType(phi_exc_value, RefType::OWNED);
emitter.setType(phi_exc_tb, RefType::OWNED);
for (auto e : this->incoming_exc_state) { for (auto e : this->incoming_exc_state) {
phi_exc_type->addIncoming(e.exc_type->getValue(), e.from_block); phi_exc_type->addIncoming(e.exc_type->getValue(), e.from_block);
phi_exc_value->addIncoming(e.exc_value->getValue(), e.from_block); phi_exc_value->addIncoming(e.exc_value->getValue(), e.from_block);
phi_exc_tb->addIncoming(e.exc_tb->getValue(), e.from_block); phi_exc_tb->addIncoming(e.exc_tb->getValue(), e.from_block);
emitter.refConsumed(e.exc_type->getValue(), e.from_block->getTerminator());
emitter.refConsumed(e.exc_value->getValue(), e.from_block->getTerminator());
emitter.refConsumed(e.exc_tb->getValue(), e.from_block->getTerminator());
} }
exc_type = new ConcreteCompilerVariable(UNKNOWN, phi_exc_type); exc_type = new ConcreteCompilerVariable(UNKNOWN, phi_exc_type);
exc_value = new ConcreteCompilerVariable(UNKNOWN, phi_exc_value); exc_value = new ConcreteCompilerVariable(UNKNOWN, phi_exc_value);
...@@ -786,6 +794,7 @@ private: ...@@ -786,6 +794,7 @@ private:
emitter.setType(name_arg, RefType::BORROWED); 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);
emitter.setType(r, RefType::OWNED);
CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r); CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r);
return v; return v;
...@@ -802,6 +811,7 @@ private: ...@@ -802,6 +811,7 @@ private:
llvm::Value* r = emitter.createCall2(unw_info, g.funcs.importStar, converted_module->getValue(), llvm::Value* r = emitter.createCall2(unw_info, g.funcs.importStar, converted_module->getValue(),
irstate->getGlobals()); irstate->getGlobals());
emitter.setType(r, RefType::OWNED);
CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r); CompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, r);
return v; return v;
} }
...@@ -826,6 +836,7 @@ private: ...@@ -826,6 +836,7 @@ private:
{ getConstantInt(level, g.i32), converted_froms->getValue(), { getConstantInt(level, g.i32), converted_froms->getValue(),
emitter.setType(embedRelocatablePtr(module_name.c_str(), g.i8_ptr), RefType::BORROWED), emitter.setType(embedRelocatablePtr(module_name.c_str(), g.i8_ptr), RefType::BORROWED),
getConstantInt(module_name.size(), g.i64) }); getConstantInt(module_name.size(), g.i64) });
emitter.setType(imported, RefType::OWNED);
ConcreteCompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, imported); ConcreteCompilerVariable* v = new ConcreteCompilerVariable(UNKNOWN, imported);
return v; return v;
} }
...@@ -1020,6 +1031,7 @@ private: ...@@ -1020,6 +1031,7 @@ private:
CompilerVariable* evalDict(AST_Dict* node, const UnwindInfo& unw_info) { CompilerVariable* evalDict(AST_Dict* node, const UnwindInfo& unw_info) {
llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createDict); llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createDict);
emitter.setType(v, RefType::OWNED);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(DICT, v); ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(DICT, v);
if (node->keys.size()) { if (node->keys.size()) {
static BoxedString* setitem_str = getStaticString("__setitem__"); static BoxedString* setitem_str = getStaticString("__setitem__");
...@@ -1070,6 +1082,7 @@ private: ...@@ -1070,6 +1082,7 @@ private:
} }
llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createList); llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createList);
emitter.setType(v, RefType::OWNED);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(LIST, v); ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(LIST, v);
llvm::Value* f = g.funcs.listAppendInternal; llvm::Value* f = g.funcs.listAppendInternal;
...@@ -1251,6 +1264,7 @@ private: ...@@ -1251,6 +1264,7 @@ private:
std::vector<llvm::Value*> args{ cvar->getValue() }; std::vector<llvm::Value*> args{ cvar->getValue() };
llvm::Value* rtn = emitter.createCall(unw_info, g.funcs.repr, args); llvm::Value* rtn = emitter.createCall(unw_info, g.funcs.repr, args);
rtn = emitter.getBuilder()->CreateBitCast(rtn, g.llvm_value_type_ptr); rtn = emitter.getBuilder()->CreateBitCast(rtn, g.llvm_value_type_ptr);
emitter.setType(rtn, RefType::OWNED);
return new ConcreteCompilerVariable(STR, rtn); return new ConcreteCompilerVariable(STR, rtn);
} }
...@@ -1263,6 +1277,7 @@ private: ...@@ -1263,6 +1277,7 @@ private:
} }
llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createSet); llvm::Value* v = emitter.getBuilder()->CreateCall(g.funcs.createSet);
emitter.setType(v, RefType::OWNED);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(SET, v); ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(SET, v);
static BoxedString* add_str = getStaticString("add"); static BoxedString* add_str = getStaticString("add");
...@@ -1363,6 +1378,7 @@ private: ...@@ -1363,6 +1378,7 @@ private:
llvm::Value* rtn llvm::Value* rtn
= emitter.createCall2(unw_info, g.funcs.yield, convertedGenerator->getValue(), convertedValue->getValue()); = emitter.createCall2(unw_info, g.funcs.yield, convertedGenerator->getValue(), convertedValue->getValue());
emitter.setType(rtn, RefType::OWNED);
return new ConcreteCompilerVariable(UNKNOWN, rtn); return new ConcreteCompilerVariable(UNKNOWN, rtn);
} }
...@@ -1824,9 +1840,11 @@ private: ...@@ -1824,9 +1840,11 @@ private:
// We could patchpoint this or try to avoid the overhead, but this should only // We could patchpoint this or try to avoid the overhead, but this should only
// happen when the assertion is actually thrown so I don't think it will be necessary. // happen when the assertion is actually thrown so I don't think it will be necessary.
static BoxedString* AssertionError_str = getStaticString("AssertionError"); static BoxedString* AssertionError_str = getStaticString("AssertionError");
llvm_args.push_back(emitter.createCall2( llvm_args.push_back(emitter.setType(
unw_info, g.funcs.getGlobal, irstate->getGlobals(), emitter.createCall2(unw_info, g.funcs.getGlobal, irstate->getGlobals(),
emitter.setType(embedRelocatablePtr(AssertionError_str, g.llvm_boxedstring_type_ptr), RefType::BORROWED))); emitter.setType(embedRelocatablePtr(AssertionError_str, g.llvm_boxedstring_type_ptr),
RefType::BORROWED)),
RefType::OWNED));
ConcreteCompilerVariable* converted_msg = NULL; ConcreteCompilerVariable* converted_msg = NULL;
if (node->msg) { if (node->msg) {
......
...@@ -1916,7 +1916,7 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa ...@@ -1916,7 +1916,7 @@ Box* BoxedCApiFunction::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ArgPa
RELEASE_ASSERT(0, "0x%x", flags); RELEASE_ASSERT(0, "0x%x", flags);
} }
assert(paramspec.totalReceived() < 3); assert(paramspec.totalReceived() <= 3);
assert(!oargs); assert(!oargs);
if (rewrite_args) { if (rewrite_args) {
......
...@@ -667,7 +667,7 @@ Box* BoxedWrapperDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, ...@@ -667,7 +667,7 @@ Box* BoxedWrapperDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args,
RELEASE_ASSERT(0, "%d", flags); RELEASE_ASSERT(0, "%d", flags);
} }
assert(paramspec.totalReceived() < 3); assert(paramspec.totalReceived() <= 3);
assert(!oargs); assert(!oargs);
switch (paramspec.totalReceived()) { switch (paramspec.totalReceived()) {
......
...@@ -1673,8 +1673,8 @@ Box* descriptorClsSpecialCases(GetattrRewriteArgs* rewrite_args, BoxedClass* cls ...@@ -1673,8 +1673,8 @@ Box* descriptorClsSpecialCases(GetattrRewriteArgs* rewrite_args, BoxedClass* cls
if (rewrite_args) { if (rewrite_args) {
// return an unbound instancemethod // return an unbound instancemethod
RewriterVar* r_cls = rewrite_args->obj; RewriterVar* r_cls = rewrite_args->obj;
RewriterVar* r_rtn RewriterVar* r_rtn = rewrite_args->rewriter->call(true, (void*)boxUnboundInstanceMethod, r_descr, r_cls)
= rewrite_args->rewriter->call(true, (void*)boxUnboundInstanceMethod, r_descr, r_cls); ->setType(RefType::OWNED);
rewrite_args->setReturn(r_rtn, ReturnConvention::HAS_RETURN); rewrite_args->setReturn(r_rtn, ReturnConvention::HAS_RETURN);
} }
return boxUnboundInstanceMethod(descr, cls); return boxUnboundInstanceMethod(descr, cls);
......
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