Skip to content

Commit

Permalink
use IRnode generated id
Browse files Browse the repository at this point in the history
in case of copies, the ID will be copied appropriately
  • Loading branch information
charles-cooper committed Mar 16, 2024
1 parent 686b726 commit 11535df
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions vyper/codegen/ir_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class IRnode:
func_ir: Any
common_ir: Any

_id: int
_next_id: int = -1

def __init__(
self,
value: Union[str, int],
Expand All @@ -153,6 +156,7 @@ def __init__(
encoding: Encoding = Encoding.VYPER,
is_self_call: bool = False,
passthrough_metadata: dict[str, Any] = None,
_id: int = None,
):
if args is None:
args = []
Expand All @@ -175,6 +179,8 @@ def __init__(
self.func_ir = None
self.common_ir = None

self._id = self.ensure_id()

assert self.value is not None, "None is not allowed as IRnode value"

# Determine this node's valency (1 if it pushes a value on the stack,
Expand Down Expand Up @@ -358,6 +364,16 @@ def __deepcopy__(self, memo):
ret.args = [copy.deepcopy(arg) for arg in ret.args]
return ret

@classmethod
def generate_id(cls):
cls._next_id += 1
return cls._next_id

def ensure_id(self):
if not hasattr(self, "_id"):
self._id = self.generate_id()
return self._id

# TODO would be nice to rename to `gas_estimate` or `gas_bound`
@property
def gas(self):
Expand Down
4 changes: 2 additions & 2 deletions vyper/ir/compile_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ def apply_line_no_wrapper(*args, **kwargs):
def check_duplicated_nodes(ir_node, seen=None):
seen = seen or set()

if ir_node.is_complex_ir and id(ir_node) in seen:
if ir_node.is_complex_ir and ir_node._id in seen:
raise CompilerPanic(f"bad code {ir_node}", ir_node.ast_source)
seen.add(id(ir_node))
seen.add(ir_node._id)

for arg in ir_node.args:
check_duplicated_nodes(arg, seen)
Expand Down

0 comments on commit 11535df

Please sign in to comment.