Mojo nightly
This version is still a work in progress.
Highlights
- Code that performs many implicit conversions, most visibly large collection literals, compiles faster: the compiler no longer runs parameter inference on constructors that cannot be used for an implicit conversion in the first place. Files that are mostly data, such as the standard library's Unicode lookup tables, compile about 1.3x faster.
Language changes
-
Renamed the
@parameterdecorator on parametric closures to@__parameter. The deprecated@parameter if/@parameter forforms are unchanged; prefercomptime if/comptime forfor compile-time control flow. -
The module & package system:
-
Directories may now have "namespace" semantics; a single directory name may resolve across distinct locations on disk which share that name.
# .# ├── one# │ └── foo# │ └── bar.mojo# └── two# └── foo# └── baz.mojo## Compiles with -Ione -Itwoimport foo.barimport foo.baz -
Importing functions with the same name from different modules, combining them into one overload set, is now an error, following a period of deprecation.
-
Intra-package accesses without explicit
imports are now an error, following a period of deprecation.
-
Library changes
-
StringDictnow conforms toWritablewhen its value type isWritable, matching the existing behavior ofDict. This lets youprint()aStringDictor convert it to aString. -
The
charsargument ofstrip(),lstrip()andrstrip()onStringSpan,StringandStringLiteralis now anImmStringSpan, so a mutable string is accepted aschars, including the string being stripped (s.strip(s)). -
StringDict.__getitem__()now accepts aStringSpan, so you can index aStringDictwith a borrowed string view without first allocating aStringjust to perform the lookup. -
Renamed the variadic type-list parameter on
TupleandVariadicPacktoTs, standardizing the naming convention used across the standard library. The old name,element_types, remains as a deprecated alias. -
Added experimental
DType.float6_e2m3fnandDType.float6_e3m2fn, the two 6-bit encodings from the Open Compute microscaling specification. Both are finite-only, so neither has an inf nor a NaN encoding.These are experimental storage formats for packed weights rather than general-purpose numeric types, and standard library support is deliberately partial. As with the existing
DType.float4_e2m1fn, they are excluded fromis_numeric(), arithmetic is not implemented, and converting to or from another floating-point type is unsupported on every target, so values cannot be printed either. -
Arraynow conforms toDefaultablewhen its typeTis alsoDefaultable. -
Deprecated
is_trivially_movable(),is_trivially_copyable(), andis_trivially_deletable()instd.memoryin favor ofIsTriviallyMovable[T],IsTriviallyCopyable[T], andIsTriviallyDeinitable[T]instd.traits. The replacements arecomptimepredicates rather than functions, so drop the call parens at use sites, for exampleIsTriviallyCopyable[T]instead ofis_trivially_copyable[T](). -
Atomicis now parameterized on a value typeTinstead of aDType. Update call sites fromAtomic[DType.float32]toAtomic[Float32]. The atomic operations (load(),store(),fetch_add(),compare_exchange(), and so on) still only supportScalartypes. -
Added
Pointer[T].unsafe_write(def() -> T), which initializes the pointee with the value returned by a closure, constructing it directly in place rather than moving an already-constructed value there. Unlikeunsafe_write(var T), this does not require the pointee type to beMovable. -
The following APIs have been migrated to unified closures:
sort,debug_assert,Span.apply.
Tooling changes
mojo docnow reports the condition of a conditional trait conformance, and the generated API docs show it alongside the trait. Previously the condition was dropped, making a conditional conformance indistinguishable from an unconditional one. Also fixed rendering of somewhereclauses.
Removed
This release completes the removal of APIs deprecated during the v1.0 cycle. Each entry names its replacement.
-
Removed the temporary
InlineArrayalias forArray, including its re-exports fromstd.collectionsand the prelude. UseArraydirectly. -
Removed the
std.gpu.profilermodule and itsProfileBlockcontext manager. It timed host wall-clock, not GPU work, and reported the elapsed time with the operands reversed. Time a block of host code withperf_counter_ns()directly, and use a GPU profiler such as Nsight Systems orrocproffor device timings. -
Removed
memcmpand itsstd.memoryre-export. Useunsafe_memcmpinstead. -
Removed the
validateparameter fromb64decode(), which now always validates. Passingvalidate=Falsedid not skip any work on valid input; it only turned characters outside the base64 alphabet into silently corrupt output bytes. Drop[validate=True]from existing calls; calls that relied on the default now raise instead of returning garbage.
Fixed
-
Parametric
raisesnow accepts any primary expression as the thrown type in a function signature, matching the syntax positions where types otherwise appear. This most notably fixesraises Self.SomeAssocTypeon trait and struct methods, which would previously fail with an error. The parenthesized workaround (raises (Self.DriveErrorType)) is no longer required. -
An integer
range()with a step of zero is now always empty. It previously used to be an infinite loop - iterating forever at runtime, and hanging the compiler at comptime. -
Fixed
ceildiv()returning0for unsigned operands near the type's maximum value. The unsigned code path computednumerator + denominator - 1, which overflows and wraps for large operands; it now derives the ceiling from the floor division and remainder instead. -
Counter.most_common(n)now returns all elements whennexceeds the number of unique elements, matching Python, instead of aborting. -
os.path.join()now inserts separators based on the accumulated path rather than the first argument, sojoin("/", "a", "b")returns/a/b(previously/ab) andjoin("a", "b/", "c")returnsa/b/c(previouslya/b//c). -
base64.b64decode()now raises an error when the input length is not divisible by 4 instead of reading past the end of the input (or aborting when asserts are enabled).