reflex-frp / reflex-platform

A curated package set and set of tools that let you build Haskell packages so they can run on a variety of platforms. reflex-platform is built on top of the nix package manager.
https://reflex-frp.org
BSD 3-Clause "New" or "Revised" License
723 stars 164 forks source link

GHCJS typechecker plugins #626

Open zarybnicky opened 4 years ago

zarybnicky commented 4 years ago

I'm trying to use plugins in my Reflex experiments. While I dimly recall reading somewhere that GHCJS doesn't support plugins, that might've been a long time ago as I can't find that information again anywhere, and from reading the Nix files, I got the impression that Reflex.Optimizer is usable when compiling with GHCJS as well.

In particular I'm having trouble compiling ghc-tcplugins-extra due to its ghc dependency - I did manage to discover ghc-api-ghcjs by thorough Googling, but patching ghc-tcplugins-extra to look for ghc-api-ghcjs instead of ghc doesn't help (Encountered missing dependencies: ghc-api-ghcjs -any).

It seems to me that ghc-api-ghcjs is getting compiled with GHC 8.6.4 - the full path to the .so is /nix/store/2cx3p3ywpzz47f23zw3i1ssdjfddjjjw-ghc-api-ghcjs-8.6.5/lib/ghc-8.6.4/x86_64-linux-ghc-8.6.4/libHSghc-api-ghcjs-8.6.5-F0KeWR7UxRl4rynnmWSnQM-ghc8.6.4.so (note the two ghc-8.6.4), but I can't find where this is coming from. I'd assume it's the ghcjs-ng machinery inside nixpkgs, but that is as far as I got...

I did see that using Reflex.Optimizer with GHCJS adds an extra ghcLibdir (ghcLibdir = "${self.ghc.bootPackages.ghcWithPackages (p: [ p.reflex ])}/lib/${self.ghc.bootPackages.ghc.name}";), but I didn't manage to make it work for other plugins.

My ultimate goal is to get ghc-typelits-knownnat, ghc-typelits-normalize, and polysemy-plugin working in GHCJS, but that seems a long way off right now...

zarybnicky commented 4 years ago

Also a clue as to whether GHCJS plugins are supported is https://github.com/ghcjs/ghcjs/commit/e36e50ac0c696fb663385fb35094117505e4a805, where I can see 'something' that touches plugins.

I'd assume that the thing to do is to compile the plugins with GHC and pass them through to GHCJS via ghcLibdir, manually dropping the ghc (or ghc-tcplugins-extra or whatever) dependency via callCabal2nix "pkg" src { ghc = null; } - am I on the right track?

locallycompact commented 3 years ago

Hi @zarybnicky. I'm also trying to get polysemy-plugin to work with GHCJS, did you discover anything more about this?

zarybnicky commented 3 years ago

@locallycompact No progress to report, no. I did discover that IOHK used to use GHC plugins with GHCJS, but it wasn't a straightforward process and I instead postponed the reflex+polysemy project indefinitely... :man_shrugging: Nowadays, I'd say eff, or one of the effect system alternatives that don't require a plugin would be cleaner - but the ghc-typelits-* plugins are still something desirable.

locallycompact commented 3 years ago

Polysemy doesn't require the plugin to work, it just saves on type applications, but thanks for trying this and reporting!