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

[mypyc] Add 'bit' primitive type and streamline branching #9606

Merged
merged 13 commits into from
Oct 17, 2020
Prev Previous commit
Next Next commit
Use bit type for some primitives
  • Loading branch information
JukkaL committed Oct 17, 2020
commit dcab0885d2f294c7b7b568b142e7f44b7f3ac3d2
4 changes: 2 additions & 2 deletions mypyc/primitives/dict_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from mypyc.ir.rtypes import (
dict_rprimitive, object_rprimitive, bool_rprimitive, int_rprimitive,
list_rprimitive, dict_next_rtuple_single, dict_next_rtuple_pair, c_pyssize_t_rprimitive,
c_int_rprimitive
c_int_rprimitive, bit_rprimitive
)

from mypyc.primitives.registry import (
Expand Down Expand Up @@ -203,7 +203,7 @@
# check that len(dict) == const during iteration
dict_check_size_op = c_custom_op(
arg_types=[dict_rprimitive, int_rprimitive],
return_type=bool_rprimitive,
return_type=bit_rprimitive,
c_function_name='CPyDict_CheckSize',
error_kind=ERR_FALSE)

Expand Down
8 changes: 5 additions & 3 deletions mypyc/primitives/exc_ops.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Exception-related primitive ops."""

from mypyc.ir.ops import ERR_NEVER, ERR_FALSE, ERR_ALWAYS
from mypyc.ir.rtypes import bool_rprimitive, object_rprimitive, void_rtype, exc_rtuple
from mypyc.ir.rtypes import (
bool_rprimitive, object_rprimitive, void_rtype, exc_rtuple, bit_rprimitive
)
from mypyc.primitives.registry import c_custom_op

# If the argument is a class, raise an instance of the class. Otherwise, assume
Expand Down Expand Up @@ -37,7 +39,7 @@
# Propagate exception if the CPython error indicator is set (an exception was raised).
no_err_occurred_op = c_custom_op(
arg_types=[],
return_type=bool_rprimitive,
return_type=bit_rprimitive,
c_function_name='CPy_NoErrOccured',
error_kind=ERR_FALSE)

Expand All @@ -52,7 +54,7 @@
# This doesn't actually raise an exception.
keep_propagating_op = c_custom_op(
arg_types=[],
return_type=bool_rprimitive,
return_type=bit_rprimitive,
c_function_name='CPy_KeepPropagating',
error_kind=ERR_FALSE)

Expand Down
4 changes: 2 additions & 2 deletions mypyc/primitives/list_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mypyc.ir.ops import ERR_MAGIC, ERR_NEVER, ERR_FALSE, EmitterInterface
from mypyc.ir.rtypes import (
int_rprimitive, short_int_rprimitive, list_rprimitive, object_rprimitive, bool_rprimitive,
c_int_rprimitive, c_pyssize_t_rprimitive
c_int_rprimitive, c_pyssize_t_rprimitive, bit_rprimitive
)
from mypyc.primitives.registry import (
load_address_op, c_function_op, c_binary_op, c_method_op, c_custom_op, ERR_NEG_INT
Expand Down Expand Up @@ -62,7 +62,7 @@
list_set_item_op = c_method_op(
name='__setitem__',
arg_types=[list_rprimitive, int_rprimitive, object_rprimitive],
return_type=bool_rprimitive,
return_type=bit_rprimitive,
c_function_name='CPyList_SetItem',
error_kind=ERR_FALSE,
steals=[False, False, True])
Expand Down
4 changes: 2 additions & 2 deletions mypyc/primitives/misc_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mypyc.ir.ops import ERR_NEVER, ERR_MAGIC, ERR_FALSE
from mypyc.ir.rtypes import (
RTuple, bool_rprimitive, object_rprimitive, str_rprimitive,
int_rprimitive, dict_rprimitive, c_int_rprimitive
int_rprimitive, dict_rprimitive, c_int_rprimitive, bit_rprimitive
)
from mypyc.primitives.registry import (
simple_emit, func_op, custom_op, c_function_op, c_custom_op, load_address_op, ERR_NEG_INT
Expand Down Expand Up @@ -177,6 +177,6 @@
# CPyDataclass_SleightOfHand for more docs.
dataclass_sleight_of_hand = c_custom_op(
arg_types=[object_rprimitive, object_rprimitive, dict_rprimitive, dict_rprimitive],
return_type=bool_rprimitive,
return_type=bit_rprimitive,
c_function_name='CPyDataclass_SleightOfHand',
error_kind=ERR_FALSE)
5 changes: 3 additions & 2 deletions mypyc/primitives/set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from mypyc.primitives.registry import c_function_op, c_method_op, c_binary_op, ERR_NEG_INT
from mypyc.ir.ops import ERR_MAGIC, ERR_FALSE
from mypyc.ir.rtypes import (
object_rprimitive, bool_rprimitive, set_rprimitive, c_int_rprimitive, pointer_rprimitive
object_rprimitive, bool_rprimitive, set_rprimitive, c_int_rprimitive, pointer_rprimitive,
bit_rprimitive
)


Expand Down Expand Up @@ -46,7 +47,7 @@
c_method_op(
name='remove',
arg_types=[set_rprimitive, object_rprimitive],
return_type=bool_rprimitive,
return_type=bit_rprimitive,
c_function_name='CPySet_Remove',
error_kind=ERR_FALSE)

Expand Down