-
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
refactor: Use span instead of vectors in ExternalFunction #668
Conversation
Codecov Report
@@ Coverage Diff @@
## master #668 +/- ##
=======================================
Coverage 99.28% 99.28%
=======================================
Files 72 72
Lines 9918 9954 +36
=======================================
+ Hits 9847 9883 +36
Misses 71 71
Flags with carried forward coverage won't be shown. Click here to find out more.
|
fc6bff3
to
38844d9
Compare
38844d9
to
27fb67c
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.
Looks ok, but this even more complicates the function-related types like "imported function", "exported function", "execute function", "execute fn", etc.
27fb67c
to
06c2923
Compare
Added comments to |
@@ -59,6 +59,8 @@ class span | |||
constexpr T* data() const noexcept { return m_begin; } | |||
constexpr std::size_t size() const noexcept { return m_size; } | |||
|
|||
constexpr bool empty() const noexcept { return m_size == 0; } |
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.
Matches std definition: https://en.cppreference.com/w/cpp/container/span/empty
lib/fizzy/instantiate.hpp
Outdated
@@ -22,9 +22,14 @@ namespace fizzy | |||
struct ExecutionResult; | |||
struct Instance; | |||
|
|||
// Function representing WebAssembly or host function execution. |
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.
Can you make these (and on the struct) comments doxygen?
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.
Changed.
06c2923
to
1171838
Compare
This allows to avoid extra vector allocation when going from C
FizzyExternalFunction
to C++fizzy::ExternalFunction
and also when C++ API returns fromfind_exported_function()
.Also I it helps with
std::function
refactoring in #643The downside is that user has to ensure that arrays pointed to by spans live long enough (usually these arrays are in
Instance
, and you need thisInstance
to runExternalFunction
anyway).This leaves
ImportedFunction
still usingvector<ValType>
for input types, I think it's convenient to leave it like this, otherwise it wouldn't be possible to pass input types as inline initializer list like this:neither like this
(Spans have to point to some container, so explicit vector declarations would be required on the user side)
Also note that to make above use cases work,
resolve_imported_functions()
producesExternalFunction
s with typespan
s pointing to the type vector insideModule
, not to the passed vector. Not sure whether it's confusing from the API standpoint, but it works.