Commit 476ba43e authored by Marius Wachtler's avatar Marius Wachtler

Add more Rewritable template args to functions

           django_template3.py             2.7s (4)             2.7s (4)  -0.3%
                 pyxl_bench.py             2.3s (4)             2.2s (4)  -4.1%
     sqlalchemy_imperative2.py             2.7s (4)             2.6s (4)  -1.4%
                       geomean                 2.5s                 2.5s  -2.0%
parent 30f254d3
...@@ -52,8 +52,8 @@ enum ExceptionStyle { ...@@ -52,8 +52,8 @@ enum ExceptionStyle {
}; };
enum Rewritable { enum Rewritable {
REWRITABLE,
NOT_REWRITABLE, NOT_REWRITABLE,
REWRITABLE,
}; };
template <typename T> struct ExceptionSwitchable { template <typename T> struct ExceptionSwitchable {
......
...@@ -97,8 +97,8 @@ void generatorEntry(BoxedGenerator* g) { ...@@ -97,8 +97,8 @@ void generatorEntry(BoxedGenerator* g) {
BoxedFunctionBase* func = g->function; BoxedFunctionBase* func = g->function;
Box** args = g->args ? &g->args->elts[0] : nullptr; Box** args = g->args ? &g->args->elts[0] : nullptr;
callCLFunc<ExceptionStyle::CXX>(func->f, nullptr, func->f->numReceivedArgs(), func->closure, g, callCLFunc<ExceptionStyle::CXX, NOT_REWRITABLE>(func->f, nullptr, func->f->numReceivedArgs(), func->closure,
func->globals, g->arg1, g->arg2, g->arg3, args); g, func->globals, g->arg1, g->arg2, g->arg3, args);
} catch (ExcInfo e) { } catch (ExcInfo e) {
// unhandled exception: propagate the exception to the caller // unhandled exception: propagate the exception to the caller
g->exception = e; g->exception = e;
......
...@@ -1730,7 +1730,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew ...@@ -1730,7 +1730,7 @@ Box* getattrInternalGeneric(Box* obj, BoxedString* attr, GetattrRewriteArgs* rew
grewrite_args.assertReturnConvention(ReturnConvention::NO_RETURN); grewrite_args.assertReturnConvention(ReturnConvention::NO_RETURN);
} }
} else { } else {
descr = typeLookup<rewritable>(obj->cls, attr, NULL); descr = typeLookup(obj->cls, attr);
} }
// Check if it's a data descriptor // Check if it's a data descriptor
...@@ -3306,11 +3306,16 @@ ArgPassSpec bindObjIntoArgs(Box* bind_obj, RewriterVar* r_bind_obj, _CallRewrite ...@@ -3306,11 +3306,16 @@ ArgPassSpec bindObjIntoArgs(Box* bind_obj, RewriterVar* r_bind_obj, _CallRewrite
return ArgPassSpec(argspec.num_args + 1, argspec.num_keywords, argspec.has_starargs, argspec.has_kwargs); return ArgPassSpec(argspec.num_args + 1, argspec.num_keywords, argspec.has_starargs, argspec.has_kwargs);
} }
template <typename FuncNameCB> template <Rewritable rewritable, typename FuncNameCB>
void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* param_names, FuncNameCB func_name_cb, void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* param_names, FuncNameCB func_name_cb,
Box** defaults, _CallRewriteArgsBase* rewrite_args, bool& rewrite_success, Box** defaults, _CallRewriteArgsBase* rewrite_args, bool& rewrite_success,
ArgPassSpec argspec, Box*& oarg1, Box*& oarg2, Box*& oarg3, Box** args, Box** oargs, ArgPassSpec argspec, Box*& oarg1, Box*& oarg2, Box*& oarg3, Box** args, Box** oargs,
const std::vector<BoxedString*>* keyword_names) { const std::vector<BoxedString*>* keyword_names) {
if (rewritable == NOT_REWRITABLE) {
assert(!rewrite_args);
rewrite_args = NULL;
}
/* /*
* Procedure: * Procedure:
* - First match up positional arguments; any extra go to varargs. error if too many. * - First match up positional arguments; any extra go to varargs. error if too many.
...@@ -3689,19 +3694,35 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa ...@@ -3689,19 +3694,35 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
} }
} }
template <Rewritable rewritable>
void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_names, const char* func_name, void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_names, const char* func_name,
Box** defaults, _CallRewriteArgsBase* rewrite_args, bool& rewrite_success, ArgPassSpec argspec, Box** defaults, _CallRewriteArgsBase* rewrite_args, bool& rewrite_success, ArgPassSpec argspec,
Box*& oarg1, Box*& oarg2, Box*& oarg3, Box** args, Box** oargs, Box*& oarg1, Box*& oarg2, Box*& oarg3, Box** args, Box** oargs,
const std::vector<BoxedString*>* keyword_names) { const std::vector<BoxedString*>* keyword_names) {
auto func = [func_name]() { return func_name; }; auto func = [func_name]() { return func_name; };
return rearrangeArgumentsInternal(paramspec, param_names, func, defaults, rewrite_args, rewrite_success, argspec, return rearrangeArgumentsInternal<rewritable>(paramspec, param_names, func, defaults, rewrite_args, rewrite_success,
oarg1, oarg2, oarg3, args, oargs, keyword_names); argspec, oarg1, oarg2, oarg3, args, oargs, keyword_names);
} }
template void rearrangeArguments<REWRITABLE>(ParamReceiveSpec, const ParamNames*, const char*, Box**,
_CallRewriteArgsBase*, bool&, ArgPassSpec, Box*&, Box*&, Box*&, Box**,
Box**, const std::vector<BoxedString*>*);
template void rearrangeArguments<NOT_REWRITABLE>(ParamReceiveSpec, const ParamNames*, const char*, Box**,
_CallRewriteArgsBase*, bool&, ArgPassSpec, Box*&, Box*&, Box*&, Box**,
Box**, const std::vector<BoxedString*>*);
static StatCounter slowpath_callfunc("slowpath_callfunc"); static StatCounter slowpath_callfunc("slowpath_callfunc");
template <ExceptionStyle S> template <ExceptionStyle S, Rewritable rewritable>
Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2,
Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI) { Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI) {
if (rewritable == NOT_REWRITABLE) {
assert(!rewrite_args);
rewrite_args = NULL;
}
if (rewritable == REWRITABLE && !rewrite_args)
return callFunc<S, NOT_REWRITABLE>(func, rewrite_args, argspec, arg1, arg2, arg3, args, keyword_names);
#if STAT_TIMERS #if STAT_TIMERS
StatTimer::assertActive(); StatTimer::assertActive();
STAT_TIMER(t0, "us_timer_slowpath_callFunc", 0); STAT_TIMER(t0, "us_timer_slowpath_callFunc", 0);
...@@ -3740,9 +3761,9 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe ...@@ -3740,9 +3761,9 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
try { try {
auto func_name_cb = [f]() { return getFunctionName(f).data(); }; auto func_name_cb = [f]() { return getFunctionName(f).data(); };
rearrangeArgumentsInternal(paramspec, &f->param_names, func_name_cb, rearrangeArgumentsInternal<rewritable>(paramspec, &f->param_names, func_name_cb,
paramspec.num_defaults ? func->defaults->elts : NULL, rewrite_args, rewrite_success, paramspec.num_defaults ? func->defaults->elts : NULL, rewrite_args,
argspec, arg1, arg2, arg3, args, oargs, keyword_names); rewrite_success, argspec, arg1, arg2, arg3, args, oargs, keyword_names);
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (S == CAPI) { if (S == CAPI) {
setCAPIException(e); setCAPIException(e);
...@@ -3842,7 +3863,8 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe ...@@ -3842,7 +3863,8 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
rewrite_args->out_success = true; rewrite_args->out_success = true;
} }
} else { } else {
res = callCLFunc<S>(f, rewrite_args, num_output_args, closure, NULL, func->globals, arg1, arg2, arg3, oargs); res = callCLFunc<S, rewritable>(f, rewrite_args, num_output_args, closure, NULL, func->globals, arg1, arg2,
arg3, oargs);
} }
return res; return res;
...@@ -3926,10 +3948,15 @@ static Box* capiCallCxxHelper(Box* (*func_ptr)(void*, void*, void*, void*, void* ...@@ -3926,10 +3948,15 @@ static Box* capiCallCxxHelper(Box* (*func_ptr)(void*, void*, void*, void*, void*
} }
} }
template <ExceptionStyle S> template <ExceptionStyle S, Rewritable rewritable>
Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure,
BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3,
Box** oargs) noexcept(S == CAPI) { Box** oargs) noexcept(S == CAPI) {
if (rewritable == NOT_REWRITABLE) {
assert(!rewrite_args);
rewrite_args = NULL;
}
CompiledFunction* chosen_cf = pickVersion(f, S, num_output_args, oarg1, oarg2, oarg3, oargs); CompiledFunction* chosen_cf = pickVersion(f, S, num_output_args, oarg1, oarg2, oarg3, oargs);
if (!chosen_cf) { if (!chosen_cf) {
...@@ -4053,11 +4080,18 @@ Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_arg ...@@ -4053,11 +4080,18 @@ Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_arg
} }
// force instantiation: // force instantiation:
template Box* callCLFunc<CAPI>(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, template Box* callCLFunc<CAPI, REWRITABLE>(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args,
BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1,
Box** oargs); Box* oarg2, Box* oarg3, Box** oargs);
template Box* callCLFunc<CXX>(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, template Box* callCLFunc<CXX, REWRITABLE>(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args,
BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs); BoxedClosure* closure, BoxedGenerator* generator, Box* globals, Box* oarg1,
Box* oarg2, Box* oarg3, Box** oargs);
template Box* callCLFunc<CAPI, NOT_REWRITABLE>(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args,
BoxedClosure* closure, BoxedGenerator* generator, Box* globals,
Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs);
template Box* callCLFunc<CXX, NOT_REWRITABLE>(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args,
BoxedClosure* closure, BoxedGenerator* generator, Box* globals,
Box* oarg1, Box* oarg2, Box* oarg3, Box** oargs);
template <ExceptionStyle S, Rewritable rewritable> template <ExceptionStyle S, Rewritable rewritable>
Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3, Box* runtimeCallInternal(Box* obj, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* arg3,
...@@ -4481,6 +4515,8 @@ Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteAr ...@@ -4481,6 +4515,8 @@ Box* binopInternal(Box* lhs, Box* rhs, int op_type, bool inplace, BinopRewriteAr
raiseExcHelper(TypeError, "unsupported operand type(s) for %s%s: '%s' and '%s'", op_sym.data(), op_sym_suffix, raiseExcHelper(TypeError, "unsupported operand type(s) for %s%s: '%s' and '%s'", op_sym.data(), op_sym_suffix,
getTypeName(lhs), getTypeName(rhs)); getTypeName(lhs), getTypeName(rhs));
} }
template Box* binopInternal<REWRITABLE>(Box*, Box*, int, bool, BinopRewriteArgs*);
template Box* binopInternal<NOT_REWRITABLE>(Box*, Box*, int, bool, BinopRewriteArgs*);
extern "C" Box* binop(Box* lhs, Box* rhs, int op_type) { extern "C" Box* binop(Box* lhs, Box* rhs, int op_type) {
STAT_TIMER(t0, "us_timer_slowpath_binop", 10); STAT_TIMER(t0, "us_timer_slowpath_binop", 10);
......
...@@ -138,7 +138,7 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI ...@@ -138,7 +138,7 @@ BoxedInt* lenInternal(Box* obj, LenRewriteArgs* rewrite_args) noexcept(S == CAPI
Box* lenCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* lenCallInternal(BoxedFunctionBase* f, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2,
Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names); Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names);
template <ExceptionStyle S> template <ExceptionStyle S, Rewritable rewritable = REWRITABLE>
Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2, Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Box* arg1, Box* arg2,
Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI); Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names) noexcept(S == CAPI);
...@@ -200,7 +200,7 @@ Box* typeNewGeneric(Box* cls, Box* arg1, Box* arg2, Box** _args); ...@@ -200,7 +200,7 @@ Box* typeNewGeneric(Box* cls, Box* arg1, Box* arg2, Box** _args);
Box* processDescriptor(Box* obj, Box* inst, Box* owner); Box* processDescriptor(Box* obj, Box* inst, Box* owner);
Box* processDescriptorOrNull(Box* obj, Box* inst, Box* owner); Box* processDescriptorOrNull(Box* obj, Box* inst, Box* owner);
template <ExceptionStyle S> template <ExceptionStyle S, Rewritable rewritable>
Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure, Box* callCLFunc(CLFunction* f, CallRewriteArgs* rewrite_args, int num_output_args, BoxedClosure* closure,
BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3, BoxedGenerator* generator, Box* globals, Box* oarg1, Box* oarg2, Box* oarg3,
Box** oargs) noexcept(S == CAPI); Box** oargs) noexcept(S == CAPI);
......
...@@ -279,6 +279,7 @@ struct CompareRewriteArgs { ...@@ -279,6 +279,7 @@ struct CompareRewriteArgs {
// The caller is responsible for guarding for paramspec, argspec, param_names, and defaults. // The caller is responsible for guarding for paramspec, argspec, param_names, and defaults.
// TODO Fix this function's signature. should we pass back out through args? the common case is that they // TODO Fix this function's signature. should we pass back out through args? the common case is that they
// match anyway. Or maybe it should call a callback function, which could save on the common case. // match anyway. Or maybe it should call a callback function, which could save on the common case.
template <Rewritable rewritable = REWRITABLE>
void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_names, const char* func_name, void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_names, const char* func_name,
Box** defaults, _CallRewriteArgsBase* rewrite_args, bool& rewrite_success, ArgPassSpec argspec, Box** defaults, _CallRewriteArgsBase* rewrite_args, bool& rewrite_success, ArgPassSpec argspec,
Box*& arg1, Box*& arg2, Box*& arg3, Box** args, Box** oargs, Box*& arg1, Box*& arg2, Box*& arg3, Box** args, Box** oargs,
......
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