-
Notifications
You must be signed in to change notification settings - Fork 34
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
api: find_exported_* improvements #776
Conversation
Codecov Report
@@ Coverage Diff @@
## master #776 +/- ##
=======================================
Coverage 99.23% 99.23%
=======================================
Files 77 77
Lines 11886 11887 +1
=======================================
+ Hits 11795 11796 +1
Misses 91 91
Flags with carried forward coverage won't be shown. Click here to find out more.
|
79890f2
to
62e3de7
Compare
62e3de7
to
bd70d73
Compare
@@ -305,7 +305,8 @@ ExternalGlobal find_imported_global(const std::string& module, const std::string | |||
return {it->value, module_global_type}; | |||
} | |||
|
|||
std::optional<uint32_t> find_export(const Module& module, ExternalKind kind, std::string_view name) | |||
std::optional<uint32_t> find_export( |
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.
Are we sure that none of the constructors used would throw through std::make_optional
? Can clang-tidy verify that at all?
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.
Perhaps we could add a test marked noexcept constructing all those, just to have an early indication if we brake something that clang-tidy can't detect.
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've added noexcept
to some constructors more, and I'm pretty sure, all External*
objects use either explicitly noexcept
or default move-constructors, which are noexcept implicitly.
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.
Perhaps we could add a test marked noexcept constructing all those, just to have an early indication if we brake something that clang-tidy can't detect.
How would we detect it in test, if clang-tidy doesn't detect it? Well setting not really, it would work only if something is really thrown.terminate_handler
might work...
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.
clang-tidy may detect it if the constructors are used directly in a test marked noexcept, while it may not detect it via make_optional
.
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 guess it makes sense to use manual loop instead of find_if
then.
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.
Also apparently
std::find_if
can throw: https://en.cppreference.com/w/cpp/algorithm/find
Actually, it's only overloads with ExecutionPolicy
can throw.
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 think regular find_if
is not noexcept
, because the predicate function is allowed to throw.
I think it's safe to leave noexcept
with find_if
here, but I made labmda noexcept
, too.
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.
Also apparently std::find_if can throw: https://en.cppreference.com/w/cpp/algorithm/find
Actually, it's only overloads with ExecutionPolicy can throw.
I am not sure, that description is kind of confusing. Makes me think it can throw bad_alloc
in any case.
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.
First of all noexcept
is not like const
that all internal function calls must be noexcept
. Usage of find_if
looks fine to me.
Makes me think it can throw
bad_alloc
in any case.
Only overloads with ExecutionPolicy
which we don't use.
clang-tidy
only reports obvious mistakes (as direct usage of throw
inside noexcept
). We can dig deeper if you know the check name that fails.
@@ -504,7 +507,8 @@ std::optional<ExternalFunction> find_exported_function(Instance& instance, std:: | |||
ExecuteFunction(instance, idx), instance.module->get_function_type(idx)}; |
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 we use *opt_index
. It is weird that operator*
is not marked noexcept, but docs say "throws nothing". Compared to that ->value()
explicitly checks and throws:
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 found some explanation, but it's not clear to me https://stackoverflow.com/a/63913833
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.
C++ is weird.
@@ -504,7 +507,8 @@ std::optional<ExternalFunction> find_exported_function(Instance& instance, std:: | |||
ExecuteFunction(instance, idx), instance.module->get_function_type(idx)}; | |||
} | |||
|
|||
std::optional<ExternalGlobal> find_exported_global(Instance& instance, std::string_view name) | |||
std::optional<ExternalGlobal> find_exported_global( |
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 function also uses operator*
.
6798328
to
4ccc254
Compare
@@ -305,7 +305,8 @@ ExternalGlobal find_imported_global(const std::string& module, const std::string | |||
return {it->value, module_global_type}; | |||
} | |||
|
|||
std::optional<uint32_t> find_export(const Module& module, ExternalKind kind, std::string_view name) | |||
std::optional<uint32_t> find_export( |
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.
First of all noexcept
is not like const
that all internal function calls must be noexcept
. Usage of find_if
looks fine to me.
Makes me think it can throw
bad_alloc
in any case.
Only overloads with ExecutionPolicy
which we don't use.
clang-tidy
only reports obvious mistakes (as direct usage of throw
inside noexcept
). We can dig deeper if you know the check name that fails.
Weird that it does detect a call to |
No description provided.