From 4f9f8133191c25841e309ad26f3124dbe2a46b21 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Wed, 17 May 2023 19:18:13 -0400 Subject: [PATCH] fix: generate separate function names depending on context (#3423) for backends (like zksync) which only have a single compilation context (i.e., they do not split initcode and runtime code like EVM), they need separate names for the two different codes generated per-function as of c202c4e3ec8. this is also hygienic - since the two functions actually have different codes as of c202c4e3ec8, give them different names. --- tests/compiler/asm/test_asm_optimizer.py | 4 ++-- tests/parser/test_call_graph_stability.py | 4 +++- vyper/codegen/function_definitions/common.py | 6 +++--- vyper/codegen/function_definitions/internal_function.py | 2 +- vyper/codegen/self_call.py | 5 +++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/compiler/asm/test_asm_optimizer.py b/tests/compiler/asm/test_asm_optimizer.py index 524b8df064..b82d568ff8 100644 --- a/tests/compiler/asm/test_asm_optimizer.py +++ b/tests/compiler/asm/test_asm_optimizer.py @@ -31,8 +31,8 @@ def __init__(): # all the labels should be in all the unoptimized asms for s in (foo_label, qux_label): - assert s in initcode_asm - assert s in runtime_asm + assert s + "_deploy" in initcode_asm + assert s + "_runtime" in runtime_asm c = CompilerData(code, no_optimize=False) initcode_asm = [i for i in c.assembly if not isinstance(i, list)] diff --git a/tests/parser/test_call_graph_stability.py b/tests/parser/test_call_graph_stability.py index 6f78b50053..b651092d16 100644 --- a/tests/parser/test_call_graph_stability.py +++ b/tests/parser/test_call_graph_stability.py @@ -70,4 +70,6 @@ def foo(): r = d.args[0].args[0].value if isinstance(r, str) and r.startswith("internal"): ir_funcs.append(r) - assert ir_funcs == [f._ir_info.internal_function_label for f in sigs.values()] + assert ir_funcs == [ + f._ir_info.internal_function_label(is_ctor_context=False) for f in sigs.values() + ] diff --git a/vyper/codegen/function_definitions/common.py b/vyper/codegen/function_definitions/common.py index 431693caaa..45b97831aa 100644 --- a/vyper/codegen/function_definitions/common.py +++ b/vyper/codegen/function_definitions/common.py @@ -57,10 +57,10 @@ def external_function_base_entry_label(self) -> str: assert not self.func_t.is_internal, "uh oh, should be external" return self.ir_identifier + "_common" - @property - def internal_function_label(self) -> str: + def internal_function_label(self, is_ctor_context: bool = False) -> str: assert self.func_t.is_internal, "uh oh, should be internal" - return self.ir_identifier + suffix = "_deploy" if is_ctor_context else "_runtime" + return self.ir_identifier + suffix def generate_ir_for_function( diff --git a/vyper/codegen/function_definitions/internal_function.py b/vyper/codegen/function_definitions/internal_function.py index d27d8e36e3..17479c4c07 100644 --- a/vyper/codegen/function_definitions/internal_function.py +++ b/vyper/codegen/function_definitions/internal_function.py @@ -46,7 +46,7 @@ def generate_ir_for_internal_function( nonreentrant_pre, nonreentrant_post = get_nonreentrant_lock(func_t) - function_entry_label = func_t._ir_info.internal_function_label + function_entry_label = func_t._ir_info.internal_function_label(context.is_ctor_context) cleanup_label = func_t._ir_info.exit_sequence_label stack_args = ["var_list"] diff --git a/vyper/codegen/self_call.py b/vyper/codegen/self_call.py index 42a9bf2f11..311576194b 100644 --- a/vyper/codegen/self_call.py +++ b/vyper/codegen/self_call.py @@ -62,7 +62,8 @@ def ir_for_self_call(stmt_expr, context): ) # note: internal_function_label asserts `func_t.is_internal`. - return_label = _generate_label(f"{func_t._ir_info.internal_function_label}_call") + _label = func_t._ir_info.internal_function_label(context.is_ctor_context) + return_label = _generate_label(f"{_label}_call") # allocate space for the return buffer # TODO allocate in stmt and/or expr.py @@ -98,7 +99,7 @@ def ir_for_self_call(stmt_expr, context): else: copy_args = make_setter(args_dst, args_as_tuple) - goto_op = ["goto", func_t._ir_info.internal_function_label] + goto_op = ["goto", func_t._ir_info.internal_function_label(context.is_ctor_context)] # pass return buffer to subroutine if return_buffer is not None: goto_op += [return_buffer]