From 74a8e0254461119af9a5d504f326877d7aed4134 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 17 Oct 2023 09:23:40 -0700 Subject: [PATCH] chore: reorder compilation of branches in stmt.py (#3603) 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). --- vyper/codegen/stmt.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/vyper/codegen/stmt.py b/vyper/codegen/stmt.py index c2951986c8..254cad32e6 100644 --- a/vyper/codegen/stmt.py +++ b/vyper/codegen/stmt.py @@ -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"]