samufi
samufi
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
Same error with
struct Bar:
fn __init__(out self):
pass


struct Foo:
var bar: Bar
fn __init__(out self):
self.bar = Bar()

fn get(self) -> ref[self.bar] Bar:
return self.bar


fn main() raises -> None:
foo = Foo()
bazz = foo.get()
struct Bar:
fn __init__(out self):
pass


struct Foo:
var bar: Bar
fn __init__(out self):
self.bar = Bar()

fn get(self) -> ref[self.bar] Bar:
return self.bar


fn main() raises -> None:
foo = Foo()
bazz = foo.get()
34 replies
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
struct Bar:
fn __init__(out self):
pass

struct Foo:
var bar: Bar
fn __init__(out self):
self.bar = Bar()

fn main() raises -> None:
foo = Foo()
bazz = foo.bar
struct Bar:
fn __init__(out self):
pass

struct Foo:
var bar: Bar
fn __init__(out self):
self.bar = Bar()

fn main() raises -> None:
foo = Foo()
bazz = foo.bar
gives you the error
/mojo_proj/source/prog.mojo:13:13: error: 'Bar' is not copyable because it has no '__copyinit__'
bazz = foo.bar
~~~^~~~
mojo: error: failed to parse the provided Mojo source module
/mojo_proj/source/prog.mojo:13:13: error: 'Bar' is not copyable because it has no '__copyinit__'
bazz = foo.bar
~~~^~~~
mojo: error: failed to parse the provided Mojo source module
34 replies
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
Is there any instance where you can create a ref[...] ... explicitly or where a = f() with f -> ref[...] ... does something else than a copy?
34 replies
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
Can you provide an example?
34 replies
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
This may be true (and would be useful in some instances). But I think that after the old references were renamed to Pointer, references behave in a way that they cannot be stored in a variable.
34 replies
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
@value
struct MyInt:
var value: Int
fn __copyinit__(out self, other: Self):
print("Copy")
self.value = other.value



struct MyList:
var list: List[MyInt]

fn __init__(out self):
self.list = List[MyInt]()

fn __getitem__(self, index: Int) -> ref[self.list] MyInt:
return self.list[index]

fn append(mut self, value: MyInt) -> None:
self.list.append(value)

fn do_stuff(mut self, index: Int) -> None:
self.list[index].value = 1

fn main() raises -> None:
var mylist = MyList()
mylist.append(MyInt(0))
print("Will this copy?")
var q1 = mylist[0]
print(q1.value)
mylist.do_stuff(0)
print(q1.value)
print(mylist[0].value)
@value
struct MyInt:
var value: Int
fn __copyinit__(out self, other: Self):
print("Copy")
self.value = other.value



struct MyList:
var list: List[MyInt]

fn __init__(out self):
self.list = List[MyInt]()

fn __getitem__(self, index: Int) -> ref[self.list] MyInt:
return self.list[index]

fn append(mut self, value: MyInt) -> None:
self.list.append(value)

fn do_stuff(mut self, index: Int) -> None:
self.list[index].value = 1

fn main() raises -> None:
var mylist = MyList()
mylist.append(MyInt(0))
print("Will this copy?")
var q1 = mylist[0]
print(q1.value)
mylist.do_stuff(0)
print(q1.value)
print(mylist[0].value)
34 replies
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
I may be wrong w.r.t. trivial types; after trying it out I think this also happens at other types. But I am sure that q1 = mylist[0] creates a copy.
34 replies
MModular
Created by Deftioon on 1/11/2025 in #questions
Is there a way to reflect changes to a variable in the reference?
I thought this is intended behaviour for register passable types. Since they are always passed by copy and not by reference, q1 is not a reference to anything but a simple copy. If it were a reference, you'd need to dereference it first, and the issue Owen pointed out would occur.
34 replies
MModular
Created by samufi on 1/9/2025 in #community-showcase
Larecs: a performance-centred archetype-based ECS
The components are already stored in SoA. Just that the arrays are filled with structs themselves. As long as each component is just a trivial SIMD, everything is fine. But if the components have multiple fields, things get tricky.
16 replies
MModular
Created by samufi on 1/9/2025 in #community-showcase
Larecs: a performance-centred archetype-based ECS
The components are always stored as Arrays of structs. How would the ECS know that it can split a struct into separate attributes that can be stored in separate arrays?
16 replies
MModular
Created by samufi on 1/9/2025 in #community-showcase
Larecs: a performance-centred archetype-based ECS
Sorry, I may have misunderstood you. I meant the fields can have different sizes. Each struct (component) has the same size of course.
16 replies
MModular
Created by samufi on 1/9/2025 in #community-showcase
Larecs: a performance-centred archetype-based ECS
Well, users can come up with weird stuff sometimes. For example a position component where the z coordinate can be lower precision for some reason.
16 replies
MModular
Created by samufi on 1/9/2025 in #community-showcase
Larecs: a performance-centred archetype-based ECS
My thought was to do something in this direction for components that are an alias for SIMD, but I am not sure how to enforce that this functionality would be used appropriately. More user friendly might be an integration of numojo data types.
16 replies
MModular
Created by samufi on 1/9/2025 in #community-showcase
Larecs: a performance-centred archetype-based ECS
Of course you could use a larger stride, but this is something the users would need to do - as I do not see a way how Larecs could figure out the memory layout of the components.
16 replies
MModular
Created by samufi on 1/9/2025 in #community-showcase
Larecs: a performance-centred archetype-based ECS
To me the question is what to do if the components are structs themselves. What do you do if you have a component with components of different sizes? Edit: a component with fields of different sizes
16 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
What would be the side effects besides adding raises to a bunch of places in your code?
89 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
ah, no, I think I got it.
89 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
What does that mean? That all functions that do allocations need raises?
89 replies
MModular
Created by gamendez98 on 2/19/2024 in #questions
How long until mojo is production ready(guesstimate)?
Which changes are you talking about? The derefencing operator?
89 replies
MModular
Created by samufi on 9/21/2024 in #questions
How can I use a fixed-size integer type to index a list?
I was not sure if the int is a function call (introducing some overhead, maybe copying of values). If it is really equivalent to a "reinterpret cast" in C++, then this is awesome. I do not yet have a feel for what is going on under the hood in mojo.
7 replies