unison
unison copied to clipboard
Some 'foreign' functions are too lazy
Foreign functions are based on wrapping Haskell functions with type a -> IO b, given that a and b belong to appropriate classes. None of our machinery surrounding this actually evaluates b before storing it, though. This is fine if b writes back as an unboxed value, because the unboxed write will demand it. But boxed values are just stored in Haskell pointer-based arrays, which do not evaluate anything.
So, we should go through and check that every case is evaluated appropriately. There are a few options for this, and I'm not sure which is best.
- Go through each function and add an
evaluateif needed. This is probably the most precise about not wasting time evaluating things unnecessarily, but requires the most (ongoing) effort. - Make something like
mkForeignperform the evaluation. This would automatically catch everything, but might cause a little redundant work. I'm not even sure it could distinguish the unboxed case. - Make
ForeignConventionperform the evaluation. This is more precise than 2 but less than 1.
It's possible that some machine instructions (the other big enum of operations) suffer from this, too, so they should probably be looked at.