Skip to content

Commit 562183a

Browse files
Merge branch 'master' into fix/varinfo-compare
2 parents 09dd1a3 + 99304da commit 562183a

File tree

18 files changed

+205
-34
lines changed

18 files changed

+205
-34
lines changed

FUNDING.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"drips": {
3+
"ethereum": {
4+
"ownedBy": "0x70CCBE10F980d80b7eBaab7D2E3A73e87D67B775"
5+
}
6+
}
7+
}

docs/compiling-a-contract.rst

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ The following example describes the expected input format of ``vyper-json``. (Co
308308
// devdoc - Natspec developer documentation
309309
// evm.bytecode.object - Bytecode object
310310
// evm.bytecode.opcodes - Opcodes list
311+
// evm.bytecode.sourceMap - Source mapping (useful for debugging)
311312
// evm.deployedBytecode.object - Deployed bytecode object
312313
// evm.deployedBytecode.opcodes - Deployed opcodes list
313-
// evm.deployedBytecode.sourceMap - Solidity-style source mapping
314-
// evm.deployedBytecode.sourceMapFull - Deployed source mapping (useful for debugging)
314+
// evm.deployedBytecode.sourceMap - Deployed source mapping (useful for debugging)
315315
// evm.methodIdentifiers - The list of function hashes
316316
//
317317
// Using `evm`, `evm.bytecode`, etc. will select every target part of that output.
@@ -388,15 +388,37 @@ The following example describes the output format of ``vyper-json``. Comments ar
388388
// The bytecode as a hex string.
389389
"object": "00fe",
390390
// Opcodes list (string)
391-
"opcodes": ""
391+
"opcodes": "",
392+
// The deployed source mapping.
393+
"sourceMap": {
394+
"breakpoints": [],
395+
"error_map": {},
396+
"pc_ast_map": {},
397+
"pc_ast_map_item_keys": [],
398+
"pc_breakpoints": [],
399+
"pc_jump_map": {},
400+
"pc_pos_map": {},
401+
// The deployed source mapping as a string.
402+
"pc_pos_map_compressed": ""
403+
}
392404
},
393405
"deployedBytecode": {
394406
// The deployed bytecode as a hex string.
395407
"object": "00fe",
396408
// Deployed opcodes list (string)
397409
"opcodes": "",
398-
// The deployed source mapping as a string.
399-
"sourceMap": ""
410+
// The deployed source mapping.
411+
"sourceMap": {
412+
"breakpoints": [],
413+
"error_map": {},
414+
"pc_ast_map": {},
415+
"pc_ast_map_item_keys": [],
416+
"pc_breakpoints": [],
417+
"pc_jump_map": {},
418+
"pc_pos_map": {},
419+
// The deployed source mapping as a string.
420+
"pc_pos_map_compressed": ""
421+
}
400422
},
401423
// The list of function hashes
402424
"methodIdentifiers": {

docs/constants-and-vars.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Name Type Value
2626
``chain.id`` ``uint256`` Chain ID
2727
``msg.data`` ``Bytes`` Message data
2828
``msg.gas`` ``uint256`` Remaining gas
29+
``msg.mana`` ``uint256`` Remaining gas (alias for ``msg.gas``)
2930
``msg.sender`` ``address`` Sender of the message (current call)
3031
``msg.value`` ``uint256`` Number of wei sent with the message
3132
``tx.origin`` ``address`` Sender of the transaction (full call chain)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def test_mana_call(get_contract):
2+
mana_call = """
3+
@external
4+
def foo() -> uint256:
5+
return msg.mana
6+
"""
7+
8+
c = get_contract(mana_call)
9+
10+
assert c.foo(gas=50000) < 50000
11+
assert c.foo(gas=50000) > 25000

tests/functional/grammar/test_grammar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def test_basic_grammar_empty():
3737
assert len(tree.children) == 0
3838

3939

40-
def fix_terminal(terminal: str) -> bool:
40+
def fix_terminal(terminal: str) -> str:
4141
# these throw exceptions in the grammar
42-
for bad in ("\x00", "\\ ", "\x0c"):
42+
for bad in ("\x00", "\\ ", "\x0c", "\x0d"):
4343
terminal = terminal.replace(bad, " ")
4444
return terminal
4545

tests/functional/syntax/test_interfaces.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from vyper import compiler
44
from vyper.exceptions import (
55
ArgumentException,
6+
FunctionDeclarationException,
67
InterfaceViolation,
78
InvalidReference,
89
InvalidType,
@@ -421,3 +422,65 @@ def test_builtins_not_found2(erc):
421422
compiler.compile_code(code)
422423
assert e.value._message == f"ethereum.ercs.{erc}"
423424
assert e.value._hint == f"try renaming `{erc}` to `I{erc}`"
425+
426+
427+
def test_interface_body_check(make_input_bundle):
428+
interface_code = """
429+
@external
430+
def foobar():
431+
return ...
432+
"""
433+
434+
input_bundle = make_input_bundle({"foo.vyi": interface_code})
435+
436+
code = """
437+
import foo as Foo
438+
439+
implements: Foo
440+
441+
@external
442+
def foobar():
443+
pass
444+
"""
445+
with pytest.raises(FunctionDeclarationException) as e:
446+
compiler.compile_code(code, input_bundle=input_bundle)
447+
448+
assert e.value._message == "function body in an interface can only be `...`!"
449+
450+
451+
def test_interface_body_check2(make_input_bundle):
452+
interface_code = """
453+
@external
454+
def foobar():
455+
...
456+
457+
@external
458+
def bar():
459+
...
460+
461+
@external
462+
def baz():
463+
...
464+
"""
465+
466+
input_bundle = make_input_bundle({"foo.vyi": interface_code})
467+
468+
code = """
469+
import foo
470+
471+
implements: foo
472+
473+
@external
474+
def foobar():
475+
pass
476+
477+
@external
478+
def bar():
479+
pass
480+
481+
@external
482+
def baz():
483+
pass
484+
"""
485+
486+
assert compiler.compile_code(code, input_bundle=input_bundle) is not None

tests/unit/compiler/venom/test_algebraic_optimizer.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,54 @@ def test_interleaved_case(interleave_point):
127127
assert bb.instructions[-1].operands[0] == op3_inv
128128
else:
129129
assert bb.instructions[-1].operands[0] == op3
130+
131+
132+
def test_offsets():
133+
ctx = IRContext()
134+
fn = ctx.create_function("_global")
135+
136+
bb = fn.get_basic_block()
137+
138+
br1 = IRBasicBlock(IRLabel("then"), fn)
139+
fn.append_basic_block(br1)
140+
br2 = IRBasicBlock(IRLabel("else"), fn)
141+
fn.append_basic_block(br2)
142+
143+
p1 = bb.append_instruction("param")
144+
op1 = bb.append_instruction("store", 32)
145+
op2 = bb.append_instruction("add", 0, IRLabel("mem"))
146+
op3 = bb.append_instruction("store", 64)
147+
bb.append_instruction("dloadbytes", op1, op2, op3)
148+
op5 = bb.append_instruction("mload", op3)
149+
op6 = bb.append_instruction("iszero", op5)
150+
bb.append_instruction("jnz", op6, br1.label, br2.label)
151+
152+
op01 = br1.append_instruction("store", 32)
153+
op02 = br1.append_instruction("add", 0, IRLabel("mem"))
154+
op03 = br1.append_instruction("store", 64)
155+
br1.append_instruction("dloadbytes", op01, op02, op03)
156+
op05 = br1.append_instruction("mload", op03)
157+
op06 = br1.append_instruction("iszero", op05)
158+
br1.append_instruction("return", p1, op06)
159+
160+
op11 = br2.append_instruction("store", 32)
161+
op12 = br2.append_instruction("add", 0, IRLabel("mem"))
162+
op13 = br2.append_instruction("store", 64)
163+
br2.append_instruction("dloadbytes", op11, op12, op13)
164+
op15 = br2.append_instruction("mload", op13)
165+
op16 = br2.append_instruction("iszero", op15)
166+
br2.append_instruction("return", p1, op16)
167+
168+
ac = IRAnalysesCache(fn)
169+
MakeSSA(ac, fn).run_pass()
170+
AlgebraicOptimizationPass(ac, fn).run_pass()
171+
RemoveUnusedVariablesPass(ac, fn).run_pass()
172+
173+
offset_count = 0
174+
for bb in fn.get_basic_blocks():
175+
for instruction in bb.instructions:
176+
assert instruction.opcode != "add"
177+
if instruction.opcode == "offset":
178+
offset_count += 1
179+
180+
assert offset_count == 3

vyper/cli/vyper_compile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ def _parse_args(argv):
121121
)
122122
parser.add_argument(
123123
"--evm-version",
124-
help=f"Select desired EVM version (default {evm.DEFAULT_EVM_VERSION}). "
125-
"note: cancun support is EXPERIMENTAL",
124+
help=f"Select desired EVM version (default {evm.DEFAULT_EVM_VERSION})",
126125
choices=list(evm.EVM_VERSIONS),
127126
dest="evm_version",
128127
)

vyper/codegen/abi_encoder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def _encode_dyn_array_helper(dst, ir_node, context):
7373
# TODO handle this upstream somewhere
7474
if ir_node.value == "multi":
7575
buf = context.new_internal_variable(dst.typ)
76-
buf = IRnode.from_list(buf, typ=dst.typ, location=MEMORY)
7776
_bufsz = dst.typ.abi_type.size_bound()
7877
return [
7978
"seq",

vyper/codegen/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ def ensure_in_memory(ir_var, context):
11171117
return ir_var
11181118

11191119
typ = ir_var.typ
1120-
buf = IRnode.from_list(context.new_internal_variable(typ), typ=typ, location=MEMORY)
1120+
buf = context.new_internal_variable(typ)
11211121
do_copy = make_setter(buf, ir_var)
11221122

11231123
return IRnode.from_list(["seq", do_copy, buf], typ=typ, location=MEMORY)

0 commit comments

Comments
 (0)