Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment lambda_counter #7889

Merged
merged 2 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions mypyc/genops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3999,6 +3999,7 @@ def visit_lambda_expr(self, expr: LambdaExpr) -> Value:
fsig = FuncSignature(runtime_args, ret_type)

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

Expand Down
49 changes: 39 additions & 10 deletions mypyc/test-data/genops-nested.test
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,8 @@ L0:
[case testLambdas]
def f(x: int, y: int) -> None:
s = lambda a, b: a + b
return s(x, y)
t = lambda a, b: s(a, b)
return t(x, y)

[out]
def __mypyc_lambda__0_f_obj.__get__(__mypyc_self__, instance, owner):
Expand All @@ -811,23 +812,51 @@ L0:
r0 = __mypyc_self__.__mypyc_env__
r1 = a + b
return r1
def __mypyc_lambda__1_f_obj.__get__(__mypyc_self__, instance, owner):
__mypyc_self__, instance, owner, r0 :: object
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
return __mypyc_self__
L2:
r2 = method_new __mypyc_self__, instance
return r2
def __mypyc_lambda__1_f_obj.__call__(__mypyc_self__, a, b):
__mypyc_self__ :: __main__.__mypyc_lambda__1_f_obj
a, b :: object
r0 :: __main__.f_env
r1, r2 :: object
L0:
r0 = __mypyc_self__.__mypyc_env__
r1 = r0.s
r2 = py_call(r1, a, b)
return r2
def f(x, y):
x, y :: int
r0 :: __main__.f_env
r1 :: __main__.__mypyc_lambda__0_f_obj
r2 :: bool
s, r3, r4, r5 :: object
r6 :: None
r2, r3 :: bool
r4 :: __main__.__mypyc_lambda__1_f_obj
r5 :: bool
t, r6, r7, r8 :: object
r9 :: None
L0:
r0 = f_env()
r1 = __mypyc_lambda__0_f_obj()
r1.__mypyc_env__ = r0; r2 = is_error
s = r1
r3 = box(int, x)
r4 = box(int, y)
r5 = py_call(s, r3, r4)
r6 = unbox(None, r5)
return r6
r0.s = r1; r3 = is_error
r4 = __mypyc_lambda__1_f_obj()
r4.__mypyc_env__ = r0; r5 = is_error
t = r4
r6 = box(int, x)
r7 = box(int, y)
r8 = py_call(t, r6, r7)
r9 = unbox(None, r8)
return r9

[case testRecursiveFunction]
from typing import Callable
Expand Down