-
Notifications
You must be signed in to change notification settings - Fork 444
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
Refactor ReferenceResolver to use native C++-enumerators in some places #4432
Conversation
Maybe it would make sense to wait until C++20 adoption and replace |
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.
Generally I think this is a good change, thank you for your contribution. You may consider special-casing the common task of taking the first element of an enumerator in the enumerator itself. Do you have any performance measurements? I wonder what is the visible impact.
auto decls = ns->getDeclsByName(name)->toVector(); | ||
if (!decls.empty()) { |
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.
Idea: This pattern seems to be repeated often enough it might be good to add something like std::optional<T> first()
or maybe T first()
(with BUG_CHECK
) + std::optional<T> optFirst()
to Enumerator
and use it instead of toVector()
-- there is no point in creating a vector just to get first element (and even a singleton vector allocates on heap, while this would do no allocation).
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.
Yes, I thought about this, but somehow decided to not to add... Will check it out.
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.
Actually, there is already single()
method that does exactly this. It's just Enumerator
interface is quite alien for C++ so noone seem to use is :)
auto *ctorCall = | ||
new IR::ConstructorCallExpression(decl->srcInfo, decl->type, decl->arguments); | ||
v.push_back(ctorCall); | ||
const auto *decl = declVector[0]->to<IR::Declaration_Instance>(); |
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.
const auto *decl = declVector[0]->to<IR::Declaration_Instance>(); | |
const auto *decl = declVector.front()->to<IR::Declaration_Instance>(); |
// FIXME: should just insert() | ||
for (const auto *decl : *nnDecls) decls.push_back(decl); |
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.
Why is not not possible to call insert
now?
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.
Because the way how Enumerator
is implemented.... Enumerator::begin() / Enumerator::end()
return so-called EnumeratorHandle
which does not satisfy iterator requirements (no trait types like reference
/ value_type
, etc.)
I was thinking about that too. I was also wondering if there is 3rd party ranges implementation that is (C++17) GCC 9 compatible. I think this change is worth it by itself, but I would not go over the entire codebase trying to root out the old enumerators now. |
We do not have much visible impact after memoization patch :) If we'd get rid of memoization, then there will be quite visible impact for large apps. |
e4a2a41
to
97ba34e
Compare
@ChrisDodd Can you take a look at this PR? |
7f5b8e8
to
a7709c1
Compare
I am going to merge this unless noone would object as this would allow us to get rid additional boost bits. |
c281353
to
8385379
Compare
… heap-allocated object does not make any sense here.
Refactor ReferenceResolver to get rid of majority of unnecessary heap allocations due to obsessive
Enumerator<>
usage:Enumerator<>->toVector()
: make it return result by value. It seems that the use in the tree is always about creating some temporaries. And it does not make any sense to allocate vectors on heap thenPartially addresses #4412
Ideally, we'd switch from memory allocation at
getDeclarations
/getDeclsByName
, but it's a bit long way to go for now.