Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(351)

Issue 144079: Add support for fixed-arity functions with arity greater than METH_O (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 8 months ago by Collin Winter
Modified:
15 years, 8 months ago
CC:
unladen-swallow_googlegroups.com
Visibility:
Public.

Description

Committed in r890. Benchmarking vs http://codereview.appspot.com/144078. This was implemented to help Django, and accordingly it benefits the most. django: Min: 0.925832 -> 0.866477: 6.85% faster Avg: 0.929429 -> 0.870545: 6.76% faster Significant (t=75.111745, a=0.95) Stddev: 0.00525 -> 0.00582: 9.72% larger 2to3: Min: 32.098121 -> 31.701180: 1.25% faster Avg: 32.125116 -> 31.745574: 1.20% faster Significant (t=10.993610, a=0.95) Stddev: 0.02732 -> 0.07220: 62.17% larger ai: Min: 0.460347 -> 0.451982: 1.85% faster Avg: 0.463752 -> 0.455268: 1.86% faster Significant (t=5.747795, a=0.95) Stddev: 0.01022 -> 0.01065: 4.11% larger rietveld: Min: 0.504553 -> 0.490781: 2.81% faster Avg: 0.613619 -> 0.601696: 1.98% faster Not significant Stddev: 0.18400 -> 0.18798: 2.11% larger slowpickle: Min: 0.599689 -> 0.588905: 1.83% faster Avg: 0.616109 -> 0.604985: 1.84% faster Not significant Stddev: 0.08503 -> 0.08518: 0.18% larger slowspitfire: Min: 0.619873 -> 0.624143: 0.68% slower Avg: 0.621270 -> 0.626009: 0.76% slower Significant (t=-8.066078, a=0.95) Stddev: 0.00167 -> 0.00563: 70.44% larger slowunpickle: Min: 0.263925 -> 0.264087: 0.06% slower Avg: 0.276726 -> 0.277567: 0.30% slower Not significant Stddev: 0.04327 -> 0.04422: 2.13% larger

Patch Set 1 #

Patch Set 2 : Polish #

Total comments: 33

Patch Set 3 : Address jyasskin's comments #

Total comments: 11

Patch Set 4 : Address jyasskin's and nnorwitz's comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+246 lines, -181 lines) Patch
M Include/methodobject.h View 1 2 3 4 chunks +24 lines, -7 lines 0 comments Download
M Include/modsupport.h View 2 chunks +4 lines, -2 lines 0 comments Download
M Lib/test/test_llvm.py View 1 2 1 chunk +24 lines, -0 lines 0 comments Download
M Objects/methodobject.c View 1 2 3 4 chunks +44 lines, -16 lines 0 comments Download
M Python/bltinmodule.c View 1 2 8 chunks +13 lines, -37 lines 0 comments Download
M Python/eval.cc View 1 2 3 2 chunks +38 lines, -15 lines 0 comments Download
M Python/llvm_fbuilder.h View 1 2 1 chunk +4 lines, -0 lines 0 comments Download
M Python/llvm_fbuilder.cc View 1 2 26 chunks +68 lines, -101 lines 0 comments Download
M Util/ConstantMirror.h View 1 chunk +2 lines, -1 line 0 comments Download
M Util/ConstantMirror.cc View 3 chunks +22 lines, -2 lines 0 comments Download
M Util/RuntimeFeedback.h View 1 chunk +1 line, -0 lines 0 comments Download
M Util/RuntimeFeedback.cc View 2 chunks +2 lines, -0 lines 0 comments Download

Messages

Total messages: 8
Collin Winter
PTAL
15 years, 8 months ago (2009-11-03 22:28:51 UTC) #1
Jeffrey Yasskin
I'm going to be gone tomorrow, but if Neal becomes happy with this, go ahead ...
15 years, 8 months ago (2009-11-04 01:06:39 UTC) #2
Reid Kleckner
http://codereview.appspot.com/144079/diff/24/30 File Python/llvm_fbuilder.cc (right): http://codereview.appspot.com/144079/diff/24/30#newcode3546 Line 3546: LlvmFunctionBuilder::GetNull() On 2009/11/04 01:06:39, Jeffrey Yasskin wrote: > ...
15 years, 8 months ago (2009-11-04 02:49:57 UTC) #3
Collin Winter
http://codereview.appspot.com/144079/diff/24/25 File Include/methodobject.h (right): http://codereview.appspot.com/144079/diff/24/25#newcode41 Line 41: /* GET_ARITY only makes sense for METH_FIXED functions. ...
15 years, 8 months ago (2009-11-04 21:15:08 UTC) #4
James Abbatiello
http://codereview.appspot.com/144079/diff/24/25 File Include/methodobject.h (right): http://codereview.appspot.com/144079/diff/24/25#newcode41 Line 41: /* GET_ARITY only makes sense for METH_FIXED functions. ...
15 years, 8 months ago (2009-11-05 03:41:25 UTC) #5
Jeffrey Yasskin
LGTM http://codereview.appspot.com/144079/diff/24/25 File Include/methodobject.h (right): http://codereview.appspot.com/144079/diff/24/25#newcode41 Line 41: /* GET_ARITY only makes sense for METH_FIXED ...
15 years, 8 months ago (2009-11-05 18:08:35 UTC) #6
nnorwitz
http://codereview.appspot.com/144079/diff/2001/2002 File Include/methodobject.h (right): http://codereview.appspot.com/144079/diff/2001/2002#newcode54 Line 54: int ml_arity; /* Number of parameters for METH_FIXED ...
15 years, 8 months ago (2009-11-05 18:59:22 UTC) #7
Collin Winter
15 years, 8 months ago (2009-11-05 19:15:45 UTC) #8
Committing.

http://codereview.appspot.com/144079/diff/24/25
File Include/methodobject.h (right):

http://codereview.appspot.com/144079/diff/24/25#newcode41
Line 41: /* GET_ARITY only makes sense for METH_FIXED functions. */
On 2009/11/05 18:08:35, Jeffrey Yasskin wrote:
> On 2009/11/05 03:41:25, James Abbatiello wrote:
> > On 2009/11/04 21:15:08, Collin Winter wrote:
> > > If you have some magic way of getting around
> > > those, I'll implement this.
> > How about
> > (assert(((PyCFunctionObject *)func) -> ml -> ml_flags & METH_FIXED),
> > ((PyCFunctionObject *)func) -> m_ml -> ml_arity)
> > 
> 
> Yep, the comma operator should work.

I had tried that, but I figured out what I was doing wrong. I had


#define PyCFunction_GET_ARITY(func) \
	assert(PyCFunction_GET_FLAGS(func) & METH_FIXED), \
	(((PyCFunctionObject *)func) -> m_ml -> ml_arity)

instead of the correct

#define PyCFunction_GET_ARITY(func) \
	(assert(PyCFunction_GET_FLAGS(func) & METH_FIXED), \
	(((PyCFunctionObject *)func) -> m_ml -> ml_arity))

Done.

http://codereview.appspot.com/144079/diff/24/25#newcode71
Line 71: #define METH_FIXED    0x0010  /* Function arity = constant */
On 2009/11/05 18:08:35, Jeffrey Yasskin wrote:
> On 2009/11/04 21:15:08, Collin Winter wrote:
> > On 2009/11/04 01:06:39, Jeffrey Yasskin wrote:
> > > Arguably, you could just replace METH_NOARGS with METH_FIXED. ml_arity
will
> be
> > 0
> > > by default if it's not specified in an argument list.
> > 
> > Is that default behaviour in the standard, or an accident of gcc? I was
trying
> > to be conservative to avoid breaking MSVC, etc.
> 
> Setting all unspecified struct fields to 0 is standard behavior. "If there are
> fewer initializers in a brace-enclosed list than there are elements or members
> of an aggregate, or fewer characters in a string literal used to initialize an
> array of known size than there are elements in the array, the remainder of the
> aggregate shall be initialized implicitly the same as objects that have static
> storage duration."

Ok. I've removed a constant associated with METH_NOARGS and #defined it to be
METH_FIXED.

http://codereview.appspot.com/144079/diff/2001/2002#newcode72
Line 72: 
On 2009/11/05 18:59:22, nnorwitz wrote:
> One thing my original patch did is to support variable arguments too (IIRC). 
I
> don't think it's worth doing in this first pass, but there are quite a number
of
> APIs that could use this.  e.g., {}.get()

Yeah, I saw that part of the patch. I wanted to get the basic concept in before
taking on variadic functions.

http://codereview.appspot.com/144079/diff/2001/2004
File Objects/methodobject.c (right):

http://codereview.appspot.com/144079/diff/2001/2004#newcode42
Line 42: ml->ml_arity = 1;
On 2009/11/05 18:59:22, nnorwitz wrote:
> These two conditions could be handled as one, but I'm not sure it's worth it. 
I
> don't know if people would find the condensed code more readable:
> 
>          if (ml->ml_flags & (METH_NOARGS|METH_O)) {
>                  ml->ml_flags &= ~(METH_NOARGS|METH_O);
>                  ml->ml_flags |= METH_FIXED;
>                  ml->ml_arity = ((ml->ml_flags & (METH_NOARGS|METH_O)) >> 4) -
> 1;
>          }
> 

I got rid of the METH_NOARGS case by defining it to be METH_FIXED and letting C
fill in ml_arity=0.

http://codereview.appspot.com/144079/diff/2001/2004#newcode113
Line 113: default: abort();
On 2009/11/05 18:08:35, Jeffrey Yasskin wrote:
> Py_BadInternalCall()?

Done.

http://codereview.appspot.com/144079/diff/2001/2004#newcode147
Line 147: to convert them to METH_FIXED and set ml_arity correctly. */
On 2009/11/05 18:59:22, nnorwitz wrote:
> Note this will be reached by any module that hasn't been recompiled and uses
> these flags (which is likely a large number).
> 
> You should make sure to change the module API version number  (in
> Include/modsupport.h) if you didn't.

This is the ABI, not the API, and we've already broken ABI compatibility.
Looking at the past reasons for changing the API version, do we really need to
bump this? I suppose it can't hurt, even though we're not really changing the
API.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b