promise icon indicating copy to clipboard operation
promise copied to clipboard

Make native reason-promise covariant, like JS

Open aantron opened this issue 6 years ago • 0 comments

c9d8008 marked JS promises covariant. We should do the same in the native version. However, that is a full implementation, and a correct implementation of promises usually prevents the compiler from admitting covariance (the compiler infers invariance). This is because such an implementation requires several helper data structures to defer callbacks and avoid memory leaks, so we need to either:

  • Add casts to fool the compiler (as in Lwt).
  • Search more thoroughly for data structures that don't prevent the compiler from inferring covariance.

The current data structures don't (or shouldn't!!) make the promises invariant, the compiler just can't tell that they don't.

After dealing with this, the covariance tests should be made to run (rather, build) on both JS and native:

https://github.com/aantron/promise/blob/c9d8008ce37307748f619bd51487b6912c7ebc8b/test/js/test_ffi.re#L316-L360

aantron avatar Dec 31 '19 00:12 aantron