Skip to main content

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 an owned value (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 the someValue value, and pass that value instead of someValue, because there may be other uses of someValue after the call.

    The Mojo compiler is now smart enough to detect when there are no uses of someValue later, and it will elide the copy just as if you had manually specified the transfer operator like takeValueAsOwned(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

  • finally clauses are now supported on try statements. In addition, try statements no longer require except clauses, allowing try-finally blocks. finally clauses contain code that is always executed from control-flow leaves any of the other clauses of a try statement by any means.

🦋 Changed

  • with statement emission changed to use the new finally logic so that

    with ContextMgr():
        return

    Will 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_passable type 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_int method has a misleading name
  • Issue #189 - PythonObject bool conversion is incorrect
  • Issue #65 - Add SIMD constructor from Bool
  • Issue #153 - Meaning of Time.now function result is unclear
  • Issue #165 - Type in Pointer.free documentation
  • 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.unreachable inside 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.

  • PythonObject is now printable from Mojo, instead of requiring you to import Python's print function.

🛠️ Fixed

  • Issue #98: Incorrect error with lifetime tracking in loop.

  • Issue #49: Type inference issue (?) in 'ternary assignment' operation (FloatLiteral vs. 'SIMD[f32, 1]').

  • Issue #48: and/or don't work with memory-only types.

  • Issue #11: setitem Support for PythonObject.

2023-05-11

⭐️ New

  • NDBuffer and Buffer are now constructable via Pointer and DTypePointer.

  • String now supports indexing with either integers or slices.

  • Added factorial function to the Math module.

🦋 Changed

  • The "byref" syntax with the & sigil has changed to use an inout keyword to be more similar to the borrowed and owned syntax 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

  • Fixed missing overloads for Testing.assertEqual so that they work on Integer and String values.

  • Issue #6: Playground stops evaluating cells when a simple generic is defined.

  • Issue #18: Memory leak in Python interoperability was removed.

2023-05-02

📢 Released

⭐️ 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 sleep function.

Was this page helpful?