Skip to content

Commit

Permalink
[Docs] Fix some broken links.
Browse files Browse the repository at this point in the history
Also fixed an outdated sample & fixed an omission in the Mojo changelog
reported on Discord.

MODULAR_ORIG_COMMIT_REV_ID: 9f85b1b52a973283e3b6110557c8581212779241
  • Loading branch information
arthurevans authored and modularbot committed Jun 9, 2024
1 parent 8ea8166 commit 4b7bfc4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 70 deletions.
28 changes: 17 additions & 11 deletions docs/changelog-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Big themes for this release:

- New traits and related features:

- Added built-in [`repr()`](mojo/stdlib/builtin/repr/repr) function and
- Added built-in [`repr()`](/mojo/stdlib/builtin/repr/repr) function and
[`Representable`](/mojo/stdlib/builtin/repr/Representable) trait.
([PR #2361](https://github.com/modularml/mojo/pull/2361))

Expand Down Expand Up @@ -489,6 +489,9 @@ Big themes for this release:
- Many functions returning a pointer type have been unified to have a public
API function of `unsafe_ptr()`.
- The `Tensor.data()` method has been renamed to `unsafe_ptr()`. The return
type is still a `DTypePointer[T]`.
- Collections:
- [`List`](/mojo/stdlib/collections/list/List) now has an
Expand Down Expand Up @@ -783,7 +786,9 @@ Big themes for this release:
- `math.limit.min_finite()`: use `utils.numerics.min_finite()`
- The `tensor.random` module has been removed. The same functionality is now
accessible via the `Tensor.rand()` and `Tensor.randn()` static methods.
accessible via the [`Tensor.rand()`](/mojo/stdlib/tensor/tensor/Tensor#rand)
and [`Tensor.randn()`](/mojo/stdlib/tensor/tensor/Tensor#randn) static
methods.
- The builtin `SIMD` struct no longer conforms to `Indexer`; users must
explicitly cast `Scalar` values using `int`.
Expand Down Expand Up @@ -1611,7 +1616,7 @@ fixed in a future release.
type, a register-passable alternative to
[`Optional`](/mojo/stdlib/collections/optional/Optional).

- The [`ulp()`](/mojo/stdlib/math/math/ulp) function has been added to the
- The [`ulp()`](/mojo/stdlib/utils/numerics/ulp) function has been added to the
`math` module. This allows you to get the units of least precision (or units
of last place) of a floating point value.

Expand Down Expand Up @@ -1700,10 +1705,11 @@ fixed in a future release.
from buffer import parallel_memcpy
```
- The [`rand()`](/mojo/stdlib/tensor/random/rand) and
[`randn()`](/mojo/stdlib/tensor/random/randn) functions from the `random`
package that return a `Tensor` have moved to the `tensor` package. Note that
the overloads that write to a `DTypePointer` remain in the `random` package.
- The [`rand()`](/mojo/stdlib/tensor/tensor/Tensor#rand) and
[`randn()`](/mojo/stdlib/tensor/tensor/Tensor#randn) functions from the
`random` package that return a `Tensor` have moved to the `tensor` package.
Note that the overloads that write to a `DTypePointer` remain in the
`random` package.
If you happen to be using both versions in the same source file, you can
import them both using the `import as` syntax:
Expand All @@ -1721,9 +1727,9 @@ fixed in a future release.
from os import abort
```
- The [`isinf()`](/mojo/stdlib/math/math/isinf) and
[`isfinite()`](/mojo/stdlib/math/math/isfinite) methods have been moved from
`math.limits` to the `math` module.
- The [`isinf()`](/mojo/stdlib/utils/numerics/isfinite) and
[`isfinite()`](/mojo/stdlib/utils/numerics/isfinite) methods have been moved
from `math.limits` to the `math` module.
```mojo
from math import ininf, isfinite
Expand Down Expand Up @@ -2061,7 +2067,7 @@ installation issues. Otherwise it is functionally identical to Mojo 24.1.
`UnusualSlice` constructor.

- The `__refitem__()` accessor method may now return a
[`Reference`](/mojo/stdlib/memory/reference/reference) instead of having to
[`Reference`](/mojo/stdlib/memory/reference/Reference) instead of having to
return an MLIR internal reference type.

- Added [`AnyPointer.move_into()`](/mojo/stdlib/memory/unsafe_pointer/UnsafePointer#move_into)
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
"Memory-only types, such as `String`, are available as a \n",
"[`VariadicListMem`](/mojo/stdlib/builtin/builtin_list/VariadicListMem).\n",
"Iterating over this list directly with a `for..in` loop currently produces a\n",
"[`Reference`](/mojo/stdlib/memory/unsafe/reference) for each value instead\n",
"[`Reference`](/mojo/stdlib/memory/reference/Reference) for each value instead\n",
"of the value itself. You must add an empty subscript operator `[]` to\n",
"dereference the reference and retrieve the value:\n"
]
Expand Down
6 changes: 3 additions & 3 deletions docs/manual/get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ Now let's write the code in a Mojo source file and run it with the
Hello, world!
```
If this didn't work for you, double-check that your code looks exactly like the code
in step 1, and make sure you correctly [installed
mojo](/mojo/install) (it includes Mojo).
If this didn't work for you, double-check that your code looks exactly like the
code in step 1, and make sure you correctly installed either [MAX](/max/install)
(which includes Mojo) or [Mojo](#1-install-mojo).

## 4. Build an executable binary

Expand Down
2 changes: 1 addition & 1 deletion docs/manual/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ feedback](/mojo/community).

- **Get started**

- [Why Mojo](/mojo/manual/why-mojo)
- [Why Mojo](/mojo/why-mojo)
- [Get started with Mojo](/mojo/manual/get-started)

- **Language basics**
Expand Down
67 changes: 14 additions & 53 deletions docs/manual/lifecycle/death.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@
"dynamically allocate memory. \n",
"\n",
"Whereas, the following struct must define the `__del__()` method to free the\n",
"memory allocated for its [`Pointer`](/mojo/stdlib/memory/unsafe/Pointer):"
"memory allocated by its\n",
"[`UnsafePointer`](/mojo/stdlib/memory/unsafe_pointer/UnsafePointer):"
]
},
{
Expand All @@ -209,17 +210,21 @@
"metadata": {},
"outputs": [],
"source": [
"from memory.unsafe_pointer import UnsafePointer\n",
"\n",
"struct HeapArray:\n",
" var data: Pointer[Int]\n",
" var data: UnsafePointer[Int]\n",
" var size: Int\n",
"\n",
" fn __init__(inout self, size: Int, val: Int):\n",
" self.size = size\n",
" self.data = Pointer[Int].alloc(self.size)\n",
" self.data = UnsafePointer[Int].alloc(self.size)\n",
" for i in range(self.size):\n",
" self.data.store(i, val)\n",
" (self.data + i).init_pointee_copy(val)\n",
"\n",
" fn __del__(owned self):\n",
" for i in range(self.size):\n",
" (self.data + 1).destroy_pointee()\n",
" self.data.free()"
]
},
Expand All @@ -231,40 +236,9 @@
"when a pointer is destroyed, Mojo doesn't call the destructors on those values.\n",
"\n",
"So in the `HeapArray` example above, calling `free()` on the pointer releases\n",
"the memory, but doesn't call the destructors on the stored `Int` values. That's\n",
"OK in this case, because trivial types like `Int` have no-op destructors.\n",
"However, in the general case—if you're storing values that _might_ have\n",
"functional destructors—it's not enough to call `free()` on the pointer. You\n",
"should also ensure that Mojo completely destroys all the allocated types\n",
"through their destructors.\n",
"\n",
"The following example updates the previous `__del__()` method to ensure\n",
"destructors are called on array elements. It does this by assigning each of the\n",
"stored values in turn to the `_` \"discard\" pattern. Assigning a value to the\n",
"`_` discard variable tells the compiler that this is the last use of that\n",
"value, so it can be destroyed immediately."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"struct HeapArray:\n",
" var data: Pointer[Int]\n",
" var size: Int\n",
"\n",
" fn __del__(owned self):\n",
" for i in range(self.size):\n",
" _ = __get_address_as_owned_value((self.data + i).address)\n",
" self.data.free()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"the memory, but doesn't call the destructors on the stored values. To invoke\n",
"the destructors, use the `destroy_pointee()` method provided by the \n",
"`UnsafePointer` type.\n",
"\n",
":::note\n",
"\n",
Expand All @@ -274,20 +248,7 @@
"destroys a value, however, it passes in the original value as `self`, not a\n",
"copy.\n",
"\n",
":::\n",
"\n",
"For instances of the \n",
"[`UnsafePointer`](/mojo/stdlib/memory/unsafe_pointer/UnsafePointer) type, use\n",
"the [`destroy_pointee()`](/mojo/stdlib/memory/unsafe_pointer/destroy_pointee)\n",
"function instead of the discard pattern. For example, if the previous example\n",
"used `UnsafePointer`, the `__del__()` method would look like this:\n",
"\n",
"```mojo\n",
"fn __del__(owned self):\n",
" for i in range(self.size):\n",
" destroy_pointee(self.data + i)\n",
" self.data.free()\n",
"```"
":::"
]
},
{
Expand All @@ -303,7 +264,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/python/types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
"using the built-in \n",
"[`int()`](/mojo/stdlib/builtin/int/int-function),\n",
"[`str()`](/mojo/stdlib/builtin/str/str),\n",
"and [`bool()`](/mojo/stdlib/builtin/bool/bool) functions, and print Python \n",
"and [`bool()`](/mojo/stdlib/builtin/bool/bool-function) functions, and print Python \n",
"values using the built-in [`print()`](/mojo/stdlib/builtin/io/print) function.\n",
" \n",
"`PythonObject` also provides the\n",
Expand Down

0 comments on commit 4b7bfc4

Please sign in to comment.