b4rdarian
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
I will do the same.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
Apparently I am not the first to notice. There is already an issue open https://github.com/modularml/mojo/issues/747. I can see @Weichen-威辰 has added his experience to it.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
Good call. Will do.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
VSCode's mojo extension is not picking up on the error. Only when trying to compile.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
You might be right and it's a bug. I am on an M2 MacBook.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
In that integers are copied rather than owned.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
Btw I am also basing my understanding on rust documentation on ownership https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html#ownership-and-functions
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
I can't really say. It might be, all I am saying is that it doesn't work as it's described in the docs for primitive types.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
I think the docs need updating / clarification. I believe it relates to stack vs heap. So copying only works for objects stored in the heap.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
These will fail compilation if the the commented lines are uncommented
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
Last call will fail as expected if uncommented.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
From the example
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
Added a
__copyinit__
to UniquePointer
to allow copying.
32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
I suspect it relates to how
Int
s are actually stored under the hood with comparison to String
objects. I played a bit with another example from the docs (https://docs.modular.com/mojo/programming-manual.html#transfer-arguments-owned-and) yesterday,32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
I think the compiler's behavior on this isn't fully fleshed out, or blocked on traits, and that's why it worked with String
when it ideally shouldn't
The example with the String was taken from the docs. Either the docs are wrong or I am missing something about how owned
should behave. Further down in the example it talks about how using ^
actually gives complete ownership, making the passed variable out of scope.32 replies
MModular
•Created by b4rdarian on 10/24/2023 in #questions
Confusion with owned integers
Btw the error is similar to what I get if I call
32 replies