Mojo🔥: a deep dive on ownership with Chris Lattner

31,635
0
Published 2024-05-13
Learn everything you need to know about ownership in Mojo, a deep dive with Modular CEO Chris Lattner

If you have any questions make sure to join our friendly discord community: modul.ar/discord

If you're ready to get started with Mojo, check out the programming manual and installation guide: modul.ar/mojo-get-started

0:00 Mojo🔥: a deep dive on ownership with Chris Lattner
00:00 Introduction
00:55 Define Terms
01:11 Garbage Collectors
01:23 Copies
01:39 Goal of ownership model
02:15 Learning from Rust
03:26 How the compiler works
04:18 Type Checker
06:13 Context Insensitive Type Checker
07:20 No traditional AST
08:07 Ownership
08:20 RValue: an owned value
10:35 LValues: assignable and mutable
14:04 BValues: Borrowed Values
16:10 Ownership conversions
16:38 BValue Conversions
17:25 RValue Conversions
18:58 LValue Conversions
20:42 Examples of RValues
21:10 Memory and SSA Types
21:59 Ownership Transfer with ^
22:56 std::move from C++
24:39 Marking variables as uninitialized after transfer with ^
27:51 Data flow checker with argument conventions
31:49 Destructor Insertion
34:40 ASAP Destruction
37:19 Avoiding allocations optimization
38:00 Copy to move optimizations
40:13 @value decorator
41:00 Where does destructor run on borrowed argument
41:46 Copy to move optimization clarification
42:12 Is liveness representable in debug info?
42:27 How ASAP destruction works with loops
42:48 Being simple and optimal
44:14 Allowing more advanced use cases and reducing copies
45:04 Field sensitive and composes with member variables
46:27 Dangling pointers
47:51 What safe references will fi

All Comments (21)
  • @liquidmobius
    Please more videos just like this! I also really appreciated the additional explanations with code examples 👌
  • @romanpopov1041
    great introduction to ownership, please more videos from Chris Lattner, he has great ability to explain things!
  • Very interesting talk, thanks for posting it. It gives me more confidence that coding in Mojo will handle lifetimes while avoiding some of the complicated issues which I've seen come up when programming in Rust.
  • @JaceComix
    Coming from a high-level language background, really appreciate this content!
  • @Ivoshevo
    Am an iOS developer working with swift and I love this Mojo language.
  • @g1m0kolis
    Thank you for sharing this publicly!
  • @oscbit
    Excited for this type of content!
  • @malekabbassi9275
    I enjoyed this so much <3 Mojo is going to be a great language :)
  • @mojoloop
    Started learning mojo recently. I’m mostly excited to get to tensors. But I know I have to go through the basics of Strings, Lists, Dicts, and Sets before I move on. Logic flow is pretty straight forward as well. But, really excited to start working on AI related problems.
  • @Navhkrin
    "You don't have to write std::move" ok im sold
  • @BulbaWarrior
    42:17 So what happens with early destruction under control flow? Will ASAP destruction be able to eliminate an allocation in this case: ``` var s = String("mojo") if false: use(s) ``` Not sure if I have access to IR tools as a simple user Also a design question: does __init__() allow partially initialized objects or is it a compiler error?
  • @alurma
    What a cliff hanger at the end!!!
  • @TheQwerty2584
    very well explained, thanks!! Personally i (and think many more people) just need 1 more think to be fully invested, the capacity of creating a python library with mojo.
  • @alurma
    Wow, how early destruction works with tail calls really impresses me.
  • @ephemer
    Great conversation and information here, thanks a lot for sharing. Chris referred to directories of the Mojo compiler source code – I thought just the stdlib was open sourced so far? Am I right in thinking this is not accessible to us still? Also, I was surprised to hear some of the questions from the team about many of these points: do I understand correctly that Chris is hacking away at this in real time and then sharing with the team as it comes along? I'm mostly curious about how the work is being divvied up in the team at Modular. edit: I watched the first seconds of the video again and it answered a lot of the questions I had, thanks.