-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix memleaks in work with struct types #1885
Conversation
bb999ab
to
b45623c
Compare
b45623c
to
34a1494
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I see in SemanticAnalyser::visit(Tuple &tuple)
I see an unconditional CreateTuple()
. Doesn't this cause us to store 10x the values in StructManager::tuples_
? If so, anything we can do to avoid that?
You're right, this is unnecessary. Two solutions come to mind:
|
Option 1 sounds incorrect although I haven't thought about it too hard. Option 2 sounds reasonable to me. Couple thoughts on option 2:
|
34a1494
to
5553ee0
Compare
I implemented
I'm not sure if getting rid of Still, the approach of running a fixed number of 10 iterations is not very good, but that's for another discussion. We could be able to implement a more "clever" AST pass that would not re-visit nodes for which the state didn't change in 2 successive iterations. Then we could get rid of |
So I think But I agree, we should discuss this somewhere else. |
I originally tagged this for the 0.13 release but I'm hoping to do that release on the first. Should we try and get this in or just leave it for the next release? The leak isn't too bad |
If we can get it in by the 1st that'd be nice. If not, not a huge deal IMO |
5553ee0
to
db75183
Compare
Updated based on @danobi's review. Should be ready for merge if we want to get this in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed on IRC: this PR has potential to cause subtle bugs. So better if we let this get tested through another development cycle to iron out issues.
Using std::shared_ptr to store the inner struct in SizedType causes memleaks when working with recursive types (due to cycles in shared pointers). This commit replaces the std::shared_ptr by a raw pointer. Since we use the same pointer to store the inner structure of tuples, we move the tuple definitions into StructMap.
Until now, array and tuple types were compred by size only. As this may be imprecise, compare them by the inner structure.
This allows to use SizedType and related types (such as Struct) in std::unordered_set/map. Also will be handy once we implement type uniqueness.
Store tuple types inside an unordered_set instead of a vector. Thanks to this, we don't store a new tuple type in each iteration of the semantic analyser. This required to re-implement std::hash and std::equal_to for std::unique_ptr<Struct>.
db75183
to
cd21f1e
Compare
Using
std::shared_ptr
to store the inner struct inSizedType
causes memleaks when working with recursive types (due to cycles in shared pointers). This PR replaces thestd::shared_ptr
by a raw pointer.Fixes #1879.
Checklist
docs/reference_guide.md
CHANGELOG.md