modus icon indicating copy to clipboard operation
modus copied to clipboard

Make stuff (A)Rc?

Open maowtm opened this issue 3 years ago • 3 comments

Not something urgent now, but it looks like we are cloning Literal etc a lot. Plus when we add source info into literal (?) it will be even more information needed to clone.

Also now that ClauseID need to store a literal for built-in rules it also has the same problem.

maowtm avatar Oct 31 '21 16:10 maowtm

Immutable data structures and cloning is better, especially considering that there is no conceptual sharing in our problem domain: we just take a tree and return another tree. So, I would suggest to introduce (A)rc only in few places where it is really needed.

mechtaev avatar Oct 31 '21 21:10 mechtaev

I agree that we should not have shared mutable data especially in our use cases, but since we're cloning and not modifying the data a lot (for example, in each step of the resolution process we create a new list of goals with only one of the literal replaced, and all others copied. With the amount of branching and depth of the resolution tree this could grow quite quickly) I think it might still be a good idea to try this, maybe later when we have other core functions ready, and especially if resolution starts to take very long...

Since Rc itself does not provide any mutability, as long as we don't start introducing RefCells we should be able to share data in a safe way, so I actually wouldn't worry too much about that. It's just whether it is worth the trouble of adding Rc::new everywhere, in my opinion.

maowtm avatar Oct 31 '21 21:10 maowtm

Yes, for SLD resolution we may need some sharing, but I would suggest to wait until we decide on the optimisations, because this will impact the memory management approach.

mechtaev avatar Oct 31 '21 21:10 mechtaev