May 2023
2023-05-31
⭐️ New
-
Mojo Playground now includes the following Python packages (in response to popular demand):
torch,tensorflow,polars,opencv-python,keras,Pillow,plotly,seaborn,sympy,transformers. -
A new optimization is applied to non-trivial copyable values that are passed as an owned value without using the transfer (
^) operator. Consider code like this:var someValue: T = ... ... takeValueAsOwned(someValue) ...When
takeValueAsOwned()takes its argument as anownedvalue (this is common in initializers for example), it is allowed to do whatever it wants with the value and destroy it when it is finished. In order to support this, the Mojo compiler is forced to make a temporary copy of thesomeValuevalue, and pass that value instead ofsomeValue, because there may be other uses ofsomeValueafter the call.The Mojo compiler is now smart enough to detect when there are no uses of
someValuelater, and it will elide the copy just as if you had manually specified the transfer operator liketakeValueAsOwned(someValue^). This provides a nice "it just works" behavior for non-trivial types without requiring manual management of transfers.If you'd like to take full control and expose full ownership for your type, just don't make it copyable. Move-only types require the explicit transfer operator so you can see in your code where all ownership transfer happen.
-
Similarly, the Mojo compiler now transforms calls to
__copyinit__methods into calls to__moveinit__when that is the last use of the source value along a control flow path. This allows types which are both copyable and movable to get transparent move optimization. For example, the following code is compiled into moves instead of copies even without the use of the transfer operator:var someValue = somethingCopyableAndMovable() use(someValue) ... let otherValue = someValue # Last use of someValue use(otherValue) ... var yetAnother = otherValue # Last use of otherValue mutate(yetAnother)This is a significant performance optimization for things like
PythonObject(and more complex value semantic types) that are commonly used in a fluid programming style. These don't want extraneous reference counting operations performed by its copy constructor.If you want explicit control over copying, it is recommended to use a non-dunder
.copy()method instead of__copyinit__, and recall that non-copyable types must always use of the transfer operator for those that want fully explicit behavior.
🛠️ Fixed
- Issue #231 - Unexpected error when a Python expression raises an exception
- Issue #119 - The REPL fails when a python variable is redefined
2023-05-24
⭐️ New
finallyclauses are now supported ontrystatements. In addition,trystatements no longer requireexceptclauses, allowingtry-finallyblocks.finallyclauses contain code that is always executed from control-flow leaves any of the other clauses of atrystatement by any means.
🦋 Changed
-
withstatement emission changed to use the newfinallylogic so thatwith ContextMgr(): returnWill correctly execute
ContextMgr.__exit__before returning.
🛠️ Fixed
- Issue #204 - Mojo REPL crash when returning a String at compile-time
- Issue #143 - synthesized
init in
@register_passabletype doesn't get correct convention. - Issue #201 - String literal concatenation is too eager.
- Issue #209 - [QoI] Terrible error message trying to convert a type to itself.
- Issue #32 - Include struct fields in docgen
- Issue #50 - Int to string conversion crashes due to buffer overflow
- Issue #132 - PythonObject
to_intmethod has a misleading name - Issue #189 - PythonObject bool conversion is incorrect
- Issue #65 - Add SIMD constructor from Bool
- Issue #153 - Meaning of
Time.nowfunction result is unclear - Issue #165 - Type in
Pointer.freedocumentation - Issue #210 - Parameter results cannot be declared outside top-level in function
- Issue #214 - Pointer offset calculations at compile-time are incorrect
- Issue #115 - Float printing does not include the right number of digits
- Issue #202 -
kgen.unreachableinside nested functions is illegal - Issue #235 - Crash when register passable struct field is not register passable
- Issue #237 - Parameter closure sharp edges are not documented
2023-05-16
⭐️ New
-
Added missing dunder methods to
PythonObject, enabling the use of common arithmetic and logical operators on imported Python values. -
PythonObjectis now printable from Mojo, instead of requiring you to import Python's print function.
🛠️ Fixed
2023-05-11
⭐️ New
-
NDBufferandBufferare now constructable viaPointerandDTypePointer. -
Stringnow supports indexing with either integers or slices. -
Added factorial function to the
Mathmodule.
🦋 Changed
-
The "byref" syntax with the
&sigil has changed to use aninoutkeyword to be more similar to theborrowedandownedsyntax in arguments. Please see Issue #7 for more information. -
Optimized the Matrix multiplication implementation in the notebook. Initially we were optimizing for expandability rather than performance. We have found a way to get the best of both worlds and now the performance of the optimized Matmul implementation is 3x faster.
-
Renamed the
^postfix operator from "consume" to "transfer."
🛠️ Fixed
2023-05-02
📢 Released
- Mojo publicly launched! This was epic, with lots of great coverage online including a wonderful post by Jeremy Howard. The team is busy this week.
⭐️ New
- Added a Base64 encoding function to perform base64 encoding on strings.
🦋 Changed
-
Decreased memory usage of serialization of integers to strings.
-
Speedup the sort function.
🛠️ Fixed
- Fixed time unit in the
sleepfunction.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!