Skip to content

Commit e7f77b3

Browse files
committed
don't abort the rewrite before typeCallInner just because starargs is passed
1 parent fd0c77b commit e7f77b3

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/runtime/objmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,7 @@ extern "C" Box* callattr(Box* obj, BoxedString* attr, CallattrFlags flags, Box*
27452745
const std::vector<BoxedString*>* keyword_names) {
27462746
STAT_TIMER(t0, "us_timer_slowpath_callattr", 10);
27472747

2748+
27482749
#if 0 && STAT_TIMERS
27492750
static uint64_t* st_id = Stats::getStatCounter("us_timer_slowpath_callattr_patchable");
27502751
static uint64_t* st_id_nopatch = Stats::getStatCounter("us_timer_slowpath_callattr_nopatch");
@@ -2756,7 +2757,7 @@ extern "C" Box* callattr(Box* obj, BoxedString* attr, CallattrFlags flags, Box*
27562757
else if (icinfo->isMegamorphic())
27572758
counter = st_id_megamorphic;
27582759
else {
2759-
//counter = Stats::getStatCounter("us_timer_slowpath_callattr_patchable_" + std::string(obj->cls->tp_name));
2760+
// counter = Stats::getStatCounter("us_timer_slowpath_callattr_patchable_" + std::string(obj->cls->tp_name));
27602761
counter = Stats::getStatCounter("us_timer_slowpath_callattr_patchable_" + std::string(attr->s()));
27612762
}
27622763
ScopedStatTimer st(counter, 10);

src/runtime/rearrange_arguments.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name
150150
Box** defaults, CallRewriteArgs* rewrite_args, bool& rewrite_success, ArgPassSpec argspec,
151151
Box* arg1, Box* arg2, Box* arg3, Box** args, const std::vector<BoxedString*>* keyword_names,
152152
Box*& oarg1, Box*& oarg2, Box*& oarg3, Box** oargs) {
153-
154153
/*
155154
* Procedure:
156155
* - First match up positional arguments; any extra go to varargs. error if too many.
@@ -398,7 +397,8 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name
398397
} else {
399398
if (argspec.num_args <= 3) {
400399
assert(paramspec.num_args >= argspec.num_args);
401-
int bufSize = paramspec.num_args - argspec.num_args + (paramspec.takes_varargs ? 1 : 0) + (paramspec.takes_kwargs ? 1 : 0);
400+
int bufSize = paramspec.num_args - argspec.num_args + (paramspec.takes_varargs ? 1 : 0)
401+
+ (paramspec.takes_kwargs ? 1 : 0);
402402
RewriterVar* r_buf_ptr = bufSize > 0 ? rewrite_args->rewriter->allocate(bufSize)
403403
: rewrite_args->rewriter->loadConst(0);
404404
rewrite_args->rewriter->call(true /* has side effects */,
@@ -408,7 +408,9 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name
408408
rewrite_args->rewriter->loadConst(argspec.asInt()),
409409
rewrite_args->rewriter->loadConst(paramspec.asInt()),
410410
rewrite_args->rewriter->loadConst((int64_t)func_name));
411-
for (int i = argspec.num_args; i < (paramspec.num_args + (paramspec.takes_varargs ? 1 : 0) + (paramspec.takes_kwargs ? 1 : 0)); i++) {
411+
for (int i = argspec.num_args;
412+
i < (paramspec.num_args + (paramspec.takes_varargs ? 1 : 0) + (paramspec.takes_kwargs ? 1 : 0));
413+
i++) {
412414
int buf_offset = sizeof(Box*) * (i - argspec.num_args);
413415
if (i == 0)
414416
rewrite_args->arg1 = r_buf_ptr->getAttr(buf_offset);

src/runtime/types.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,6 @@ static Box* typeTppCall(Box* self, CallRewriteArgs* rewrite_args, ArgPassSpec ar
565565
Box** args, const std::vector<BoxedString*>* keyword_names) {
566566
int npassed_args = argspec.totalPassed();
567567

568-
if (argspec.has_starargs) {
569-
// This would fail in typeCallInner
570-
rewrite_args = NULL;
571-
}
572-
573568
Box** new_args = NULL;
574569
if (npassed_args >= 3) {
575570
new_args = (Box**)alloca(sizeof(Box*) * (npassed_args + 1 - 3));
@@ -681,6 +676,10 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
681676
return cpythonTypeCall(cls, oarg2, oarg3);
682677
}
683678

679+
if (argspec.has_starargs) {
680+
rewrite_args = NULL;
681+
}
682+
684683
RewriterVar* r_ccls = NULL;
685684
RewriterVar* r_new = NULL;
686685
RewriterVar* r_init = NULL;
@@ -694,7 +693,6 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
694693
// Need to create a clear contract of who guards on what
695694
r_ccls->addGuard((intptr_t)arg1 /* = _cls */);
696695

697-
698696
if (!rewrite_args->args_guarded) {
699697
// TODO should know which args don't need to be guarded, ex if we're guaranteed that they
700698
// already fit, either since the type inferencer could determine that,

0 commit comments

Comments
 (0)