Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/nightly' into add-stringiter-s…
Browse files Browse the repository at this point in the history
…plitlines
  • Loading branch information
martinvuyk committed Dec 26, 2024
2 parents f652e52 + d8ab58b commit d77d51f
Show file tree
Hide file tree
Showing 84 changed files with 2,537 additions and 2,081 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
48 changes: 47 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@ 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.

- The legacy `borrowed`/`inout` keywords and `-> T as foo` syntax now generate
a warning. Please move to `read`/`mut`/`out` argument syntax instead.

### 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 @@ -44,7 +59,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 @@ -62,6 +77,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 All @@ -74,6 +116,7 @@ what we publish.
### ❌ Removed
- `StringRef` is being deprecated. Use `StringSlice` instead.
- Changed `sys.argv()` to return list of `StringSlice`.
- removed `StringRef.startswith()` and `StringRef.endswith()`
### 🛠️ Fixed
Expand All @@ -86,5 +129,8 @@ what we publish.
- [Issue #3796](https://github.com/modularml/mojo/issues/3796) - Compiler crash
handling for-else statement.
- [Issue #3540](https://github.com/modularml/mojo/issues/3540) - Using named
output slot breaks trait conformance
- The Mojo Language Server doesn't crash anymore on empty **init**.mojo files.
[Issue #3826](https://github.com/modularml/mojo/issues/3826).
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/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ In the case of `str()`, it requires a type to conform to either the `Stringable`
or `StringableRaising` trait. Each trait requires a conforming type to implement
a `__str__()` method that returns a `String` representation. The only difference
between the two traits is that `Stringable` requires that the method *cannot*
raise and error, whereas `StringableRaising` indicates that the method *might*
raise an error, whereas `StringableRaising` indicates that the method *might*
raise an error. (To learn more, read [The `Stringable`, `Representable`, and
`Writable`
traits](/mojo/manual/traits#the-stringable-representable-and-writable-traits).)
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 d77d51f

Please sign in to comment.