-
-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Borrow inference #6621
Borrow inference #6621
Conversation
52138c8
to
9f80665
Compare
Hi again, |
True, but the alternative is worse. We've seen really bad performance in simple programs due to the So basically, we're giving up the property of bounded memory usage (a problem in theory) for improved performance (a problem in practice). Our assumption is that the difference in peak memory usage in practice will be small.
The current analysis only considers function arguments with a layout of That is naive in several ways, but relatively straightforward to implement. There is a bug somewhere though, but sadly none of our fine-grained tests hit it. Only the (massive) |
Thank you for your contribution! Sometimes PRs end up staying open for a long time without activity, which can make the list of open PRs get long and time-consuming to review. To keep things manageable for reviewers, this bot automatically closes PRs that haven’t had activity in 60 days. This PR hasn’t had activity in 30 days, so it will be automatically closed if there is no more activity in the next 30 days. Keep in mind that PRs marked |
Adds borrow inference for arguments of type
List _
andStr
(not tag unions of any kind, not structs containing these types).Our observation has been for a while that while perceus etc. are excellent for algebraic types, they cause suboptimal behavior for roc's builtin data structures (list and str).
In the perceus implementation, arguments are always passed as
Owned
to another function. This is desirable when the callee can perform an update to the argument value: if the argument is unique at runtime, the update can occur in-place.But passing as owned is suboptimal when the callee only reads from the argument (e.g.
List.get
). Passing the argument as owned in this case likely requires an extra reference count increment, because it is likely that the code performs another read of the data. That means the data needs to be kept alive, hence the additional increment.A concrete example:
with the old approach,
helper
takes its arguments as owned values. To make that work, an additionalinc
is needed:With borrow inference, because no updates can ever happen to
list
in the body ofhelper
, the argument is inferred as borrowed.That means the inferred incs/decs are instead
I've opened the PR now mostly for CI reasons: I don't know for sure if the implementation is entirely correct.
I've disabled an assert in
inc_dec.rs
that verifies that initially join point arguments are owned. No idea if that is correct.cc @JTeeuwissen @bhansconnect