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

refactor: remove FunctionSignature #3390

Merged
merged 112 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 108 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
2b188db
remove constant_override
tserg May 8, 2023
9f4f129
remove vdb and debugger
tserg May 8, 2023
efc64d3
fix lint
tserg May 8, 2023
910a310
remove debugger codegen
tserg May 8, 2023
4e365af
fix lint
tserg May 8, 2023
0bcd71d
remove parse_type
tserg May 8, 2023
e3c6300
try removing parse_type entirely
tserg May 8, 2023
9fd5d31
fix type fetching
tserg May 8, 2023
c29179b
fix return type for convert
tserg May 8, 2023
c58312f
undo deletion
tserg May 8, 2023
1009ad4
Merge branch 'chore/ir_dead_code' into chore/parse_type
tserg May 9, 2023
09ade31
refactor function signature wip
tserg May 9, 2023
e86bbe8
fn sig wip
tserg May 9, 2023
0e7638b
fix kwargs
tserg May 9, 2023
05038cc
fix imports
tserg May 9, 2023
e1036dd
remove fn sig
tserg May 9, 2023
2ac2633
add typing
tserg May 9, 2023
23136d6
fix lint
tserg May 9, 2023
857aed0
improve comments
tserg May 9, 2023
70af3e8
fix mypy lint
tserg May 9, 2023
428e56c
minor refactor
tserg May 9, 2023
455c530
fix _to_dict
tserg May 9, 2023
1b5ade7
fix mypy
tserg May 9, 2023
5a24888
fix mypy
tserg May 9, 2023
77d62c7
remove base signature
tserg May 9, 2023
66f0b58
more refactoring
tserg May 9, 2023
3267971
fix typing
tserg May 9, 2023
5cb95cd
add properties to avoid cyclic imports
tserg May 9, 2023
3f6ecba
wip
tserg May 11, 2023
168d7e9
remove generate_signature
tserg May 11, 2023
a9be7c6
remove debug prints
tserg May 11, 2023
d599838
wip
tserg May 11, 2023
5f30f85
rename to args wip
tserg May 11, 2023
31a5f21
remove arguments temporarily wip
tserg May 11, 2023
6aa2158
fix metadata
tserg May 11, 2023
cb38b43
fixes and refactoring wip
tserg May 11, 2023
4fd56f8
rename args back to arguments
tserg May 11, 2023
182900a
change kwarg_keys to attribute
tserg May 11, 2023
7ec03f0
fix output
tserg May 11, 2023
6e55691
rename attribute
tserg May 11, 2023
14684ae
minor clean up
tserg May 11, 2023
eec6e03
more clean up
tserg May 11, 2023
c327b4e
remove unused properties; fix mypy
tserg May 11, 2023
38dd675
clean up type
tserg May 11, 2023
61c047f
split args to positional and keyword wip
tserg May 12, 2023
984b6a5
fix signature
tserg May 12, 2023
58a6e7f
remove default_args and base_args properties
tserg May 12, 2023
e5147b8
remove kwarg_keys property
tserg May 12, 2023
2786c29
Merge branch 'master' of https://github.com/vyperlang/vyper into chor…
tserg May 12, 2023
429278a
some fixes
tserg May 12, 2023
4cbd423
refactor wip
tserg May 12, 2023
b6c9719
replace ordered dict with list
tserg May 12, 2023
8cc93f5
add function ir info
tserg May 12, 2023
d80f7ad
fix mypy lint
tserg May 12, 2023
ab6515e
move frame info inside ir info
tserg May 12, 2023
057b808
fix generate_inline_fn
tserg May 12, 2023
5b9d267
fix failing hypothesis tests; weird
tserg May 12, 2023
6a8af4f
fix kwargs vals
tserg May 12, 2023
e7a5ce3
fix argname check
tserg May 12, 2023
6d911ce
fix call graph test
tserg May 12, 2023
ad374e1
preserve custom types in namespace
tserg May 13, 2023
98e6317
improve comment
tserg May 13, 2023
5fe5011
fix lint
tserg May 13, 2023
29ff538
Merge branch 'master' of https://github.com/vyperlang/vyper into chor…
tserg May 14, 2023
a75d4b8
add tests
tserg May 14, 2023
2d03561
fix lint
tserg May 14, 2023
193c44c
skip early return when adding module custom types
tserg May 14, 2023
2f057d0
remove module_custom_types
charles-cooper May 15, 2023
ff47457
rename arguments_typs
charles-cooper May 15, 2023
d1c8373
fix lint
charles-cooper May 15, 2023
1b2bce7
split out Positional and KeywordArgs
charles-cooper May 15, 2023
35f58e6
fix __str__
charles-cooper May 15, 2023
f47e8ad
Merge branch 'master' into chore/parse_type
charles-cooper May 15, 2023
ff7edb3
move call_site_kwargs into a property
charles-cooper May 15, 2023
cec2901
remove a comment
charles-cooper May 15, 2023
7f8985c
rewrite get_default_value into cached property
charles-cooper May 15, 2023
ab8cc62
fix mypy
charles-cooper May 15, 2023
13c8bd0
revert deletion of vdb
tserg May 16, 2023
dd1c974
refactor is_mutable
tserg May 16, 2023
b47526b
fix references to ir_info
tserg May 16, 2023
c085d38
undo formatting changes
tserg May 16, 2023
1d7b3a1
fix kwarg instantiation
tserg May 16, 2023
09cf337
undo vdb deletion
tserg May 16, 2023
7bfbdf9
fix mypy
tserg May 16, 2023
30b7ab9
rename sig to func_t
tserg May 16, 2023
3901359
fix lint
tserg May 16, 2023
08a7245
set IR info in codegen
tserg May 16, 2023
731fbe2
refactor function.ir_info a bit
charles-cooper May 16, 2023
5c2ebd4
undo a change sig->func_t
charles-cooper May 16, 2023
cb8bd15
reverse order of func_t and context
charles-cooper May 16, 2023
32eb3bb
clean up a mypy hint
charles-cooper May 16, 2023
62166df
some small fixes
charles-cooper May 16, 2023
88df8c6
remove func_ts (formerly sigs) from Context, vyper.codegen.modules no…
charles-cooper May 16, 2023
7226a9d
move lookup_internal_function to the right module (finally!)
charles-cooper May 16, 2023
727923e
fix a signature
charles-cooper May 16, 2023
c31e4b1
fix function_signatures
charles-cooper May 16, 2023
19cf410
fix metadata output again
charles-cooper May 16, 2023
cae0b49
update comments
tserg May 17, 2023
9554dec
fix lint
tserg May 17, 2023
2d754af
update error msg
tserg May 17, 2023
e6bf56d
fix a comment
charles-cooper May 17, 2023
db51949
improve a comment
charles-cooper May 17, 2023
ccacb08
clarify a kwarg
charles-cooper May 17, 2023
e5896f9
clean up convert a bit
charles-cooper May 17, 2023
6a9dcb6
rename: FunctionIRInfo -> FuncIRInfo
charles-cooper May 17, 2023
34421e2
streamline _align_kwargs
charles-cooper May 17, 2023
2af7ab1
add an assert
charles-cooper May 17, 2023
13541a1
fix is_internal check
charles-cooper May 17, 2023
1135f13
add missing args dict to metadata output
charles-cooper May 17, 2023
9c23c7d
fix default_values
charles-cooper May 17, 2023
7717a11
add internal field to metadata
charles-cooper May 17, 2023
37af37c
remove internal and args from metadata
charles-cooper May 17, 2023
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
3 changes: 3 additions & 0 deletions tests/base_conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import pytest
import web3.exceptions
from eth_tester import EthereumTester, PyEVMBackend
Expand Down Expand Up @@ -120,6 +122,7 @@ def _get_contract(w3, source_code, no_optimize, *args, **kwargs):
show_gas_estimates=True, # Enable gas estimates for testing
)
parse_vyper_source(source_code) # Test grammar.
json.dumps(out["metadata"]) # test metadata is json serializable
abi = out["abi"]
bytecode = out["bytecode"]
value = kwargs.pop("value_in_eth", 0) * 10**18 # Handle deploying with an eth value.
Expand Down
21 changes: 21 additions & 0 deletions tests/parser/syntax/test_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ def __init__():
def foo() -> int128:
return self.x / self.y / self.z
""",
# expansion of public user-defined struct
"""
struct Foo:
a: uint256

x: public(HashMap[uint256, Foo])
""",
# expansion of public user-defined enum
"""
enum Foo:
BAR

x: public(HashMap[uint256, Foo])
""",
# expansion of public user-defined interface
"""
interface Foo:
def bar(): nonpayable

x: public(HashMap[uint256, Foo])
""",
]


Expand Down
2 changes: 1 addition & 1 deletion tests/parser/test_call_graph_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def foo():
r = d.args[0].args[0].value
if isinstance(r, str) and r.startswith("internal"):
ir_funcs.append(r)
assert ir_funcs == [f.internal_function_label for f in sigs.values()]
assert ir_funcs == [f._ir_info.internal_function_label for f in sigs.values()]
8 changes: 4 additions & 4 deletions tests/parser/types/numbers/test_sqrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def test_sqrt_bounds(sqrt_contract, value):
min_value=Decimal(0), max_value=Decimal(SizeLimits.MAX_INT128), places=DECIMAL_PLACES
)
)
@hypothesis.example(Decimal(SizeLimits.MAX_INT128))
@hypothesis.example(Decimal(0))
@hypothesis.example(value=Decimal(SizeLimits.MAX_INT128))
@hypothesis.example(value=Decimal(0))
@hypothesis.settings(deadline=1000)
def test_sqrt_valid_range(sqrt_contract, value):
vyper_sqrt = sqrt_contract.test(value)
Expand All @@ -159,8 +159,8 @@ def test_sqrt_valid_range(sqrt_contract, value):
)
)
@hypothesis.settings(deadline=400)
@hypothesis.example(Decimal(SizeLimits.MIN_INT128))
@hypothesis.example(Decimal("-1E10"))
@hypothesis.example(value=Decimal(SizeLimits.MIN_INT128))
@hypothesis.example(value=Decimal("-1E10"))
def test_sqrt_invalid_range(sqrt_contract, value):
with pytest.raises(TransactionFailed):
sqrt_contract.test(value)
5 changes: 5 additions & 0 deletions vyper/ast/expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from vyper import ast as vy_ast
from vyper.exceptions import CompilerPanic
from vyper.semantics.types.function import ContractFunctionT
Fixed Show fixed Hide fixed


def expand_annotated_ast(vyper_module: vy_ast.Module) -> None:
Expand Down Expand Up @@ -85,6 +86,10 @@ def generate_public_variable_getters(vyper_module: vy_ast.Module) -> None:
decorator_list=[vy_ast.Name(id="external"), vy_ast.Name(id="view")],
returns=return_node,
)

with vyper_module.namespace():
func_type = ContractFunctionT.from_FunctionDef(expanded)

expanded._metadata["type"] = func_type
return_node.set_parent(expanded)
vyper_module.add_to_body(expanded)
Expand Down
14 changes: 14 additions & 0 deletions vyper/ast/nodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast as python_ast
import contextlib
import copy
import decimal
import operator
Expand Down Expand Up @@ -664,6 +665,19 @@ def remove_from_body(self, node: VyperNode) -> None:
self.body.remove(node)
self._children.remove(node)

@contextlib.contextmanager
def namespace(self):
from vyper.semantics.namespace import get_namespace, override_global_namespace

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [vyper.semantics.namespace](1) begins an import cycle.

# kludge implementation for backwards compatibility.
# TODO: replace with type_from_ast
try:
ns = self._metadata["namespace"]
except AttributeError:
ns = get_namespace()
with override_global_namespace(ns):
yield


class FunctionDef(TopLevel):
__slots__ = ("args", "returns", "decorator_list", "pos")
Expand Down
1 change: 1 addition & 0 deletions vyper/ast/nodes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Module(TopLevel):
def replace_in_tree(self, old_node: VyperNode, new_node: VyperNode) -> None: ...
def add_to_body(self, node: VyperNode) -> None: ...
def remove_from_body(self, node: VyperNode) -> None: ...
def namespace(self) -> Any: ... # context manager

class FunctionDef(TopLevel):
args: arguments = ...
Expand Down
1 change: 0 additions & 1 deletion vyper/ast/signatures/__init__.py

This file was deleted.

194 changes: 0 additions & 194 deletions vyper/ast/signatures/function_signature.py

This file was deleted.

6 changes: 3 additions & 3 deletions vyper/builtins/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,13 @@ def to_enum(expr, arg, out_typ):


def convert(expr, context):
if len(expr.args) != 2:
raise StructureException("The convert function expects two parameters.", expr)
assert len(expr.args) == 2, "bad typecheck: convert"

arg_ast = expr.args[0]
arg = Expr(arg_ast, context).ir_node
original_arg = arg
out_typ = context.parse_type(expr.args[1])

out_typ = expr.args[1]._metadata["type"].typedef

if arg.typ._is_prim_word:
arg = unwrap_location(arg)
Expand Down
2 changes: 1 addition & 1 deletion vyper/builtins/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def generate_inline_function(code, variables, variables_2, memory_allocator):
# `ContractFunctionT` type to rely on the annotation visitors in semantics
# module.
ast_code.body[0]._metadata["type"] = ContractFunctionT(
"sqrt_builtin", {}, 0, 0, None, FunctionVisibility.INTERNAL, StateMutability.NONPAYABLE
"sqrt_builtin", [], [], None, FunctionVisibility.INTERNAL, StateMutability.NONPAYABLE
)
# The FunctionNodeVisitor's constructor performs semantic checks
# annotate the AST as side effects.
Expand Down
Loading