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

HPCC-33154 Refactor WebAssembly Support #19375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GordonSmith
Copy link
Member

@GordonSmith GordonSmith commented Jan 2, 2025

Added list / set support

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Cloud-compatibility
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Smoketest:

  • Send notifications about my Pull Request position in Smoketest queue.
  • Test my draft Pull Request.

Testing:

@GordonSmith GordonSmith requested a review from ghalliday January 2, 2025 11:56
Copy link

github-actions bot commented Jan 2, 2025

Jira Issue: https://hpccsystems.atlassian.net//browse/HPCC-33154

Jirabot Action Result:
Workflow Transition To: Merge Pending
Updated PR

@GordonSmith GordonSmith force-pushed the HPCC-33154-WASM_TAKE_II branch 2 times, most recently from 233c948 to 0505cc9 Compare January 2, 2025 12:43
Added list / set support

Signed-off-by: Gordon Smith <[email protected]>
@GordonSmith GordonSmith force-pushed the HPCC-33154-WASM_TAKE_II branch from 0505cc9 to 75808aa Compare January 2, 2025 14:04
Copy link
Member

@ghalliday ghalliday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments. Some may be invalid as I gradually understood the code better.

My main thought is that I'm not sure the string functions are correct - latin1 v utf8 v utf16. It wasn't clear what encoding were in use, where, and some of the tests against 1<<8 looked wrong. It needs test cases for i) ascii ii) latin1, iii) extended unicode.

}

template <Float T>
T maybe_scramble_nan(T f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identical to the function above - is that deliberate?

WasmValVector lower_flat(CallContext &cx, const list_t<T> &v)
{
std::size_t maybe_length = 0;
if (maybe_length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this planned to be implemented later? Currently it will always be 0

Copy link
Member Author

@GordonSmith GordonSmith Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - looking at the ref, it is for future support of fixed length arrays. Will remove for now.

{
assert(maybe_length == v.size());
WasmValVector flat;
for (auto e : v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto &? If T is non trivial then cloning the items may be expensive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed for now (fixed length array support)

list_t<T> lift_flat(const CallContext &cx, const WasmValVectorIterator &vi)
{
std::size_t maybe_length = 0;
if (maybe_length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about about maybe_length always being 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed for now.

std::tuple<offset, size> store_into_range(CallContext &cx, const list_t<T> &v)
{
auto elem_type = ValTrait<T>::type;
size_t nbytes = ValTrait<T>::size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this copes with sets of variable length strings - that would need a different implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strings should be stored as a pair of uint32_t, (its trait size is 8) one is a ptr to var length string and the other is its length.

{
case Encoding::Latin1:
case Encoding::Utf8:
std::memcpy(dest, src, byte_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful if src_len is 0 - this can lead to src being null, which can cause an internal error when sanitizing is enabled.

{
case Encoding::Latin1:
case Encoding::Utf8:
std::memcpy(dest, src, byte_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utf8 is not the same encoding as latin1 - some conversion is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a "fake host" for the unit tests, so was only concerned with utf8 <-> utf8 conversion, but I can either flesh this out (with an off the shelf lib) or fail when not utf8 (for now).

{
case Encoding::Latin1:
case Encoding::Utf8:
// {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Work in progress? Same above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I need to pick a unicode lib for the fake host...

case type_boolean:
memIdxVar = wasmStore->callRealloc(wasmName, {0, 0, 1, (int32_t)numElems});
memIdx = memIdxVar[0].i32();
assert(elemSize == sizeof(int32_t));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be relaxed later to support other sizes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes wasm + 64bit addressable memory is being rolled out currently, but our version of the wasmtime runtime does not support it (their latest does).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a concept of "Flags" in wit, which translates to bit fields.

}
}

void hpcc_scalar_test_list_bool_test_bool(hpcc_scalar_test_list_bool_t *a, hpcc_scalar_test_list_bool_t *ret)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't very clear from these function names what the functions do. For instance this seems to reverse a list.

@GordonSmith GordonSmith requested a review from ghalliday January 10, 2025 18:25
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.

2 participants