Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pc maps for function selectors #3487

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions vyper/codegen/function_definitions/external_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def _generate_kwarg_handlers(func_t: ContractFunctionT, context: Context) -> Lis
# copy calldata args to memory
# write default args to memory
# goto external_function_common_ir

def handler_for(calldata_kwargs, default_kwargs):
calldata_args = func_t.positional_args + calldata_kwargs
# create a fake type so that get_element_ptr works
Expand Down Expand Up @@ -201,22 +200,25 @@ def generate_ir_for_external_function(code, func_t, context, skip_nonpayable_che
if context.return_type is not None:
exit_sequence_args += ["ret_ofst", "ret_len"]
# wrap the exit in a labeled block
exit = ["label", func_t._ir_info.exit_sequence_label, exit_sequence_args, exit_sequence]
exit_ = ["label", func_t._ir_info.exit_sequence_label, exit_sequence_args, exit_sequence]

# the ir which comprises the main body of the function,
# besides any kwarg handling
func_common_ir = ["seq", body, exit]
func_common_ir = IRnode.from_list(["seq", body, exit_], source_pos=getpos(code))

if func_t.is_fallback or func_t.is_constructor:
ret = ["seq"]
# add a goto to make the function entry look like other functions
# (for zksync interpreter)
ret.append(["goto", func_t._ir_info.external_function_base_entry_label])
ret.append(func_common_ir)
ret.append(IRnode.from_list(func_common_ir, source_pos=getpos(code)))
else:
ret = kwarg_handlers
# sneak the base code into the kwarg handler
# TODO rethink this / make it clearer
ret[-1][-1].append(func_common_ir)
# annotate the first node in the function as soon as we have validated
# the method id.
ret[-1][2] = IRnode.from_list(ret[-1][2], source_pos=getpos(code))

return IRnode.from_list(ret, source_pos=getpos(code))
return IRnode.from_list(ret)
9 changes: 4 additions & 5 deletions vyper/codegen/ir_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _colorise_keywords(val):
return OKMAGENTA + val + ENDC
return val

def repr(self) -> str:
def __repr__(self) -> str:
if not len(self.args):
if self.annotation:
return f"{self.repr_value} " + OKLIGHTBLUE + f"<{self.annotation}>" + ENDC
Expand All @@ -460,6 +460,8 @@ def repr(self) -> str:
o = ""
if self.annotation:
o += f"/* {self.annotation} */ \n"
# if self.source_pos:
# o += f"/* POS {self.source_pos} */ "
if self.repr_show_gas and self.gas:
o += OKBLUE + "{" + ENDC + str(self.gas) + OKBLUE + "} " + ENDC # add gas for info.
o += "[" + self._colorise_keywords(self.repr_value)
Expand All @@ -474,7 +476,7 @@ def repr(self) -> str:
o += f"# Line {(arg_lineno)}\n "
prev_lineno = arg_lineno
annotated = True
arg_repr = arg.repr()
arg_repr = repr(arg)
if "\n" in arg_repr:
has_inner_newlines = True
sub = arg_repr.replace("\n", "\n ").strip(" ")
Expand All @@ -491,9 +493,6 @@ def repr(self) -> str:
else:
return output

def __repr__(self):
return self.repr()

@classmethod
def from_list(
cls,
Expand Down
2 changes: 1 addition & 1 deletion vyper/ir/compile_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _rewrite_return_sequences(ir_node, label_params=None):
# works for both internal and external exit_to
more_args = ["pass" if t.value == "return_pc" else t for t in args[1:]]
_t.append(["goto", dest] + more_args)
ir_node.args = IRnode.from_list(_t, source_pos=ir_node.source_pos).args
ir_node.args = IRnode.from_list(_t).args

if ir_node.value == "label":
label_params = set(t.value for t in ir_node.args[1].args)
Expand Down