Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdlib] Update stdlib corresponding to 2024-05-03 nightly/mojo #2480

Merged
merged 43 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e2c4e0f
[External] [stdlib] Removed FileCheck from the dev guide (#38904)
gabrieldemarmiesse Apr 30, 2024
b49f2be
[stdlib] Narrow disabling of test in `test_string.mojo` (#38209)
JoeLoser Apr 30, 2024
0f91b00
[******][mojo-stdlib] Implement generic `floor` method in `math` (#38…
laszlokindrat Apr 30, 2024
95b92cd
[******][mojo-stdlib] Implement generic `ceil` method in `math` (#38807)
laszlokindrat Apr 30, 2024
d4eff1c
[External] [stdlib] Allow `String()` to be created from `UInt8` ptr a…
gabrieldemarmiesse Apr 30, 2024
8177cd6
[mojo-stdlib] Fix aarch64 config (#38980)
keith Apr 30, 2024
cc22ef5
[stdlib] Make `min` and `max` built-ins (#38901)
JoeLoser May 1, 2024
0ae73e4
[stdlib] Use built-in `max` and `min` functions (#38902)
JoeLoser May 1, 2024
f2fa84e
[docs] Update docs about telemetry for 24.3 (#38356)
scottamain May 1, 2024
0d601ee
[External] [stdlib] Enhance Handling of Infinity and NaN in `assert_a…
modularbot May 1, 2024
4ffbada
[External] [stdlib] SIMD.shuffle with StaticIntTuple mask (#38832)
modularbot May 1, 2024
60f2f95
[External] [stdlib] Add `repr()` function and `Representable` trait (…
gabrieldemarmiesse May 1, 2024
9f983c5
[Docs] Update release changelog for 24.3. (#38900)
arthurevans May 1, 2024
2c7a815
[break-glass] Revert "[External] [stdlib] Enhance Handling of Infinit…
laszlokindrat May 1, 2024
442814d
[External] [mojo-stdlib] Add `List.count(value)` method (#38915)
StandinKP May 1, 2024
750727e
[docs] Add post-process to strip docs domain name from built docs (#3…
scottamain May 1, 2024
55ad997
[mojo-lsp] Add support for traits in DocumentSymbols (#38988)
River707 May 1, 2024
c8fcc4d
[******][mojo-stdlib] Move `clamp` from `math` to `simd` (#38932)
laszlokindrat May 1, 2024
462a8ec
[mojo-stdlib] Implement `FloatLiteral.__floordiv__` (#39061)
laszlokindrat May 1, 2024
8de54b9
[******][mojo-stdlib] Remove `math.round_half{up,down}` (#38936)
laszlokindrat May 1, 2024
93f5ca0
[mojo-stdlib][Docs] Update changelog with `FloatLiteral.__floordiv__`…
laszlokindrat May 1, 2024
e61e09a
[docs] Mention `min` and `max` built-in in changelog (#39030)
JoeLoser May 1, 2024
8e21bc8
[External] [stdlib] Allow `StringRef` to work with both Int8 and UInt…
gabrieldemarmiesse May 1, 2024
85235b2
[******][mojo-stdlib] Move binary elementwise wrappers out of `math` …
laszlokindrat May 1, 2024
39029d1
[docs] Add recent OSS contributions to changelog (#39064)
JoeLoser May 1, 2024
d91c5b3
[stdlib] Use built-in `abs` function (#38903)
JoeLoser May 1, 2024
ea3294f
Internal commit
JoeLoser May 2, 2024
c4706c4
[docs] Mojo 24.3 changelog edits (#39106)
arthurevans May 2, 2024
faaa7a4
[******] Use reversed(range(...)) to visit range in reverse, NFC (#39…
abduld May 2, 2024
47bed5c
[mojo-stdlib] Abort when using Python interop without `MOJO_PYTHON_LI…
laszlokindrat May 2, 2024
fd0f060
[******][mojo-stdlib] Move `roundeven` from `math` to `SIMD` (#38961)
laszlokindrat May 2, 2024
79fa177
[mojo-stdlib] Rename `sys._exit` to `sys.terminate` (#39136)
laszlokindrat May 2, 2024
c657ec0
[mojo-stdlib] Move `round` to `builtin` and implement it generically …
laszlokindrat May 2, 2024
32ce2bc
[Docs] Remove note about Atomic from 24.3 changelog. Related to MOCO…
arthurevans May 2, 2024
f14bdfa
[mojo-stdlib] Move more register passable types off `-> Self` inits. …
lattner May 2, 2024
754b5e9
[docs] Fix broken links (#39176)
scottamain May 2, 2024
d9ea505
[docs] Fix broken/redirecting links in mojodocs (#39178)
scottamain May 2, 2024
e52e550
[mojo-stdlib] Move `builtin/object` off of `-> Self`. (#39192)
lattner May 2, 2024
c937163
[stdlib] Make `List.index` take borrowed values (#39195)
Dan13llljws May 2, 2024
2c4b1e1
[******][GPU] Implement powfi function that does not go through llvm …
abduld May 2, 2024
8405122
[mojo-stdlib] Remove more `-> Self` initializers, NFC. (#39181)
lattner May 2, 2024
7d02e12
[KGEN] Move `CoroutineType` to the `co` dialect (NFC) (#39180)
Mogball May 3, 2024
86afb14
[stdlib] Bump compiler version
JoeLoser May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
654 changes: 625 additions & 29 deletions docs/changelog-released.md

Large diffs are not rendered by default.

521 changes: 56 additions & 465 deletions docs/changelog.md

Large diffs are not rendered by default.

42 changes: 26 additions & 16 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,27 +346,37 @@ containers to enable remote development in Mojo.

### Does the Mojo SDK collect telemetry?

Yes, in combination with the Modular CLI tool, the Mojo SDK collects some basic
system information and crash reports that enable us to identify, analyze, and
prioritize Mojo issues.
Yes, the Mojo SDK collects some basic system information, basic
compiler/runtime events, and crash reports that enable us to identify, analyze,
and prioritize Mojo issues.

Mojo is still in its early days, and this telemetry is crucial to help us
quickly identify problems and improve Mojo. Without this telemetry, we would
have to rely on user-submitted bug reports, and in our decades of building
developer products, we know that most people don’t bother. Plus, a lot of
product issues are not easily identified by users or quantifiable with
individual bug reports. The telemetry provides us the insights we need to build
Mojo into a premier developer product.
This telemetry is crucial to help us quickly identify problems and improve our
products. Without this telemetry, we would have to rely on user-submitted bug
reports, and in our decades of experience building developer products, we know
that most people don’t do that. The telemetry provides us the insights we need
to build better products for you.

Of course, if you don't want to share this information with us, you can easily
opt-out of all telemetry, using the [`modular` CLI](/cli). To stop sharing
system information, run this:
You can opt-out of the crash report and compiler/runtime telemetry, but
package install/update/uninstall events cannot be
disabled (see the [MAX SDK terms](https://www.modular.com/legal/max)).

`modular config-set telemetry.enabled=false`
To disable crash reports, use this command:

To stop sharing crash reports, run this:
```sh
modular config-set crash_reporting.enabled=false
```

`modular config-set crash_reporting.enabled=false`
To reduce other telemetry to only the required telemetry events, use this
command:

```sh
modular config-set telemetry.level=0
```

There are 3 telemetry levels: `0` currently records nothing (unless you're also
using MAX, which records hardware information and session durations); `1`
records high-level events such as when the compiler is invoked; and `2` records
more detail such as the time spend compiling.

## Versioning & compatibility

Expand Down
2 changes: 1 addition & 1 deletion docs/manual/functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
"source": [
"\n",
"Memory-only types, such as `String`, are available as a \n",
"[`VariadicListMem`](/mojo/stdlib/builtin/builtin_list/VariadicListmem).\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",
"of the value itself. You must add an empty subscript operator `[]` to\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/lifecycle/life.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"destroyed](/mojo/manual/lifecycle/death.html).)\n",
"\n",
"All data types in Mojo—including basic types in the standard library such as\n",
"[`Bool`](/mojo/stdlib/builtin/bool/bool),\n",
"[`Bool`](/mojo/stdlib/builtin/bool/Bool),\n",
"[`Int`](/mojo/stdlib/builtin/int/Int), and\n",
"[`String`](/mojo/stdlib/builtin/string/String), up to complex types such\n",
"as [`SIMD`](/mojo/stdlib/builtin/simd/SIMD) and\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/parameters/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@
"\n",
"The Mojo compiler is also smart about type inference with parameters. Note\n",
"that the above function is able to call the parametric\n",
"[`sqrt[]()`](https://docs.modular.com/mojo/stdlib/math/math/sqrt) function\n",
"[`sqrt[]()`](/mojo/stdlib/math/math/sqrt) function\n",
"without specifying the parameters—the compiler infers its parameters based on\n",
"the parametric `x` value passed into it, as if you\n",
"wrote `sqrt[dt, width](x)` explicitly. Also note that `rsqrt()` chose to\n",
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/types.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@
"\n",
"The collection types are _generic types_: while a given collection can only\n",
"hold a specific type of value (such as `Int` or `Float64`), you specify the\n",
"type at compile time using a [parameter]((/mojo/manual/parameters/)). For\n",
"type at compile time using a [parameter](/mojo/manual/parameters/). For\n",
"example, you can create a `List` of `Int` values like this:"
]
},
Expand Down
3 changes: 0 additions & 3 deletions examples/notebooks/RayTracing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,6 @@
}
],
"source": [
"from math import max\n",
"\n",
"\n",
"fn scene_intersect(\n",
" orig: Vec3f,\n",
" dir: Vec3f,\n",
Expand Down
2 changes: 1 addition & 1 deletion stdlib/COMPATIBLE_COMPILER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.4.2923
2024.5.303
60 changes: 24 additions & 36 deletions stdlib/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ Let's try adding a small piece of functionality to `path.mojo`:
```mojo
# ./stdlib/src/pathlib/path.mojo

fn print_cwd() raises:
print("cwd:", cwd())
fn get_cwd_message() raises -> String:
return "Your cwd is: " + cwd()
```

And make sure you're importing it from the module root:
Expand All @@ -165,7 +165,7 @@ And make sure you're importing it from the module root:
from .path import (
DIR_SEPARATOR,
cwd,
print_cwd,
get_cwd_message,
Path,
)
```
Expand All @@ -180,13 +180,13 @@ functionality before you write tests:
from src import pathlib

def main():
pathlib.print_cwd()
print(pathlib.get_cwd_message())
```

Now when you run `mojo main.mojo` it'll reflect the changes:

```plaintext
cwd: /Users/jack/src/mojo/stdlib
Your cwd is: /Users/jack/src/mojo/stdlib
```

### A change with dependencies
Expand All @@ -202,10 +202,11 @@ Try adding this to `os.mojo`, which depends on what we just added to

import pathlib

fn print_paths() raises:
pathlib.print_cwd()
fn get_cwd_and_paths() raises -> List[String]:
result = List[String]()
result.append(pathlib.get_cwd_message())
for path in cwd().listdir():
print(path[])
result.append(str(path[]))
```

This won't work because it's importing `pathlib` from the `stdlib.mojopkg` that
Expand All @@ -224,7 +225,8 @@ syntax:
import os

def main():
os.print_paths()
all_paths = os.get_cwd_and_paths()
print(__type_of(all_paths).__str__(all_paths))
```

We also need to set the following environment variable that tells Mojo to
Expand Down Expand Up @@ -268,30 +270,25 @@ If you haven't already, follow the steps at:

### Adding a test

This will show you how the `FileCheck` utility works. First, turn it on by
adding it to the end of line 7 in `./stdlib/test/pathlib/test_pathlib.mojo`:
This section will show you how to add a unit test.
Add the following at the top of `./stdlib/test/pathlib/test_pathlib.mojo`:

```mojo
# RUN: %mojo -debug-level full -D TEMP_FILE=%t %s | FileCheck %s
# RUN: %mojo %s
```

Now we can add the test and force it to fail:

```mojo
# CHECK-LABEL: test_print_cwd

def test_print_cwd():
print("== test_print_cwd")

# CHECK: This will fail
print_cwd()
def test_get_cwd_message():
assert_equal(get_cwd_message(), "Some random text")
```

Don't forget to call it from `main()`:

```bash
def main():
test_print_cwd()
test_get_cwd_message()
```

Now, instead of testing all the modules, we can just test `pathlib`:
Expand All @@ -304,29 +301,20 @@ This will give you an error showing exactly what went wrong:

```plaintext
/Users/jack/src/mojo-toy-2/stdlib/test/pathlib/test_pathlib.mojo:27:11:
error: CHECK: expected string not found in input

# CHECK: This will fail
^
<stdin>:1:18: note: scanning from here
== test_print_cwd
^
AssertionError: `left == right` comparison failed:
left: Your cwd is: /Users/jack/src/mojo/stdlib
right: Some random text
```

Lets fix the test that we just added:

```mojo
# CHECK-LABEL: test_print_cwd

def test_print_cwd():
print("== test_print_cwd")

# CHECK: cwd:
print_cwd()
def test_get_cwd_message():
assert_true(get_cwd_message().startswith("Your cwd is:"))
```

We're now checking that `print_cwd` is prefixed with `cwd:` just like the
function we added. Run the test again:
We're now checking that `get_cwd_message` is prefixed with `Your cwd is:` just
like the function we added. Run the test again:

```plaintext
Testing Time: 0.65s
Expand Down
16 changes: 6 additions & 10 deletions stdlib/src/builtin/_closure.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ struct __ParameterClosureCaptureList[fn_type: AnyRegType, fn_ref: fn_type]:
# Parameter closure invariant requires this function be marked 'capturing'.
@parameter
@always_inline
fn __init__() -> Self:
return Self {
value: __mlir_op.`kgen.capture_list.create`[callee=fn_ref]()
}
fn __init__(inout self):
self.value = __mlir_op.`kgen.capture_list.create`[callee=fn_ref]()

@always_inline
fn __copyinit__(existing: Self) -> Self:
return Self {
value: __mlir_op.`kgen.capture_list.copy`[callee=fn_ref](
existing.value
)
}
fn __copyinit__(inout self, existing: Self):
self.value = __mlir_op.`kgen.capture_list.copy`[callee=fn_ref](
existing.value
)

@always_inline
fn __del__(owned self):
Expand Down
81 changes: 81 additions & 0 deletions stdlib/src/builtin/_math.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2024, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #
"""Module to contain some components of the future math module.

This is needed to work around some circular dependencies; all elements of this
module should be exposed by the current `math` module. The contents of this
module should be eventually moved to the `math` module when it's open sourced.
"""

# ===----------------------------------------------------------------------===#
# Ceilable
# ===----------------------------------------------------------------------===#


trait Ceilable:
"""
The `Ceilable` trait describes a type that defines a ceiling operation.

Types that conform to `Ceilable` will work with the builtin `ceil`
function. The ceiling operation always returns the same type as the input.

For example:
```mojo
from math import Ceilable, ceil

@value
struct Complex(Ceilable):
var re: Float64
var im: Float64

fn __ceil__(self) -> Self:
return Self(ceil(re), ceil(im))
```
"""

# TODO(MOCO-333): Reconsider the signature when we have parametric traits or
# associated types.
fn __ceil__(self) -> Self:
...


# ===----------------------------------------------------------------------===#
# Floorable
# ===----------------------------------------------------------------------===#


trait Floorable:
"""
The `Floorable` trait describes a type that defines a floor operation.

Types that conform to `Floorable` will work with the builtin `floor`
function. The floor operation always returns the same type as the input.

For example:
```mojo
from math import Floorable, floor

@value
struct Complex(Floorable):
var re: Float64
var im: Float64

fn __floor__(self) -> Self:
return Self(floor(re), floor(im))
```
"""

# TODO(MOCO-333): Reconsider the signature when we have parametric traits or
# associated types.
fn __floor__(self) -> Self:
...
2 changes: 2 additions & 0 deletions stdlib/src/builtin/abs.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ trait Absable:
```
"""

# TODO(MOCO-333): Reconsider the signature when we have parametric traits or
# associated types.
fn __abs__(self) -> Self:
...

Expand Down