February 2023
Week of 2023-02-27β
-
π’ The
@interface,@implements, and@evaluatortrio of decorators have been removed, replaced by the@parameter ifand@adaptivefeatures. -
π’ Parameter inference can now infer the type of variadic lists.
-
π’ Memory primary types are now supported in function results. A result slot is allocated in the caller, and the callee writes the result of the function into that slow. This is more efficient for large types that don't fit into registers neatly! And initializers for memory-primary types now initialize the value in-place, instead of emitting a copy!
-
Support for
letdecls of memory primary types has been implemented. These are constant, ready-only values of memory primary types but which are allocated on the function stack. -
Overload conversion resolution and parameter inference has been improved:
- Inference now works with
letdecls in some scenarios that weren't working before. - Parameter bindings can now infer types into parameter expressions. This helps resolve higher-order functions in parameter expressions.
- Inference now works with
-
π Optimize floor, ceil, and ldexp on X86 hardware.
-
π Implement the log math function.
Week of 2023-02-20β
-
π’ A new
@__memory_primarystruct decorator has been introduced. Memory primary types must always have an address. For instance, they are always stack-allocated when declared in a function and their values are passed into function calls by address instead of copy. This is in contract with register primary types that may not have an address, and which are passed by value in function calls. Memory-primary fields are not allowed inside register-primary structs, because struct elements are stored in-line. -
π’ A new
_CompilerBuiltinmodule was added. This module defines core types and functions of the language that are referenced by the parser, and hence, is auto-imported by all other modules. For example new types for literal values like the boolean True/False will be included in_CompilerBuiltin. -
π’ A special
__adaptive_setproperty can be accessed on a function reference marked as@adaptive. The property returns the adaptive overload set of that function. The return type is a!kgen.variadic. This feature is useful to implement a genericevaluatefunction in the standard library. -
π’ A new built-in literal type
BoolLiteralwas added in_CompilerBuiltin. It represents the literal boolean valuesTrueandFalse. This is the first Mojo literal to be emitted as a standard library type! -
π Add the prefetch intrinsic to enable HW prefetching a cache line.
-
π Add the
InlinedFixedVector, which is optimized for small vectors and stores values on both the stack and the heap.
Week of 2023-02-13β
-
Unqualified lookups of struct members apply contextual parameters. This means for instance that you can refer to static methods without binding the struct parameters.
struct Foo[x: Int]: @staticmethod bar(): pass foo(self): bar() # implicitly binds to Foo[x].bar() Foo[2].bar() # explicitly bind to another parameter -
π’ A new
Selftype refers to the enclosing type with all parameters bound to their current values. This is useful when working with complex parametric types, e.g.:struct MyArray[size: Int, element_type: type]: fn __new__() -> Self: return Self {...}which is a lot nicer than having to say
MyArray[size, element_type]over and over again. -
π’ Mojo now supports an
@adaptivedecorator. This decorator will supersede interfaces, and it represents an overloaded function that is allowed to resolve to multiple valid candidates. In that case, the call is emitted as a fork, resulting in multiple function candidates to search over.@adaptive fn sort(arr: ArraySlice[Int]): bubble_sort(arr) @adaptive fn sort(arr: ArraySlice[Int]): merge_sort(arr) fn concat_and_sort(lhs: ArraySlice[Int], rhs: ArraySlice[Int]): let arr = lhs + rhs sort(arr) # this forks compilation, creating two instances # of the surrounding function -
π’ Mojo now requires that types implement the
__clone__special member in order to copy them. This allows the safe definition of non-copyable types like Atomic. Note that Mojo still doesn't implement destructors, and (due to the absence of non-mutable references) it doesn't actually invoke the__clone__member when copying a let value. As such, this forces to you as a Mojo user to write maximal boilerplate without getting much value out of it.In the future, we will reduce the boilerplate with decorators, and we will actually start using it. This will take some time to build out though.
-
π’ A special
__mlir_regionstatement was added to provide stronger invariants around defining MLIR operation regions in Mojo. It similar syntax to function declarations, except it there are no results and no input conventions. -
π Implement the log math function.
-
π Improve the DType struct to enable compile-time equality checks.
-
π Add the Complex struct class.
Week of 2023-02-06β
-
π’ The
ifstatement now supports a@parameterdecorator, which requires its condition to be a parameter expression, but which only emits the 'True' side of the condition to the binary, providing a "static if" functionality. This should eliminate many uses of@interfacethat are just used to provide different constraint on the implementations. -
π’
fn main():is now automatically exported and directly runnable by the command-linemojotool. This is a stop-gap solution to enable script-like use cases until we have more of the language built out. -
πͺ¦ The
@nodebug_inlinefeature has been removed, please use@alwaysinline("nodebug")for methods that must be inlined and that we don't want to step into. -
π’ Python chained comparisons, ex.
a < b < c, are now supported in Mojo. -
π’ Functions can now be defined with default argument values, such as
def f(x: Int, y: Int = 5):. The default argument value is used when callers do not provide a value for that argument:f(3), for example, uses the default argument value ofy = 5. -
Unused coroutine results are now nicely diagnosed as "missing await" warnings.
-
π Introduce a vectorized reduction operations to the SIMD type.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!