Skip to content

Commit

Permalink
chore: reorder compilation of branches in stmt.py (#3603)
Browse files Browse the repository at this point in the history
the if and else branches were being allocated out-of-source-order. this
commit switches the order of compilation of the if and else branches to
be in source order. this is a hygienic fix, right now the only thing
that should be affected is the memory allocator (but if more side
effects are ever introduced in codegen, the existing code might compile
the side effects out of order).
  • Loading branch information
charles-cooper authored Oct 17, 2023
1 parent 68da04b commit 74a8e02
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions vyper/codegen/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,15 @@ def parse_Assign(self):
return IRnode.from_list(ret)

def parse_If(self):
with self.context.block_scope():
test_expr = Expr.parse_value_expr(self.stmt.test, self.context)
body = ["if", test_expr, parse_body(self.stmt.body, self.context)]

if self.stmt.orelse:
with self.context.block_scope():
add_on = [parse_body(self.stmt.orelse, self.context)]
else:
add_on = []
body.extend([parse_body(self.stmt.orelse, self.context)])

with self.context.block_scope():
test_expr = Expr.parse_value_expr(self.stmt.test, self.context)
body = ["if", test_expr, parse_body(self.stmt.body, self.context)] + add_on
ir_node = IRnode.from_list(body)
return ir_node
return IRnode.from_list(body)

def parse_Log(self):
event = self.stmt._metadata["type"]
Expand Down

0 comments on commit 74a8e02

Please sign in to comment.