Skip to content

Commit bc3e9d4

Browse files
jag426msullivan
authored andcommitted
[mypyc] Actually increment lambda_counter (python#7889)
1 parent 29252f8 commit bc3e9d4

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

mypyc/genops.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,6 +4121,7 @@ def visit_lambda_expr(self, expr: LambdaExpr) -> Value:
41214121
fsig = FuncSignature(runtime_args, ret_type)
41224122

41234123
fname = '{}{}'.format(LAMBDA_NAME, self.lambda_counter)
4124+
self.lambda_counter += 1
41244125
func_ir, func_reg = self.gen_func_item(expr, fname, fsig)
41254126
assert func_reg is not None
41264127

mypyc/test-data/genops-nested.test

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ L0:
786786
[case testLambdas]
787787
def f(x: int, y: int) -> None:
788788
s = lambda a, b: a + b
789-
return s(x, y)
789+
t = lambda a, b: s(a, b)
790+
return t(x, y)
790791

791792
[out]
792793
def __mypyc_lambda__0_f_obj.__get__(__mypyc_self__, instance, owner):
@@ -811,23 +812,51 @@ L0:
811812
r0 = __mypyc_self__.__mypyc_env__
812813
r1 = a + b
813814
return r1
815+
def __mypyc_lambda__1_f_obj.__get__(__mypyc_self__, instance, owner):
816+
__mypyc_self__, instance, owner, r0 :: object
817+
r1 :: bool
818+
r2 :: object
819+
L0:
820+
r0 = builtins.None :: object
821+
r1 = instance is r0
822+
if r1 goto L1 else goto L2 :: bool
823+
L1:
824+
return __mypyc_self__
825+
L2:
826+
r2 = method_new __mypyc_self__, instance
827+
return r2
828+
def __mypyc_lambda__1_f_obj.__call__(__mypyc_self__, a, b):
829+
__mypyc_self__ :: __main__.__mypyc_lambda__1_f_obj
830+
a, b :: object
831+
r0 :: __main__.f_env
832+
r1, r2 :: object
833+
L0:
834+
r0 = __mypyc_self__.__mypyc_env__
835+
r1 = r0.s
836+
r2 = py_call(r1, a, b)
837+
return r2
814838
def f(x, y):
815839
x, y :: int
816840
r0 :: __main__.f_env
817841
r1 :: __main__.__mypyc_lambda__0_f_obj
818-
r2 :: bool
819-
s, r3, r4, r5 :: object
820-
r6 :: None
842+
r2, r3 :: bool
843+
r4 :: __main__.__mypyc_lambda__1_f_obj
844+
r5 :: bool
845+
t, r6, r7, r8 :: object
846+
r9 :: None
821847
L0:
822848
r0 = f_env()
823849
r1 = __mypyc_lambda__0_f_obj()
824850
r1.__mypyc_env__ = r0; r2 = is_error
825-
s = r1
826-
r3 = box(int, x)
827-
r4 = box(int, y)
828-
r5 = py_call(s, r3, r4)
829-
r6 = unbox(None, r5)
830-
return r6
851+
r0.s = r1; r3 = is_error
852+
r4 = __mypyc_lambda__1_f_obj()
853+
r4.__mypyc_env__ = r0; r5 = is_error
854+
t = r4
855+
r6 = box(int, x)
856+
r7 = box(int, y)
857+
r8 = py_call(t, r6, r7)
858+
r9 = unbox(None, r8)
859+
return r9
831860

832861
[case testRecursiveFunction]
833862
from typing import Callable

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy