Skip to content

[mypyc] Properly box int32/int64 #9119

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

Merged
merged 2 commits into from
Jul 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions mypyc/codegen/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,10 @@ def emit_box(self, src: str, dest: str, typ: RType, declare_dest: bool = False,
self.emit_lines('{}{} = Py_None;'.format(declaration, dest))
if not can_borrow:
self.emit_inc_ref(dest, object_rprimitive)
# TODO: This is a hack to handle mypy's false negative on unreachable code.
# All ops returning int32/int64 should not be coerced into object.
# Since their result will not be used elsewhere, it's safe to use NULL here
elif is_int32_rprimitive(typ) or is_int64_rprimitive(typ):
self.emit_lines('{}{} = NULL;'.format(declaration, dest))
elif is_int32_rprimitive(typ):
self.emit_line('{}{} = PyLong_FromLong({});'.format(declaration, dest, src))
elif is_int64_rprimitive(typ):
self.emit_line('{}{} = PyLong_FromLongLong({});'.format(declaration, dest, src))
elif isinstance(typ, RTuple):
self.declare_tuple_struct(typ)
self.emit_line('{}{} = PyTuple_New({});'.format(declaration, dest, len(typ.types)))
Expand Down