From ba56c5b37875c42f2680dfe19a2d3c5095107930 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 4 Mar 2022 21:00:52 -0800 Subject: [PATCH 1/3] fix source code annotation for sqrt the `parse_body` call in `generate_inline_function` attaches incorrect position info into the generated code. --- vyper/builtin_functions/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vyper/builtin_functions/utils.py b/vyper/builtin_functions/utils.py index 476cf44898..ec501fc9bd 100644 --- a/vyper/builtin_functions/utils.py +++ b/vyper/builtin_functions/utils.py @@ -4,10 +4,22 @@ from vyper.codegen.stmt import parse_body +def _strip_pos(lll_node): + lll_node.pos = None + for x in lll_node.args: + strip_pos(x) + def generate_inline_function(code, variables, memory_allocator): ast_code = parse_to_ast(code) new_context = Context( vars_=variables, global_ctx=GlobalContext(), memory_allocator=memory_allocator ) generated_lll = parse_body(ast_code.body, new_context) + # strip source position info from the generated_lll since + # it doesn't make any sense (e.g. the line numbers will start from 0 + # instead of where we are in the code) + # NOTE if we ever use this for inlining user-code, it would make + # sense to fix the offsets of the source positions in the generated + # code instead of stripping them. + _strip_pos(generated_lll) return new_context, generated_lll From 127391d1124d12f3749a2c393d81ef7dfe5c230a Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Sat, 5 Mar 2022 16:42:17 +0000 Subject: [PATCH 2/3] fix a typo --- vyper/builtin_functions/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vyper/builtin_functions/utils.py b/vyper/builtin_functions/utils.py index ec501fc9bd..173b475246 100644 --- a/vyper/builtin_functions/utils.py +++ b/vyper/builtin_functions/utils.py @@ -7,7 +7,8 @@ def _strip_pos(lll_node): lll_node.pos = None for x in lll_node.args: - strip_pos(x) + _strip_pos(x) + def generate_inline_function(code, variables, memory_allocator): ast_code = parse_to_ast(code) From e2883324d7db671cb09c7e0337be8eb1c63f8393 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Mon, 28 Mar 2022 13:52:18 -0700 Subject: [PATCH 3/3] rename pos to source_pos --- vyper/builtin_functions/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vyper/builtin_functions/utils.py b/vyper/builtin_functions/utils.py index 7423638a55..095d5a53f6 100644 --- a/vyper/builtin_functions/utils.py +++ b/vyper/builtin_functions/utils.py @@ -4,10 +4,10 @@ from vyper.codegen.stmt import parse_body -def _strip_pos(ir_node): - ir_node.pos = None +def _strip_source_pos(ir_node): + ir_node.source_pos = None for x in ir_node.args: - _strip_pos(x) + _strip_source_pos(x) def generate_inline_function(code, variables, memory_allocator): @@ -22,5 +22,5 @@ def generate_inline_function(code, variables, memory_allocator): # NOTE if we ever use this for inlining user-code, it would make # sense to fix the offsets of the source positions in the generated # code instead of stripping them. - _strip_pos(generated_ir) + _strip_source_pos(generated_ir) return new_context, generated_ir