From 6d5e0fde97b1198fccd4dd148b2019994dcb2734 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 26 Nov 2024 21:31:44 -0300 Subject: [PATCH 01/29] Rename List.size to List._len adding getattr and setattr for size Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 93 ++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 29 deletions(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 19b477a47e..8dbbf1146f 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -102,11 +102,44 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Fields var data: UnsafePointer[T] """The underlying storage for the list.""" - var size: Int + var _len: Int """The number of elements in the list.""" var capacity: Int """The amount of elements that can fit in the list without resizing it.""" + @always_inline + fn __getattr__[name: StringLiteral](self) -> Int: + """Get the number of elements in the list. + + Parameters: + name: The name of the attribute (`"size"`). + + Returns: + The attribute value. + """ + + @parameter + if name == "size": + return len(self) + else: + constrained[False, "that attr does not exist"]() + return abort[Int]() + + # FIXME: default is only because otherwise += assignments won't work + @always_inline + fn __setattr__[name: StringLiteral = "size"](inout self, value: Int): + """Set the number of elements in the list. + + Parameters: + name: The name of the attribute (`"size"`). + """ + + @parameter + if name == "size": + self._len = value + else: + debug_assert[assert_mode="safe"](False, "that attr does not exist") + # ===-------------------------------------------------------------------===# # Life cycle methods # ===-------------------------------------------------------------------===# @@ -114,7 +147,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn __init__(out self): """Constructs an empty list.""" self.data = UnsafePointer[T]() - self.size = 0 + self._len = 0 self.capacity = 0 fn __init__(out self, *, other: Self): @@ -134,7 +167,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( capacity: The requested capacity of the list. """ self.data = UnsafePointer[T].alloc(capacity) - self.size = 0 + self._len = 0 self.capacity = capacity @implicit @@ -165,7 +198,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Mark the elements as unowned to avoid del'ing uninitialized objects. variadic_list._is_owned = False - self.size = length + self._len = length @implicit fn __init__(out self, span: Span[T]): @@ -187,7 +220,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( capacity: The capacity of the list. """ self.data = ptr - self.size = length + self._len = length self.capacity = capacity fn __moveinit__(out self, owned existing: Self): @@ -197,7 +230,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( existing: The existing list. """ self.data = existing.data - self.size = existing.size + self._len = existing._len self.capacity = existing.capacity fn __copyinit__(out self, existing: Self): @@ -212,7 +245,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn __del__(owned self): """Destroy all elements in the list and free its memory.""" - for i in range(self.size): + for i in range(len(self)): (self.data + i).destroy_pointee() self.data.free() @@ -369,13 +402,14 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Trait implementations # ===-------------------------------------------------------------------===# + @always_inline("nodebug") fn __len__(self) -> Int: """Gets the number of elements in the list. Returns: The number of elements in the list. """ - return self.size + return self._len fn __bool__(self) -> Bool: """Checks whether the list has any elements or not. @@ -467,6 +501,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Methods # ===-------------------------------------------------------------------===# + # FIXME: this needs to be consistent with {String, StringSlice}.byte_length() fn bytecount(self) -> Int: """Gets the bytecount of the List. @@ -481,7 +516,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( _move_pointee_into_many_elements[hint_trivial_type]( dest=new_data, src=self.data, - size=self.size, + size=self._len, ) if self.data: @@ -495,10 +530,10 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Args: value: The value to append. """ - if self.size >= self.capacity: + if len(self) >= self.capacity: self._realloc(max(1, self.capacity * 2)) - (self.data + self.size).init_pointee_move(value^) - self.size += 1 + (self.data + len(self)).init_pointee_move(value^) + self._len += 1 fn insert(mut self, i: Int, owned value: T): """Inserts a value to the list at the given index. @@ -508,7 +543,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( i: The index for the value. value: The value to insert. """ - debug_assert(i <= self.size, "insert index out of range") + debug_assert(i <= len(self), "insert index out of range") var normalized_idx = i if i < 0: @@ -586,7 +621,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Update the size now that all new elements have been moved into this # list. - self.size = final_size + self._len = final_size fn pop(mut self, i: Int = -1) -> T: """Pops a value from the list at the given index. @@ -604,10 +639,10 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( normalized_idx += len(self) var ret_val = (self.data + normalized_idx).take_pointee() - for j in range(normalized_idx + 1, self.size): + for j in range(normalized_idx + 1, len(self)): (self.data + j).move_pointee_into(self.data + j - 1) - self.size -= 1 - if self.size * 4 < self.capacity: + self._len -= 1 + if len(self) * 4 < self.capacity: if self.capacity > 1: self._realloc(self.capacity // 2) return ret_val^ @@ -636,13 +671,13 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( new_size: The new size. value: The value to use to populate new elements. """ - if new_size <= self.size: + if new_size <= len(self): self.resize(new_size) else: self.reserve(new_size) - for i in range(self.size, new_size): + for i in range(len(self), new_size): (self.data + i).init_pointee_copy(value) - self.size = new_size + self._len = new_size fn resize(mut self, new_size: Int): """Resizes the list to the given new size. @@ -653,16 +688,16 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Args: new_size: The new size. """ - if self.size < new_size: + if len(self) < new_size: abort( "You are calling List.resize with a new_size bigger than the" " current size. If you want to make the List bigger, provide a" " value to fill the new slots with. If not, make sure the new" " size is smaller than the current size." ) - for i in range(new_size, self.size): + for i in range(new_size, len(self)): (self.data + i).destroy_pointee() - self.size = new_size + self._len = new_size self.reserve(new_size) fn reverse(mut self): @@ -744,9 +779,9 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn clear(mut self): """Clears the elements in the list.""" - for i in range(self.size): + for i in range(len(self)): (self.data + i).destroy_pointee() - self.size = 0 + self._len = 0 fn steal_data(mut self) -> UnsafePointer[T]: """Take ownership of the underlying pointer from the list. @@ -756,7 +791,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( """ var ptr = self.data self.data = UnsafePointer[T]() - self.size = 0 + self._len = 0 self.capacity = 0 return ptr @@ -798,11 +833,11 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( var normalized_idx = idx debug_assert( - -self.size <= normalized_idx < self.size, + -len(self) <= normalized_idx < len(self), "index: ", normalized_idx, - " is out of bounds for `List` of size: ", - self.size, + " is out of bounds for `List` of length: ", + len(self), ) if normalized_idx < 0: normalized_idx += len(self) From 4419121732ad63441ec64ba7eae71771474c1f62 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 26 Nov 2024 21:36:46 -0300 Subject: [PATCH 02/29] add length attribute overload Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 8dbbf1146f..d4ee8187ec 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -109,17 +109,18 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( @always_inline fn __getattr__[name: StringLiteral](self) -> Int: - """Get the number of elements in the list. + """Get the length of the list. Parameters: - name: The name of the attribute (`"size"`). + name: The name of the attribute (`"length"` or `"size"` (soft + deprecated)). Returns: The attribute value. """ @parameter - if name == "size": + if name == "size" or name == "length": return len(self) else: constrained[False, "that attr does not exist"]() @@ -128,14 +129,18 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # FIXME: default is only because otherwise += assignments won't work @always_inline fn __setattr__[name: StringLiteral = "size"](inout self, value: Int): - """Set the number of elements in the list. + """Set the length of the list. Parameters: - name: The name of the attribute (`"size"`). + name: The name of the attribute (`"length"` or `"size"` (soft + deprecated)). + + Args: + value: The value to set the length to. """ @parameter - if name == "size": + if name == "size" or name == "length": self._len = value else: debug_assert[assert_mode="safe"](False, "that attr does not exist") From b6e9e36e47f026bb4315e05744fd57dab5cf5d7a Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 26 Nov 2024 21:38:47 -0300 Subject: [PATCH 03/29] fix detail Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index d4ee8187ec..b50941cde5 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -143,7 +143,8 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( if name == "size" or name == "length": self._len = value else: - debug_assert[assert_mode="safe"](False, "that attr does not exist") + constrained[False, "that attr does not exist"]() + abort() # ===-------------------------------------------------------------------===# # Life cycle methods From 720e043eb369a89187cab79d19c76c0517a36a88 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 26 Nov 2024 21:48:49 -0300 Subject: [PATCH 04/29] fix detail Signed-off-by: martinvuyk --- stdlib/test/collections/test_list_getitem_invalid_index.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/test/collections/test_list_getitem_invalid_index.mojo b/stdlib/test/collections/test_list_getitem_invalid_index.mojo index f5ce83a0e2..ed0b48ca63 100644 --- a/stdlib/test/collections/test_list_getitem_invalid_index.mojo +++ b/stdlib/test/collections/test_list_getitem_invalid_index.mojo @@ -17,7 +17,7 @@ # CHECK-FAIL-LABEL: test_fail_list_index fn main(): print("== test_fail_list_index") - # CHECK-FAIL: index: 4 is out of bounds for `List` of size: 3 + # CHECK-FAIL: index: 4 is out of bounds for `List` of length: 3 nums = List[Int](1, 2, 3) print(nums[4]) From 0f439491ae32df5d06a0906a82833a2619d2faa4 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 4 Dec 2024 10:06:46 -0300 Subject: [PATCH 05/29] try removing all uses of list.size Signed-off-by: martinvuyk --- magic.lock | 497 +++++++++++++------------ pixi.toml | 6 +- stdlib/src/base64/_b64encode.mojo | 27 +- stdlib/src/builtin/file.mojo | 4 +- stdlib/src/builtin/string_literal.mojo | 14 +- stdlib/src/collections/list.mojo | 99 +++-- stdlib/src/collections/string.mojo | 76 ++-- stdlib/src/utils/format.mojo | 3 +- stdlib/src/utils/index.mojo | 20 +- stdlib/src/utils/string_slice.mojo | 6 +- 10 files changed, 362 insertions(+), 390 deletions(-) diff --git a/magic.lock b/magic.lock index 818c254d76..19edbf6da2 100644 --- a/magic.lock +++ b/magic.lock @@ -11,7 +11,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/aiohappyeyeballs-2.4.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/aiohttp-3.11.9-py312h178313f_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/aiosignal-1.3.1-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/anyio-4.6.2.post1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/asgiref-3.8.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/attrs-24.2.0-pyh71513ae_0.conda @@ -52,7 +52,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.2.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-0.115.5-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-cli-0.0.5-pyhd8ed1ab_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/freetype-2.12.1-h267a509_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/frozenlist-1.5.0-py312h66e93f0_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fsspec-2024.10.0-pyhff2d567_0.conda @@ -60,8 +60,8 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/glog-0.7.1-hbabe93e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/googleapis-common-protos-1.66.0-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/h11-0.14.0-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyh9f0ad1d_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpcore-1.0.7-pyh29332c3_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/httptools-0.6.4-py312h66e93f0_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpx-0.28.0-pyhd8ed1ab_0.conda @@ -69,7 +69,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/idna-3.10-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.2-pyha770c72_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_client-8.6.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_core-5.7.2-pyh31011fe_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/keyutils-1.6.1-h166bdaf_0.tar.bz2 @@ -159,10 +159,10 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/orc-2.0.3-he039a57_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-24.2-pyhd8ed1ab_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pandas-2.2.3-py312hf9745cd_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pillow-11.0.0-py312h7b63e92_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/propcache-0.2.0-py312h66e93f0_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/protobuf-5.28.2-py312h2ec8cdc_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pthread-stubs-0.4-hb9d3cd8_1002.conda @@ -172,9 +172,9 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.2-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pydantic-core-2.27.1-py312h12e396e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-settings-2.6.1-pyh3cfb1c2_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pyinstrument-5.0.0-py312h66e93f0_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha55dd90_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.12.7-hc5c86c4_0_cpython.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhff2d567_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_0.conda @@ -197,7 +197,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/snappy-1.2.1-ha2e4443_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sse-starlette-2.1.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/starlette-0.41.3-pyh7900ff3_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/tk-8.6.13-noxft_h4845f30_101.conda @@ -234,7 +234,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/aiohappyeyeballs-2.4.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/aiohttp-3.11.9-py312hcc812fe_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/aiosignal-1.3.1-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/anyio-4.6.2.post1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/asgiref-3.8.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/attrs-24.2.0-pyh71513ae_0.conda @@ -275,7 +275,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.2.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-0.115.5-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-cli-0.0.5-pyhd8ed1ab_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/freetype-2.12.1-hf0a5ef3_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/frozenlist-1.5.0-py312hb2c0f52_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fsspec-2024.10.0-pyhff2d567_0.conda @@ -283,8 +283,8 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/glog-0.7.1-h468a4a4_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/googleapis-common-protos-1.66.0-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/h11-0.14.0-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyh9f0ad1d_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpcore-1.0.7-pyh29332c3_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/httptools-0.6.4-py312hb2c0f52_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpx-0.28.0-pyhd8ed1ab_0.conda @@ -293,7 +293,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/icu-75.1-hf9b3779_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/idna-3.10-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.2-pyha770c72_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_client-8.6.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_core-5.7.2-pyh31011fe_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/keyutils-1.6.1-h4e544f5_0.tar.bz2 @@ -383,10 +383,10 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/orc-2.0.3-h90de224_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-24.2-pyhd8ed1ab_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pandas-2.2.3-py312ha2895bd_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pillow-11.0.0-py312h5ab5af3_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/propcache-0.2.0-py312hb2c0f52_2.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/protobuf-5.28.2-py312h6f74592_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pthread-stubs-0.4-h86ecc28_1002.conda @@ -396,9 +396,9 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.2-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pydantic-core-2.27.1-py312h8cbf658_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-settings-2.6.1-pyh3cfb1c2_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pyinstrument-5.0.0-py312hb2c0f52_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha55dd90_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/python-3.12.7-h5d932e8_0_cpython.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhff2d567_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_0.conda @@ -421,7 +421,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/snappy-1.2.1-h1088aeb_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sse-starlette-2.1.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/starlette-0.41.3-pyh7900ff3_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/tk-8.6.13-h194ca79_0.conda @@ -457,7 +457,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/aiohappyeyeballs-2.4.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/aiohttp-3.11.9-py312h998013c_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/aiosignal-1.3.1-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/anyio-4.6.2.post1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/asgiref-3.8.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/attrs-24.2.0-pyh71513ae_0.conda @@ -498,7 +498,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.2.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-0.115.5-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-cli-0.0.5-pyhd8ed1ab_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/freetype-2.12.1-hadb7bae_2.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/frozenlist-1.5.0-py312h0bf5046_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fsspec-2024.10.0-pyhff2d567_0.conda @@ -506,8 +506,8 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/glog-0.7.1-heb240a5_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/googleapis-common-protos-1.66.0-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/h11-0.14.0-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_0.tar.bz2 - - conda: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyh9f0ad1d_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpcore-1.0.7-pyh29332c3_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/httptools-0.6.4-py312hea69d52_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpx-0.28.0-pyhd8ed1ab_0.conda @@ -515,7 +515,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/idna-3.10-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.2-pyha770c72_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_client-8.6.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jupyter_core-5.7.2-pyh31011fe_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/krb5-1.21.3-h237132a_0.conda @@ -533,7 +533,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcblas-3.9.0-25_osxarm64_openblas.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcrc32c-1.1.2-hbdafb3b_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcurl-8.10.1-h13a7ad3_0.conda - - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-19.1.4-ha82da77_0.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-19.1.5-ha82da77_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libdeflate-1.22-hd74edd7_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libedit-3.1.20191231-hc8eb9b7_2.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libev-4.33-h93a5062_2.conda @@ -597,10 +597,10 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/orc-2.0.3-h121fd32_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/packaging-24.2-pyhd8ed1ab_2.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pandas-2.2.3-py312hcd31e36_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pillow-11.0.0-py312haf37ca6_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/propcache-0.2.0-py312h024a12e_2.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/protobuf-5.28.2-py312hf02c72a_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pthread-stubs-0.4-hd74edd7_1002.conda @@ -610,9 +610,9 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.2-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pydantic-core-2.27.1-py312hcd83bfe_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-settings-2.6.1-pyh3cfb1c2_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pyinstrument-5.0.0-py312h0bf5046_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha55dd90_7.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python-3.12.7-h739c21a_0_cpython.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhff2d567_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_0.conda @@ -634,7 +634,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/snappy-1.2.1-hd02b534_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sse-starlette-2.1.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/starlette-0.41.3-pyh7900ff3_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/tk-8.6.13-h5083fa2_1.conda @@ -819,19 +819,19 @@ packages: - kind: conda name: annotated-types version: 0.7.0 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_0.conda - sha256: 668f0825b6c18e4012ca24a0070562b6ec801ebc7008228a428eb52b4038873f - md5: 7e9f4612544c8edbfd6afad17f1bd045 + url: https://conda.anaconda.org/conda-forge/noarch/annotated-types-0.7.0-pyhd8ed1ab_1.conda + sha256: e0ea1ba78fbb64f17062601edda82097fcf815012cf52bb704150a2668110d48 + md5: 2934f256a8acfe48f6ebb4fce6cde29c depends: - - python >=3.7 + - python >=3.9 - typing-extensions >=4.0.0 license: MIT - license_family: MIT - size: 18235 - timestamp: 1716290348421 + size: 18074 + timestamp: 1733247158254 - kind: conda name: anyio version: 4.6.2.post1 @@ -2174,49 +2174,50 @@ packages: - kind: conda name: charset-normalizer version: 3.4.0 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_0.conda - sha256: 1873ac45ea61f95750cb0b4e5e675d1c5b3def937e80c7eebb19297f76810be8 - md5: a374efa97290b8799046df7c5ca17164 + url: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_1.conda + sha256: 63022ee2c6a157a9f980250a66f54bdcdf5abee817348d0f9a74c2441a6fbf0e + md5: 6581a17bba6b948bb60130026404a9d6 depends: - - python >=3.7 + - python >=3.9 license: MIT - license_family: MIT - size: 47314 - timestamp: 1728479405343 + size: 47533 + timestamp: 1733218182393 - kind: conda name: click version: 8.1.7 - build: unix_pyh707e725_0 + build: unix_pyh707e725_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_0.conda - sha256: f0016cbab6ac4138a429e28dbcb904a90305b34b3fe41a9b89d697c90401caec - md5: f3ad426304898027fc619827ff428eca + url: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_1.conda + sha256: 1cd5fc6ccdd5141378e51252a7a3810b07fd5a7e6934a5b4a7eccba66566224b + md5: cb8e52f28f5e592598190c562e7b5bf1 depends: - __unix - - python >=3.8 + - python >=3.9 license: BSD-3-Clause license_family: BSD - size: 84437 - timestamp: 1692311973840 + size: 84513 + timestamp: 1733221925078 - kind: conda name: colorama version: 0.4.6 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2 - sha256: 2c1b2e9755ce3102bca8d69e8f26e4f087ece73f50418186aee7c74bef8e1698 - md5: 3faab06a954c2a04039983f2c4a50d99 + url: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda + sha256: ab29d57dc70786c1269633ba3dff20288b81664d3ff8d21af995742e2bb03287 + md5: 962b9857ee8e7018c22f2776ffa0b2d7 depends: - - python >=3.7 + - python >=3.9 license: BSD-3-Clause - license_family: BSD - size: 25170 - timestamp: 1666700778190 + size: 27011 + timestamp: 1733218222191 - kind: conda name: datasets version: 2.14.4 @@ -2280,58 +2281,61 @@ packages: - kind: conda name: dnspython version: 2.7.0 - build: pyhff2d567_0 + build: pyhff2d567_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_0.conda - sha256: 3e2ea1bfd90969e0e1f152bb1f969c56661278ad6bfaa3272027b1ff0d9a1a23 - md5: 0adf8f63d500d20418656289249533f9 + url: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_1.conda + sha256: 3ec40ccf63f2450c5e6c7dd579e42fc2e97caf0d8cd4ba24aa434e6fc264eda0 + md5: 5fbd60d61d21b4bd2f9d7a48fe100418 depends: - - python >=3.9.0,<4.0.0 + - python >=3.9,<4.0.0 - sniffio constrains: - - cryptography >=43 + - aioquic >=1.0.0 - wmi >=1.5.1 - - h2 >=4.1.0 + - httpx >=0.26.0 - trio >=0.23 + - cryptography >=43 - httpcore >=1.0.0 - - aioquic >=1.0.0 - - httpx >=0.26.0 - idna >=3.7 + - h2 >=4.1.0 license: ISC license_family: OTHER - size: 172740 - timestamp: 1728178868478 + size: 172172 + timestamp: 1733256829961 - kind: conda name: email-validator version: 2.2.0 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_0.conda - sha256: ea9e936ed7c49ea6d66fa3554afe31ba311f2a3d5e384d8c38925fda9e37bdb9 - md5: 3067adf57ee658ddf5bfad47b0041ce4 + url: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_1.conda + sha256: b91a19eb78edfc2dbb36de9a67f74ee2416f1b5273dd7327abe53f2dbf864736 + md5: da16dd3b0b71339060cd44cb7110ddf9 depends: - dnspython >=2.0.0 - idna >=2.0.0 - - python >=3.7 + - python >=3.9 license: Unlicense - size: 44157 - timestamp: 1718984716782 + size: 44401 + timestamp: 1733300827551 - kind: conda name: email_validator version: 2.2.0 - build: hd8ed1ab_0 + build: hd8ed1ab_1 + build_number: 1 subdir: noarch noarch: generic - url: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_0.conda - sha256: 2cbbbe9e0f3872214227c27b8b775dd2296a435c90ef50a7cc69934c329b6c65 - md5: 0214a004f7cf5ac28fc10a390dfc47ee + url: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_1.conda + sha256: e0d0fdf587aa0ed0ff08b2bce3ab355f46687b87b0775bfba01cc80a859ee6a2 + md5: 0794f8807ff2c6f020422cacb1bd7bfa depends: - email-validator >=2.2.0,<2.2.1.0a0 license: Unlicense - size: 6690 - timestamp: 1718984720419 + size: 6552 + timestamp: 1733300828176 - kind: conda name: exceptiongroup version: 1.2.2 @@ -2392,17 +2396,18 @@ packages: - kind: conda name: filelock version: 3.16.1 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_0.conda - sha256: 1da766da9dba05091af87977922fe60dc7464091a9ccffb3765d403189d39be4 - md5: 916f8ec5dd4128cd5f207a3c4c07b2c6 + url: https://conda.anaconda.org/conda-forge/noarch/filelock-3.16.1-pyhd8ed1ab_1.conda + sha256: 18dca6e2194732df7ebf824abaefe999e4765ebe8e8a061269406ab88fc418b9 + md5: d692e9ba6f92dc51484bf3477e36ce7c depends: - - python >=3.7 + - python >=3.9 license: Unlicense - size: 17357 - timestamp: 1726613593584 + size: 17441 + timestamp: 1733240909987 - kind: conda name: freetype version: 2.12.1 @@ -2648,35 +2653,37 @@ packages: - kind: conda name: h2 version: 4.1.0 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_0.tar.bz2 - sha256: bfc6a23849953647f4e255c782e74a0e18fe16f7e25c7bb0bc57b83bb6762c7a - md5: b748fbf7060927a6e82df7cb5ee8f097 + url: https://conda.anaconda.org/conda-forge/noarch/h2-4.1.0-pyhd8ed1ab_1.conda + sha256: 843ddad410c370672a8250470697027618f104153612439076d4d7b91eeb7b5c + md5: 825927dc7b0f287ef8d4d0011bb113b1 depends: - hpack >=4.0,<5 - hyperframe >=6.0,<7 - - python >=3.6.1 + - python >=3.9 license: MIT license_family: MIT - size: 46754 - timestamp: 1634280590080 + size: 52000 + timestamp: 1733298867359 - kind: conda name: hpack version: 4.0.0 - build: pyh9f0ad1d_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyh9f0ad1d_0.tar.bz2 - sha256: 5dec948932c4f740674b1afb551223ada0c55103f4c7bf86a110454da3d27cb8 - md5: 914d6646c4dbb1fd3ff539830a12fd71 + url: https://conda.anaconda.org/conda-forge/noarch/hpack-4.0.0-pyhd8ed1ab_1.conda + sha256: ec89b7e5b8aa2f0219f666084446e1fb7b54545861e9caa892acb24d125761b5 + md5: 2aa5ff7fa34a81b9196532c84c10d865 depends: - - python + - python >=3.9 license: MIT license_family: MIT - size: 25341 - timestamp: 1598856368685 + size: 29412 + timestamp: 1733299296857 - kind: conda name: httpcore version: 1.0.7 @@ -2794,18 +2801,19 @@ packages: - kind: conda name: hyperframe version: 6.0.1 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_0.tar.bz2 - sha256: e374a9d0f53149328134a8d86f5d72bca4c6dcebed3c0ecfa968c02996289330 - md5: 9f765cbfab6870c8435b9eefecd7a1f4 + url: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_1.conda + sha256: e91c6ef09d076e1d9a02819cd00fa7ee18ecf30cdd667605c853980216584d1b + md5: 566e75c90c1d0c8c459eb0ad9833dc7a depends: - - python >=3.6 + - python >=3.9 license: MIT license_family: MIT - size: 14646 - timestamp: 1619110249723 + size: 17239 + timestamp: 1733298862681 - kind: conda name: icu version: '75.1' @@ -2856,19 +2864,19 @@ packages: - kind: conda name: jinja2 version: 3.1.4 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_0.conda - sha256: 27380d870d42d00350d2d52598cddaf02f9505fb24be09488da0c9b8d1428f2d - md5: 7b86ecb7d3557821c649b3c31e3eb9f2 + url: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_1.conda + sha256: 85a7169c078b8065bd9d121b0e7b99c8b88c42a411314b6ae5fcd81c48c4710a + md5: 08cce3151bde4ecad7885bd9fb647532 depends: - markupsafe >=2.0 - - python >=3.7 + - python >=3.9 license: BSD-3-Clause - license_family: BSD - size: 111565 - timestamp: 1715127275924 + size: 110963 + timestamp: 1733217424408 - kind: conda name: jupyter_client version: 8.6.3 @@ -3849,18 +3857,18 @@ packages: timestamp: 1726659794676 - kind: conda name: libcxx - version: 19.1.4 + version: 19.1.5 build: ha82da77_0 subdir: osx-arm64 - url: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-19.1.4-ha82da77_0.conda - sha256: 342896ebc1d6acbf022ca6df006a936b9a472579e91e3c502cb1f52f218b78e9 - md5: a2d3d484d95889fccdd09498d8f6bf9a + url: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-19.1.5-ha82da77_0.conda + sha256: 7918cc0bb7a6554cdd3eee634c3dc414a1ab8ec49faeca1567367bb92118f9d7 + md5: 3c7be0df28ccda1d193ea6de56dcb5ff depends: - __osx >=11.0 license: Apache-2.0 WITH LLVM-exception license_family: Apache - size: 520678 - timestamp: 1732060258949 + size: 519819 + timestamp: 1733291654212 - kind: conda name: libdeflate version: '1.22' @@ -5792,27 +5800,29 @@ packages: - kind: conda name: markdown-it-py version: 3.0.0 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_0.conda - sha256: c041b0eaf7a6af3344d5dd452815cdc148d6284fec25a4fa3f4263b3a021e962 - md5: 93a8e71256479c62074356ef6ebf501b + url: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_1.conda + sha256: 0fbacdfb31e55964152b24d5567e9a9996e1e7902fb08eb7d91b5fd6ce60803a + md5: fee3164ac23dfca50cfcc8b85ddefb81 depends: - mdurl >=0.1,<1 - - python >=3.8 + - python >=3.9 license: MIT license_family: MIT - size: 64356 - timestamp: 1686175179621 + size: 64430 + timestamp: 1733250550053 - kind: conda name: markupsafe version: 3.0.2 - build: py312h178313f_0 + build: py312h178313f_1 + build_number: 1 subdir: linux-64 - url: https://conda.anaconda.org/conda-forge/linux-64/markupsafe-3.0.2-py312h178313f_0.conda - sha256: 15f14ab429c846aacd47fada0dc4f341d64491e097782830f0906d00cb7b48b6 - md5: a755704ea0e2503f8c227d84829a8e81 + url: https://conda.anaconda.org/conda-forge/linux-64/markupsafe-3.0.2-py312h178313f_1.conda + sha256: 4a6bf68d2a2b669fecc9a4a009abd1cf8e72c2289522ff00d81b5a6e51ae78f5 + md5: eb227c3e0bf58f5bd69c0532b157975b depends: - __glibc >=2.17,<3.0.a0 - libgcc >=13 @@ -5822,16 +5832,17 @@ packages: - jinja2 >=3.0.0 license: BSD-3-Clause license_family: BSD - size: 24878 - timestamp: 1729351558563 + size: 24604 + timestamp: 1733219911494 - kind: conda name: markupsafe version: 3.0.2 - build: py312h74ce7d3_0 + build: py312h74ce7d3_1 + build_number: 1 subdir: linux-aarch64 - url: https://conda.anaconda.org/conda-forge/linux-aarch64/markupsafe-3.0.2-py312h74ce7d3_0.conda - sha256: 997baf7f46bce112f6e0390efaa7fbb892b8f31567d3c554f08ac636774d74f7 - md5: 8992b90e8374193d53118f7651db0b73 + url: https://conda.anaconda.org/conda-forge/linux-aarch64/markupsafe-3.0.2-py312h74ce7d3_1.conda + sha256: 1d500158262f30b9c23e37d1c861fe76e127a3926d69b3b38c25d20d3faa6f9f + md5: bc8607ab678073a0441808a31465f4fb depends: - libgcc >=13 - python >=3.12,<3.13.0a0 @@ -5840,16 +5851,17 @@ packages: - jinja2 >=3.0.0 license: BSD-3-Clause license_family: BSD - size: 25013 - timestamp: 1729352489213 + size: 25079 + timestamp: 1733220639175 - kind: conda name: markupsafe version: 3.0.2 - build: py312ha0ccf2a_0 + build: py312h998013c_1 + build_number: 1 subdir: osx-arm64 - url: https://conda.anaconda.org/conda-forge/osx-arm64/markupsafe-3.0.2-py312ha0ccf2a_0.conda - sha256: 360e958055f35e5087942b9c499eaafae984a951b84cf354ef7481a2806f340d - md5: c6ff9f291d011c9d4f0b840f49435c64 + url: https://conda.anaconda.org/conda-forge/osx-arm64/markupsafe-3.0.2-py312h998013c_1.conda + sha256: 4aa997b244014d3707eeef54ab0ee497d12c0d0d184018960cce096169758283 + md5: 46e547061080fddf9cf95a0327e8aba6 depends: - __osx >=11.0 - python >=3.12,<3.13.0a0 @@ -5859,8 +5871,8 @@ packages: - jinja2 >=3.0.0 license: BSD-3-Clause license_family: BSD - size: 24495 - timestamp: 1729351534830 + size: 24048 + timestamp: 1733219945697 - kind: conda name: max version: 24.6.0.dev2024120306 @@ -6048,18 +6060,18 @@ packages: - kind: conda name: mdurl version: 0.1.2 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_0.conda - sha256: 64073dfb6bb429d52fff30891877b48c7ec0f89625b1bf844905b66a81cce6e1 - md5: 776a8dd9e824f77abac30e6ef43a8f7a + url: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_1.conda + sha256: 78c1bbe1723449c52b7a9df1af2ee5f005209f67e40b6e1d3c7619127c43b1c7 + md5: 592132998493b3ff25fd7479396e8351 depends: - - python >=3.6 + - python >=3.9 license: MIT - license_family: MIT - size: 14680 - timestamp: 1704317789138 + size: 14465 + timestamp: 1733255681319 - kind: conda name: mojo-jupyter version: 24.6.0.dev2024120306 @@ -6189,18 +6201,19 @@ packages: - kind: conda name: mypy_extensions version: 1.0.0 - build: pyha770c72_0 + build: pyha770c72_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda - sha256: f240217476e148e825420c6bc3a0c0efb08c0718b7042fae960400c02af858a3 - md5: 4eccaeba205f0aed9ac3a9ea58568ca3 + url: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_1.conda + sha256: 1895f47b7d68581a6facde5cb13ab8c2764c2e53a76bd746f8f98910dc4e08fe + md5: 29097e7ea634a45cc5386b95cac6568f depends: - - python >=3.5 + - python >=3.9 license: MIT license_family: MIT - size: 10492 - timestamp: 1675543414256 + size: 10854 + timestamp: 1733230986902 - kind: conda name: ncurses version: '6.5' @@ -6767,18 +6780,18 @@ packages: - kind: conda name: pathspec version: 0.12.1 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_0.conda - sha256: 4e534e66bfe8b1e035d2169d0e5b185450546b17e36764272863e22e0370be4d - md5: 17064acba08d3686f1135b5ec1b32b12 + url: https://conda.anaconda.org/conda-forge/noarch/pathspec-0.12.1-pyhd8ed1ab_1.conda + sha256: 9f64009cdf5b8e529995f18e03665b03f5d07c0b17445b8badef45bde76249ee + md5: 617f15191456cc6a13db418a275435e5 depends: - - python >=3.7 + - python >=3.9 license: MPL-2.0 - license_family: MOZILLA - size: 41173 - timestamp: 1702250135032 + size: 41075 + timestamp: 1733233471940 - kind: conda name: pillow version: 11.0.0 @@ -6856,33 +6869,34 @@ packages: - kind: conda name: platformdirs version: 4.3.6 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_0.conda - sha256: c81bdeadc4adcda216b2c7b373f0335f5c78cc480d1d55d10f21823590d7e46f - md5: fd8f2b18b65bbf62e8f653100690c8d2 + url: https://conda.anaconda.org/conda-forge/noarch/platformdirs-4.3.6-pyhd8ed1ab_1.conda + sha256: bb50f6499e8bc1d1a26f17716c97984671121608dc0c3ecd34858112bce59a27 + md5: 577852c7e53901ddccc7e6a9959ddebe depends: - - python >=3.8 + - python >=3.9 license: MIT - license_family: MIT - size: 20625 - timestamp: 1726613611845 + size: 20448 + timestamp: 1733232756001 - kind: conda name: prometheus_client version: 0.21.0 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_0.conda - sha256: 01f0c3dd00081637ed920a922b17bcc8ed49608404ee466ced806856e671f6b9 - md5: 07e9550ddff45150bfc7da146268e165 + url: https://conda.anaconda.org/conda-forge/noarch/prometheus_client-0.21.0-pyhd8ed1ab_1.conda + sha256: 0215ecb6f134a66478e41292e25f43f161d5609ffe6f008d81cf048d54e6707a + md5: 0d061da74f3f1ce77cc805e40f59ca5f depends: - - python >=3.8 + - python >=3.9 license: Apache-2.0 license_family: Apache - size: 49024 - timestamp: 1726902073034 + size: 48934 + timestamp: 1733302033341 - kind: conda name: propcache version: 0.2.0 @@ -7288,18 +7302,18 @@ packages: - kind: conda name: pygments version: 2.18.0 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_0.conda - sha256: 78267adf4e76d0d64ea2ffab008c501156c108bb08fecb703816fb63e279780b - md5: b7f5c092b8f9800150d998a71b76d5a1 + url: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_1.conda + sha256: 0d6133545f268b2b89c2617c196fc791f365b538d4057ecd636d658c3b1e885d + md5: b38dc0206e2a530e5c2cf11dc086b31a depends: - - python >=3.8 + - python >=3.9 license: BSD-2-Clause - license_family: BSD - size: 879295 - timestamp: 1714846885370 + size: 876700 + timestamp: 1733221731178 - kind: conda name: pyinstrument version: 5.0.0 @@ -7354,20 +7368,20 @@ packages: - kind: conda name: pysocks version: 1.7.1 - build: pyha2e5f31_6 - build_number: 6 + build: pyha55dd90_7 + build_number: 7 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha2e5f31_6.tar.bz2 - sha256: a42f826e958a8d22e65b3394f437af7332610e43ee313393d1cf143f0a2d274b - md5: 2a7de29fb590ca14b5243c4c812c8025 + url: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha55dd90_7.conda + sha256: ba3b032fa52709ce0d9fd388f63d330a026754587a2f461117cac9ab73d8d0d8 + md5: 461219d1a5bd61342293efa2c0c90eac depends: - __unix - - python >=3.8 + - python >=3.9 license: BSD-3-Clause license_family: BSD - size: 18981 - timestamp: 1661604969727 + size: 21085 + timestamp: 1733217331982 - kind: conda name: python version: 3.12.7 @@ -7474,18 +7488,19 @@ packages: - kind: conda name: python-dotenv version: 1.0.1 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_0.conda - sha256: 2d4c80364f03315d606a50eddd493dbacc078e21412c2462c0f781eec49b572c - md5: c2997ea9360ac4e015658804a7a84f94 + url: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_1.conda + sha256: 99713f6b534fef94995c6c16fd21d59f3548784e9111775d692bdc7c44678f02 + md5: e5c6ed218664802d305e79cc2d4491de depends: - - python >=3.8 + - python >=3.9 license: BSD-3-Clause license_family: BSD - size: 24278 - timestamp: 1706018281544 + size: 24215 + timestamp: 1733243277223 - kind: conda name: python-json-logger version: 2.0.7 @@ -7519,18 +7534,18 @@ packages: - kind: conda name: python-tzdata version: '2024.2' - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_0.conda - sha256: fe3f62ce2bc714bdaa222ab3f0344a2815ad9e853c6df38d15c9f25de8a3a6d4 - md5: 986287f89929b2d629bd6ef6497dc307 + url: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_1.conda + sha256: 57c9a02ec25926fb48edca59b9ede107823e5d5c473b94a0e05cc0b9a193a642 + md5: c0def296b2f6d2dd7b030c2a7f66bb1f depends: - - python >=3.6 + - python >=3.9 license: Apache-2.0 - license_family: APACHE - size: 142527 - timestamp: 1727140688093 + size: 142235 + timestamp: 1733235414217 - kind: conda name: python-xxhash version: 3.5.0 @@ -8055,18 +8070,18 @@ packages: - kind: conda name: shellingham version: 1.5.4 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda - sha256: 3c49a0a101c41b7cf6ac05a1872d7a1f91f1b6d02eecb4a36b605a19517862bb - md5: d08db09a552699ee9e7eec56b4eb3899 + url: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_1.conda + sha256: 0557c090913aa63cdbe821dbdfa038a321b488e22bc80196c4b3b1aace4914ef + md5: 7c3c2a0f3ebdea2bbc35538d162b43bf depends: - - python >=3.7 + - python >=3.9 license: MIT - license_family: MIT - size: 14568 - timestamp: 1698144516278 + size: 14462 + timestamp: 1733301007770 - kind: conda name: six version: 1.16.0 @@ -8131,18 +8146,19 @@ packages: - kind: conda name: sniffio version: 1.3.1 - build: pyhd8ed1ab_0 + build: pyhd8ed1ab_1 + build_number: 1 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_0.conda - sha256: bc12100b2d8836b93c55068b463190505b8064d0fc7d025e89f20ebf22fe6c2b - md5: 490730480d76cf9c8f8f2849719c6e2b + url: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_1.conda + sha256: c2248418c310bdd1719b186796ae50a8a77ce555228b6acd32768e2543a15012 + md5: bf7a226e58dfb8346c70df36065d86c9 depends: - - python >=3.7 + - python >=3.9 license: Apache-2.0 license_family: Apache - size: 15064 - timestamp: 1708953086199 + size: 15019 + timestamp: 1733244175724 - kind: conda name: sse-starlette version: 2.1.3 @@ -8425,6 +8441,7 @@ packages: - python >=3.9 - typing_extensions >=3.7.4.3 constrains: + - typer >=0.15.0,<0.15.1.0a0 - shellingham >=1.3.0 - rich >=10.11.0 - typer >=0.14.0,<0.14.1.0a0 diff --git a/pixi.toml b/pixi.toml index 0067a5d6c1..9e83e5530a 100644 --- a/pixi.toml +++ b/pixi.toml @@ -10,6 +10,6 @@ examples = "./examples/run-examples.sh" benchmarks = { cmd = ["./stdlib/scripts/run-benchmarks.sh"], env = { MODULAR_MOJO_NIGHTLY_IMPORT_PATH = "$CONDA_PREFIX/lib/mojo" } } [dependencies] -python = ">=3.9,<3.13" -lit = "*" -max = "*" \ No newline at end of file +python = ">=3.12.7,<3.13" +lit = ">=19.1.5,<19.2" +max = ">=24.6.0.dev2024120306,<24.7" diff --git a/stdlib/src/base64/_b64encode.mojo b/stdlib/src/base64/_b64encode.mojo index 74b8c31501..a7005a36ec 100644 --- a/stdlib/src/base64/_b64encode.mojo +++ b/stdlib/src/base64/_b64encode.mojo @@ -195,21 +195,6 @@ fn load_incomplete_simd[ return result -fn store_incomplete_simd[ - simd_width: Int -]( - pointer: UnsafePointer[UInt8], - owned simd_vector: SIMD[DType.uint8, simd_width], - nb_of_elements_to_store: Int, -): - var tmp_buffer_pointer = UnsafePointer.address_of(simd_vector).bitcast[ - UInt8 - ]() - - memcpy(dest=pointer, src=tmp_buffer_pointer, count=nb_of_elements_to_store) - _ = simd_vector # We make it live long enough - - # TODO: Use Span instead of List as input when Span is easier to use @no_inline fn b64encode_with_buffers( @@ -229,11 +214,8 @@ fn b64encode_with_buffers( var input_vector = start_of_input_chunk.load[width=simd_width]() - result_vector = _to_b64_ascii(input_vector) - - (result.unsafe_ptr() + len(result)).store(result_vector) + result.append(_to_b64_ascii(input_vector)) - result.size += simd_width input_index += input_simd_width # We handle the last 0, 1 or 2 chunks @@ -268,12 +250,7 @@ fn b64encode_with_buffers( ]( nb_of_elements_to_load ) - store_incomplete_simd( - result.unsafe_ptr() + len(result), - result_vector_with_equals, - nb_of_elements_to_store, - ) - result.size += nb_of_elements_to_store + result.append(result_vector_with_equals, nb_of_elements_to_store) input_index += input_simd_width diff --git a/stdlib/src/builtin/file.mojo b/stdlib/src/builtin/file.mojo index 823cbf9348..136d1ea644 100644 --- a/stdlib/src/builtin/file.mojo +++ b/stdlib/src/builtin/file.mojo @@ -140,7 +140,7 @@ struct FileHandle: """Reads data from a file and sets the file handle seek position. If size is left as the default of -1, it will read to the end of the file. Setting size to a number larger than what's in the file will set - String.size to the total number of bytes, and read all the data. + the String length to the total number of bytes, and read all the data. Args: size: Requested number of bytes to read (Default: -1 = EOF). @@ -284,7 +284,7 @@ struct FileHandle: """Reads data from a file and sets the file handle seek position. If size is left as default of -1, it will read to the end of the file. Setting size to a number larger than what's in the file will be handled - and set the List.size to the total number of bytes in the file. + and set the List length to the total number of bytes in the file. Args: size: Requested number of bytes to read (Default: -1 = EOF). diff --git a/stdlib/src/builtin/string_literal.mojo b/stdlib/src/builtin/string_literal.mojo index 554ddeddfd..44754d3654 100644 --- a/stdlib/src/builtin/string_literal.mojo +++ b/stdlib/src/builtin/string_literal.mojo @@ -355,17 +355,11 @@ struct StringLiteral( # inline the string slice constructor to work around an elaborator # memory leak. # return self.as_string_slice() - var string = String() var length = self.byte_length() - var buffer = String._buffer_type() - var new_capacity = length + 1 - buffer._realloc(new_capacity) - buffer.size = new_capacity - var data: UnsafePointer[UInt8] = self.unsafe_ptr() - memcpy(buffer.data, data, length) - (buffer.data + length).init_pointee_move(0) - string._buffer = buffer^ - return string + var buffer = String._buffer_type(capacity=length + 1) + buffer.append(self.as_bytes()) + buffer.append(0) + return String(buffer^) @no_inline fn __repr__(self) -> String: diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index b50941cde5..3a00b7caa2 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -107,45 +107,6 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( var capacity: Int """The amount of elements that can fit in the list without resizing it.""" - @always_inline - fn __getattr__[name: StringLiteral](self) -> Int: - """Get the length of the list. - - Parameters: - name: The name of the attribute (`"length"` or `"size"` (soft - deprecated)). - - Returns: - The attribute value. - """ - - @parameter - if name == "size" or name == "length": - return len(self) - else: - constrained[False, "that attr does not exist"]() - return abort[Int]() - - # FIXME: default is only because otherwise += assignments won't work - @always_inline - fn __setattr__[name: StringLiteral = "size"](inout self, value: Int): - """Set the length of the list. - - Parameters: - name: The name of the attribute (`"length"` or `"size"` (soft - deprecated)). - - Args: - value: The value to set the length to. - """ - - @parameter - if name == "size" or name == "length": - self._len = value - else: - constrained[False, "that attr does not exist"]() - abort() - # ===-------------------------------------------------------------------===# # Life cycle methods # ===-------------------------------------------------------------------===# @@ -537,10 +498,66 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( value: The value to append. """ if len(self) >= self.capacity: - self._realloc(max(1, self.capacity * 2)) + self._realloc(self.capacity * 2 + int(capacity == 0)) (self.data + len(self)).init_pointee_move(value^) self._len += 1 + fn append[ + D: DType, // + ](inout self: List[Scalar[D], *_, **_], owned value: SIMD[D, _]): + """Appends a vector to this list. + + Parameters: + D: The DType. + + Args: + value: The value to append. + """ + if len(self) + value.size > self.capacity: + self._realloc(self.capacity + value.size) + (self.data + len(self)).store(value^) + self._len += value.size + + fn append[ + D: DType, // + ]( + inout self: List[Scalar[D], *_, **_], + owned value: SIMD[D, _], + count: Int, + ): + """Appends count items from a vector to this list. + + Parameters: + D: The DType. + + Args: + value: The value to append. + count: The ammount of items to append. + """ + + if len(self) + count > self.capacity: + self._realloc(self.capacity + count) + var ptr = self.unsafe_ptr() + var v_ptr = UnsafePointer.address_of(value).bitcast[Scalar[D]]() + memcpy(ptr, v_ptr, count) + self._len += count + + fn append[ + D: DType, // + ](inout self: List[Scalar[D], *_, **_], owned value: Span[Scalar[D]]): + """Appends a Span to this list. + + Parameters: + D: The DType. + + Args: + value: The value to append. + """ + if len(self) + len(value) > self.capacity: + self._realloc(self.capacity + len(value)) + memcpy(self.data + len(self), value.unsafe_ptr(), len(value)) + self._len += len(value) + fn insert(mut self, i: Int, owned value: T): """Inserts a value to the list at the given index. `a.insert(len(a), value)` is equivalent to `a.append(value)`. @@ -610,7 +627,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # visible outside this function if a `__moveinit__()` constructor were # to throw (not currently possible AFAIK though) part way through the # logic below. - other.size = 0 + other._len = 0 var dest_ptr = self.data + len(self) diff --git a/stdlib/src/collections/string.mojo b/stdlib/src/collections/string.mojo index a6051bbb81..589c31c562 100644 --- a/stdlib/src/collections/string.mojo +++ b/stdlib/src/collections/string.mojo @@ -805,15 +805,15 @@ struct String( len(impl) > 0 and impl[-1] == 0, "expected last element of String buffer to be null terminator", ) - # We make a backup because steal_data() will clear size and capacity. - var size = impl.size + # We make a backup because steal_data() will clear length and capacity. + var length = len(impl) debug_assert( - impl[size - 1] == 0, + length > 0 and impl[length - 1] == 0, "expected last element of String buffer to be null terminator", ) var capacity = impl.capacity self._buffer = Self._buffer_type( - ptr=impl.steal_data(), length=size, capacity=capacity + ptr=impl.steal_data(), length=length, capacity=capacity ) @always_inline @@ -911,7 +911,7 @@ struct String( bytes: The byte span to write to this String. Must NOT be null terminated. """ - self._iadd[False](bytes) + self._iadd(bytes) fn write[*Ts: Writable](mut self, *args: *Ts): """Write a sequence of Writable arguments to the provided Writer. @@ -1173,7 +1173,7 @@ struct String( return not (self < rhs) @staticmethod - fn _add[rhs_has_null: Bool](lhs: Span[Byte], rhs: Span[Byte]) -> String: + fn _add(lhs: Span[Byte], rhs: Span[Byte]) -> String: var lhs_len = len(lhs) var rhs_len = len(rhs) var lhs_ptr = lhs.unsafe_ptr() @@ -1185,14 +1185,9 @@ struct String( return String(S(ptr=lhs_ptr, length=lhs_len)) var sum_len = lhs_len + rhs_len var buffer = Self._buffer_type(capacity=sum_len + 1) - var ptr = buffer.unsafe_ptr() - memcpy(ptr, lhs_ptr, lhs_len) - memcpy(ptr + lhs_len, rhs_ptr, rhs_len + int(rhs_has_null)) - buffer.size = sum_len + 1 - - @parameter - if not rhs_has_null: - ptr[sum_len] = 0 + buffer.append(lhs) + buffer.append(rhs) + buffer.append(0) return Self(buffer^) @always_inline @@ -1205,7 +1200,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](self.as_bytes(), other.as_bytes()) + return Self._add(self.as_bytes(), other.as_bytes()) @always_inline fn __add__(self, other: StringLiteral) -> String: @@ -1217,7 +1212,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[False](self.as_bytes(), other.as_bytes()) + return Self._add(self.as_bytes(), other.as_bytes()) @always_inline fn __add__(self, other: StringSlice) -> String: @@ -1229,7 +1224,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[False](self.as_bytes(), other.as_bytes()) + return Self._add(self.as_bytes(), other.as_bytes()) @always_inline fn __radd__(self, other: String) -> String: @@ -1241,7 +1236,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](other.as_bytes(), self.as_bytes()) + return Self._add(other.as_bytes(), self.as_bytes()) @always_inline fn __radd__(self, other: StringLiteral) -> String: @@ -1253,7 +1248,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](other.as_bytes(), self.as_bytes()) + return Self._add(other.as_bytes(), self.as_bytes()) @always_inline fn __radd__(self, other: StringSlice) -> String: @@ -1265,9 +1260,9 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](other.as_bytes(), self.as_bytes()) + return Self._add(other.as_bytes(), self.as_bytes()) - fn _iadd[has_null: Bool](mut self, other: Span[Byte]): + fn _iadd(mut self, other: Span[Byte]): var s_len = self.byte_length() var o_len = len(other) var o_ptr = other.unsafe_ptr() @@ -1278,14 +1273,8 @@ struct String( elif o_len == 0: return var sum_len = s_len + o_len - self._buffer.reserve(sum_len + 1) - var s_ptr = self.unsafe_ptr() - memcpy(s_ptr + s_len, o_ptr, o_len + int(has_null)) - self._buffer.size = sum_len + 1 - - @parameter - if not has_null: - s_ptr[sum_len] = 0 + self._buffer.append(other) + self._buffer.append(0) @always_inline fn __iadd__(mut self, other: String): @@ -1294,7 +1283,7 @@ struct String( Args: other: The string to append. """ - self._iadd[True](other.as_bytes()) + self._iadd(other.as_bytes()) @always_inline fn __iadd__(mut self, other: StringLiteral): @@ -1303,7 +1292,7 @@ struct String( Args: other: The string to append. """ - self._iadd[False](other.as_bytes()) + self._iadd(other.as_bytes()) @always_inline fn __iadd__(mut self, other: StringSlice): @@ -1312,7 +1301,7 @@ struct String( Args: other: The string to append. """ - self._iadd[False](other.as_bytes()) + self._iadd(other.as_bytes()) fn __iter__(self) -> _StringSliceIter[__origin_of(self)]: """Iterate over the string, returning immutable references. @@ -1541,10 +1530,9 @@ struct String( # This can hugely improve the performance on large lists for e_ref in elems: len_elems += len(e_ref[].as_bytes()) - var capacity = len_self * (n_elems - 1) + len_elems - var buf = Self._buffer_type(capacity=capacity) + var capacity = len_self * (n_elems - 1) + len_elems + 1 var self_ptr = self.unsafe_ptr() - var ptr = buf.unsafe_ptr() + var ptr = UnsafePointer[Byte].alloc(capacity) var offset = 0 var i = 0 var is_first = True @@ -1559,9 +1547,8 @@ struct String( memcpy(dest=ptr + offset, src=e.unsafe_ptr(), count=e_len) offset += e_len i += 1 - buf.size = capacity - buf.append(0) - return String(buf^) + ptr[capacity - 1] = 0 + return String(List(ptr=ptr, length=capacity, capacity=capacity)) fn unsafe_ptr(self) -> UnsafePointer[UInt8]: """Retrieves a pointer to the underlying memory. @@ -1622,19 +1609,6 @@ struct String( var length = len(self._buffer) return length - int(length > 0) - fn _steal_ptr(mut self) -> UnsafePointer[UInt8]: - """Transfer ownership of pointer to the underlying memory. - The caller is responsible for freeing up the memory. - - Returns: - The pointer to the underlying memory. - """ - var ptr = self.unsafe_ptr() - self._buffer.data = UnsafePointer[UInt8]() - self._buffer.size = 0 - self._buffer.capacity = 0 - return ptr - fn count(self, substr: String) -> Int: """Return the number of non-overlapping occurrences of substring `substr` in the string. diff --git a/stdlib/src/utils/format.mojo b/stdlib/src/utils/format.mojo index af4bbc8d7c..e5aa90209b 100644 --- a/stdlib/src/utils/format.mojo +++ b/stdlib/src/utils/format.mojo @@ -155,8 +155,7 @@ struct _FormatCurlyEntry(CollectionElement, CollectionElementNew): entries, size_estimation = Self._create_entries(fmt_src, len_pos_args) var fmt_len = fmt_src.byte_length() var buf = String._buffer_type(capacity=fmt_len + size_estimation) - buf.size = 1 - buf.unsafe_set(0, 0) + buf.append(0) var res = String(buf^) var offset = 0 var ptr = fmt_src.unsafe_ptr() diff --git a/stdlib/src/utils/index.mojo b/stdlib/src/utils/index.mojo index 0ea645ee88..9920c947e0 100644 --- a/stdlib/src/utils/index.mojo +++ b/stdlib/src/utils/index.mojo @@ -730,29 +730,25 @@ struct IndexList[ """ # Reserve space for opening and closing parentheses, plus each element # and its trailing commas. - var buf = String._buffer_type() var initial_buffer_size = 2 for i in range(size): initial_buffer_size += _calc_initial_buffer_size(self[i]) + 2 - buf.reserve(initial_buffer_size) + var res = String(capacity=initial_buffer_size) # Print an opening `(`. - buf.size += _snprintf["("](buf.data, 2) + res.write("(") for i in range(size): # Print separators between each element. if i != 0: - buf.size += _snprintf[", "](buf.data + buf.size, 3) - buf.size += _snprintf[_get_dtype_printf_format[DType.index]()]( - buf.data + buf.size, _calc_initial_buffer_size(self[i]), self[i] - ) + res.write(", ") + res.write(self[i]) # Single element tuples should be printed with a trailing comma. if size == 1: - buf.size += _snprintf[","](buf.data + buf.size, 2) + res.write(", ") # Print a closing `)`. - buf.size += _snprintf[")"](buf.data + buf.size, 2) - - buf.size += 1 # for the null terminator. - return buf^ + res.write(")") + res.write(0) # for the null terminator. + return res^ @no_inline fn write_to[W: Writer](self, mut writer: W): diff --git a/stdlib/src/utils/string_slice.mojo b/stdlib/src/utils/string_slice.mojo index 666a25c45c..368527f639 100644 --- a/stdlib/src/utils/string_slice.mojo +++ b/stdlib/src/utils/string_slice.mojo @@ -603,13 +603,11 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable].type,]( var len_self = self.byte_length() var count = len_self * n + 1 - var buf = String._buffer_type(capacity=count) - buf.size = count - var b_ptr = buf.unsafe_ptr() + var b_ptr = UnsafePointer[Byte].alloc(count) for i in range(n): memcpy(b_ptr + len_self * i, self.unsafe_ptr(), len_self) b_ptr[count - 1] = 0 - return String(buf^) + return String(List(ptr=b_ptr, length=count, capacity=count)) # ===------------------------------------------------------------------===# # Methods From 2c7857d54084839f38f02e9621c7211300e2ea82 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 4 Dec 2024 10:51:53 -0300 Subject: [PATCH 06/29] fix uses of buf.size Signed-off-by: martinvuyk --- magic.lock | 106 ++++++++++++++-------------- pixi.toml | 1 + stdlib/src/collections/list.mojo | 6 +- stdlib/src/collections/string.mojo | 2 +- stdlib/src/utils/inline_string.mojo | 22 ++---- 5 files changed, 62 insertions(+), 75 deletions(-) diff --git a/magic.lock b/magic.lock index 19edbf6da2..c4f17198cc 100644 --- a/magic.lock +++ b/magic.lock @@ -40,15 +40,15 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/ca-certificates-2024.8.30-hbcca054_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/certifi-2024.8.30-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/cffi-1.17.1-py312h06ac9bb_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/datasets-2.14.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/deprecated-1.2.15-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/dill-0.3.7-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.2.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-0.115.5-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-cli-0.0.5-pyhd8ed1ab_1.conda @@ -66,7 +66,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/httptools-0.6.4-py312h66e93f0_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpx-0.28.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/huggingface_hub-0.26.3-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/idna-3.10-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.2-pyha770c72_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_1.conda @@ -128,19 +128,19 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/libxcrypt-4.4.36-hd590300_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libxml2-2.13.5-h064dc61_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/libzlib-1.3.1-hb9d3cd8_2.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.4-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.5-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/lz4-c-1.9.4-hcb278e6_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/linux-64/markupsafe-3.0.2-py312h178313f_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-64/markupsafe-3.0.2-py312h178313f_1.conda - conda: https://conda.modular.com/max-nightly/noarch/max-24.6.0.dev2024120306-release.conda - conda: https://conda.modular.com/max-nightly/linux-64/max-core-24.6.0.dev2024120306-release.conda - conda: https://conda.modular.com/max-nightly/linux-64/max-python-24.6.0.dev2024120306-3.12release.conda - conda: https://conda.modular.com/max-nightly/noarch/mblack-24.6.0.dev2024120306-release.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_1.conda - conda: https://conda.modular.com/max-nightly/noarch/mojo-jupyter-24.6.0.dev2024120306-release.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/multidict-6.1.0-py312h178313f_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/multiprocess-0.70.15-py312h98912ed_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.5-he02047a_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/numpy-1.26.4-py312heda63a1_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/openjpeg-2.5.2-h488ebb8_0.conda @@ -177,10 +177,10 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha55dd90_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.12.7-hc5c86c4_0_cpython.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhff2d567_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-json-logger-2.0.7-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-multipart-0.0.19-pyhff2d567_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/python-xxhash-3.5.0-py312h66e93f0_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/python_abi-3.12-5_cp312.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytz-2024.1-pyhd8ed1ab_0.conda @@ -194,7 +194,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/s2n-1.5.9-h0fd0ee4_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/safetensors-0.4.5-py312h12e396e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.6.0-pyhff2d567_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/snappy-1.2.1-ha2e4443_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_1.conda @@ -263,15 +263,15 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/ca-certificates-2024.8.30-hcefe29a_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/certifi-2024.8.30-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/cffi-1.17.1-py312hac81daf_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/datasets-2.14.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/deprecated-1.2.15-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/dill-0.3.7-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.2.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-0.115.5-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-cli-0.0.5-pyhd8ed1ab_1.conda @@ -289,7 +289,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/httptools-0.6.4-py312hb2c0f52_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpx-0.28.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/huggingface_hub-0.26.3-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/icu-75.1-hf9b3779_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/idna-3.10-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.2-pyha770c72_0.conda @@ -352,19 +352,19 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/libxcrypt-4.4.36-h31becfc_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/libxml2-2.13.5-hf4efe5d_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/libzlib-1.3.1-h86ecc28_2.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.4-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.5-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/lz4-c-1.9.4-hd600fc2_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/markupsafe-3.0.2-py312h74ce7d3_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/markupsafe-3.0.2-py312h74ce7d3_1.conda - conda: https://conda.modular.com/max-nightly/noarch/max-24.6.0.dev2024120306-release.conda - conda: https://conda.modular.com/max-nightly/linux-aarch64/max-core-24.6.0.dev2024120306-release.conda - conda: https://conda.modular.com/max-nightly/linux-aarch64/max-python-24.6.0.dev2024120306-3.12release.conda - conda: https://conda.modular.com/max-nightly/noarch/mblack-24.6.0.dev2024120306-release.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_1.conda - conda: https://conda.modular.com/max-nightly/noarch/mojo-jupyter-24.6.0.dev2024120306-release.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/multidict-6.1.0-py312hcc812fe_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/multiprocess-0.70.15-py312hdd3e373_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/ncurses-6.5-hcccb83c_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/numpy-1.26.4-py312h470d778_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/openjpeg-2.5.2-h0d9d63b_0.conda @@ -401,10 +401,10 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha55dd90_7.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/python-3.12.7-h5d932e8_0_cpython.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhff2d567_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-json-logger-2.0.7-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-multipart-0.0.19-pyhff2d567_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/python-xxhash-3.5.0-py312h52516f5_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/python_abi-3.12-5_cp312.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytz-2024.1-pyhd8ed1ab_0.conda @@ -418,7 +418,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/s2n-1.5.9-h636ded1_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/safetensors-0.4.5-py312h8cbf658_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.6.0-pyhff2d567_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/snappy-1.2.1-h1088aeb_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_1.conda @@ -486,15 +486,15 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ca-certificates-2024.8.30-hf0a4a13_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/certifi-2024.8.30-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/cffi-1.17.1-py312h0fad829_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/charset-normalizer-3.4.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-unix_pyh707e725_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/datasets-2.14.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/deprecated-1.2.15-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/dill-0.3.7-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/dnspython-2.7.0-pyhff2d567_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/email-validator-2.2.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/email_validator-2.2.0-hd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/exceptiongroup-1.2.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-0.115.5-pyhff2d567_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/fastapi-cli-0.0.5-pyhd8ed1ab_1.conda @@ -512,7 +512,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/httptools-0.6.4-py312hea69d52_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/httpx-0.28.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/huggingface_hub-0.26.3-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/hyperframe-6.0.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/idna-3.10-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/importlib-metadata-7.0.2-pyha770c72_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/jinja2-3.1.4-pyhd8ed1ab_1.conda @@ -565,20 +565,20 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libxcb-1.17.0-hdb1d25a_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libxml2-2.13.5-h376fa9f_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libzlib-1.3.1-h8359307_2.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.4-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.5-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/llvm-openmp-19.1.4-hdb05f8b_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/lz4-c-1.9.4-hb7217d7_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/osx-arm64/markupsafe-3.0.2-py312ha0ccf2a_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/markdown-it-py-3.0.0-pyhd8ed1ab_1.conda + - conda: https://conda.anaconda.org/conda-forge/osx-arm64/markupsafe-3.0.2-py312h998013c_1.conda - conda: https://conda.modular.com/max-nightly/noarch/max-24.6.0.dev2024120306-release.conda - conda: https://conda.modular.com/max-nightly/osx-arm64/max-core-24.6.0.dev2024120306-release.conda - conda: https://conda.modular.com/max-nightly/osx-arm64/max-python-24.6.0.dev2024120306-3.12release.conda - conda: https://conda.modular.com/max-nightly/noarch/mblack-24.6.0.dev2024120306-release.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mdurl-0.1.2-pyhd8ed1ab_1.conda - conda: https://conda.modular.com/max-nightly/noarch/mojo-jupyter-24.6.0.dev2024120306-release.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/multidict-6.1.0-py312hdb8e49c_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/multiprocess-0.70.15-py312h02f2b3b_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/mypy_extensions-1.0.0-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.5-h7bae524_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/numpy-1.26.4-py312h8442bc7_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/openjpeg-2.5.2-h9f1df11_0.conda @@ -615,10 +615,10 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/pysocks-1.7.1-pyha55dd90_7.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python-3.12.7-h739c21a_0_cpython.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhff2d567_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-dotenv-1.0.1-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-json-logger-2.0.7-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/python-multipart-0.0.19-pyhff2d567_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/python-tzdata-2024.2-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python-xxhash-3.5.0-py312h024a12e_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/python_abi-3.12-5_cp312.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pytz-2024.1-pyhd8ed1ab_0.conda @@ -631,7 +631,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/rich-13.9.4-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/safetensors-0.4.5-py312he431725_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-75.6.0-pyhff2d567_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/shellingham-1.5.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/snappy-1.2.1-hd02b534_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/sniffio-1.3.1-pyhd8ed1ab_1.conda @@ -5723,20 +5723,19 @@ packages: timestamp: 1727963148474 - kind: conda name: lit - version: 19.1.4 - build: pyhd8ed1ab_1 - build_number: 1 + version: 19.1.5 + build: pyhd8ed1ab_0 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.4-pyhd8ed1ab_1.conda - sha256: 52614f2f02b16c07759a69cf7b3f7f0794428b811df28fdc672eed1cc498454c - md5: 2b74a4939cd6f0fe32e61dd9617506b9 + url: https://conda.anaconda.org/conda-forge/noarch/lit-19.1.5-pyhd8ed1ab_0.conda + sha256: 07854df4ab39a333155b4813338caf8e0f6fe5a9abc84518d9409aa5cd91f94c + md5: ad3f4f4e25b666610c281c6fb92f06f9 depends: - python >=3 license: Apache-2.0 WITH LLVM-exception license_family: Apache - size: 128390 - timestamp: 1732691055432 + size: 128621 + timestamp: 1733310809397 - kind: conda name: llvm-openmp version: 19.1.4 @@ -8441,7 +8440,6 @@ packages: - python >=3.9 - typing_extensions >=3.7.4.3 constrains: - - typer >=0.15.0,<0.15.1.0a0 - shellingham >=1.3.0 - rich >=10.11.0 - typer >=0.14.0,<0.14.1.0a0 diff --git a/pixi.toml b/pixi.toml index 9e83e5530a..64d735de29 100644 --- a/pixi.toml +++ b/pixi.toml @@ -13,3 +13,4 @@ benchmarks = { cmd = ["./stdlib/scripts/run-benchmarks.sh"], env = { MODULAR_MOJ python = ">=3.12.7,<3.13" lit = ">=19.1.5,<19.2" max = ">=24.6.0.dev2024120306,<24.7" +charset-normalizer = "*" \ No newline at end of file diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 3a00b7caa2..3a403f2b2b 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -412,7 +412,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Returns: A string representation of the list. """ - var output = String() + var output = String(capacity=len(self) + 1) # at least self.write_to(output) return output^ @@ -498,7 +498,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( value: The value to append. """ if len(self) >= self.capacity: - self._realloc(self.capacity * 2 + int(capacity == 0)) + self._realloc(self.capacity * 2 + int(self.capacity == 0)) (self.data + len(self)).init_pointee_move(value^) self._len += 1 @@ -515,7 +515,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( """ if len(self) + value.size > self.capacity: self._realloc(self.capacity + value.size) - (self.data + len(self)).store(value^) + (self.data + len(self)).store(value) self._len += value.size fn append[ diff --git a/stdlib/src/collections/string.mojo b/stdlib/src/collections/string.mojo index 589c31c562..76415264a0 100644 --- a/stdlib/src/collections/string.mojo +++ b/stdlib/src/collections/string.mojo @@ -1272,7 +1272,7 @@ struct String( return elif o_len == 0: return - var sum_len = s_len + o_len + _ = self._buffer.pop() self._buffer.append(other) self._buffer.append(0) diff --git a/stdlib/src/utils/inline_string.mojo b/stdlib/src/utils/inline_string.mojo index cf8caafc31..224e200e65 100644 --- a/stdlib/src/utils/inline_string.mojo +++ b/stdlib/src/utils/inline_string.mojo @@ -147,28 +147,16 @@ struct InlineString(Sized, Stringable, CollectionElement, CollectionElementNew): # Begin by heap allocating enough space to store the combined # string. var buffer = List[UInt8](capacity=total_len) - # Copy the bytes from the current small string layout - memcpy( - dest=buffer.unsafe_ptr(), - src=self._storage[_FixedString[Self.SMALL_CAP]].unsafe_ptr(), - count=len(self), + var span_self = Span[Byte, __origin_of(self)]( + ptr=self._storage[_FixedString[Self.SMALL_CAP]].unsafe_ptr(), + length=len(self), ) - + buffer.append(span_self) # Copy the bytes from the additional string. - memcpy( - dest=buffer.unsafe_ptr() + len(self), - src=str_slice.unsafe_ptr(), - count=str_slice.byte_length(), - ) - - # Record that we've initialized `total_len` count of elements - # in `buffer` - buffer.size = total_len - + buffer.append(str_slice.as_bytes()) # Add the NUL byte buffer.append(0) - self._storage = Self.Layout(String(buffer^)) fn __add__(self, other: StringLiteral) -> Self: From 1cc618ec5cddb06c83fab7a29f8037f254b6a6f9 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 4 Dec 2024 11:12:24 -0300 Subject: [PATCH 07/29] fix pixi.toml diff Signed-off-by: martinvuyk --- pixi.toml | 7 +++---- stdlib/src/utils/index.mojo | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pixi.toml b/pixi.toml index 64d735de29..7194b50209 100644 --- a/pixi.toml +++ b/pixi.toml @@ -10,7 +10,6 @@ examples = "./examples/run-examples.sh" benchmarks = { cmd = ["./stdlib/scripts/run-benchmarks.sh"], env = { MODULAR_MOJO_NIGHTLY_IMPORT_PATH = "$CONDA_PREFIX/lib/mojo" } } [dependencies] -python = ">=3.12.7,<3.13" -lit = ">=19.1.5,<19.2" -max = ">=24.6.0.dev2024120306,<24.7" -charset-normalizer = "*" \ No newline at end of file +python = ">=3.9,<3.13" +lit = "*" +max = "*" diff --git a/stdlib/src/utils/index.mojo b/stdlib/src/utils/index.mojo index 9920c947e0..ed211fdb8e 100644 --- a/stdlib/src/utils/index.mojo +++ b/stdlib/src/utils/index.mojo @@ -747,7 +747,6 @@ struct IndexList[ res.write(", ") # Print a closing `)`. res.write(")") - res.write(0) # for the null terminator. return res^ @no_inline From 4c4e1fe15a15d8fad290a01de412afca5ac9919c Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 4 Dec 2024 11:16:09 -0300 Subject: [PATCH 08/29] fix pixi.toml diff Signed-off-by: martinvuyk --- magic.lock | 80 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/magic.lock b/magic.lock index c4f17198cc..c480f42504 100644 --- a/magic.lock +++ b/magic.lock @@ -169,7 +169,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-64/pyarrow-18.1.0-py312h7900ff3_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pyarrow-core-18.1.0-py312h01725c0_0_cpu.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pycparser-2.22-pyh29332c3_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.2-pyh3cfb1c2_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.3-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/pydantic-core-2.27.1-py312h12e396e_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-settings-2.6.1-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_1.conda @@ -206,9 +206,9 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/tqdm-4.67.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/transformers-4.46.3-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-0.14.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.14.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.14.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-0.15.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.15.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.15.0-hd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.12.2-hd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.12.2-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024b-hc8b5060_0.conda @@ -393,7 +393,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pyarrow-18.1.0-py312h8025657_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pyarrow-core-18.1.0-py312h66f7834_0_cpu.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pycparser-2.22-pyh29332c3_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.2-pyh3cfb1c2_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.3-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/pydantic-core-2.27.1-py312h8cbf658_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-settings-2.6.1-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_1.conda @@ -430,9 +430,9 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/tqdm-4.67.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/transformers-4.46.3-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-0.14.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.14.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.14.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-0.15.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.15.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.15.0-hd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.12.2-hd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.12.2-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024b-hc8b5060_0.conda @@ -607,7 +607,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pyarrow-18.1.0-py312h1f38498_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pyarrow-core-18.1.0-py312hc40f475_0_cpu.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pycparser-2.22-pyh29332c3_1.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.2-pyh3cfb1c2_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.3-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/pydantic-core-2.27.1-py312hcd83bfe_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pydantic-settings-2.6.1-pyh3cfb1c2_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.18.0-pyhd8ed1ab_1.conda @@ -643,9 +643,9 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/tqdm-4.67.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/traitlets-5.14.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/transformers-4.46.3-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-0.14.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.14.0-pyhd8ed1ab_0.conda - - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.14.0-hd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-0.15.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.15.0-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.15.0-hd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing-extensions-4.12.2-hd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/typing_extensions-4.12.2-pyha770c72_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/tzdata-2024b-hc8b5060_0.conda @@ -7204,13 +7204,13 @@ packages: timestamp: 1733195786147 - kind: conda name: pydantic - version: 2.10.2 + version: 2.10.3 build: pyh3cfb1c2_0 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.2-pyh3cfb1c2_0.conda - sha256: 47368f0eeb63b2dd4c9c54ff35b216d01ae1c27b90d3c7a2066ef8e005f32103 - md5: e661b732b4d7514ace55a01873f03201 + url: https://conda.anaconda.org/conda-forge/noarch/pydantic-2.10.3-pyh3cfb1c2_0.conda + sha256: cac9eebd3d5f8d8a497a9025d756257ddc75b8b3393e6737cb45077bd744d4f8 + md5: 194ef7f91286978521350f171b117f01 depends: - annotated-types >=0.6.0 - pydantic-core 2.27.1 @@ -7219,8 +7219,8 @@ packages: - typing_extensions >=4.12.2 license: MIT license_family: MIT - size: 316818 - timestamp: 1732689481710 + size: 317037 + timestamp: 1733316963547 - kind: conda name: pydantic-core version: 2.27.1 @@ -7482,6 +7482,7 @@ packages: - python >=3.9 - six >=1.5 license: Apache-2.0 + license_family: APACHE size: 222505 timestamp: 1733215763718 - kind: conda @@ -7942,6 +7943,7 @@ packages: constrains: - chardet >=3.0.2,<6 license: Apache-2.0 + license_family: APACHE size: 58723 timestamp: 1733217126197 - kind: conda @@ -8412,58 +8414,58 @@ packages: timestamp: 1731981383171 - kind: conda name: typer - version: 0.14.0 + version: 0.15.0 build: pyhd8ed1ab_0 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/typer-0.14.0-pyhd8ed1ab_0.conda - sha256: 4d7f1c77b928a66ae3b0089e288e7fdeb826bf0dabba9799488017e6a9b84f38 - md5: 9eb8a3f5d36ca3e7f686e7a5d85aff72 + url: https://conda.anaconda.org/conda-forge/noarch/typer-0.15.0-pyhd8ed1ab_0.conda + sha256: 90503b2a518434fb554d621cc4e1c533dc524ef1c0f63fde39fdf4328163a0c8 + md5: cf9393f5733c7277b1a5f79145f8485b depends: - python >=3.9 - - typer-slim-standard 0.14.0 hd8ed1ab_0 + - typer-slim-standard 0.15.0 hd8ed1ab_0 license: MIT license_family: MIT - size: 54637 - timestamp: 1732848384457 + size: 56455 + timestamp: 1733279871129 - kind: conda name: typer-slim - version: 0.14.0 + version: 0.15.0 build: pyhd8ed1ab_0 subdir: noarch noarch: python - url: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.14.0-pyhd8ed1ab_0.conda - sha256: 883969c10b9837bb18a340ffb01a984ef6b4655fc72ff05aeb7bc659c9a1229d - md5: 3674a4cd7fd8e8a7277af2b30965925d + url: https://conda.anaconda.org/conda-forge/noarch/typer-slim-0.15.0-pyhd8ed1ab_0.conda + sha256: f6a85917292aaea0577792090ac74dbdb0280a656934746f715bfa9feaa9b2dc + md5: 629fef89115de5a907fb9765cdd45b26 depends: - click >=8.0.0 - python >=3.9 - typing_extensions >=3.7.4.3 constrains: + - typer >=0.15.0,<0.15.1.0a0 - shellingham >=1.3.0 - rich >=10.11.0 - - typer >=0.14.0,<0.14.1.0a0 license: MIT license_family: MIT - size: 43504 - timestamp: 1732848371202 + size: 43480 + timestamp: 1733279858535 - kind: conda name: typer-slim-standard - version: 0.14.0 + version: 0.15.0 build: hd8ed1ab_0 subdir: noarch noarch: generic - url: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.14.0-hd8ed1ab_0.conda - sha256: 0e09e393e75028a0e827c7177e0fb1a070c87756e47b5ae6418423e22b10dfac - md5: 9e1e1f9c84add9637ca715f8fb71a83f + url: https://conda.anaconda.org/conda-forge/noarch/typer-slim-standard-0.15.0-hd8ed1ab_0.conda + sha256: df52ddd24439aff384a82d00a751947b12127ab571f4aa674a1053c703ce8ed0 + md5: a4746fc9efbff02c1a288d8fcd8ffba9 depends: - rich - shellingham - - typer-slim 0.14.0 pyhd8ed1ab_0 + - typer-slim 0.15.0 pyhd8ed1ab_0 license: MIT license_family: MIT - size: 49180 - timestamp: 1732848371718 + size: 50259 + timestamp: 1733279859017 - kind: conda name: typing-extensions version: 4.12.2 From 6c178fb6b8b83853ee7a2b1a0f6f6b1af38f159f Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 4 Dec 2024 11:21:51 -0300 Subject: [PATCH 09/29] fix details Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 13 ++++--------- stdlib/test/python/my_module.py | 3 ++- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 3a403f2b2b..6d2681dc40 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -504,7 +504,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn append[ D: DType, // - ](inout self: List[Scalar[D], *_, **_], owned value: SIMD[D, _]): + ](mut self: List[Scalar[D], *_, **_], value: SIMD[D, _]): """Appends a vector to this list. Parameters: @@ -520,11 +520,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn append[ D: DType, // - ]( - inout self: List[Scalar[D], *_, **_], - owned value: SIMD[D, _], - count: Int, - ): + ](mut self: List[Scalar[D], *_, **_], value: SIMD[D, _], count: Int): """Appends count items from a vector to this list. Parameters: @@ -537,14 +533,13 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( if len(self) + count > self.capacity: self._realloc(self.capacity + count) - var ptr = self.unsafe_ptr() var v_ptr = UnsafePointer.address_of(value).bitcast[Scalar[D]]() - memcpy(ptr, v_ptr, count) + memcpy(self.data + len(self), v_ptr, count) self._len += count fn append[ D: DType, // - ](inout self: List[Scalar[D], *_, **_], owned value: Span[Scalar[D]]): + ](mut self: List[Scalar[D], *_, **_], value: Span[Scalar[D]]): """Appends a Span to this list. Parameters: diff --git a/stdlib/test/python/my_module.py b/stdlib/test/python/my_module.py index 8147b0a382..c78c39556e 100644 --- a/stdlib/test/python/my_module.py +++ b/stdlib/test/python/my_module.py @@ -25,7 +25,8 @@ def __init__(self, bar): class AbstractPerson(ABC): @abstractmethod - def method(self): ... + def method(self): + ... def my_function(name): From 8e88d3492e0e5251f300cc87aab9485021c36de0 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 4 Dec 2024 11:40:01 -0300 Subject: [PATCH 10/29] fix details Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 55 ++++++++++---------------- stdlib/src/memory/memory.mojo | 3 +- stdlib/test/collections/test_list.mojo | 2 +- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 6d2681dc40..7cfc9e1293 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -468,23 +468,23 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Methods # ===-------------------------------------------------------------------===# - # FIXME: this needs to be consistent with {String, StringSlice}.byte_length() - fn bytecount(self) -> Int: - """Gets the bytecount of the List. + fn byte_length(self) -> Int: + """Gets the byte length of the List. Returns: - The bytecount of the List. + The byte length of the List. """ return len(self) * sizeof[T]() fn _realloc(mut self, new_capacity: Int): var new_data = UnsafePointer[T].alloc(new_capacity) - _move_pointee_into_many_elements[hint_trivial_type]( - dest=new_data, - src=self.data, - size=self._len, - ) + @parameter + if hint_trivial_type: + memcpy(new_data, self.data, len(self)) + else: + for i in range(len(self)): + (self.data + i).move_pointee_into(new_data + i) if self.data: self.data.free() @@ -492,7 +492,8 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( self.capacity = new_capacity fn append(mut self, owned value: T): - """Appends a value to this list. + """Appends a value to this list. If there is no capacity left, resizes + to twice the current capacity. Except for 0 capacity where it sets 1. Args: value: The value to append. @@ -505,7 +506,8 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn append[ D: DType, // ](mut self: List[Scalar[D], *_, **_], value: SIMD[D, _]): - """Appends a vector to this list. + """Appends a vector to this list. If there is no capacity left, resizes + to `len(self) + value.size`. Parameters: D: The DType. @@ -513,15 +515,15 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Args: value: The value to append. """ - if len(self) + value.size > self.capacity: - self._realloc(self.capacity + value.size) + self.reserve(len(self) + value.size) (self.data + len(self)).store(value) self._len += value.size fn append[ D: DType, // ](mut self: List[Scalar[D], *_, **_], value: SIMD[D, _], count: Int): - """Appends count items from a vector to this list. + """Appends a vector to this list. If there is no capacity left, resizes + to `len(self) + count`. Parameters: D: The DType. @@ -530,9 +532,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( value: The value to append. count: The ammount of items to append. """ - - if len(self) + count > self.capacity: - self._realloc(self.capacity + count) + self.reserve(len(self) + count) var v_ptr = UnsafePointer.address_of(value).bitcast[Scalar[D]]() memcpy(self.data + len(self), v_ptr, count) self._len += count @@ -540,7 +540,8 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn append[ D: DType, // ](mut self: List[Scalar[D], *_, **_], value: Span[Scalar[D]]): - """Appends a Span to this list. + """Appends a Span to this list. If there is no capacity left, resizes + to `len(self) + len(value)`. Parameters: D: The DType. @@ -548,8 +549,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Args: value: The value to append. """ - if len(self) + len(value) > self.capacity: - self._realloc(self.capacity + len(value)) + self.reserve(len(self) + len(value)) memcpy(self.data + len(self), value.unsafe_ptr(), len(value)) self._len += len(value) @@ -986,18 +986,3 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn _clip(value: Int, start: Int, end: Int) -> Int: return max(start, min(value, end)) - - -fn _move_pointee_into_many_elements[ - T: CollectionElement, //, hint_trivial_type: Bool -](dest: UnsafePointer[T], src: UnsafePointer[T], size: Int): - @parameter - if hint_trivial_type: - memcpy( - dest=dest.bitcast[Int8](), - src=src.bitcast[Int8](), - count=size * sizeof[T](), - ) - else: - for i in range(size): - (src + i).move_pointee_into(dest + i) diff --git a/stdlib/src/memory/memory.mojo b/stdlib/src/memory/memory.mojo index 1cbf5c43d3..266ac2c921 100644 --- a/stdlib/src/memory/memory.mojo +++ b/stdlib/src/memory/memory.mojo @@ -251,11 +251,10 @@ fn memcpy[ src: The source pointer. count: The number of elements to copy. """ - var n = count * sizeof[dest.type]() _memcpy_impl( dest.bitcast[Byte, origin=MutableAnyOrigin](), src.bitcast[Byte, origin=MutableAnyOrigin](), - n, + count * sizeof[T](), ) diff --git a/stdlib/test/collections/test_list.mojo b/stdlib/test/collections/test_list.mojo index cd173fc66c..a7c202749b 100644 --- a/stdlib/test/collections/test_list.mojo +++ b/stdlib/test/collections/test_list.mojo @@ -41,7 +41,7 @@ def test_list(): list.append(i) assert_equal(5, len(list)) - assert_equal(5 * sizeof[Int](), list.bytecount()) + assert_equal(5 * sizeof[Int](), list.byte_length()) assert_equal(0, list[0]) assert_equal(1, list[1]) assert_equal(2, list[2]) From 5bc5722796178197b18a33eb94d51c8764b555d0 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 4 Dec 2024 11:44:25 -0300 Subject: [PATCH 11/29] fix details Signed-off-by: martinvuyk --- docs/changelog.md | 1 + stdlib/src/utils/index.mojo | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 640824629c..c1ff0ac449 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -570,6 +570,7 @@ what we publish. - The `UnsafePointer.bitcast` overload for `DType` has been removed. Wrap your `DType` in a `Scalar[my_dtype]` to call the only overload of `bitcast` now. +- Direct access to `List.size` has been removed. Use the public API instead. ### 🛠️ Fixed diff --git a/stdlib/src/utils/index.mojo b/stdlib/src/utils/index.mojo index ed211fdb8e..29d74c2ebe 100644 --- a/stdlib/src/utils/index.mojo +++ b/stdlib/src/utils/index.mojo @@ -744,7 +744,7 @@ struct IndexList[ res.write(self[i]) # Single element tuples should be printed with a trailing comma. if size == 1: - res.write(", ") + res.write(",") # Print a closing `)`. res.write(")") return res^ From abc6e26c802c86c339d1659243a9ffee9802b2e2 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Mon, 9 Dec 2024 22:29:09 -0300 Subject: [PATCH 12/29] fix details Signed-off-by: martinvuyk --- stdlib/src/collections/string.mojo | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/stdlib/src/collections/string.mojo b/stdlib/src/collections/string.mojo index b0ed0c7faa..f257688154 100644 --- a/stdlib/src/collections/string.mojo +++ b/stdlib/src/collections/string.mojo @@ -819,30 +819,23 @@ struct String( @always_inline @implicit fn __init__(out self, impl: Self._buffer_type): - """Construct a string from a buffer of bytes, copying the allocated - data. Use the transfer operator ^ to avoid the copy. + """Construct a string from a buffer of null terminated bytes, copying + the allocated data. Use the transfer operator `^` to avoid the copy. - The buffer must be terminated with a null byte: + Args: + impl: The null-terminated buffer. + + Examples: ```mojo - var buf = List[UInt8]() - buf.append(ord('H')) - buf.append(ord('i')) - buf.append(0) - var hi = String(buf) + print(String(List[Byte](ord('h'), ord('i'), 0))) # hi ``` - - Args: - impl: The buffer. + . """ + # We make a backup because steal_data() will clear length and capacity. + var length = len(impl) debug_assert( - len(impl) > 0 and impl[-1] == 0, - "expected last element of String buffer to be null terminator", - ) - # We make a backup because steal_data() will clear size and capacity. - var size = impl.size - debug_assert( - impl[size - 1] == 0, + length > 0 and impl[length-1] == 0, "expected last element of String buffer to be null terminator", ) self._buffer = impl From 554a0b63cf0ac0c9c1971678a0805adca94a42d1 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Mon, 9 Dec 2024 22:29:34 -0300 Subject: [PATCH 13/29] fix details Signed-off-by: martinvuyk --- stdlib/src/collections/string.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/src/collections/string.mojo b/stdlib/src/collections/string.mojo index f257688154..2aef31cfed 100644 --- a/stdlib/src/collections/string.mojo +++ b/stdlib/src/collections/string.mojo @@ -835,7 +835,7 @@ struct String( # We make a backup because steal_data() will clear length and capacity. var length = len(impl) debug_assert( - length > 0 and impl[length-1] == 0, + length > 0 and impl[length - 1] == 0, "expected last element of String buffer to be null terminator", ) self._buffer = impl From a3bfe405cee1ae122234cad41f99b509fb232714 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Mon, 9 Dec 2024 22:43:43 -0300 Subject: [PATCH 14/29] fix details Signed-off-by: martinvuyk --- stdlib/src/collections/string.mojo | 44 +++--------------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/stdlib/src/collections/string.mojo b/stdlib/src/collections/string.mojo index 2aef31cfed..e7717f29f3 100644 --- a/stdlib/src/collections/string.mojo +++ b/stdlib/src/collections/string.mojo @@ -784,42 +784,8 @@ struct String( @always_inline @implicit - fn __init__(out self, owned impl: List[UInt8, *_]): - """Construct a string from a buffer of bytes without copying the - allocated data. - - The buffer must be terminated with a null byte: - - ```mojo - var buf = List[UInt8]() - buf.append(ord('H')) - buf.append(ord('i')) - buf.append(0) - var hi = String(buf) - ``` - - Args: - impl: The buffer. - """ - debug_assert( - len(impl) > 0 and impl[-1] == 0, - "expected last element of String buffer to be null terminator", - ) - # We make a backup because steal_data() will clear length and capacity. - var length = len(impl) - debug_assert( - length > 0 and impl[length - 1] == 0, - "expected last element of String buffer to be null terminator", - ) - var capacity = impl.capacity - self._buffer = Self._buffer_type( - ptr=impl.steal_data(), length=length, capacity=capacity - ) - - @always_inline - @implicit - fn __init__(out self, impl: Self._buffer_type): - """Construct a string from a buffer of null terminated bytes, copying + fn __init__(out self, impl: List[Byte, *_]): + """Construct a string from a buffer of null-terminated bytes, copying the allocated data. Use the transfer operator `^` to avoid the copy. Args: @@ -832,13 +798,11 @@ struct String( ``` . """ - # We make a backup because steal_data() will clear length and capacity. - var length = len(impl) debug_assert( - length > 0 and impl[length - 1] == 0, + len(impl) > 0 and impl[-1] == 0, "expected last element of String buffer to be null terminator", ) - self._buffer = impl + self._buffer = rebind[Self._buffer_type](impl) @always_inline fn __init__(out self): From 64cd704d6cf02e0e481ade439055bef8ea013052 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 31 Dec 2024 20:04:17 -0300 Subject: [PATCH 15/29] fix after merge Signed-off-by: martinvuyk --- stdlib/src/builtin/string_literal.mojo | 2 +- stdlib/src/collections/list.mojo | 85 ++++------------------- stdlib/src/collections/string/string.mojo | 69 +++++++----------- stdlib/test/collections/test_list.mojo | 2 +- stdlib/test/python/my_module.py | 3 +- 5 files changed, 42 insertions(+), 119 deletions(-) diff --git a/stdlib/src/builtin/string_literal.mojo b/stdlib/src/builtin/string_literal.mojo index 3e9170b8ef..8d245c0ff6 100644 --- a/stdlib/src/builtin/string_literal.mojo +++ b/stdlib/src/builtin/string_literal.mojo @@ -383,7 +383,7 @@ struct StringLiteral( # return self.as_string_slice() var length = self.byte_length() var buffer = String._buffer_type(capacity=length + 1) - buffer.append(self.as_bytes()) + buffer.extend(self.as_bytes()) buffer.append(0) return String(buffer^) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 0068d05bd4..cdc9cdc5fd 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -471,11 +471,11 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( # Methods # ===-------------------------------------------------------------------===# - fn byte_length(self) -> Int: - """Gets the byte length of the List. + fn bytecount(self) -> Int: + """Gets the bytecount of the List. Returns: - The byte length of the List. + The bytecount of the List. """ return len(self) * sizeof[T]() @@ -495,8 +495,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( self.capacity = new_capacity fn append(mut self, owned value: T): - """Appends a value to this list. If there is no capacity left, resizes - to twice the current capacity. Except for 0 capacity where it sets 1. + """Appends a value to this list. Args: value: The value to append. @@ -612,9 +611,9 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Notes: If there is no capacity left, resizes to `len(self) + value.size`. """ - self.reserve(self.size + value.size) - (self.data + self.size).store(value) - self.size += value.size + self.reserve(self._len + value.size) + (self.data + self._len).store(value) + self._len += value.size fn extend[ D: DType, // @@ -633,10 +632,10 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( If there is no capacity left, resizes to `len(self) + count`. """ debug_assert(count <= value.size, "count must be <= value.size") - self.reserve(self.size + count) + self.reserve(self._len + count) var v_ptr = UnsafePointer.address_of(value).bitcast[Scalar[D]]() - memcpy(self.data + self.size, v_ptr, count) - self.size += count + memcpy(self.data + self._len, v_ptr, count) + self._len += count fn extend[ D: DType, // @@ -652,67 +651,9 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Notes: If there is no capacity left, resizes to `len(self) + len(value)`. """ - self.reserve(self.size + len(value)) - memcpy(self.data + self.size, value.unsafe_ptr(), len(value)) - self.size += len(value) - - fn extend[ - D: DType, // - ](mut self: List[Scalar[D], *_, **_], value: SIMD[D, _]): - """Extends this list with the elements of a vector. - - Parameters: - D: The DType. - - Args: - value: The value to append. - - Notes: - If there is no capacity left, resizes to `len(self) + value.size`. - """ - self.reserve(self.size + value.size) - (self.data + self.size).store(value) - self.size += value.size - - fn extend[ - D: DType, // - ](mut self: List[Scalar[D], *_, **_], value: SIMD[D, _], *, count: Int): - """Extends this list with `count` number of elements from a vector. - - Parameters: - D: The DType. - - Args: - value: The value to append. - count: The ammount of items to append. Must be less than or equal to - `value.size`. - - Notes: - If there is no capacity left, resizes to `len(self) + count`. - """ - debug_assert(count <= value.size, "count must be <= value.size") - self.reserve(self.size + count) - var v_ptr = UnsafePointer.address_of(value).bitcast[Scalar[D]]() - memcpy(self.data + self.size, v_ptr, count) - self.size += count - - fn extend[ - D: DType, // - ](mut self: List[Scalar[D], *_, **_], value: Span[Scalar[D]]): - """Extends this list with the elements of a `Span`. - - Parameters: - D: The DType. - - Args: - value: The value to append. - - Notes: - If there is no capacity left, resizes to `len(self) + len(value)`. - """ - self.reserve(self.size + len(value)) - memcpy(self.data + self.size, value.unsafe_ptr(), len(value)) - self.size += len(value) + self.reserve(self._len + len(value)) + memcpy(self.data + self._len, value.unsafe_ptr(), len(value)) + self._len += len(value) fn pop(mut self, i: Int = -1) -> T: """Pops a value from the list at the given index. diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index b31dbf6a49..55a004ef0e 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -803,7 +803,7 @@ struct String( "expected last element of String buffer to be null terminator", ) # We make a backup because steal_data() will clear size and capacity. - var size = impl.size + var size = len(impl) debug_assert( impl[size - 1] == 0, "expected last element of String buffer to be null terminator", @@ -837,7 +837,7 @@ struct String( "expected last element of String buffer to be null terminator", ) # We make a backup because steal_data() will clear size and capacity. - var size = impl.size + var size = len(impl) debug_assert( impl[size - 1] == 0, "expected last element of String buffer to be null terminator", @@ -934,7 +934,7 @@ struct String( bytes: The byte span to write to this String. Must NOT be null terminated. """ - self._iadd[False](bytes) + self._iadd(bytes) fn write[*Ts: Writable](mut self, *args: *Ts): """Write a sequence of Writable arguments to the provided Writer. @@ -1196,7 +1196,7 @@ struct String( return not (self < rhs) @staticmethod - fn _add[rhs_has_null: Bool](lhs: Span[Byte], rhs: Span[Byte]) -> String: + fn _add(lhs: Span[Byte], rhs: Span[Byte]) -> String: var lhs_len = len(lhs) var rhs_len = len(rhs) var lhs_ptr = lhs.unsafe_ptr() @@ -1206,16 +1206,10 @@ struct String( return String(S(ptr=rhs_ptr, length=rhs_len)) elif rhs_len == 0: return String(S(ptr=lhs_ptr, length=lhs_len)) - var sum_len = lhs_len + rhs_len - var buffer = Self._buffer_type(capacity=sum_len + 1) - var ptr = buffer.unsafe_ptr() - memcpy(ptr, lhs_ptr, lhs_len) - memcpy(ptr + lhs_len, rhs_ptr, rhs_len + int(rhs_has_null)) - buffer.size = sum_len + 1 - - @parameter - if not rhs_has_null: - ptr[sum_len] = 0 + var buffer = Self._buffer_type(capacity=lhs_len + rhs_len + 1) + buffer.extend(lhs) + buffer.extend(rhs) + buffer.append(0) return Self(buffer^) @always_inline @@ -1228,7 +1222,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](self.as_bytes(), other.as_bytes()) + return Self._add(self.as_bytes(), other.as_bytes()) @always_inline fn __add__(self, other: StringLiteral) -> String: @@ -1240,7 +1234,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[False](self.as_bytes(), other.as_bytes()) + return Self._add(self.as_bytes(), other.as_bytes()) @always_inline fn __add__(self, other: StringSlice) -> String: @@ -1252,7 +1246,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[False](self.as_bytes(), other.as_bytes()) + return Self._add(self.as_bytes(), other.as_bytes()) @always_inline fn __radd__(self, other: String) -> String: @@ -1264,7 +1258,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](other.as_bytes(), self.as_bytes()) + return Self._add(other.as_bytes(), self.as_bytes()) @always_inline fn __radd__(self, other: StringLiteral) -> String: @@ -1276,7 +1270,7 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](other.as_bytes(), self.as_bytes()) + return Self._add(other.as_bytes(), self.as_bytes()) @always_inline fn __radd__(self, other: StringSlice) -> String: @@ -1288,9 +1282,9 @@ struct String( Returns: The new constructed string. """ - return Self._add[True](other.as_bytes(), self.as_bytes()) + return Self._add(other.as_bytes(), self.as_bytes()) - fn _iadd[has_null: Bool](mut self, other: Span[Byte]): + fn _iadd(mut self, other: Span[Byte]): var s_len = self.byte_length() var o_len = len(other) var o_ptr = other.unsafe_ptr() @@ -1300,15 +1294,10 @@ struct String( return elif o_len == 0: return - var sum_len = s_len + o_len - self._buffer.reserve(sum_len + 1) - var s_ptr = self.unsafe_ptr() - memcpy(s_ptr + s_len, o_ptr, o_len + int(has_null)) - self._buffer.size = sum_len + 1 - @parameter - if not has_null: - s_ptr[sum_len] = 0 + _ = self._buffer.pop() + self._buffer.extend(other) + self._buffer.append(0) @always_inline fn __iadd__(mut self, other: String): @@ -1317,7 +1306,7 @@ struct String( Args: other: The string to append. """ - self._iadd[True](other.as_bytes()) + self._iadd(other.as_bytes()) @always_inline fn __iadd__(mut self, other: StringLiteral): @@ -1326,7 +1315,7 @@ struct String( Args: other: The string to append. """ - self._iadd[False](other.as_bytes()) + self._iadd(other.as_bytes()) @always_inline fn __iadd__(mut self, other: StringSlice): @@ -1335,7 +1324,7 @@ struct String( Args: other: The string to append. """ - self._iadd[False](other.as_bytes()) + self._iadd(other.as_bytes()) fn __iter__(self) -> _StringSliceIter[__origin_of(self)]: """Iterate over the string, returning immutable references. @@ -1564,10 +1553,9 @@ struct String( # This can hugely improve the performance on large lists for e_ref in elems: len_elems += len(e_ref[].as_bytes()) - var capacity = len_self * (n_elems - 1) + len_elems - var buf = Self._buffer_type(capacity=capacity) + var capacity = len_self * (n_elems - 1) + len_elems + 1 var self_ptr = self.unsafe_ptr() - var ptr = buf.unsafe_ptr() + var ptr = UnsafePointer[Byte].alloc(capacity) var offset = 0 var i = 0 var is_first = True @@ -1582,9 +1570,8 @@ struct String( memcpy(dest=ptr + offset, src=e.unsafe_ptr(), count=e_len) offset += e_len i += 1 - buf.size = capacity - buf.append(0) - return String(buf^) + ptr[capacity - 1] = 0 + return String(List(ptr=ptr, length=capacity, capacity=capacity)) fn unsafe_ptr( ref self, @@ -1658,11 +1645,7 @@ struct String( Returns: The pointer to the underlying memory. """ - var ptr = self.unsafe_ptr() - self._buffer.data = UnsafePointer[UInt8]() - self._buffer.size = 0 - self._buffer.capacity = 0 - return ptr + return self._buffer.steal_data() fn count(self, substr: StringSlice) -> Int: """Return the number of non-overlapping occurrences of substring diff --git a/stdlib/test/collections/test_list.mojo b/stdlib/test/collections/test_list.mojo index 2f18ac342f..c6b3e4fb1e 100644 --- a/stdlib/test/collections/test_list.mojo +++ b/stdlib/test/collections/test_list.mojo @@ -39,7 +39,7 @@ def test_list(): list.append(i) assert_equal(5, len(list)) - assert_equal(5 * sizeof[Int](), list.byte_length()) + assert_equal(5 * sizeof[Int](), list.bytecount()) assert_equal(0, list[0]) assert_equal(1, list[1]) assert_equal(2, list[2]) diff --git a/stdlib/test/python/my_module.py b/stdlib/test/python/my_module.py index c78c39556e..8147b0a382 100644 --- a/stdlib/test/python/my_module.py +++ b/stdlib/test/python/my_module.py @@ -25,8 +25,7 @@ def __init__(self, bar): class AbstractPerson(ABC): @abstractmethod - def method(self): - ... + def method(self): ... def my_function(name): From f97b7e9bb40ec4cb257827bea4b9765f77de25ac Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 31 Dec 2024 20:18:26 -0300 Subject: [PATCH 16/29] fix allocation Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index cdc9cdc5fd..23a8ad1fc5 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -415,7 +415,9 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Returns: A string representation of the list. """ - var output = String(capacity=len(self) + 1) # at least + # at least 1 byte per item e.g.: [a, b, c, d] = 4 + 2 * 3 + [] + null + var l = len(self) + var output = String(capacity=l + 2 * (l - 1) * int(l > 1) + 3) self.write_to(output) return output^ From a8f2cd91966fbb7bb78ce1ebee16a1c4df1552c3 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 31 Dec 2024 20:48:18 -0300 Subject: [PATCH 17/29] fix detail Signed-off-by: martinvuyk --- stdlib/src/collections/string/string.mojo | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index 55a004ef0e..4388705a1d 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -1199,13 +1199,11 @@ struct String( fn _add(lhs: Span[Byte], rhs: Span[Byte]) -> String: var lhs_len = len(lhs) var rhs_len = len(rhs) - var lhs_ptr = lhs.unsafe_ptr() - var rhs_ptr = rhs.unsafe_ptr() alias S = StringSlice[ImmutableAnyOrigin] if lhs_len == 0: - return String(S(ptr=rhs_ptr, length=rhs_len)) + return String(S(ptr=rhs.unsafe_ptr(), length=rhs_len)) elif rhs_len == 0: - return String(S(ptr=lhs_ptr, length=lhs_len)) + return String(S(ptr=lhs.unsafe_ptr(), length=lhs_len)) var buffer = Self._buffer_type(capacity=lhs_len + rhs_len + 1) buffer.extend(lhs) buffer.extend(rhs) @@ -1285,17 +1283,13 @@ struct String( return Self._add(other.as_bytes(), self.as_bytes()) fn _iadd(mut self, other: Span[Byte]): - var s_len = self.byte_length() var o_len = len(other) - var o_ptr = other.unsafe_ptr() - if s_len == 0: - alias S = StringSlice[ImmutableAnyOrigin] - self = String(S(ptr=o_ptr, length=o_len)) - return - elif o_len == 0: + if o_len == 0: return - _ = self._buffer.pop() + self._buffer.reserve(len(self._buffer) + o_len) + if len(self._buffer) > 0: + _ = self._buffer.pop() self._buffer.extend(other) self._buffer.append(0) From 6113bc284deb3f3f6c02cac35677c09514d521e9 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 31 Dec 2024 20:53:55 -0300 Subject: [PATCH 18/29] fix detail Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 14 +++++++------- stdlib/src/collections/string/string.mojo | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 23a8ad1fc5..b165ee276a 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -666,17 +666,17 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( Returns: The popped value. """ - debug_assert(-len(self) <= i < len(self), "pop index out of range") + debug_assert(-self._len <= i < self._len, "pop index out of range") var normalized_idx = i if i < 0: - normalized_idx += len(self) + normalized_idx += self._len var ret_val = (self.data + normalized_idx).take_pointee() - for j in range(normalized_idx + 1, len(self)): + for j in range(normalized_idx + 1, self._len): (self.data + j).move_pointee_into(self.data + j - 1) self._len -= 1 - if len(self) * 4 < self.capacity: + if self._len * 4 < self.capacity: if self.capacity > 1: self._realloc(self.capacity // 2) return ret_val^ @@ -705,11 +705,11 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( new_size: The new size. value: The value to use to populate new elements. """ - if new_size <= len(self): + if new_size <= self._len: self.resize(new_size) else: self.reserve(new_size) - for i in range(len(self), new_size): + for i in range(self._len, new_size): (self.data + i).init_pointee_copy(value) self._len = new_size @@ -813,7 +813,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( fn clear(mut self): """Clears the elements in the list.""" - for i in range(len(self)): + for i in range(self._len): (self.data + i).destroy_pointee() self._len = 0 diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index 4388705a1d..68b4946d40 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -1287,9 +1287,9 @@ struct String( if o_len == 0: return - self._buffer.reserve(len(self._buffer) + o_len) if len(self._buffer) > 0: _ = self._buffer.pop() + self._buffer.reserve(len(self._buffer) + o_len + 1) self._buffer.extend(other) self._buffer.append(0) From b25008db3120373598588a93efeef809b05efaec Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Thu, 2 Jan 2025 09:53:56 -0300 Subject: [PATCH 19/29] fix bug in pathlib Signed-off-by: martinvuyk --- stdlib/src/pathlib/path.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/src/pathlib/path.mojo b/stdlib/src/pathlib/path.mojo index b81c184e06..3f0b544041 100644 --- a/stdlib/src/pathlib/path.mojo +++ b/stdlib/src/pathlib/path.mojo @@ -142,7 +142,7 @@ struct Path( Returns: A string representation of the path. """ - return String.write(self) + return self.path @always_inline fn __bool__(self) -> Bool: From 2f327635d5c2bc03c5177388a91944c1b80e5047 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Sun, 2 Feb 2025 09:29:30 -0300 Subject: [PATCH 20/29] add changelog examples Signed-off-by: martinvuyk --- docs/changelog.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 406eb6f819..280cb5d0b5 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -414,6 +414,38 @@ what we publish. intermediary allocations. - Direct access to `List.size` has been removed. Use the public API instead. + Examples: + + Extending a List + ```mojo + base_data = List[Byte](1, 2, 3) + + data_list = List[Byte](4, 5, 6) + ext_data_list = base_data.copy() + ext_data_list.extend(data_list) # [1, 2, 3, 4, 5, 6] + + data_span = Span(List[Byte](4, 5, 6)) + ext_data_span = base_data.copy() + ext_data_span.extend(data_span) # [1, 2, 3, 4, 5, 6] + + data_vec = SIMD[DType.uint8, 4](4, 5, 6, 7) + ext_data_vec_full = base_data.copy() + ext_data_vec_full.extend(data_vec) # [1, 2, 3, 4, 5, 6, 7] + + ext_data_vec_partial = base_data.copy() + ext_data_vec_partial.extend(data_vec, count=3) # [1, 2, 3, 4, 5, 6] + ``` + + Slicing and extending a list efficiently + ```mojo + base_data = List[Byte](1, 2, 3, 4, 5, 6) + n4_n5 = Span(base_data)[3:5] + extra_data = Span(List[Byte](8, 10)) + end_result = List[Byte](capacity=len(n4_n5) + len(extra_data)) + end_result.extend(n4_n5) + end_result.extend(extra_data) # [4, 5, 8, 10] + ``` + ### 🛠️ Fixed - The Mojo Kernel for Jupyter Notebooks is working again on nightly releases. From 727656279a0115ac01f8e0ed1ac5f7869dc8d8d5 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Sun, 2 Feb 2025 09:53:11 -0300 Subject: [PATCH 21/29] fix change implementations to use the public API Signed-off-by: martinvuyk --- stdlib/src/builtin/char.mojo | 2 +- stdlib/src/collections/list.mojo | 2 +- stdlib/src/collections/string/_unicode.mojo | 22 +++++-------- stdlib/src/collections/string/string.mojo | 32 ++++++------------- .../src/collections/string/string_slice.mojo | 10 +++--- 5 files changed, 24 insertions(+), 44 deletions(-) diff --git a/stdlib/src/builtin/char.mojo b/stdlib/src/builtin/char.mojo index 20d4b1c665..4155670006 100644 --- a/stdlib/src/builtin/char.mojo +++ b/stdlib/src/builtin/char.mojo @@ -258,7 +258,7 @@ struct Char(CollectionElement, EqualityComparable, Intable, Stringable): var buffer = List[Byte](capacity=char_len + 1) _ = self.unsafe_write_utf8(buffer.unsafe_ptr()) buffer.unsafe_ptr()[char_len] = 0 - buffer.size = char_len + 1 + buffer._len = char_len + 1 return String(buffer=buffer^) # ===-------------------------------------------------------------------===# diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index e1b9ea3dc5..65cb6b4ad1 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -414,7 +414,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( """ # at least 1 byte per item e.g.: [a, b, c, d] = 4 + 2 * 3 + [] + null var l = len(self) - var output = String(capacity=l + 2 * (l - 1) * int(l > 1) + 3) + var output = String(capacity=l + 2 * (l - 1) * Int(l > 1) + 3) self.write_to(output) return output^ diff --git a/stdlib/src/collections/string/_unicode.mojo b/stdlib/src/collections/string/_unicode.mojo index d5ac9972c9..9df0a1895a 100644 --- a/stdlib/src/collections/string/_unicode.mojo +++ b/stdlib/src/collections/string/_unicode.mojo @@ -181,22 +181,19 @@ fn to_lowercase(s: StringSlice) -> String: var rune_and_size = Char.unsafe_decode_utf8_char(input + input_offset) var lowercase_char_opt = _get_lowercase_mapping(rune_and_size[0]) if lowercase_char_opt is None: - memcpy( - output._unsafe_next_uninit_ptr(), - input + input_offset, - rune_and_size[1], + output.extend( + Span[Byte, s.origin](ptr=input + input_offset, length=rune_and_size[1]) ) - output.size += rune_and_size[1] else: var lower_char: Char = lowercase_char_opt.unsafe_value() - output.size += lower_char.unsafe_write_utf8( + output._len += lower_char.unsafe_write_utf8( output._unsafe_next_uninit_ptr() ) input_offset += rune_and_size[1] # Check if we need to reserve additional capacity. - if output.size >= output.capacity - 5: + if len(output) >= output.capacity - 5: output.reserve( output.capacity + _estimate_needed_size(s.byte_length() - input_offset) @@ -234,21 +231,18 @@ fn to_uppercase(s: StringSlice) -> String: ) for char_idx in range(count): var char: Char = uppercase_replacement_chars[char_idx] - output.size += char.unsafe_write_utf8( + output._len += char.unsafe_write_utf8( output._unsafe_next_uninit_ptr() ) else: - memcpy( - output._unsafe_next_uninit_ptr(), - input + input_offset, - rune_and_size[1], + output.extend( + Span[Byte, s.origin](ptr=input + input_offset, length=rune_and_size[1]) ) - output.size += rune_and_size[1] input_offset += rune_and_size[1] # Check if we need to reserve additional capacity. - if output.size >= output.capacity - 5: + if len(output) >= output.capacity - 5: output.reserve( output.capacity + _estimate_needed_size(s.byte_length() - input_offset) diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index a9ba23c840..d9876d4db6 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -995,17 +995,11 @@ struct String( if lhs_len == 0: return String(S(ptr=rhs.unsafe_ptr(), length=rhs_len)) elif rhs_len == 0: - return String(S(ptr=lhs_ptr, length=lhs_len)) - var sum_len = lhs_len + rhs_len - var buffer = Self._buffer_type(capacity=sum_len + 1) - var ptr = buffer.unsafe_ptr() - memcpy(ptr, lhs_ptr, lhs_len) - memcpy(ptr + lhs_len, rhs_ptr, rhs_len + Int(rhs_has_null)) - buffer.size = sum_len + 1 - - @parameter - if not rhs_has_null: - ptr[sum_len] = 0 + return String(S(ptr=lhs.unsafe_ptr(), length=lhs_len)) + var buffer = Self._buffer_type(capacity=lhs_len + rhs_len + 1) + buffer.extend(lhs) + buffer.extend(rhs) + buffer.append(0) return Self(buffer^) @always_inline @@ -1036,17 +1030,11 @@ struct String( var o_len = len(other) if o_len == 0: return - elif o_len == 0: - return - var sum_len = s_len + o_len - self._buffer.reserve(sum_len + 1) - var s_ptr = self.unsafe_ptr() - memcpy(s_ptr + s_len, o_ptr, o_len + Int(has_null)) - self._buffer.size = sum_len + 1 - - @parameter - if not has_null: - s_ptr[sum_len] = 0 + self._buffer.reserve(self.byte_length() + o_len + 1) + if len(self._buffer) > 0: + _ = self._buffer.pop() + self._buffer.extend(other) + self._buffer.append(0) @always_inline fn __iadd__(mut self, other: StringSlice): diff --git a/stdlib/src/collections/string/string_slice.mojo b/stdlib/src/collections/string/string_slice.mojo index 6d03b916e9..a25183d21e 100644 --- a/stdlib/src/collections/string/string_slice.mojo +++ b/stdlib/src/collections/string/string_slice.mojo @@ -753,13 +753,11 @@ struct StringSlice[mut: Bool, //, origin: Origin[mut]]( The string concatenated `n` times. """ - var len_self = self.byte_length() - var count = len_self * n + 1 - var b_ptr = UnsafePointer[Byte].alloc(count) + var buffer = List[Byte](capacity=self.byte_length() * n + 1) for i in range(n): - memcpy(b_ptr + len_self * i, self.unsafe_ptr(), len_self) - b_ptr[count - 1] = 0 - return String(List(ptr=b_ptr, length=count, capacity=count)) + buffer.extend(self.as_bytes()) + buffer.append(0) + return String(buffer=buffer) # ===------------------------------------------------------------------===# # Methods From d361412060e1f57ef842e8f455c1b1a8aa20a5e3 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Sun, 2 Feb 2025 09:55:53 -0300 Subject: [PATCH 22/29] mojo format Signed-off-by: martinvuyk --- stdlib/src/collections/string/_unicode.mojo | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/src/collections/string/_unicode.mojo b/stdlib/src/collections/string/_unicode.mojo index 9df0a1895a..dcab202ce1 100644 --- a/stdlib/src/collections/string/_unicode.mojo +++ b/stdlib/src/collections/string/_unicode.mojo @@ -182,7 +182,9 @@ fn to_lowercase(s: StringSlice) -> String: var lowercase_char_opt = _get_lowercase_mapping(rune_and_size[0]) if lowercase_char_opt is None: output.extend( - Span[Byte, s.origin](ptr=input + input_offset, length=rune_and_size[1]) + Span[Byte, s.origin]( + ptr=input + input_offset, length=rune_and_size[1] + ) ) else: var lower_char: Char = lowercase_char_opt.unsafe_value() @@ -236,7 +238,9 @@ fn to_uppercase(s: StringSlice) -> String: ) else: output.extend( - Span[Byte, s.origin](ptr=input + input_offset, length=rune_and_size[1]) + Span[Byte, s.origin]( + ptr=input + input_offset, length=rune_and_size[1] + ) ) input_offset += rune_and_size[1] From a9a26092976349257200602a3b431235366e767f Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Sun, 2 Feb 2025 09:57:18 -0300 Subject: [PATCH 23/29] fix assert message Signed-off-by: martinvuyk --- stdlib/src/collections/list.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/src/collections/list.mojo b/stdlib/src/collections/list.mojo index 65cb6b4ad1..96b9924691 100644 --- a/stdlib/src/collections/list.mojo +++ b/stdlib/src/collections/list.mojo @@ -898,7 +898,7 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False]( -self._len <= normalized_idx < self._len, "index: ", normalized_idx, - " is out of bounds for `List` of size: ", + " is out of bounds for `List` of length: ", self._len, ) if normalized_idx < 0: From 498f4d304739b26851f43e4c5e6446577518c36c Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Sun, 2 Feb 2025 10:05:51 -0300 Subject: [PATCH 24/29] fix details Signed-off-by: martinvuyk --- docs/changelog.md | 6 ++++-- stdlib/src/builtin/string_literal.mojo | 5 ++--- stdlib/src/collections/string/format.mojo | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 280cb5d0b5..79e93e484d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -416,7 +416,8 @@ what we publish. Examples: - Extending a List + Extending a List: + ```mojo base_data = List[Byte](1, 2, 3) @@ -436,7 +437,8 @@ what we publish. ext_data_vec_partial.extend(data_vec, count=3) # [1, 2, 3, 4, 5, 6] ``` - Slicing and extending a list efficiently + Slicing and extending a list efficiently: + ```mojo base_data = List[Byte](1, 2, 3, 4, 5, 6) n4_n5 = Span(base_data)[3:5] diff --git a/stdlib/src/builtin/string_literal.mojo b/stdlib/src/builtin/string_literal.mojo index 08a4b2ca71..0d41705bca 100644 --- a/stdlib/src/builtin/string_literal.mojo +++ b/stdlib/src/builtin/string_literal.mojo @@ -387,11 +387,10 @@ struct StringLiteral( # inline the string slice constructor to work around an elaborator # memory leak. # return self.as_string_slice() - var length = self.byte_length() - var buffer = String._buffer_type(capacity=length + 1) + var buffer = String._buffer_type(capacity=self.byte_length() + 1) buffer.extend(self.as_bytes()) buffer.append(0) - return String(buffer^) + return String(buffer=buffer^) @no_inline fn __repr__(self) -> String: diff --git a/stdlib/src/collections/string/format.mojo b/stdlib/src/collections/string/format.mojo index 4b5855a000..7392f231fb 100644 --- a/stdlib/src/collections/string/format.mojo +++ b/stdlib/src/collections/string/format.mojo @@ -146,7 +146,7 @@ struct _FormatCurlyEntry(CollectionElement, CollectionElementNew): var fmt_len = fmt_src.byte_length() var buf = String._buffer_type(capacity=fmt_len + size_estimation) buf.append(0) - var res = String(buf^) + var res = String(buffer=buf^) var offset = 0 var ptr = fmt_src.unsafe_ptr() alias S = StringSlice[StaticConstantOrigin] From 58b81a521e6421f478bc5bc08c8c36f9a9239ed8 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Sun, 2 Feb 2025 10:25:10 -0300 Subject: [PATCH 25/29] fix more uses of string buffer constructor Signed-off-by: martinvuyk --- stdlib/src/collections/string/string.mojo | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index d9876d4db6..badacfa5d6 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -847,7 +847,7 @@ struct String( if buff[-1]: buff.append(0) - return String(buff^) + return String(buffer=buff^) # ===------------------------------------------------------------------=== # # Operator dunders @@ -867,10 +867,7 @@ struct String( """ # TODO(#933): implement this for unicode when we support llvm intrinsic evaluation at compile time var normalized_idx = normalize_index["String"](index(idx), self) - var buf = Self._buffer_type(capacity=1) - buf.append(self._buffer[normalized_idx]) - buf.append(0) - return String(buf^) + return String(buffer=Self._buffer_type(self._buffer[normalized_idx], 0)) fn __getitem__(self, span: Slice) -> String: """Gets the sequence of characters at the specified positions. @@ -895,14 +892,12 @@ struct String( ) ) - var buffer = Self._buffer_type() - var result_len = len(r) - buffer.resize(result_len + 1, 0) + var buffer = Self._buffer_type(capacity=len(r) + 1) var ptr = self.unsafe_ptr() - for i in range(result_len): - buffer[i] = ptr[r[i]] - buffer[result_len] = 0 - return Self(buffer^) + for i in r: + buffer.append(ptr[i]) + buffer.append(0) + return Self(buffer=buffer^) @always_inline fn __eq__(self, other: String) -> Bool: @@ -1980,7 +1975,7 @@ struct String( buffer.resize(width, fillbyte) buffer.append(0) memcpy(buffer.unsafe_ptr().offset(start), self.unsafe_ptr(), len(self)) - var result = String(buffer) + var result = String(buffer=buffer) return result^ fn reserve(mut self, new_capacity: Int): From 87a1a539f7135f5d9ce81a0e8ad0669a5dc7998c Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Sun, 2 Feb 2025 10:32:42 -0300 Subject: [PATCH 26/29] fix more uses of string buffer constructor Signed-off-by: martinvuyk --- stdlib/src/collections/string/string.mojo | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index badacfa5d6..eeb4f0d31e 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -897,7 +897,7 @@ struct String( for i in r: buffer.append(ptr[i]) buffer.append(0) - return Self(buffer=buffer^) + return String(buffer=buffer^) @always_inline fn __eq__(self, other: String) -> Bool: @@ -995,7 +995,7 @@ struct String( buffer.extend(lhs) buffer.extend(rhs) buffer.append(0) - return Self(buffer^) + return String(buffer=buffer^) @always_inline fn __add__(self, other: StringSlice) -> String: @@ -1975,8 +1975,7 @@ struct String( buffer.resize(width, fillbyte) buffer.append(0) memcpy(buffer.unsafe_ptr().offset(start), self.unsafe_ptr(), len(self)) - var result = String(buffer=buffer) - return result^ + return String(buffer=buffer) fn reserve(mut self, new_capacity: Int): """Reserves the requested capacity. From fc70e1e061cc729fe5d0d941476b4841ea063ae1 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Tue, 25 Feb 2025 13:38:14 -0300 Subject: [PATCH 27/29] fix detail Signed-off-by: martinvuyk --- stdlib/src/memory/span.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/src/memory/span.mojo b/stdlib/src/memory/span.mojo index 290c720f61..70a0482a52 100644 --- a/stdlib/src/memory/span.mojo +++ b/stdlib/src/memory/span.mojo @@ -166,7 +166,7 @@ struct Span[ list: The list to which the span refers. """ self._data = list.data.address_space_cast[address_space]() - self._len = list.size + self._len = list._len @always_inline @implicit From ffab93a1554e46194baaab3f654043568cbad6f8 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 26 Feb 2025 10:32:43 -0300 Subject: [PATCH 28/29] fix iadd length to use byte_length Signed-off-by: martinvuyk --- stdlib/src/collections/string/string.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index ff58ea9f05..b7c2b63a78 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -1017,7 +1017,7 @@ struct String( return Self._add(other.as_bytes(), self.as_bytes()) fn _iadd(mut self, other: Span[Byte]): - var o_len = len(other) + var o_len = other.byte_length() if o_len == 0: return self._buffer.reserve(self.byte_length() + o_len + 1) From 0b128533081197425dd7b6ab4a0b5a1ddc665999 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 26 Feb 2025 10:37:37 -0300 Subject: [PATCH 29/29] revert: fix iadd length to use byte_length Signed-off-by: martinvuyk --- stdlib/src/collections/string/string.mojo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/src/collections/string/string.mojo b/stdlib/src/collections/string/string.mojo index b7c2b63a78..ff58ea9f05 100644 --- a/stdlib/src/collections/string/string.mojo +++ b/stdlib/src/collections/string/string.mojo @@ -1017,7 +1017,7 @@ struct String( return Self._add(other.as_bytes(), self.as_bytes()) fn _iadd(mut self, other: Span[Byte]): - var o_len = other.byte_length() + var o_len = len(other) if o_len == 0: return self._buffer.reserve(self.byte_length() + o_len + 1)