Commit fc238ed8 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get rid of void-returning functions

Module-level code used to return void, but this causes some
special-casing, so switch to having them return None.
Also, CPython has their module code objects return None, so
it's a small compatibility gain as well.
parent 0915db4e
......@@ -781,13 +781,8 @@ Box* ASTInterpreter::doOSR(AST_Jump* node) {
Box* r = partial_func->call(std::get<0>(arg_tuple), std::get<1>(arg_tuple), std::get<2>(arg_tuple),
std::get<3>(arg_tuple));
// This is one of the few times that we are allowed to have an invalid value in a Box* Value.
// Check for it, and return as an int so that we don't trigger a potential assert when
// creating the Value.
if (compiled_func->getReturnType() != VOID)
assert(r);
return r ? r : None;
return r;
}
Value ASTInterpreter::visit_invoke(AST_Invoke* node) {
......
......@@ -1965,14 +1965,6 @@ CompilerVariable* makeStr(BoxedString* s) {
return new ValuedCompilerVariable<BoxedString*>(STR_CONSTANT, s, true);
}
class VoidType : public ConcreteCompilerType {
public:
llvm::Type* llvmType() override { return g.void_; }
Box* deserializeFromFrame(const FrameVals& vals) override { abort(); }
};
ConcreteCompilerType* VOID = new VoidType();
ConcreteCompilerType* typeFromClass(BoxedClass* c) {
assert(c);
return NormalObjectType::fromClass(c);
......
......@@ -579,11 +579,7 @@ static void emitBBs(IRGenState* irstate, TypeAnalysis* types, const OSREntryDesc
// printf("%ld\n", args.size());
llvm::CallInst* postcall = emitter->getBuilder()->CreateCall(bitcast_r, args);
postcall->setTailCall(true);
if (rtn_type == VOID) {
emitter->getBuilder()->CreateRetVoid();
} else {
emitter->getBuilder()->CreateRet(postcall);
}
emitter->getBuilder()->SetInsertPoint(llvm_entry_blocks[source->cfg->getStartingBlock()]);
}
......
......@@ -323,7 +323,7 @@ void compileAndRunModule(AST_Module* m, BoxedModule* bm) {
assert(scoping->areGlobalsFromModule());
cf = compileFunction(cl_f, new FunctionSpecialization(VOID), effort, NULL);
cf = compileFunction(cl_f, new FunctionSpecialization(NONE), effort, NULL);
assert(cf->clfunc->versions.size());
}
......@@ -355,7 +355,7 @@ Box* evalOrExec(CLFunction* cl, Box* globals, Box* boxedLocals) {
setGlobal(boxedLocals, doc_box, doc_string);
}
CompiledFunction* cf = compileFunction(cl, new FunctionSpecialization(VOID), effort, NULL);
CompiledFunction* cf = compileFunction(cl, new FunctionSpecialization(NONE), effort, NULL);
assert(cf->clfunc->versions.size());
return astInterpretFunctionEval(cf, globals, boxedLocals);
......
......@@ -531,9 +531,6 @@ private:
emitter.getBuilder()->SetInsertPoint(curblock);
llvm::Value* v = emitter.createCall2(UnwindInfo(current_statement, NULL), g.funcs.deopt,
embedRelocatablePtr(node, g.llvm_aststmt_type_ptr), node_value);
if (irstate->getReturnType() == VOID)
emitter.getBuilder()->CreateRetVoid();
else
emitter.getBuilder()->CreateRet(v);
curblock = success_bb;
......@@ -1955,12 +1952,6 @@ private:
CompilerVariable* val;
if (node->value == NULL) {
if (irstate->getReturnType() == VOID) {
endBlock(DEAD);
emitter.getBuilder()->CreateRetVoid();
return;
}
val = getNone();
} else {
val = evalExpr(node->value, unw_info);
......@@ -2185,9 +2176,6 @@ private:
converted_args[i]->decvref(emitter);
}
if (irstate->getReturnType() == VOID)
emitter.getBuilder()->CreateRetVoid();
else
emitter.getBuilder()->CreateRet(rtn);
emitter.getBuilder()->SetInsertPoint(starting_block);
......
......@@ -74,8 +74,8 @@ template <class V> class ValuedCompilerType;
typedef ValuedCompilerType<llvm::Value*> ConcreteCompilerType;
ConcreteCompilerType* typeFromClass(BoxedClass*);
extern ConcreteCompilerType* INT, *BOXED_INT, *LONG, *FLOAT, *BOXED_FLOAT, *VOID, *UNKNOWN, *BOOL, *STR, *NONE, *LIST,
*SLICE, *MODULE, *DICT, *BOOL, *BOXED_BOOL, *BOXED_TUPLE, *SET, *FROZENSET, *CLOSURE, *GENERATOR, *BOXED_COMPLEX,
extern ConcreteCompilerType* INT, *BOXED_INT, *LONG, *FLOAT, *BOXED_FLOAT, *UNKNOWN, *BOOL, *STR, *NONE, *LIST, *SLICE,
*MODULE, *DICT, *BOOL, *BOXED_BOOL, *BOXED_TUPLE, *SET, *FROZENSET, *CLOSURE, *GENERATOR, *BOXED_COMPLEX,
*FRAME_INFO;
extern CompilerType* UNDEF;
......
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