Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Fix "float unrepresentable in integer range" runtime error due to incorrect unsigned conversion #632

Merged
merged 2 commits into from
May 3, 2020

Conversation

TerrorJack
Copy link
Member

Closes #629. Thanks to @mikesol @InBetweenNames, we located a very old runtime bug. The symptom is a "float unrepresentable in integer range" runtime error, and the root cause is:

  • We have quite a few rts builtin functions which are implemented in JavaScript, and imported into WebAssembly
  • Since our word size is 64-bit and our WebAssembly functions mostly use i64 in parameter/return types, the JavaScript functions need to be imported to use f64, and a layer of wrapper functions will generate casts between i64 and f64.
  • Our mechanism to generate the wrapper functions incorrectly used an unsigned cast for function results. When an rts function returns a negative result (e.g. _hs_text_memcmp), this will result in an error.

In the longer term we should be using the linear memory to pass FFI paramters/results in a uniform manner, without worrying about precision losses or signedness issues. But this PR suffices to fix the error for now.

@TerrorJack TerrorJack added P0 blocker: fix immediately! type: bug labels May 3, 2020
@TerrorJack TerrorJack self-assigned this May 3, 2020
@TerrorJack TerrorJack merged commit 83b1afe into master May 3, 2020
@TerrorJack TerrorJack deleted the wip-fix-builtins-wrapper branch May 3, 2020 18:05
@InBetweenNames
Copy link

Happy to help!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P0 blocker: fix immediately! type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError: float unrepresentable in integer range
2 participants