Skip to content
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

Ownership/Lifetimes #1

Open
danakj opened this issue Feb 11, 2023 · 2 comments
Open

Ownership/Lifetimes #1

danakj opened this issue Feb 11, 2023 · 2 comments

Comments

@danakj
Copy link

danakj commented Feb 11, 2023

Hello, I saw you ask for feedback on Reddit and I don’t have an account so sharing it here.

This is where I have gotten stuck with the ideas of tracking lifetimes and without changing C++. Maybe you can see alternatives.

https://sunny.garden/@blinkygal/109846557503442563

@ladroid
Copy link
Owner

ladroid commented Feb 11, 2023

Hello,

Unfortunately, I don't have an account in Mastodon, so will write here(hope the message will be delivered). First of all thanks for your comment, thanks to you it was easier for me to understand and implement the class Owner which tracks lifetime. I also read your article which is on the google page, it was very interesting. Thanks for the hint about the implementation of the ownership, I have an "almost similar" solution, of course not ideal, and maybe I am avoiding some of the rules that are laid down in the Rust language, but at least I more or less understood the idea that was originally laid down in the Rust language.

P.S.
I thought before to track lifetime through the memory using unique_ptr or shared_ptr or even more dive in and use some functions for controlling memory from C but I realize that it's too complicated to track after. I also believe that the real implementation of the borrow checker can be rewritten in some parts of the code in the compiler itself or by creating new annotations that are again sewn into the compiler (such as clang).

Most likely I think that such an opportunity will appear in the annotations. I will also leave here Herb Sutter's article about Lifetime perhaps in his proposed cpp2 there will be such or in the new version of C++.

P.P.S
I have a very rough implementation, but if you're interested, it is in the v2.h file. I will figure out how I can improve my solution maybe a stateful template will help or static_assert, of course, it's not a real implementation but some advantages can be.

@danakj
Copy link
Author

danakj commented Feb 15, 2023

Local analysis has been poked at a lot. I would love to see a solution that provides exclusivity across functions, while keeping the analysis local to each function (so it can scale and stay understandable).

Have you seen crubit's lifetime annotations ideas btw? Maybe you will find some inspiration there.

https://github.com/google/crubit/blob/main/docs/lifetime_annotations_cpp.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants