Skip to content

Commit

Permalink
remove set_length fn
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 11, 2023
1 parent ba527d3 commit 50e5000
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
24 changes: 9 additions & 15 deletions vyper/builtins/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,6 @@ class Slice(BuiltinFunction):
def fetch_call_return(self, node):
arg_type, _, _ = self.infer_arg_types(node)

if isinstance(arg_type, StringT):
return_type = StringT()
else:
return_type = BytesT()

# validate start and length are in bounds

arg = node.args[0]
Expand Down Expand Up @@ -331,8 +326,11 @@ def fetch_call_return(self, node):
raise ArgumentException(f"slice out of bounds for {arg_type}", node)

# we know the length statically
if length_literal is not None:
return_type.set_length(length_literal)
length = length_literal if not None else 0
if isinstance(arg_type, StringT):
return_type = StringT(length)
else:
return_type = BytesT(length)

return return_type

Expand Down Expand Up @@ -497,10 +495,9 @@ def fetch_call_return(self, node):
length += arg_t.length

if isinstance(arg_types[0], (StringT)):
return_type = StringT()
return_type = StringT(length)
else:
return_type = BytesT()
return_type.set_length(length)
return_type = BytesT(length)
return return_type

def infer_arg_types(self, node):
Expand Down Expand Up @@ -1087,8 +1084,7 @@ def fetch_call_return(self, node):
raise

if outsize.value:
return_type = BytesT()
return_type.set_length(outsize.value)
return_type = BytesT(outsize.value)

if revert_on_failure:
return return_type
Expand Down Expand Up @@ -2421,9 +2417,7 @@ def fetch_call_return(self, node):
# the output includes 4 bytes for the method_id.
maxlen += 4

ret = BytesT()
ret.set_length(maxlen)
return ret
return BytesT(maxlen)

@staticmethod
def _parse_method_id(method_id_literal):
Expand Down
14 changes: 1 addition & 13 deletions vyper/semantics/types/bytestrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ def size_in_bytes(self):

return 32 + ceil32(self.length)

def set_length(self, length):
"""
Sets the exact length of the type.
May only be called once, and only on a type that does not yet have
a fixed length.
"""
if self._length:
raise CompilerPanic("Type already has a fixed length")
self._length = length

def compare_type(self, other):
if not super().compare_type(other):
return False
Expand Down Expand Up @@ -118,8 +107,7 @@ def from_annotation(cls, node: vy_ast.VyperNode) -> "_BytestringT":
def from_literal(cls, node: vy_ast.Constant) -> "_BytestringT":
if not isinstance(node, cls._valid_literal):
raise UnexpectedNodeType(f"Not a {cls._id}: {node}")
t = cls()
t.set_length(len(node.value))
t = cls(len(node.value))
t._is_literal = True
return t

Expand Down

0 comments on commit 50e5000

Please sign in to comment.