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] Merge misc object ops #9320

Merged
merged 3 commits into from
Aug 18, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mypyc/irbuild/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def transform_bytes_expr(builder: IRBuilder, expr: BytesExpr) -> Value:


def transform_ellipsis(builder: IRBuilder, o: EllipsisExpr) -> Value:
return builder.primitive_op(ellipsis_op, [], o.line)
return builder.add(LoadAddress(ellipsis_op.type, ellipsis_op.src, o.line))


# Display expressions
Expand Down
4 changes: 2 additions & 2 deletions mypyc/irbuild/ll_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
LoadStatic, MethodCall, PrimitiveOp, OpDescription, RegisterOp, CallC, Truncate,
RaiseStandardError, Unreachable, LoadErrorValue, LoadGlobal,
NAMESPACE_TYPE, NAMESPACE_MODULE, NAMESPACE_STATIC, BinaryIntOp, GetElementPtr,
LoadMem
LoadMem, LoadAddress
)
from mypyc.ir.rtypes import (
RType, RUnion, RInstance, optional_value_type, int_rprimitive, float_rprimitive,
Expand Down Expand Up @@ -438,7 +438,7 @@ def false(self) -> Value:

def none_object(self) -> Value:
"""Load Python None value (type: object_rprimitive)."""
return self.add(PrimitiveOp([], none_object_op, line=-1))
return self.add(LoadAddress(none_object_op.type, none_object_op.src, line=-1))

def literal_static_name(self, value: Union[int, float, complex, str, bytes]) -> str:
return STATIC_PREFIX + self.mapper.literal_static_name(self.current_module, value)
Expand Down
23 changes: 9 additions & 14 deletions mypyc/primitives/misc_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,22 @@
int_rprimitive, dict_rprimitive, c_int_rprimitive
)
from mypyc.primitives.registry import (
simple_emit, unary_op, func_op, custom_op, call_emit, name_emit,
simple_emit, unary_op, func_op, custom_op, call_emit,
c_function_op, c_custom_op, load_address_op
)


# Get the boxed Python 'None' object
none_object_op = custom_op(result_type=object_rprimitive,
arg_types=[],
error_kind=ERR_NEVER,
format_str='{dest} = builtins.None :: object',
emit=name_emit('Py_None'),
is_borrowed=True)

none_object_op = load_address_op(
name='Py_None',
type=object_rprimitive,
src='_Py_NoneStruct')

# Get the boxed object '...'
ellipsis_op = custom_op(name='...',
arg_types=[],
result_type=object_rprimitive,
error_kind=ERR_NEVER,
emit=name_emit('Py_Ellipsis'),
is_borrowed=True)
ellipsis_op = load_address_op(
name='...',
type=object_rprimitive,
src='_Py_EllipsisObject')

# Get the boxed NotImplemented object
not_implemented_op = load_address_op(
Expand Down
6 changes: 0 additions & 6 deletions mypyc/primitives/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ def emit(emitter: EmitterInterface, args: List[str], dest: str) -> None:
return emit


def name_emit(name: str, target_type: Optional[str] = None) -> EmitCallback:
"""Construct a PrimitiveOp emit callback function that assigns a C name."""
cast = "({})".format(target_type) if target_type else ""
return simple_emit('{dest} = %s%s;' % (cast, name))


def call_emit(func: str) -> EmitCallback:
"""Construct a PrimitiveOp emit callback function that calls a C function."""
return simple_emit('{dest} = %s({comma_args});' % func)
Expand Down
28 changes: 14 additions & 14 deletions mypyc/test-data/irbuild-basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ def opt_int(x):
r4 :: native_int
r5, r6, r7, r8 :: bool
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = x is not r0
if r1 goto L1 else goto L6 :: bool
L1:
Expand Down Expand Up @@ -1436,7 +1436,7 @@ def opt_a(x):
r0 :: object
r1 :: bool
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = x is not r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -1453,7 +1453,7 @@ def opt_o(x):
r3 :: int32
r4 :: bool
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = x is not r0
if r1 goto L1 else goto L3 :: bool
L1:
Expand Down Expand Up @@ -1541,7 +1541,7 @@ def __top_level__():
r15, r16, r17 :: object
L0:
r0 = builtins :: module
r1 = builtins.None :: object
r1 = load_address _Py_NoneStruct
r2 = r0 is not r1
if r2 goto L2 else goto L1 :: bool
L1:
Expand Down Expand Up @@ -2579,7 +2579,7 @@ def __top_level__():
r81 :: int32
L0:
r0 = builtins :: module
r1 = builtins.None :: object
r1 = load_address _Py_NoneStruct
r2 = r0 is not r1
if r2 goto L2 else goto L1 :: bool
L1:
Expand All @@ -2588,7 +2588,7 @@ L1:
builtins = r4 :: module
L2:
r5 = typing :: module
r6 = builtins.None :: object
r6 = load_address _Py_NoneStruct
r7 = r5 is not r6
if r7 goto L4 else goto L3 :: bool
L3:
Expand Down Expand Up @@ -2798,7 +2798,7 @@ def g_a_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -2855,7 +2855,7 @@ def g_b_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -2912,7 +2912,7 @@ def __mypyc_d_decorator_helper_____mypyc_c_decorator_helper___obj.__get__(__mypy
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -3001,7 +3001,7 @@ def __top_level__():
r29 :: int32
L0:
r0 = builtins :: module
r1 = builtins.None :: object
r1 = load_address _Py_NoneStruct
r2 = r0 is not r1
if r2 goto L2 else goto L1 :: bool
L1:
Expand All @@ -3010,7 +3010,7 @@ L1:
builtins = r4 :: module
L2:
r5 = typing :: module
r6 = builtins.None :: object
r6 = load_address _Py_NoneStruct
r7 = r5 is not r6
if r7 goto L4 else goto L3 :: bool
L3:
Expand Down Expand Up @@ -3056,7 +3056,7 @@ def g_a_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -3123,7 +3123,7 @@ def __top_level__():
r15 :: int32
L0:
r0 = builtins :: module
r1 = builtins.None :: object
r1 = load_address _Py_NoneStruct
r2 = r0 is not r1
if r2 goto L2 else goto L1 :: bool
L1:
Expand All @@ -3132,7 +3132,7 @@ L1:
builtins = r4 :: module
L2:
r5 = typing :: module
r6 = builtins.None :: object
r6 = load_address _Py_NoneStruct
r7 = r5 is not r6
if r7 goto L4 else goto L3 :: bool
L3:
Expand Down
6 changes: 3 additions & 3 deletions mypyc/test-data/irbuild-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def __top_level__():
r80 :: int32
L0:
r0 = builtins :: module
r1 = builtins.None :: object
r1 = load_address _Py_NoneStruct
r2 = r0 is not r1
if r2 goto L2 else goto L1 :: bool
L1:
Expand All @@ -360,7 +360,7 @@ L1:
builtins = r4 :: module
L2:
r5 = typing :: module
r6 = builtins.None :: object
r6 = load_address _Py_NoneStruct
r7 = r5 is not r6
if r7 goto L4 else goto L3 :: bool
L3:
Expand All @@ -379,7 +379,7 @@ L4:
r18 = unicode_3 :: static ('Generic')
r19 = CPyDict_SetItem(r11, r18, r17)
r20 = mypy_extensions :: module
r21 = builtins.None :: object
r21 = load_address _Py_NoneStruct
r22 = r20 is not r21
if r22 goto L6 else goto L5 :: bool
L5:
Expand Down
36 changes: 18 additions & 18 deletions mypyc/test-data/irbuild-nested.test
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def inner_a_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -74,7 +74,7 @@ def second_b_first_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -100,7 +100,7 @@ def first_b_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -145,7 +145,7 @@ def inner_c_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -184,7 +184,7 @@ def inner_d_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -279,7 +279,7 @@ def inner_a_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -321,7 +321,7 @@ def inner_b_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -367,7 +367,7 @@ def inner_c_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -391,7 +391,7 @@ def inner_c_obj_0.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -453,7 +453,7 @@ def c_a_b_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -479,7 +479,7 @@ def b_a_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -548,7 +548,7 @@ def inner_f_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -572,7 +572,7 @@ def inner_f_obj_0.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -641,7 +641,7 @@ def foo_f_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -666,7 +666,7 @@ def bar_f_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -692,7 +692,7 @@ def baz_f_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down Expand Up @@ -785,7 +785,7 @@ def __mypyc_lambda__0_f_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand All @@ -807,7 +807,7 @@ def __mypyc_lambda__1_f_obj.__get__(__mypyc_self__, instance, owner):
r1 :: bool
r2 :: object
L0:
r0 = builtins.None :: object
r0 = load_address _Py_NoneStruct
r1 = instance is r0
if r1 goto L1 else goto L2 :: bool
L1:
Expand Down
Loading