Skip to content

[mypyc] Merge most generic ops #9258

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 10 commits into from
Aug 5, 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
10 changes: 5 additions & 5 deletions mypyc/irbuild/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
BasicBlock, AssignmentTarget, AssignmentTargetRegister, AssignmentTargetIndex,
AssignmentTargetAttr, AssignmentTargetTuple, Environment, LoadInt, Value,
Register, Op, Assign, Branch, Unreachable, TupleGet, GetAttr, SetAttr, LoadStatic,
InitStatic, PrimitiveOp, OpDescription, NAMESPACE_MODULE, RaiseStandardError,
InitStatic, OpDescription, NAMESPACE_MODULE, RaiseStandardError,
)
from mypyc.ir.rtypes import (
RType, RTuple, RInstance, int_rprimitive, dict_rprimitive,
Expand Down Expand Up @@ -448,7 +448,7 @@ def assign(self, target: Union[Register, AssignmentTarget],
else:
key = self.load_static_unicode(target.attr)
boxed_reg = self.builder.box(rvalue_reg)
self.add(PrimitiveOp([target.obj, key, boxed_reg], py_setattr_op, line))
self.call_c(py_setattr_op, [target.obj, key, boxed_reg], line)
elif isinstance(target, AssignmentTargetIndex):
target_reg2 = self.gen_method_call(
target.base, '__setitem__', [target.index, rvalue_reg], None, line)
Expand Down Expand Up @@ -484,14 +484,14 @@ def process_iterator_tuple_assignment(self,
rvalue_reg: Value,
line: int) -> None:

iterator = self.primitive_op(iter_op, [rvalue_reg], line)
iterator = self.call_c(iter_op, [rvalue_reg], line)

# This may be the whole lvalue list if there is no starred value
split_idx = target.star_idx if target.star_idx is not None else len(target.items)

# Assign values before the first starred value
for litem in target.items[:split_idx]:
ritem = self.primitive_op(next_op, [iterator], line)
ritem = self.call_c(next_op, [iterator], line)
error_block, ok_block = BasicBlock(), BasicBlock()
self.add(Branch(ritem, error_block, ok_block, Branch.IS_ERROR))

Expand Down Expand Up @@ -532,7 +532,7 @@ def process_iterator_tuple_assignment(self,
# There is no starred value, so check if there are extra values in rhs that
# have not been assigned.
else:
extra = self.primitive_op(next_op, [iterator], line)
extra = self.call_c(next_op, [iterator], line)
error_block, ok_block = BasicBlock(), BasicBlock()
self.add(Branch(extra, ok_block, error_block, Branch.IS_ERROR))

Expand Down
10 changes: 5 additions & 5 deletions mypyc/irbuild/classdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def transform_class_def(builder: IRBuilder, cdef: ClassDef) -> None:
continue
typ = builder.load_native_type_object(cdef.fullname)
value = builder.accept(stmt.rvalue)
builder.primitive_op(
builder.call_c(
py_setattr_op, [typ, builder.load_static_unicode(lvalue.name), value], stmt.line)
if builder.non_function_scope() and stmt.is_final_def:
builder.init_final_static(lvalue, value, cdef.name)
Expand Down Expand Up @@ -182,7 +182,7 @@ def allocate_class(builder: IRBuilder, cdef: ClassDef) -> Value:
None, builder.module_name,
FuncSignature([], bool_rprimitive)), [], -1))
# Populate a '__mypyc_attrs__' field containing the list of attrs
builder.primitive_op(py_setattr_op, [
builder.call_c(py_setattr_op, [
tp, builder.load_static_unicode('__mypyc_attrs__'),
create_mypyc_attrs_tuple(builder, builder.mapper.type_to_ir[cdef.info], cdef.line)],
cdef.line)
Expand Down Expand Up @@ -241,9 +241,9 @@ def setup_non_ext_dict(builder: IRBuilder,
This class dictionary is passed to the metaclass constructor.
"""
# Check if the metaclass defines a __prepare__ method, and if so, call it.
has_prepare = builder.primitive_op(py_hasattr_op,
[metaclass,
builder.load_static_unicode('__prepare__')], cdef.line)
has_prepare = builder.call_c(py_hasattr_op,
[metaclass,
builder.load_static_unicode('__prepare__')], cdef.line)

non_ext_dict = builder.alloc_temp(dict_rprimitive)

Expand Down
2 changes: 1 addition & 1 deletion mypyc/irbuild/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,6 @@ def get_arg(arg: Optional[Expression]) -> Value:

def transform_generator_expr(builder: IRBuilder, o: GeneratorExpr) -> Value:
builder.warning('Treating generator comprehension as list', o.line)
return builder.primitive_op(
return builder.call_c(
iter_op, [translate_list_comprehension(builder, o)], o.line
)
4 changes: 2 additions & 2 deletions mypyc/irbuild/for_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def init(self, expr_reg: Value, target_type: RType) -> None:
# for the for-loop. If we are inside of a generator function, spill these into the
# environment class.
builder = self.builder
iter_reg = builder.primitive_op(iter_op, [expr_reg], self.line)
iter_reg = builder.call_c(iter_op, [expr_reg], self.line)
builder.maybe_spill(expr_reg)
self.iter_target = builder.maybe_spill(iter_reg)
self.target_type = target_type
Expand All @@ -364,7 +364,7 @@ def gen_condition(self) -> None:
# for NULL (an exception does not necessarily have to be raised).
builder = self.builder
line = self.line
self.next_reg = builder.primitive_op(next_op, [builder.read(self.iter_target, line)], line)
self.next_reg = builder.call_c(next_op, [builder.read(self.iter_target, line)], line)
builder.add(Branch(self.next_reg, self.loop_exit, self.body_block, Branch.IS_ERROR))

def begin_body(self) -> None:
Expand Down
18 changes: 9 additions & 9 deletions mypyc/irbuild/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,13 @@ def handle_ext_method(builder: IRBuilder, cdef: ClassDef, fdef: FuncDef) -> None

# Set the callable object representing the decorated method as an attribute of the
# extension class.
builder.primitive_op(py_setattr_op,
[
typ,
builder.load_static_unicode(name),
decorated_func
],
fdef.line)
builder.call_c(py_setattr_op,
[
typ,
builder.load_static_unicode(name),
decorated_func
],
fdef.line)

if fdef.is_property:
# If there is a property setter, it will be processed after the getter,
Expand Down Expand Up @@ -491,14 +491,14 @@ def handle_yield_from_and_await(builder: IRBuilder, o: Union[YieldFromExpr, Awai
received_reg = builder.alloc_temp(object_rprimitive)

if isinstance(o, YieldFromExpr):
iter_val = builder.primitive_op(iter_op, [builder.accept(o.expr)], o.line)
iter_val = builder.call_c(iter_op, [builder.accept(o.expr)], o.line)
else:
iter_val = builder.call_c(coro_op, [builder.accept(o.expr)], o.line)

iter_reg = builder.maybe_spill_assignable(iter_val)

stop_block, main_block, done_block = BasicBlock(), BasicBlock(), BasicBlock()
_y_init = builder.primitive_op(next_raw_op, [builder.read(iter_reg)], o.line)
_y_init = builder.call_c(next_raw_op, [builder.read(iter_reg)], o.line)
builder.add(Branch(_y_init, stop_block, main_block, Branch.IS_ERROR))

# Try extracting a return value from a StopIteration and return it.
Expand Down
2 changes: 1 addition & 1 deletion mypyc/irbuild/ll_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def py_get_attr(self, obj: Value, attr: str, line: int) -> Value:
Prefer get_attr() which generates optimized code for native classes.
"""
key = self.load_static_unicode(attr)
return self.add(PrimitiveOp([obj, key], py_getattr_op, line))
return self.call_c(py_getattr_op, [obj, key], line)

# isinstance() checks

Expand Down
4 changes: 2 additions & 2 deletions mypyc/irbuild/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from mypyc.ir.ops import (
Assign, Unreachable, AssignmentTarget, AssignmentTargetRegister, AssignmentTargetIndex,
AssignmentTargetAttr, AssignmentTargetTuple, PrimitiveOp, RaiseStandardError, LoadErrorValue,
AssignmentTargetAttr, AssignmentTargetTuple, RaiseStandardError, LoadErrorValue,
BasicBlock, TupleGet, Value, Register, Branch, NO_TRACEBACK_LINE_NO
)
from mypyc.ir.rtypes import exc_rtuple
Expand Down Expand Up @@ -634,7 +634,7 @@ def transform_del_item(builder: IRBuilder, target: AssignmentTarget, line: int)
)
elif isinstance(target, AssignmentTargetAttr):
key = builder.load_static_unicode(target.attr)
builder.add(PrimitiveOp([target.obj, key], py_delattr_op, line))
builder.call_c(py_delattr_op, [target.obj, key], line)
elif isinstance(target, AssignmentTargetRegister):
# Delete a local by assigning an error value to it, which will
# prompt the insertion of uninit checks.
Expand Down
Loading