Skip to content

Commit

Permalink
rename to VariableConstancy
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 15, 2023
1 parent d13eabb commit 16b069c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions vyper/semantics/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def from_abi(cls, abi_dict: Dict) -> "StateMutability":
# specifying a state mutability modifier at all. Do the same here.


class Constancy(_StringEnum):
class VariableConstancy(_StringEnum):
MUTABLE = _StringEnum.auto()
RUNTIME_CONSTANT = _StringEnum.auto()
COMPILE_TIME_CONSTANT = _StringEnum.auto()
Expand Down Expand Up @@ -165,7 +165,7 @@ class VarInfo:

typ: VyperType
location: DataLocation = DataLocation.UNSET
constancy: Constancy = Constancy.MUTABLE
constancy: VariableConstancy = VariableConstancy.MUTABLE
is_public: bool = False
is_immutable: bool = False
is_transient: bool = False
Expand Down Expand Up @@ -198,7 +198,7 @@ class ExprInfo:
typ: VyperType
var_info: Optional[VarInfo] = None
location: DataLocation = DataLocation.UNSET
constancy: Constancy = Constancy.MUTABLE
constancy: VariableConstancy = VariableConstancy.MUTABLE
is_immutable: bool = False

def __post_init__(self):
Expand Down Expand Up @@ -246,7 +246,7 @@ def validate_modification(self, node: vy_ast.VyperNode, mutability: StateMutabil

if self.location == DataLocation.CALLDATA:
raise ImmutableViolation("Cannot write to calldata", node)
if self.constancy == Constancy.COMPILE_TIME_CONSTANT:
if self.constancy == VariableConstancy.COMPILE_TIME_CONSTANT:
raise ImmutableViolation("Constant value cannot be written to", node)
if self.is_immutable:
if node.get_ancestor(vy_ast.FunctionDef).get("name") != "__init__":
Expand Down
6 changes: 3 additions & 3 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
VariableDeclarationException,
VyperException,
)
from vyper.semantics.analysis.base import Constancy, VarInfo
from vyper.semantics.analysis.base import VariableConstancy, VarInfo
from vyper.semantics.analysis.common import VyperNodeVisitorBase
from vyper.semantics.analysis.utils import (
get_common_types,
Expand Down Expand Up @@ -197,7 +197,7 @@ def __init__(
arg.typ,
location=location,
is_immutable=is_immutable,
constancy=Constancy.RUNTIME_CONSTANT,
constancy=VariableConstancy.RUNTIME_CONSTANT,
)

for node in fn_node.body:
Expand Down Expand Up @@ -484,7 +484,7 @@ def visit_For(self, node):
with self.namespace.enter_scope():
try:
self.namespace[iter_name] = VarInfo(
possible_target_type, constancy=Constancy.COMPILE_TIME_CONSTANT
possible_target_type, constancy=VariableConstancy.COMPILE_TIME_CONSTANT
)
except VyperException as exc:
raise exc.with_annotation(node) from None
Expand Down
8 changes: 4 additions & 4 deletions vyper/semantics/analysis/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
VariableDeclarationException,
VyperException,
)
from vyper.semantics.analysis.base import Constancy, VarInfo
from vyper.semantics.analysis.base import VariableConstancy, VarInfo
from vyper.semantics.analysis.common import VyperNodeVisitorBase
from vyper.semantics.analysis.local import ExprVisitor
from vyper.semantics.analysis.utils import check_constant, validate_expected_type
Expand Down Expand Up @@ -187,11 +187,11 @@ def visit_VariableDecl(self, node):
)

constancy = (
Constancy.RUNTIME_CONSTANT
VariableConstancy.RUNTIME_CONSTANT
if node.is_immutable
else Constancy.COMPILE_TIME_CONSTANT
else VariableConstancy.COMPILE_TIME_CONSTANT
if node.is_constant
else Constancy.MUTABLE
else VariableConstancy.MUTABLE
)

type_ = type_from_annotation(node.annotation, data_loc)
Expand Down
8 changes: 4 additions & 4 deletions vyper/semantics/analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ZeroDivisionException,
)
from vyper.semantics import types
from vyper.semantics.analysis.base import Constancy, ExprInfo, VarInfo
from vyper.semantics.analysis.base import VariableConstancy, ExprInfo, VarInfo
from vyper.semantics.analysis.levenshtein_utils import get_levenshtein_error_suggestions
from vyper.semantics.namespace import get_namespace
from vyper.semantics.types.base import TYPE_T, VyperType
Expand Down Expand Up @@ -198,7 +198,7 @@ def _raise_invalid_reference(name, node):
if isinstance(s, VyperType):
# ex. foo.bar(). bar() is a ContractFunctionT
return [s]
if is_self_reference and s.constancy >= Constancy.RUNTIME_CONSTANT:
if is_self_reference and s.constancy >= VariableConstancy.RUNTIME_CONSTANT:
_raise_invalid_reference(name, node)
# general case. s is a VarInfo, e.g. self.foo
return [s.typ]
Expand Down Expand Up @@ -647,7 +647,7 @@ def check_kwargable(node: vy_ast.VyperNode) -> bool:
return True

value_type = get_expr_info(node)
return value_type.constancy >= Constancy.RUNTIME_CONSTANT
return value_type.constancy >= VariableConstancy.RUNTIME_CONSTANT


def _check_literal(node: vy_ast.VyperNode) -> bool:
Expand Down Expand Up @@ -690,4 +690,4 @@ def check_constant(node: vy_ast.VyperNode) -> bool:
return True

value_type = get_expr_info(node)
return value_type.constancy == Constancy.COMPILE_TIME_CONSTANT
return value_type.constancy == VariableConstancy.COMPILE_TIME_CONSTANT
4 changes: 2 additions & 2 deletions vyper/semantics/environment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Dict

from vyper.semantics.analysis.base import Constancy, VarInfo
from vyper.semantics.analysis.base import VariableConstancy, VarInfo
from vyper.semantics.types import AddressT, BytesT, VyperType
from vyper.semantics.types.shortcuts import BYTES32_T, UINT256_T

Expand Down Expand Up @@ -52,7 +52,7 @@ def get_constant_vars() -> Dict:
"""
result = {}
for k, v in CONSTANT_ENVIRONMENT_VARS.items():
result[k] = VarInfo(v, constancy=Constancy.RUNTIME_CONSTANT)
result[k] = VarInfo(v, constancy=VariableConstancy.RUNTIME_CONSTANT)

return result

Expand Down

0 comments on commit 16b069c

Please sign in to comment.