Skip to content

Commit

Permalink
refactor[codegen]: remove redundant IRnode.from_list (#4151)
Browse files Browse the repository at this point in the history
following 7d28a50 (GH #3941), replaced occurrences of

```
IRnode.from_list(
    context.new_internal_variable(typ),
    typ=typ,
    location=MEMORY
)
```

with the simpler

```
context.new_internal_variable(typ)
```
  • Loading branch information
trocher authored Jul 26, 2024
1 parent 07e2657 commit a1af967
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
1 change: 0 additions & 1 deletion vyper/codegen/abi_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def _encode_dyn_array_helper(dst, ir_node, context):
# TODO handle this upstream somewhere
if ir_node.value == "multi":
buf = context.new_internal_variable(dst.typ)
buf = IRnode.from_list(buf, typ=dst.typ, location=MEMORY)
_bufsz = dst.typ.abi_type.size_bound()
return [
"seq",
Expand Down
2 changes: 1 addition & 1 deletion vyper/codegen/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ def ensure_in_memory(ir_var, context):
return ir_var

typ = ir_var.typ
buf = IRnode.from_list(context.new_internal_variable(typ), typ=typ, location=MEMORY)
buf = context.new_internal_variable(typ)
do_copy = make_setter(buf, ir_var)

return IRnode.from_list(["seq", do_copy, buf], typ=typ, location=MEMORY)
Expand Down
1 change: 0 additions & 1 deletion vyper/codegen/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,6 @@ def parse_Call(self):
ret = ["seq"]
if potential_overlap(darray, arg):
tmp = self.context.new_internal_variable(arg.typ)
tmp = IRnode.from_list(tmp, typ=arg.typ, location=MEMORY)
ret.append(make_setter(tmp, arg))
arg = tmp

Expand Down
6 changes: 2 additions & 4 deletions vyper/codegen/self_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ def ir_for_self_call(stmt_expr, context):
# allocate space for the return buffer
# TODO allocate in stmt and/or expr.py
if func_t.return_type is not None:
return_buffer = IRnode.from_list(
context.new_internal_variable(func_t.return_type),
annotation=f"{return_label}_return_buf",
)
return_buffer = context.new_internal_variable(func_t.return_type)
return_buffer.annotation = f"{return_label}_return_buf"
else:
return_buffer = None

Expand Down
16 changes: 3 additions & 13 deletions vyper/codegen/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)
from vyper.codegen.expr import Expr
from vyper.codegen.return_ import make_return_stmt
from vyper.evm.address_space import MEMORY
from vyper.exceptions import CodegenPanic, StructureException, TypeCheckFailure, tag_exceptions
from vyper.semantics.types import DArrayT
from vyper.semantics.types.shortcuts import UINT256_T
Expand Down Expand Up @@ -56,13 +55,11 @@ def parse_Name(self):
def parse_AnnAssign(self):
ltyp = self.stmt.target._metadata["type"]
varname = self.stmt.target.id
alloced = self.context.new_variable(varname, ltyp)
lhs = self.context.new_variable(varname, ltyp)

assert self.stmt.value is not None
rhs = Expr(self.stmt.value, self.context).ir_node

lhs = IRnode.from_list(alloced, typ=ltyp, location=MEMORY)

return make_setter(lhs, rhs)

def parse_Assign(self):
Expand All @@ -76,7 +73,6 @@ def parse_Assign(self):
# complex - i.e., it spans multiple words. for safety, we
# copy to a temporary buffer before copying to the destination.
tmp = self.context.new_internal_variable(src.typ)
tmp = IRnode.from_list(tmp, typ=src.typ, location=MEMORY)
ret.append(make_setter(tmp, src))
src = tmp

Expand Down Expand Up @@ -247,9 +243,7 @@ def _parse_For_list(self):

# user-supplied name for loop variable
varname = self.stmt.target.target.id
loop_var = IRnode.from_list(
self.context.new_variable(varname, target_type), typ=target_type, location=MEMORY
)
loop_var = self.context.new_variable(varname, target_type)

i = IRnode.from_list(self.context.fresh_varname("for_list_ix"), typ=UINT256_T)

Expand All @@ -259,11 +253,7 @@ def _parse_For_list(self):

# list literal, force it to memory first
if isinstance(self.stmt.iter, vy_ast.List):
tmp_list = IRnode.from_list(
self.context.new_internal_variable(iter_list.typ),
typ=iter_list.typ,
location=MEMORY,
)
tmp_list = self.context.new_internal_variable(iter_list.typ)
ret.append(make_setter(tmp_list, iter_list))
iter_list = tmp_list

Expand Down

0 comments on commit a1af967

Please sign in to comment.