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 Jan 9, 2025
2 parents d9f2298 + 79c4236 commit d815d4e
Show file tree
Hide file tree
Showing 96 changed files with 6,536 additions and 6,029 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
94 changes: 93 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,74 @@ 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.
- Several standard library functions have been changed to take `StringSlice`
instead of `String`. This generalizes them to be used for any appropriately
encoded string in memory, without requiring that the string be heap allocated.
- `atol()`
- `atof()`
- `ord()`
- `ascii()`
- `b64encode()`
- Additionally, the `b64encode()` overload that previously took `List` has
been changed to
take a `Span`.
- `b64decode()`
- `b16encode()`
- `b16decode()`
- Various functionality has moved from `String` and `StringRef` to the more
general `StringSlice` type.
- `StringSlice` now implements `Representable`, and that implementation is now
used by `String.__repr__()` and `StringRef.__repr__()`.
- `StringSlice` now implements `EqualityComparable`.
Up until now, `StringSlice` has implemented a more general `__eq__` and
`__ne__` comparision with `StringSlice` types that had arbitrary other
origins. However, to satisfy `EqualityComparable`, `StringSlice` now also
has narrower comparison methods that support comparing only with
`StringSlice`'s with the exact same origin.
- Removed `@implicit` decorator from some standard library initializer methods
that perform allocation. This reduces places where Mojo code could implicitly
allocate where the user may not be aware.
Remove `@implicit` from:
- `String.__init__(out self, StringRef)`
- `String.__init__(out self, StringSlice)`
- `List.__init__(out self, owned *values: T)`
- `List.__init__(out self, span: Span[T])`
- 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,7 +157,10 @@ what we publish.
### ❌ Removed
- `StringRef` is being deprecated. Use `StringSlice` instead.
- Changed `sys.argv()` to return list of `StringSlice`.
- Added `Path` explicit constructor from `StringSlice`.
- removed `StringRef.startswith()` and `StringRef.endswith()`
- removed `StringRef.strip()`
### 🛠️ Fixed
Expand All @@ -86,5 +172,11 @@ 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
- [Issue #3617](https://github.com/modularml/mojo/issues/3617) - Can't generate
the constructors for a type wrapping `!lit.ref`
- 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
10 changes: 4 additions & 6 deletions docs/manual/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ Hello, World!
Let's extend this basic program by prompting the user for their name and
including that in the greeting printed. The built-in
[`input()`](/mojo/stdlib/builtin/io/input) function accepts an optional
[`String`](/mojo/stdlib/collections/string/String) argument to use as a prompt,
and returns a `String` consisting of the characters the user entered (with the
newline character at the end stripped off).
[`String`](/mojo/stdlib/collections/string/string/String) argument to use as a
prompt, and returns a `String` consisting of the characters the user entered
(with the newline character at the end stripped off).

So let's declare a variable, assign the return value from `input()` to it, and
build a customized greeting.
Expand Down 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 Expand Up @@ -786,8 +786,6 @@ struct Grid(StringableRaising):
<summary>Click here to see the complete `gridv1.mojo` so far:</summary>

```mojo title="gridv1.mojo"
import random
@value
struct Grid(StringableRaising):
var rows: Int
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
3 changes: 2 additions & 1 deletion docs/manual/variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ floating-point type, it converts the value instead of giving a compiler error:

```mojo
var number: Float64 = Int(1)
print(number)
```

```output
1
1.0
```

As shown above, value assignment can be converted into a constructor call if the
Expand Down
Loading

0 comments on commit d815d4e

Please sign in to comment.