-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] Introduce ClassBuilder and add support for attrs classes #11328
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
Changes from all commits
87763b2
b359136
b254fe8
c5f3ab2
06745b5
5d511bf
0a29c2d
a26d9a5
4600dde
cd914bf
ec896ad
6538411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
from mypyc.primitives.set_ops import set_add_op, set_update_op | ||
from mypyc.primitives.str_ops import str_slice_op | ||
from mypyc.primitives.int_ops import int_comparison_op_mapping | ||
from mypyc.irbuild.specialize import specializers | ||
from mypyc.irbuild.specialize import apply_function_specialization, apply_method_specialization | ||
from mypyc.irbuild.builder import IRBuilder | ||
from mypyc.irbuild.for_helpers import ( | ||
translate_list_comprehension, translate_set_comprehension, | ||
|
@@ -209,7 +209,8 @@ def transform_call_expr(builder: IRBuilder, expr: CallExpr) -> Value: | |
callee = callee.analyzed.expr # Unwrap type application | ||
|
||
if isinstance(callee, MemberExpr): | ||
return translate_method_call(builder, expr, callee) | ||
return apply_method_specialization(builder, expr, callee) or \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure whether it's fine to adding a specialization here, since it's slightly different from the original semantics. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pretty sure this change is required for the feature to work. What can we do to test that it's safe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirmed that both need to be present in order to work. This second call is handling the case where |
||
translate_method_call(builder, expr, callee) | ||
elif isinstance(callee, SuperExpr): | ||
return translate_super_method_call(builder, expr, callee) | ||
else: | ||
|
@@ -219,7 +220,8 @@ def transform_call_expr(builder: IRBuilder, expr: CallExpr) -> Value: | |
def translate_call(builder: IRBuilder, expr: CallExpr, callee: Expression) -> Value: | ||
# The common case of calls is refexprs | ||
if isinstance(callee, RefExpr): | ||
return translate_refexpr_call(builder, expr, callee) | ||
return apply_function_specialization(builder, expr, callee) or \ | ||
translate_refexpr_call(builder, expr, callee) | ||
|
||
function = builder.accept(callee) | ||
args = [builder.accept(arg) for arg in expr.args] | ||
|
@@ -229,18 +231,6 @@ def translate_call(builder: IRBuilder, expr: CallExpr, callee: Expression) -> Va | |
|
||
def translate_refexpr_call(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value: | ||
"""Translate a non-method call.""" | ||
|
||
# TODO: Allow special cases to have default args or named args. Currently they don't since | ||
# they check that everything in arg_kinds is ARG_POS. | ||
|
||
# If there is a specializer for this function, try calling it. | ||
# We would return the first successful one. | ||
if callee.fullname and (callee.fullname, None) in specializers: | ||
for specializer in specializers[callee.fullname, None]: | ||
val = specializer(builder, expr, callee) | ||
if val is not None: | ||
return val | ||
|
||
# Gen the argument values | ||
arg_values = [builder.accept(arg) for arg in expr.args] | ||
|
||
|
@@ -297,11 +287,9 @@ def translate_method_call(builder: IRBuilder, expr: CallExpr, callee: MemberExpr | |
|
||
# If there is a specializer for this method name/type, try calling it. | ||
# We would return the first successful one. | ||
if (callee.name, receiver_typ) in specializers: | ||
for specializer in specializers[callee.name, receiver_typ]: | ||
val = specializer(builder, expr, callee) | ||
chadrik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if val is not None: | ||
return val | ||
val = apply_method_specialization(builder, expr, callee, receiver_typ) | ||
if val is not None: | ||
return val | ||
|
||
obj = builder.accept(callee.expr) | ||
args = [builder.accept(arg) for arg in expr.args] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a convenience. This is the sort of thing dataclasses are great for!