From 4b7bfc419c2e3a7ecde66737b49d791dee4ca4e1 Mon Sep 17 00:00:00 2001 From: Arthur Evans Date: Sat, 8 Jun 2024 16:07:47 -0700 Subject: [PATCH] [Docs] Fix some broken links. Also fixed an outdated sample & fixed an omission in the Mojo changelog reported on Discord. MODULAR_ORIG_COMMIT_REV_ID: 9f85b1b52a973283e3b6110557c8581212779241 --- docs/changelog-released.md | 28 ++++++++----- docs/manual/functions.ipynb | 2 +- docs/manual/get-started.md | 6 +-- docs/manual/index.md | 2 +- docs/manual/lifecycle/death.ipynb | 67 +++++++------------------------ docs/manual/python/types.ipynb | 2 +- 6 files changed, 37 insertions(+), 70 deletions(-) diff --git a/docs/changelog-released.md b/docs/changelog-released.md index 9acaf6c1e6..44fd4c9fc7 100644 --- a/docs/changelog-released.md +++ b/docs/changelog-released.md @@ -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)) @@ -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 @@ -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`. @@ -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. @@ -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: @@ -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 @@ -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) diff --git a/docs/manual/functions.ipynb b/docs/manual/functions.ipynb index 64e4e2e604..5cd00427b9 100644 --- a/docs/manual/functions.ipynb +++ b/docs/manual/functions.ipynb @@ -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" ] diff --git a/docs/manual/get-started.md b/docs/manual/get-started.md index 15fb479331..36e41a6bc9 100644 --- a/docs/manual/get-started.md +++ b/docs/manual/get-started.md @@ -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 diff --git a/docs/manual/index.md b/docs/manual/index.md index f0390218c4..139148920e 100644 --- a/docs/manual/index.md +++ b/docs/manual/index.md @@ -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** diff --git a/docs/manual/lifecycle/death.ipynb b/docs/manual/lifecycle/death.ipynb index 4df4001373..d13e357940 100644 --- a/docs/manual/lifecycle/death.ipynb +++ b/docs/manual/lifecycle/death.ipynb @@ -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):" ] }, { @@ -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()" ] }, @@ -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", @@ -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", - "```" + ":::" ] }, { @@ -303,7 +264,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ diff --git a/docs/manual/python/types.ipynb b/docs/manual/python/types.ipynb index 24533e268a..f3c74ebe72 100644 --- a/docs/manual/python/types.ipynb +++ b/docs/manual/python/types.ipynb @@ -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",