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

api: find_exported_* improvements #776

Merged
merged 3 commits into from
Apr 8, 2021
Merged

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Mar 31, 2021

No description provided.

@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

Merging #776 (4ccc254) into master (faddd97) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #776   +/-   ##
=======================================
  Coverage   99.23%   99.23%           
=======================================
  Files          77       77           
  Lines       11886    11887    +1     
=======================================
+ Hits        11795    11796    +1     
  Misses         91       91           
Flag Coverage Δ
rust 99.86% <ø> (ø)
spectests 90.54% <100.00%> (+<0.01%) ⬆️
unittests 99.19% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/fizzy/capi.cpp 97.83% <100.00%> (ø)
lib/fizzy/instantiate.cpp 100.00% <100.00%> (ø)
lib/fizzy/instantiate.hpp 100.00% <100.00%> (ø)
test/spectests/spectests.cpp 98.42% <100.00%> (ø)
test/unittests/api_test.cpp 100.00% <100.00%> (ø)
test/unittests/end_to_end_test.cpp 100.00% <100.00%> (ø)
test/unittests/execute_call_test.cpp 100.00% <100.00%> (ø)
test/utils/fizzy_engine.cpp 100.00% <100.00%> (ø)
tools/wasi/wasi.cpp 59.57% <100.00%> (ø)

@gumb0 gumb0 force-pushed the find-exported-improvements branch from 79890f2 to 62e3de7 Compare March 31, 2021 12:59
@gumb0 gumb0 force-pushed the find-exported-improvements branch from 62e3de7 to bd70d73 Compare March 31, 2021 14:49
@gumb0 gumb0 marked this pull request as ready for review March 31, 2021 15:18
@gumb0 gumb0 requested review from chfast and axic March 31, 2021 16:09
@@ -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(
Copy link
Member

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?

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

@gumb0 gumb0 Mar 31, 2021

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 terminate_handler might work... not really, it would work only if something is really thrown.

Copy link
Member

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator

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)};
Copy link
Member

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:

Copy link
Collaborator Author

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

Copy link
Member

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(
Copy link
Member

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*.

@gumb0 gumb0 force-pushed the find-exported-improvements branch from 6798328 to 4ccc254 Compare April 7, 2021 10:22
@@ -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(
Copy link
Collaborator

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.

@gumb0 gumb0 merged commit dbdef17 into master Apr 8, 2021
@gumb0 gumb0 deleted the find-exported-improvements branch April 8, 2021 13:00
@gumb0
Copy link
Collaborator Author

gumb0 commented Apr 8, 2021

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 bytes::resize() in grow_memory (bugprone-exception-escape check), but doesn't detect make_unique there https://github.com/wasmx/fizzy/pull/775/files#r603979857
(But it's actually a warning, not clang-tidy check)

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

Successfully merging this pull request may close these issues.

3 participants