Skip to content

Commit

Permalink
Merge branch 'nightly' into int-from-and-to-bytes
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Saelices <[email protected]>
  • Loading branch information
msaelices committed Dec 22, 2024
2 parents 98c29fc + f4b34fc commit 8db9a83
Show file tree
Hide file tree
Showing 81 changed files with 2,177 additions and 1,682 deletions.
2 changes: 1 addition & 1 deletion docs/changelog-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ Big themes for this release:
([PR 2587#](https://github.com/modularml/mojo/pull/2587))
([PR #2703](https://github.com/modularml/mojo/pull/2703))
- Added a new [`Span`](/mojo/stdlib/utils/span/Span) type for taking slices of
- Added a new [`Span`](/mojo/stdlib/memory/span/Span) type for taking slices of
contiguous collections.
([PR #2595](https://github.com/modularml/mojo/pull/2595))
Expand Down
41 changes: 40 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ what we publish.

### Language changes

- Initializers are now treated as static methods that return an instance of
`Self`. This means the `out` argument of an initializer is now treated the
same as a any other function result or `out` argument. This is generally
invisible, except that patterns like `instance.__init__()` and
`x.__copyinit__(y)` no longer work. Simply replace them with `instance = T()`
and `x = y` respectively.

### Standard library changes

- `UnsafePointer`'s `bitcast` method has now been split into `bitcast`
for changing the type, `origin_cast` for changing mutability,
`static_alignment_cast` for changing alignment,
and `address_space_cast` for changing the address space.

- `UnsafePointer` is now parameterized on mutability. Previously,
`UnsafePointer` could only represent mutable pointers.

Expand All @@ -49,7 +61,7 @@ what we publish.
```mojo
var local = 10
# Cast the mutable pointer to be immutable.
var ptr = UnsafePointer.address_of(local).bitcast[mut=False]()
var ptr = UnsafePointer.address_of(local).origin_cast[mut=False]()
```
- The `unsafe_ptr()` method on several standard library collection types have
Expand All @@ -67,6 +79,33 @@ what we publish.
var ptr2 = list2.unsafe_ptr()
```
- Added `Optional.copied()` for constructing an owned `Optional[T]` from an
`Optional[Pointer[T]]` by copying the pointee value.
- Added `Dict.get_ptr()` which returns an `Optional[Pointer[V]]`. If the given
key is present in the dictionary, the optional will hold a pointer to the
value. Otherwise, an empty optional is returned.
- Added new `List.extend()` overloads taking `SIMD` and `Span`. These enable
growing a `List[Scalar[..]]` by copying the elements of a `SIMD` vector or
`Span[Scalar[..]]`, simplifying the writing of some optimized SIMD-aware
functionality.
- Added `StringSlice.from_utf()` factor method, for validated construction of
a `StringSlice` from a buffer containing UTF-8 encoded data. This method will
raise if the buffer contents are not valid UTF-8.
- The `ExplicitlyCopyable` trait has changed to require a
`fn copy(self) -> Self` method. Previously, an initializer with the signature
`fn __init__(out self, *, other: Self)` had been required by
`ExplicitlyCopyable`.
This improves the "greppability" and at-a-glance readability when a programmer
is looking for places in their code that may be performing copies
- `bit_ceil` has been renamed to `next_power_of_two`, and `bit_floor` to
`prev_power_of_two`. This is to improve readability and clarity in their use.
### Tooling changes
- mblack (aka `mojo format`) no longer formats non-mojo files. This prevents
Expand Down
15 changes: 8 additions & 7 deletions docs/manual/decorators/parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ codeTitle: true

---

You can add the `@parameter` decorator on an `if` statement or on a nested
function to run that code at compile time.
You can add the `@parameter` decorator on an `if` or `for` statement to run that
code at compile time, or on a nested function to create a [parametric
closure](#parametric-closure).

## Parametric if statement
## Parametric `if` statement

You can add `@parameter` to any `if` condition that's based on a valid
parameter expression (it's an expression that evaluates at compile time). This
Expand All @@ -27,7 +28,7 @@ else:
this will be included in the binary
```

## Parametric for statement
## Parametric `for` statement

You can add the `@parameter` decorator to a `for` loop to create a loop that's
evaluated at compile time. The loop sequence and induction values must be
Expand All @@ -39,7 +40,7 @@ This has the effect of "unrolling" the loop.
```mojo
fn parameter_for[max: Int]():
@parameter
for i in range(max)
for i in range(max):
@parameter
if i == 10:
print("found 10!")
Expand All @@ -61,8 +62,8 @@ differences when compared to the parametric `for` statement:
(see below) and executes it a specified number of times.

- The parametric `for` statement is more versatile, since you can do anything
you can do in a `for` statement: including using arbitrary sequences,
early-exiting from the loop, skipping iterations with `continue` and so on.
you can do in a `for` statement including: using arbitrary sequences,
early-exiting from the loop, skipping iterations with `continue`, and so on.

By contrast, `unroll()` simply takes a function and a count, and executes
the function the specified number of times.
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/values/lifetimes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ However, in some cases you'll need to interact with origins directly:

* When working with types like
[`Pointer`](/mojo/stdlib/memory/pointer/Pointer) or
[`Span`](/mojo/stdlib/utils/span/Span) which are parameterized on the
[`Span`](/mojo/stdlib/memory/span/Span) which are parameterized on the
origin of the data they refer to.

This section also covers [`ref` arguments](#ref-arguments) and
Expand Down
Loading

0 comments on commit 8db9a83

Please sign in to comment.