Skip to content

Commit

Permalink
update scope exit logic
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 2, 2024
1 parent e0261dc commit 7ce131e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions vyper/codegen/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,18 @@ def mark_for_deallocation(self, varname):

# "mark-and-sweep", haha
def sweep(self):
tmp = set()
for varname in self._to_deallocate:
self.deallocate_variable(varname, self.vars[varname])
self._to_deallocate.clear()
var = self.vars[varname]
for s in self._scopes:
if s not in var.blockscopes:
# defer deallocation until we hit the end of its scope
tmp.add(varname)
break
else:
self.deallocate_variable(varname, self.vars[varname])

self._to_deallocate = tmp

def _new_variable(
self,
Expand Down
3 changes: 2 additions & 1 deletion vyper/codegen/stmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ def __init__(self, node: vy_ast.VyperNode, context: Context) -> None:
fn = getattr(self, fn_name)
with context.internal_memory_scope():
self.ir_node = fn()
context.sweep()

assert isinstance(self.ir_node, IRnode), self.ir_node

self.ir_node.annotation = self.stmt.get("node_source_code")
self.ir_node.ast_source = self.stmt

context.sweep()

def parse_Expr(self):
return Expr(self.stmt.value, self.context, is_stmt=True).ir_node

Expand Down

0 comments on commit 7ce131e

Please sign in to comment.