-
Notifications
You must be signed in to change notification settings - Fork 593
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
DataStorm linter suggested fixes #3293
Conversation
@@ -16,8 +16,8 @@ HeaderFilterRegex: '.*' | |||
ExcludeHeaderFilterRegex: 'include/lmdb.h|Grammar.h' | |||
UseColor: true | |||
FormatStyle: 'file' | |||
ExtraArgs: ['-std=c++20'] | |||
ExtraArgs: ['-std=c++17'] |
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.
Otherwise we get lints for issues that require using C++ 20 and we are still using C++ 17 with GCC.
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.
However, this breaks the linting of the Ice/span test. Maybe a better solution would be to disable the c++20 lints/suggestions?
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.
Maybe we could a .clang-tidy
file to this test folder with an override to enable -std=c++20
. I think clang-tidy supports this.
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.
I added a separate config for Ice/span test
// Public template based API implementation | ||
// | ||
|
||
namespace DataStorm |
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.
no point in declaring the same namespace twice.
cpp/include/DataStorm/Node.h
Outdated
@@ -140,7 +140,7 @@ namespace DataStorm | |||
* provided the Node will use the default callback executor that executes callback in a dedicated thread. | |||
*/ | |||
Node( | |||
Ice::CommunicatorPtr communicator, | |||
const Ice::CommunicatorPtr& communicator, |
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 we always use it as a reference.
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.
The signature is not / should not be about the implementation but what we signal to the caller.
Here, const& tells the caller: I am reading this communicator in this ctor but I don't keep a refcount on the communicator. Whereas, by value means "I keep a refcount".
I would expect the Node to keep a refcount on the communicator, possibly indirectly by holding an Ice::InstancePtr.
: sampleCount(std::move(sampleCount)), | ||
sampleLifetime(std::move(sampleLifetime)), | ||
clearHistory(std::move(clearHistory)) | ||
: sampleCount{sampleCount}, |
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.
see performance-move-const-arg for trivially-copyable
@@ -444,7 +446,6 @@ DataElementI::getConnectedElements() const | |||
{ | |||
unique_lock<mutex> lock(_parent->_mutex); | |||
vector<string> elements; | |||
elements.reserve(_listeners.size()); |
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.
This reserve doesn't match the final size, there is an inner loop.
} | ||
_executor->queue([self = shared_from_this(), init, keys = std::move(keys)] { init(std::move(keys)); }, true); | ||
_executor->queue([init = std::move(init), keys = std::move(keys)]() mutable { init(std::move(keys)); }, true); |
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.
Without marking the lambda as mutable, the move keys doesn't have any effect.
cpp/src/DataStorm/ForwarderManager.h
Outdated
Response response, | ||
Exception exception, | ||
std::function<void(bool, const Ice::ByteSeq&)> response, | ||
std::function<void(std::exception_ptr)> exception, |
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.
I added std::function
to performance-unnecessary-value-param.AllowedTypes
But this doesn't work with the alias.
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.
I added std::function to performance-unnecessary-value-param.AllowedTypes
I would not do that. When you copy of std::function that holds a lambda, you copy its capture.
We often pass std::function by value because we move them around. In some cases, it's ok to pass them by const& as clang-tidy suggests.
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.
reverted this, and fixed the forwarder manager to use pass by reference.
{ | ||
std::unique_lock<std::mutex> lock(_mutex); | ||
if (_timer) | ||
{ | ||
_timer->schedule(std::move(task), delay); | ||
_timer->schedule(task, delay); |
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.
task is a const reference
// The subscriber and publisher collocated forwarders are initalized here to avoid using a nullable proxy. These | ||
// objects are only used after the node is initialized and are removed in destroy implementation. | ||
_publisherForwarder{instance->getCollocatedForwarder()->add<PublisherSessionPrx>( | ||
[this](Ice::ByteSeq inParams, const Ice::Current& current) { forwardToPublishers(inParams, current); })}, | ||
[this](const ByteSeq& inParams, const Current& current) { forwardToPublishers(inParams, current); })}, |
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.
The forwarding methods take a const reference for inParams.
NodePrx node) | ||
: _nodeSessionManager(std::move(nodeSessionManager)), | ||
_nodeSession(std::move(nodeSession)), | ||
_nodeSession(nodeSession), |
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.
_nodeSession
is a weak_ptr. The weak_ptr constructor takes a const reference to a shared_ptr.
@@ -477,7 +475,7 @@ SessionI::initSamples(int64_t topicId, DataSamplesSeq samplesSeq, const Ice::Cur | |||
|
|||
vector<shared_ptr<Sample>> samplesI; | |||
samplesI.reserve(samples.samples.size()); | |||
auto sampleFactory = topic->getSampleFactory(); | |||
const auto& sampleFactory = topic->getSampleFactory(); |
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.
getSampleFactory returns a const reference.
@@ -984,30 +982,30 @@ SessionI::unsubscribeFromKey( | |||
int64_t keyId) | |||
{ | |||
assert(_topics.find(topicId) != _topics.end()); | |||
auto& subscriber = _topics.at(topicId).getSubscriber(element->getTopic()); | |||
auto k = subscriber.get(elementId); | |||
if (k) |
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.
Not lint related, using auto here was making the code harder to read.
} | ||
}; | ||
|
||
class Warning : public Ice::Warning |
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.
The Warning class was never used.
reader.waitForUnread(0); | ||
[[maybe_unused]] bool hasUnread = reader.hasUnread(); | ||
if (false) |
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.
I don't see the point of this if (false)
, this API test is kind of weird with lots of unused variables.
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.
I am surprised the compiler doesn't complain.
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.
Looks good except for the addition of std::function to performance-unnecessary-value-param.AllowedTypes.
cpp/include/DataStorm/Node.h
Outdated
@@ -140,7 +140,7 @@ namespace DataStorm | |||
* provided the Node will use the default callback executor that executes callback in a dedicated thread. | |||
*/ | |||
Node( | |||
Ice::CommunicatorPtr communicator, | |||
const Ice::CommunicatorPtr& communicator, |
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.
The signature is not / should not be about the implementation but what we signal to the caller.
Here, const& tells the caller: I am reading this communicator in this ctor but I don't keep a refcount on the communicator. Whereas, by value means "I keep a refcount".
I would expect the Node to keep a refcount on the communicator, possibly indirectly by holding an Ice::InstancePtr.
cpp/src/DataStorm/Node.cpp
Outdated
{ | ||
} | ||
|
||
Node::Node( | ||
Ice::CommunicatorPtr communicator, | ||
const CommunicatorPtr& communicator, |
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.
I assume _instance below keeps a refcount on communicator, so it should be by value. You may want to fix the DataStormI::Instance ctor - you actually already fixed it!
reader.waitForUnread(0); | ||
[[maybe_unused]] bool hasUnread = reader.hasUnread(); | ||
if (false) |
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.
I am surprised the compiler doesn't complain.
@@ -28,7 +28,7 @@ namespace DataStormI | |||
public: | |||
TopicI( | |||
std::shared_ptr<Instance>, | |||
std::shared_ptr<TopicFactoryI>, | |||
const std::shared_ptr<TopicFactoryI>&, |
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.
Here, switching to const shared_ptr&
makes sense: we don't adopt a refcount but create and keep a weak_ptr from this const shared_ptr&
.
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.
Looks good!
@@ -16,8 +16,8 @@ HeaderFilterRegex: '.*' | |||
ExcludeHeaderFilterRegex: 'include/lmdb.h|Grammar.h' | |||
UseColor: true | |||
FormatStyle: 'file' | |||
ExtraArgs: ['-std=c++20'] | |||
ExtraArgs: ['-std=c++17'] |
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.
Maybe we could a .clang-tidy
file to this test folder with an override to enable -std=c++20
. I think clang-tidy supports this.
This PR:
[[nodiscard]]
to more DataStorm APIs where it make sense to do so.using namespace Ice;
to DataStorm implementation.