Skip to content

Commit

Permalink
Merge branch 'nightly' into refactor/update-broken-list
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcsx authored Dec 17, 2024
2 parents a834308 + 2db5e3d commit d9f2298
Show file tree
Hide file tree
Showing 23 changed files with 2,801 additions and 2,969 deletions.
3 changes: 2 additions & 1 deletion docs/changelog-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ Special thanks to our community contributors:
[@rd4com](https://github.com/rd4com),
[@fknfilewalker](https://github.com/fknfilewalker),
[@gabrieldemarmiesse](https://github.com/gabrieldemarmiesse),
[@avitkauskas](https://github.com/avitkauskas)
[@avitkauskas](https://github.com/avitkauskas), and
[@martinvuyk](https://github.com/martinvuyk).

## v24.5 (2024-09-13)

Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,8 @@ what we publish.
- The command `mojo debug --vscode` now sets the current working directory
properly.
- [Issue #3796](https://github.com/modularml/mojo/issues/3796) - Compiler crash
handling for-else statement.
- The Mojo Language Server doesn't crash anymore on empty **init**.mojo files.
[Issue #3826](https://github.com/modularml/mojo/issues/3826).
1,181 changes: 566 additions & 615 deletions examples/life/magic.lock

Large diffs are not rendered by default.

1,077 changes: 517 additions & 560 deletions examples/magic.lock

Large diffs are not rendered by default.

1,077 changes: 527 additions & 550 deletions examples/notebooks/magic.lock

Large diffs are not rendered by default.

1,077 changes: 517 additions & 560 deletions examples/operators/magic.lock

Large diffs are not rendered by default.

1,077 changes: 517 additions & 560 deletions magic.lock

Large diffs are not rendered by default.

31 changes: 9 additions & 22 deletions stdlib/src/builtin/_format_float.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -315,30 +315,17 @@ fn _to_decimal[
](z_result.integer_part)
var r = (z_result.integer_part - FP[type].big_divisor * sig)

while True:
if r < deltai:
# Exclude the right endpoint if necessary
if (
r
| Scalar[CarrierDType](not z_result.is_integer)
| Scalar[CarrierDType](1)
) == 0:
sig -= 1
r = FP[type].big_divisor
break
elif r > deltai:
break
else:
# r == deltai, compare fractional parts
var x_result = _compute_mul_parity(
(two_fc - 1).cast[DType.uint64](), cache_index, beta
)
if not (x_result.parity | x_result.is_integer):
break
# If no break conditions were met
if r < deltai:
exp = minus_k + FP[type].kappa + 1
return _remove_trailing_zeros(sig, exp)

# compare fractional parts if r == deltai
if r == deltai:
var x_result = _compute_mul_parity(
(two_fc - 1).cast[DType.uint64](), cache_index, beta
)
if x_result.parity | x_result.is_integer:
exp = minus_k + FP[type].kappa + 1
return _remove_trailing_zeros(sig, exp)
#######################################################
# Step 3: Find the significand with the smaller divisor
#######################################################
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/builtin/file.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct FileHandle:
path: The file path.
mode: The mode to open the file in (the mode can be "r" or "w" or "rw").
"""
self.__init__(path.as_string_slice(), mode.as_string_slice())
self = Self(path.as_string_slice(), mode.as_string_slice())

fn __init__(out self, path: StringSlice, mode: StringSlice) raises:
"""Construct the FileHandle using the file path and string.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/builtin/simd.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ struct SIMD[type: DType, size: Int](
# Args:
# other: The value to copy.
# """
# self.__copyinit__(other)
# self = other

@always_inline("nodebug")
@implicit
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/collections/optional.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct Optional[T: CollectionElement](
Args:
other: The Optional to copy.
"""
self.__copyinit__(other)
self = other

# ===-------------------------------------------------------------------===#
# Operator dunders
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/collections/set.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct Set[T: KeyElement](Sized, Comparable, Hashable, Boolable):
Args:
elements: An existing set to copy.
"""
self.__init__()
self = Self()
for e in elements:
self.add(e[])

Expand All @@ -83,7 +83,7 @@ struct Set[T: KeyElement](Sized, Comparable, Hashable, Boolable):
Args:
elements: A vector of elements to add to the set.
"""
self.__init__()
self = Self()
for e in elements:
self.add(e[])

Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/hashlib/hash.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ There are a few main tools in this module:

import random
from collections import InlineArray
from sys import bitwidthof, simdwidthof
from sys import bitwidthof, sizeof, simdwidthof
from sys.ffi import _Global

from builtin.dtype import _uint_type_of_width
Expand Down Expand Up @@ -227,7 +227,7 @@ fn hash(bytes: UnsafePointer[UInt8], n: Int) -> UInt:
hash collision statistical properties for common data structures.
"""
alias type = DType.uint64
alias type_width = bitwidthof[type]() // bitwidthof[DType.int8]()
alias type_width = sizeof[type]()
alias simd_width = simdwidthof[type]()
# stride is the byte length of the whole SIMD vector
alias stride = type_width * simd_width
Expand Down
3 changes: 2 additions & 1 deletion stdlib/src/memory/__init__.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
"""Implements the memory package."""
"""The memory package provides several pointer types, as well
as utility functions for dealing with memory."""

from .arc import ArcPointer
from .memory import memcmp, memcpy, memset, memset_zero, stack_allocation
Expand Down
58 changes: 34 additions & 24 deletions stdlib/src/memory/owned_pointer.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
"""Implements `OwnedPointer`, a safe, single-ownership smart pointer.
You can import these APIs from the `memory` package. For example:
```mojo
from memory import OwnedPointer
```
"""

from memory import UnsafePointer, memcpy, stack_allocation


Expand All @@ -25,7 +34,7 @@ struct OwnedPointer[T: AnyType]:
pointers](/mojo/manual/pointers/) in the Mojo Manual.
Parameters:
T: The type to be stored in the OwnedPointer[].
T: The type to be stored in the `OwnedPointer`.
"""

var _inner: UnsafePointer[T, address_space = AddressSpace.GENERIC]
Expand All @@ -35,61 +44,62 @@ struct OwnedPointer[T: AnyType]:
# ===-------------------------------------------------------------------===#

fn __init__[T: Movable](mut self: OwnedPointer[T], owned value: T):
"""Construct a new OwnedPointer[] by moving the passed value into a new backing allocation.
"""Construct a new `OwnedPointer` by moving the passed value into a new backing allocation.
Parameters:
T: The type of the data to store. It is restricted to `Movable` here to allow efficient move construction.
Args:
value: The value to move into the OwnedPointer[].
value: The value to move into the `OwnedPointer`.
"""
self._inner = UnsafePointer[T].alloc(1)
self._inner.init_pointee_move(value^)

fn __init__[
T: ExplicitlyCopyable
](mut self: OwnedPointer[T], *, copy_value: T):
"""Construct a new OwnedPointer[] by explicitly copying the passed value into a new backing allocation.
"""Construct a new `OwnedPointer` by explicitly copying the passed value into a new backing allocation.
Parameters:
T: The type of the data to store.
T: The type of the data to store, which must be
`ExplicitlyCopyable`.
Args:
copy_value: The value to explicitly copy into the OwnedPointer[].
copy_value: The value to explicitly copy into the `OwnedPointer`.
"""
self._inner = UnsafePointer[T].alloc(1)
self._inner.init_pointee_explicit_copy(copy_value)

fn __init__[
T: Copyable, U: NoneType = None
](mut self: OwnedPointer[T], value: T):
"""Construct a new OwnedPointer[] by copying the passed value into a new backing allocation.
"""Construct a new `OwnedPointer` by copying the passed value into a new backing allocation.
Parameters:
T: The type of the data to store.
U: A dummy type parameter, to lower the selection priority of this ctor.
Args:
value: The value to copy into the OwnedPointer[].
value: The value to copy into the `OwnedPointer`.
"""
self._inner = UnsafePointer[T].alloc(1)
self._inner.init_pointee_copy(value)

fn __init__[
T: ExplicitlyCopyable
](mut self: OwnedPointer[T], *, other: OwnedPointer[T],):
"""Construct a new OwnedPointer[] by explicitly copying the value from another OwnedPointer[].
"""Construct a new `OwnedPointer` by explicitly copying the value from another `OwnedPointer`.
Parameters:
T: The type of the data to store.
Args:
other: The OwnedPointer[] to copy.
other: The `OwnedPointer` to copy.
"""
self.__init__(copy_value=other[])
self = OwnedPointer[T](copy_value=other[])

fn __moveinit__(out self, owned existing: Self):
"""Move this OwnedPointer[].
"""Move this `OwnedPointer`.
Args:
existing: The value to move.
Expand All @@ -112,7 +122,7 @@ struct OwnedPointer[T: AnyType]:
"""Returns a reference to the pointers's underlying data with parametric mutability.
Returns:
A reference to the data underlying the OwnedPointer[].
A reference to the data underlying the `OwnedPointer`.
"""
# This should have a widening conversion here that allows
# the mutable ref that is always (potentially unsafely)
Expand All @@ -126,25 +136,25 @@ struct OwnedPointer[T: AnyType]:
# ===-------------------------------------------------------------------===#

fn unsafe_ptr(self) -> UnsafePointer[T]:
"""UNSAFE: returns the backing pointer for this OwnedPointer[].
"""UNSAFE: returns the backing pointer for this `OwnedPointer`.
Returns:
An UnsafePointer to the backing allocation for this OwnedPointer[].
An UnsafePointer to the backing allocation for this `OwnedPointer`.
"""
return self._inner

fn take[T: Movable](owned self: OwnedPointer[T]) -> T:
"""Move the value within the OwnedPointer[] out of it, consuming the
OwnedPointer[] in the process.
"""Move the value within the `OwnedPointer` out of it, consuming the
`OwnedPointer` in the process.
Parameters:
T: The type of the data backing this OwnedPointer[]. `take()` only exists for T: Movable
T: The type of the data backing this `OwnedPointer`. `take()` only exists for `T: Movable`
since this consuming operation only makes sense for types that you want to avoid copying.
For types that are Copy or ExplicitlyCopy but are not Movable, you can copy them through
For types that are `Copyable` or `ExplicitlyCopyable` but are not `Movable`, you can copy them through
`__getitem__` as in `var v = some_ptr_var[]`.
Returns:
The data that is (was) backing the OwnedPointer[].
The data that is (was) backing the `OwnedPointer`.
"""
var r = self._inner.take_pointee()
self._inner.free()
Expand All @@ -156,13 +166,13 @@ struct OwnedPointer[T: AnyType]:
"""Take ownership over the heap allocated pointer backing this
`OwnedPointer`.
Safety:
**Safety:**
This function is not unsafe to call, as a memory leak is not
considered unsafe.
However, to avoid a memory leak, callers should ensure that the
returned pointer is eventually deinitialized and deallocated.
Failure to do so will leak memory.
However, to avoid a memory leak, callers should ensure that the
returned pointer is eventually deinitialized and deallocated.
Failure to do so will leak memory.
Returns:
The pointer owned by this instance.
Expand Down
6 changes: 3 additions & 3 deletions stdlib/src/memory/pointer.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ struct AddressSpace(EqualityComparable, Stringable, Writable):
@value
@register_passable("trivial")
struct Pointer[
is_mutable: Bool, //,
mut: Bool, //,
type: AnyType,
origin: Origin[is_mutable],
origin: Origin[mut],
address_space: AddressSpace = AddressSpace.GENERIC,
](CollectionElementNew, Stringable):
"""Defines a non-nullable safe pointer.
Expand All @@ -309,7 +309,7 @@ struct Pointer[
pointers](/mojo/manual/pointers/) in the Mojo Manual.
Parameters:
is_mutable: Whether the pointee data may be mutated through this.
mut: Whether the pointee data may be mutated through this.
type: Type of the underlying data.
origin: The origin of the pointer.
address_space: The address space of the pointee data.
Expand Down
Loading

0 comments on commit d9f2298

Please sign in to comment.