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

Mojo oss release 2024 04 05 210926699 fixup #1

Merged
merged 56 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6785a12
[Docs] Update load()/store() item and move it to top of removed secti…
arthurevans Mar 28, 2024
2267591
[mojo-stdlib] Move a few more regpassable inits to 'inout self'. (#36…
lattner Mar 28, 2024
6c943c9
[mojo-lang] Change mlir-ification of values of trait type. (#36166)
lattner Mar 28, 2024
b6fffb2
[mojo] Error out on defining `main` in a package (#36062)
River707 Mar 29, 2024
fe36e1b
[mojo-stdlib] Remove always_inline from debug_assert (#36065)
River707 Mar 29, 2024
3920786
[mojo-driver] Add a `-g` option that aliases `--debug-level full` (#3…
River707 Mar 29, 2024
514c99d
[Stdlib] Reconcile the div_ceil and ceildiv functions (#36203)
abduld Mar 29, 2024
07b594e
[mojo-examples] Fix incorrect logic in vectorize loop (#36196)
jackos Mar 29, 2024
8c545e6
[CHANGELOG] Update for `mojo build` change (#36210)
modocache Mar 29, 2024
b365582
[docs] Cross-link the vision and roadmap docs (#36142)
scottamain Mar 29, 2024
bd9f474
[Internal Change]
abduld Mar 29, 2024
b6df7e7
[mojo-stdlib] Move DTypePointer inits to `inout Self` (#36262)
lattner Mar 29, 2024
53b1c97
[mojo][repl] Fix erroneous destructor call emission in generated REPL…
Mar 30, 2024
d26d0b7
[mojo-lang] Expand `VariadicPack` to take parametric trait base (#36319)
lattner Mar 31, 2024
d928227
[mojo-lang] Finally add support for AnyTrait param conversion. (#36362)
lattner Apr 1, 2024
cfd479f
[stdlib] Use variadic initializer for `List` in tests (#36410)
JoeLoser Apr 1, 2024
3083a6c
[KGEN] Delete `POC::VariadicSize` (#36239)
Apr 1, 2024
6a8fb55
[mojo-stdlib] Hotfix merge conflict in main
Apr 2, 2024
17b1c47
[mojo-stdlib] Make `PythonObject` conform to `KeyElement` (#36354)
laszlokindrat Apr 2, 2024
fa92b98
[stdlib] Add `String.removeprefix` and `String.removesuffix` (#36411)
JoeLoser Apr 2, 2024
28eca82
[mojo-stdlib] Teach `PythonObject` about `__setitem__` (#36355)
laszlokindrat Apr 2, 2024
65268c8
[mojo-lsp] Fix hover snippet for functions with functional args/param…
River707 Apr 2, 2024
aff80b9
[mojo-tooling] Fix processing of argument conventions in lsp/docs (#3…
River707 Apr 2, 2024
2ce7ba3
[SDK][Debug] Enable JIT debugging in the mac sdk (#36220)
walter-erquinigo Apr 2, 2024
c75fdbf
[KGEN] Fix crash when parsing `0__` (#35899)
akirchhoff-modular Apr 3, 2024
ae3837f
[Stdlib] Add a load method to Atomic (#36495)
abduld Apr 3, 2024
b023521
[mojo-lang] Fix meta-trait type parameter rebinding logic. (#36584)
lattner Apr 3, 2024
82095db
[mojo-stdlib] Add back `Python.dict()` (#36499)
laszlokindrat Apr 3, 2024
b7ca250
[Mojo][Docs] Update changelog with fix to Python dict interop (#36446)
laszlokindrat Apr 3, 2024
25c92b3
[mojo-stdlib] Add `Python.list()` method (#36504)
laszlokindrat Apr 3, 2024
8724ea5
[mojo-stdlib] Simplify `Python.none()` (#36505)
laszlokindrat Apr 3, 2024
969a8e7
[stdlib] Fix base64 encode for non-ASCII chars (#36598)
JoeLoser Apr 3, 2024
a91194e
[mojo-stdlib] Introduce `OwnedKwargsDict` (#36468)
laszlokindrat Apr 3, 2024
f88491c
[stdlib] Add `list.pop(index)` API (#36597)
JoeLoser Apr 3, 2024
2c17046
[stdlib] Remove `List.pop_back()` (#36612)
JoeLoser Apr 3, 2024
0c4289c
[mojo-lang] Teach parameter inference about type rebinds. (#36587)
lattner Apr 3, 2024
4487840
[Docs] Fix changelog formatting. Fixes #36539 (#36634)
arthurevans Apr 3, 2024
0a6b5a1
[mojo-lang][mojo-stdlib] Use `OwnedKwargsDict` for emitting variadic …
laszlokindrat Apr 3, 2024
b5c5d42
[stdlib] Avoid `import *` in tests (#36678)
JoeLoser Apr 4, 2024
299ddd6
[stdlib] Add `Dict.update()` (#36677)
JoeLoser Apr 4, 2024
dacf20e
[stdlib] Replace `__init__ -> Self` use in `os` module (#36675)
JoeLoser Apr 4, 2024
991d6b5
[stdlib] Add `is` and `isnot` functions to `Optional` (#36674)
JoeLoser Apr 4, 2024
44178a8
[Stdlib] Constrain the mask for shuffle to be within the right domain…
abduld Apr 4, 2024
8900f36
[Kernels] Rename apple and intel amx files in linalg package, NFC (#3…
abduld Apr 4, 2024
07b7ced
[stdlib] Add move constructor to `Atomic` (#36718)
JoeLoser Apr 4, 2024
4b5085d
[mojo-lang] Enable `VariadicPack` for borrowed memory packs (#36680)
lattner Apr 4, 2024
5ef3ed0
[mojo-stdlib] Parameterize `Reference` on `AddressSpace` (#36561)
bethebunny Apr 4, 2024
5272028
[mojo-lang] Document variadic packs work in changelog. (#36781)
lattner Apr 4, 2024
f9ce2fb
[mblack] Fix tokenization error in mblack (#36826)
jmd1011 Apr 4, 2024
0c02f93
[docs] Delete playground deprecation notice (#36842)
scottamain Apr 4, 2024
b2377c7
[mojo-lang] Move testsuite off `AnyRegType` packs. (#36884)
lattner Apr 5, 2024
a49ff9c
[stdlib] Adding AddressSpace support to AnyPointer. (#36552)
rparolin Apr 5, 2024
ec47437
[mojo-lang] Reject `AnyRegType` variadic packs, pushing to `AnyType` …
lattner Apr 5, 2024
55ff418
[Docs] Add section to style guide on inheriting Python inconsistencie…
jackos Apr 5, 2024
ca54e6c
Resolved merge conflicts by accepting all incoming
modularbot Apr 5, 2024
f06a940
[stdlib] Fixup some internal sync issues
JoeLoser Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/changelog-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,6 @@ installation issues. Otherwise it is functionally identical to Mojo 24.1.
fn __copyinit__(inout self: Self, existing: Self):
self.vec = existing.vec


fn main():
var foo = Foo()
print(len(foo.vec))
Expand Down
65 changes: 65 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ and tools. Please add any significant user-visible changes here.

### ⭐️ New

- Heterogenous variadic pack arguments now work reliably even with memory types,
and have a more convenient API to use, as defined on the `VariadicPack` type.
For example, a simplified version of `print` can be implemented as:

```mojo
fn print[T: Stringable, *Ts: Stringable](first: T, *rest: *Ts):
print_string(str(first))

@parameter
fn print_elt[T: Stringable](a: T):
print_string(" ")
print_string(a)
rest.each[print_elt]()
```

- The `sys` module now contains an `exit` function that would exit a Mojo
program with the specified error code.

Expand All @@ -31,6 +46,25 @@ and tools. Please add any significant user-visible changes here.
shorter alias is equivalent to writing `--debug-level full`. This option is
also available in the `mojo debug` command, but is already the default.

- `PythonObject` now conforms to the `KeyElement` trait, meaning that it can be
used as key type for `Dict`. This allows on to easily build and interact with
Python dictionaries in mojo:

```mojo
def main():
d = PythonObject(Dict[PythonObject, PythonObject]())
d["foo"] = 12
d[7] = "bar"
d["foo"] = [1, 2, "something else"]
print(d) # prints `{'foo': [1, 2, 'something else'], 7: 'bar'}`
```

- `List` now has a `pop(index)` API for removing an element
at a particular index. By default, `List.pop()` removes the last element
in the list.

- `Dict` now has a `update()` method to update keys/values from another `Dict`.

### 🦋 Changed

- The behavior of `mojo build` when invoked without an output `-o` argument has
Expand All @@ -46,8 +80,39 @@ and tools. Please add any significant user-visible changes here.

### ❌ Removed

- Support for "register only" variadic packs has been removed. Instead of
`AnyRegType`, please upgrade your code to `AnyType` in examples like this:

```mojo
fn [*Types: AnyRegType](*args: *Ts): ...
```

This move gives you access to nicer API and has the benefit of being memory
safe and correct for non-trivial types. If you need specific APIs on the
types, please use the correct trait bound instead of `AnyType`.

- `List.pop_back()` has been removed. Use `List.pop()` instead which defaults
to popping the last element in the list.

### 🛠️ Fixed

- [#1987](https://github.com/modularml/mojo/issues/1987) Defining `main`
in a Mojo package is an error, for now. This is not intended to work yet,
erroring for now will help to prevent accidental undefined behavior.

- [#1215](https://github.com/modularml/mojo/issues/1215) and
[#1949](https://github.com/modularml/mojo/issues/1949) The Mojo LSP server no
longer cuts off hover previews for functions with functional arguments,
parameters, or results.

- [#1901](https://github.com/modularml/mojo/issues/1901) Fixed Mojo LSP and
documentation generation handling of inout arguments.

- [#1913](https://github.com/modularml/mojo/issues/1913) - `0__` no longer
crashes the Mojo parser.

- [#1924](https://github.com/modularml/mojo/issues/1924) JIT debugging on Mac
has been fixed.

- [#1963](https://github.com/modularml/mojo/issues/1963) `a!=0` is now parsed
and formatted correctly by `mojo format`.
7 changes: 0 additions & 7 deletions docs/manual/get-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,6 @@ brew upgrade modular
Instead of downloading the Mojo SDK, you can also experiment with Mojo in our
online [Playground](/mojo/playground).

:::note

The older [JupyterLab-based Playground](https://playground.modular.com) is still
available until March 20th.

:::

### What to expect

The Mojo Playground is a simple online editor where you can test out Mojo
Expand Down
7 changes: 7 additions & 0 deletions stdlib/docs/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ struct MyStruct(Sized, Stringable):

## Code conventions

### Python Standard Library

We want to be a good member of the Python family and aim to become a full
superset, so we inherit naming from the Python standard library, including any
inconsistencies. These naming inconsistencies are the only exceptions to the
naming conventions outlined below.

### Identifier naming conventions

There are several ways to capitalize and separate words, known as "case
Expand Down
54 changes: 25 additions & 29 deletions stdlib/src/builtin/builtin_list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ListLiteral[*Ts: AnyRegType](Sized):
"""The underlying storage for the list."""

@always_inline("nodebug")
fn __init__(inout self, *args: *Ts):
fn __init__(inout self, borrowed *args: *Ts):
"""Construct the list literal from the given values.

Args:
Expand Down Expand Up @@ -419,7 +419,6 @@ struct VariadicPack[
lifetime: AnyLifetime[elt_is_mutable].type,
element_trait: _AnyTypeMetaType,
*element_types: element_trait,
# TODO: Add address_space when Reference supports it.
](Sized):
"""A utility class to access variadic pack arguments and provide an API for
doing things with them.
Expand Down Expand Up @@ -487,9 +486,15 @@ struct VariadicPack[
Returns:
The number of elements in the variadic pack.
"""
return __mlir_attr[
`#kgen.param.expr<variadic_size,`, element_types, `> : index`
]

@parameter
fn variadic_size(
x: __mlir_type[`!kgen.variadic<`, element_trait, `>`]
) -> Int:
return __mlir_op.`pop.variadic.size`(x)

alias result = variadic_size(element_types)
return result

@always_inline
fn __len__(self) -> Int:
Expand All @@ -504,13 +509,7 @@ struct VariadicPack[
fn get_element[
index: Int
](self) -> Reference[
# FIXME: Shouldn't need a rebind here.
__mlir_attr[
`#kgen.param.expr<rebind, `,
element_types[index.value],
`>: `,
AnyType,
],
element_types[index.value],
Self.elt_is_mutable,
Self.lifetime,
]:
Expand All @@ -523,25 +522,22 @@ struct VariadicPack[
A reference to the element. The Reference's mutability follows the
mutability of the pack argument convention.
"""
var ref_elt = __mlir_op.`lit.ref.pack.get`[index = index.value](
self._value
)

# Rebind the !lit.ref to agree on the element type. This is needed
# because we're getting a low level rebind to AnyType when the
# element_types[index] expression is erased to AnyType for Reference.
alias result_ref = Reference[
element_types[index.value],
Self.elt_is_mutable,
Self.lifetime,
]
return rebind[result_ref.mlir_ref_type](ref_elt)

return rebind[
Reference[
# FIXME: Shouldn't need a rebind here.
__mlir_attr[
`#kgen.param.expr<rebind, `,
element_types[index.value],
`>: `,
AnyType,
],
Self.elt_is_mutable,
Self.lifetime,
]
](__mlir_op.`lit.ref.pack.get`[index = index.value](self._value))

# FIXME!: the T in the function should be element_trait bound not AnyType
# bound.
@always_inline
fn each[func: fn[T: AnyType] (T) -> None](self):
fn each[func: fn[T: element_trait] (T) capturing -> None](self):
"""Apply a function to each element of the pack in order. This applies
the specified function (which must be parametric on the element type) to
each element of the pack, from the first element to the last, passing
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/builtin/int.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ struct Int(Intable, Stringable, KeyElement, Boolable):
var x = self
var n = rhs
while n > 0:
if n&1 != 0:
if n & 1 != 0:
res *= x
x *= x
n >>= 1
Expand Down
85 changes: 17 additions & 68 deletions stdlib/src/builtin/io.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn _flush():


@no_inline
fn _printf[*types: AnyRegType](fmt: StringLiteral, *arguments: *types):
fn _printf[*types: AnyRegType](fmt: StringLiteral, borrowed *arguments: *types):
with _fdopen(_fdopen.STDOUT) as fd:
_ = __mlir_op.`pop.external_call`[
func = "KGEN_CompilerRT_fprintf".value,
Expand All @@ -121,7 +121,12 @@ fn _printf[*types: AnyRegType](fmt: StringLiteral, *arguments: *types):
@no_inline
fn _snprintf[
*types: AnyRegType
](str: Pointer[Int8], size: Int, fmt: StringLiteral, *arguments: *types) -> Int:
](
str: Pointer[Int8],
size: Int,
fmt: StringLiteral,
borrowed *arguments: *types,
) -> Int:
"""Writes a format string into an output pointer.

Args:
Expand Down Expand Up @@ -337,70 +342,6 @@ fn _put(x: DType):
# ===----------------------------------------------------------------------=== #


struct _StringableTuple[*Ts: Stringable](Sized):
alias _type = __mlir_type[
`!kgen.pack<:variadic<`, Stringable, `> `, Ts, `>`
]
var storage: Self._type

fn __init__(inout self, value: Self._type):
self.storage = value

@staticmethod
fn _offset[i: Int]() -> Int:
constrained[i >= 0, "index must be positive"]()

@parameter
if i == 0:
return 0
else:
return _align_up(
Self._offset[i - 1]()
+ _align_up(sizeof[Ts[i - 1]](), alignof[Ts[i - 1]]()),
alignof[Ts[i]](),
)

@always_inline
fn _print[i: Int](inout self, /, *, sep: StringLiteral = " "):
_put(sep)
_put(self._at[i]())

fn _at[i: Int](inout self) -> String:
alias offset = Self._offset[i]()
var i8ptr = Pointer.address_of(self).bitcast[Int8]().offset(offset)
return str(Reference(i8ptr[]).bitcast_element[Ts[i]]()[])

fn __len__(self) -> Int:
return len(VariadicList(Ts))


@always_inline
fn _print_elements[
T: Stringable, *Ts: Stringable
](
first: T,
inout rest: _StringableTuple[Ts],
sep: StringLiteral = " ",
end: StringLiteral = "\n",
flush: Bool = False,
):
_put(str(first))

@parameter
fn each[i: Int]():
rest._print[i](sep=sep)

unroll[each, len(VariadicList(Ts))]()
_put(end)
if flush:
_flush()


# ===----------------------------------------------------------------------=== #
# print
# ===----------------------------------------------------------------------=== #


@no_inline
fn print(
*, sep: StringLiteral = " ", end: StringLiteral = "\n", flush: Bool = False
Expand Down Expand Up @@ -441,7 +382,15 @@ fn print[
end: The String to write after printing the elements.
flush: If set to true, then the stream is forcibly flushed.
"""
var vals = _StringableTuple[Ts](rest)
_print_elements(first, vals, sep=sep, end=end)
_put(str(first))

@parameter
fn print_elt[T: Stringable](a: T):
_put(sep)
_put(a)

rest.each[print_elt]()

_put(end)
if flush:
_flush()
15 changes: 11 additions & 4 deletions stdlib/src/builtin/simd.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -1333,7 +1333,8 @@ struct SIMD[type: DType, size: Int = simdwidthof[type]()](
*mask: Int, output_size: Int = size
](self, other: Self) -> SIMD[type, output_size]:
"""Shuffles (also called blend) the values of the current vector with
the `other` value using the specified mask (permutation).
the `other` value using the specified mask (permutation). The mask values
must be within `2*len(self)`.

Parameters:
mask: The permutation to use in the shuffle.
Expand Down Expand Up @@ -1368,6 +1369,10 @@ struct SIMD[type: DType, size: Int = simdwidthof[type]()](
@parameter
fn fill[idx: Int]():
alias val = mask[idx]
constrained[
0 <= val < 2 * size,
"invalid index in the shuffle operation",
]()
var ptr = __mlir_op.`pop.array.gep`(
Pointer.address_of(array).address, idx.value
)
Expand All @@ -1391,7 +1396,8 @@ struct SIMD[type: DType, size: Int = simdwidthof[type]()](
@always_inline("nodebug")
fn shuffle[*mask: Int](self) -> Self:
"""Shuffles (also called blend) the values of the current vector with
the `other` value using the specified mask (permutation).
the `other` value using the specified mask (permutation). The mask values
must be within `2*len(self)`.

Parameters:
mask: The permutation to use in the shuffle.
Expand All @@ -1405,7 +1411,8 @@ struct SIMD[type: DType, size: Int = simdwidthof[type]()](
@always_inline("nodebug")
fn shuffle[*mask: Int](self, other: Self) -> Self:
"""Shuffles (also called blend) the values of the current vector with
the `other` value using the specified mask (permutation).
the `other` value using the specified mask (permutation). The mask values
must be within `2*len(self)`.

Parameters:
mask: The permutation to use in the shuffle.
Expand Down Expand Up @@ -2218,7 +2225,7 @@ fn _pow[
var x = lhs[i]
var n = rhs[i]
while n > 0:
if n&1 != 0:
if n & 1 != 0:
res *= x
x *= x
n >>= 1
Expand Down
Loading
Loading