Skip to content

Commit

Permalink
Merge branch 'master' into feat/fencing
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 20, 2024
2 parents 0582db5 + 48a5da4 commit 4f3b0ec
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions tests/functional/codegen/features/test_constructor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import pytest

from tests.evm_backends.base_env import _compile
from vyper.exceptions import StackTooDeep
from vyper.utils import method_id


Expand Down Expand Up @@ -166,6 +169,7 @@ def get_foo() -> uint256:
assert c.get_foo() == 39


@pytest.mark.venom_xfail(raises=StackTooDeep, reason="stack scheduler regression")
def test_nested_dynamic_array_constructor_arg_2(env, get_contract):
code = """
foo: int128
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/ast/nodes/test_hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def foo():
"""
foo: constant(bytes4) = 0x12_34_56
""",
"""
foo: constant(bytes4) = 0X12345678
""",
]


Expand Down
5 changes: 5 additions & 0 deletions vyper/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,15 @@ class Hex(Constant):

def validate(self):
if "_" in self.value:
# TODO: revisit this, we should probably allow underscores
raise InvalidLiteral("Underscores not allowed in hex literals", self)
if len(self.value) % 2:
raise InvalidLiteral("Hex notation requires an even number of digits", self)

if self.value.startswith("0X"):
hint = f"Did you mean `0x{self.value[2:]}`?"
raise InvalidLiteral("Hex literal begins with 0X!", self, hint=hint)

@property
def n_nibbles(self):
"""
Expand Down
37 changes: 21 additions & 16 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ def _generate_evm_for_basicblock_r(
return
self.visited_basicblocks.add(basicblock)

import sys
#print(basicblock, file=sys.stderr)
#import sys
# print(basicblock, file=sys.stderr)

ref = asm
asm = []
Expand All @@ -298,8 +298,8 @@ def _generate_evm_for_basicblock_r(

asm.extend(self._generate_evm_for_instruction(inst, stack, next_liveness))

#print(" ".join(map(str, asm)), file=sys.stderr)
#print("\n", file=sys.stderr)
# print(" ".join(map(str, asm)), file=sys.stderr)
# print("\n", file=sys.stderr)

ref.extend(asm)

Expand Down Expand Up @@ -403,18 +403,23 @@ def _generate_evm_for_instruction(
# Step 2: Emit instruction's input operands
self._emit_input_operands(assembly, inst, operands, stack)

# Step 3: Reorder stack
if opcode in ["jnz", "djmp", "jmp"]:
# prepare stack for jump into another basic block
assert inst.parent and isinstance(inst.parent.cfg_out, OrderedSet)
b = inst.parent.cfg_out.first()
target_stack = self.liveness_analysis.input_vars_from(inst.parent, b)
# TODO optimize stack reordering at entry and exit from basic blocks
# NOTE: stack in general can contain multiple copies of the same variable,
# however we are safe in the case of jmp/djmp/jnz as it's not going to
# have multiples.
target_stack_list = list(target_stack)
self._stack_reorder(assembly, stack, target_stack_list)
# Step 3: Reorder stack before join points
if opcode == "jmp":
# prepare stack for jump into a join point
# we only need to reorder stack before join points, which after
# cfg normalization, join points can only be led into by
# jmp instructions.
assert isinstance(inst.parent.cfg_out, OrderedSet)
assert len(inst.parent.cfg_out) == 1
next_bb = inst.parent.cfg_out.first()

# guaranteed by cfg normalization+simplification
assert len(next_bb.cfg_in) > 1

target_stack = self.liveness_analysis.input_vars_from(inst.parent, next_bb)
# NOTE: in general the stack can contain multiple copies of
# the same variable, however, before a jump that is not possible
self._stack_reorder(assembly, stack, list(target_stack))

if opcode in COMMUTATIVE_INSTRUCTIONS:
cost_no_swap = self._stack_reorder([], stack, operands, dry_run=True)
Expand Down

0 comments on commit 4f3b0ec

Please sign in to comment.