unison icon indicating copy to clipboard operation
unison copied to clipboard

Some 'foreign' functions are too lazy

Open dolio opened this issue 5 months ago • 0 comments

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.

  1. Go through each function and add an evaluate if needed. This is probably the most precise about not wasting time evaluating things unnecessarily, but requires the most (ongoing) effort.
  2. Make something like mkForeign perform 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.
  3. Make ForeignConvention perform 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.

dolio avatar May 22 '25 15:05 dolio