From 50e50002708b80dba2474c77ab43a2946f1c80ca Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Sat, 11 Nov 2023 22:57:44 +0800 Subject: [PATCH] remove set_length fn --- vyper/builtins/functions.py | 24 +++++++++--------------- vyper/semantics/types/bytestrings.py | 14 +------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/vyper/builtins/functions.py b/vyper/builtins/functions.py index 8acce0586a..037befc81e 100644 --- a/vyper/builtins/functions.py +++ b/vyper/builtins/functions.py @@ -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] @@ -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 @@ -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): @@ -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 @@ -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): diff --git a/vyper/semantics/types/bytestrings.py b/vyper/semantics/types/bytestrings.py index 40565888a4..4dc5128cf4 100644 --- a/vyper/semantics/types/bytestrings.py +++ b/vyper/semantics/types/bytestrings.py @@ -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 @@ -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