Skip to content

Draft: Prim: Add Opaque prim type

doyougnu requested to merge doyougnu/ghc:wip/JavaScript-value-primtype into master


Please refrain from commenting further on this MR, see #21142 for a summary of this discussion and please comment there


** ON HOLD **
This MR and related ghc-proposal is on hold until we have working code and tests in wip/javascript-backend. Until then we are using the hacked version of JSVal, i.e., data JSVal = JSVal ByteArray#


In pursuit of #21078 (closed) This MR does:

  • Adds Opaque# as a prim type. An Opaque# is an Addr# but one that does not support any pointer arithmetic. I'm open to any naming suggestions, perhaps OpaqueRef#?
  • Adds a runtime rep OpaqueRep that corresponds to the prim type
  • Add a single test case that is expected to fail but parses a javascript foreign import, dumps the ast, and checks it against .stderr (the golden file).


For new backends we want a way to refer to things in the new runtime from Haskell land, but GHC cannot know too much about these things by definition, and hence they are Opaque. Pointers in JavaScript aren't normal pointers, instead they are pointers to a buffer and and offset into that buffer. Thus, we cannot use Addr# for the js backend but we still want a handle to things in JavaScript land from Haskell.

Other Stuff

This is the first time I have added a prim type and I may have (very likely) confused things. I believe this should be a known-key thing, not a wired-in thing because of the information GHC knows about it, i.e., not all that much. Similarly, I believe this should have a runtime rep to correspond to the prim type but I'm honestly not sure how it all hooks together.

This is a draft because

Marked as Draft because we want this MR to serve as common ground to discuss supporting this feature in other backends as well, specifically Asterius (cc @TerrorJack), and with everyone else of course :)

Edited by doyougnu

Merge request reports