JavaScript backend fileStat struct population doesn't work with hsc2hs features.
Summary
The way the JavaScript backend populates a fileStat
struct is incompatible with the field ordering used by Emscripten. Usually this isn't a problem, but when these struct fields are referenced in HSC files using the #peek
feature, the usual accessor functions are replaced with the peekBytes
function, which will be looking at the wrong bytes in memory. So, the JavaScript backend will provide incorrect results for fileStat
s referenced through HSC files.
Steps to reproduce
Using FilePath
functions that check a fileStat
's mode
, such as doesDirectoryExist
and doesFileExist
. These will incorrectly always return false due to the peekBytes
function accessing memory in the JavaScript stat that is filled with 0.
There are several test cases in the GHC testsuite that fail due to the use of setSessionDynFlags
which indirectly calls doesDirectoryExist
. One such test is CallArity1
.
Expected behavior
fileStat
functions that are implemented using HSC features should return correct results using the JavaScript backend.
Environment
- GHC version used:
master
after the JavaScript backend merge - System Architecture: JavaScript