codeworld icon indicating copy to clipboard operation
codeworld copied to clipboard

WIP: [Obsolete] Integration of requirements checker plugin

Open starsandspirals opened this issue 5 years ago • 7 comments

I don't know if you're looking at this at the same time - no problem if you are - but I thought it was worth making the current state of my efforts more visible in case it makes any issues become apparent.

I've been following along with the advice received from Luite to try and fix my Cabal/GHCJS issues, but have generally just ended up running into different problems, so in the current state this is stuck at another cabal error.

The current issue is that the package ghc-api-ghcjs cannot be found; I've discovered that it's in the build/ghcjs/lib folder, but I don't know how to access it or other ghcjs packages from there in the cabal file! But as a summary of progress made in this pull request so far, I've gotten rid of the old requirements checker code in the compiler folder that's all duplicated in the new requirements folder, added the required plugin arguments to the call to ghcjs in Compile.hs, and implemented the feedback from Luite, i.e. created a stub version of the plugin and separated out the ghc and ghcjs versions to try and avoid the previous issues.

starsandspirals avatar Aug 08 '19 13:08 starsandspirals

Installing the packages using cabal as you suggested worked, so I added this to install.sh.

Now the build process completes successfully again, but I get a new and different error when trying to compile programs using CodeWorld. Now it says:

The value plugin did not have the type Plugin as required

This doesn't really make sense, as the value of plugin in both RequirementsChecker.hs and the stubbed version definitely has type Plugin, so I don't know where this is coming from; but at least it's a different error.

starsandspirals avatar Aug 09 '19 12:08 starsandspirals

@luite Please help!

cdsmith avatar Aug 09 '19 14:08 cdsmith

Ah the error messages there aren't yet as good as they should be. And the plugin loading mechanism is rather hacky right now.

Right now what GHCJS does is the following:

  1. the plugin name and module is located in the GHCJS package DB. The type of plugin should be ghc:Plugins.Plugin, where ghc is the GHC library from the GHCJS package db.
  2. GHCJS tries to find a module with the same name in the package database specified with -host-package-db
  3. GHCJS checks that the type of the plugin is ghc-api-ghcjs:Plugins.Plugin. This should be the same instance of ghc-api-ghcjs that GHCJS is built against.

Most likely 2 or 3 go wrong. What's the easiest way for me to reproduce the build?

luite avatar Aug 10 '19 12:08 luite

With the extra information about how GHCJS deals with plugins, I think I've figured out how to arrange the cabal file so that it should work. The new setup looks more like this:

flag build-plugin-for-ghcjs
  Description: Build for GHCJS
  Default:     False
  Manual:      True

library
  if impl(ghcjs)
    hs-source-dirs:    stub-src
    build-depends:     ghc >= 8.6.5,
                       ghc-boot-th
  else
    hs-source-dirs:    src
    other-modules:     CodeWorld.Requirements.Framework
                       CodeWorld.Requirements.Requirements
                       CodeWorld.Requirements.Checker.Eval
                       CodeWorld.Requirements.Checker.Language
                       CodeWorld.Requirements.Checker.Matcher
                       CodeWorld.Requirements.Checker.Types
    if flag(build-plugin-for-ghcjs)
      build-depends:   ghc-api-ghcjs
    else
      build-depends:   ghc >= 8.6.5,
                       ghc-boot-th

which matches closely with the example setup in Luite's email, and with the addition of the flag and extra conditional should install the packages with the right dependencies.

However, I'm having some trouble when actually trying to build with this flag. After adding "-f build-plugin-for-ghcjs" to the cabal install command, I get this error:

===== RUNNING: cabal_install ./codeworld-server ./codeworld-error-sanitizer ./codeworld-compiler ./codeworld-requirements ./codeworld-game-api ./codeworld-prediction ./codeworld-api ./codeworld-game-server ./codeworld-account ./codeworld-auth -f build-plugin-for-ghcjs
Warning: the --global flag is deprecated -- it is generally considered a bad
idea to install packages into the global store
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: codeworld-requirements-0.1.0.0 (user goal)
[__1] rejecting: codeworld-requirements:-build-plugin-for-ghcjs (constraint
from config file, command line flag, or user target requires opposite flag
selection)
[__1] trying: codeworld-requirements:+build-plugin-for-ghcjs
[__2] unknown package: ghc-api-ghcjs (dependency of codeworld-requirements
+build-plugin-for-ghcjs)
[__2] fail (backjumping, conflict set: codeworld-requirements, ghc-api-ghcjs,
codeworld-requirements:build-plugin-for-ghcjs)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: codeworld-requirements,
codeworld-requirements:build-plugin-for-ghcjs, ghc-api-ghcjs

It's as if ghc-api-ghcjs isn't installed, like before, except that now it is installed and works fine when it isn't being used conditionally as a result of this flag.

Any advice?

starsandspirals avatar Aug 12 '19 13:08 starsandspirals

Daniel, I'm so sorry. I've been swamped at work this week, but I'll try to take a look at this tonight or tomorrow.

Any chance you'll be at ICFP next week?

cdsmith avatar Aug 16 '19 14:08 cdsmith

It's no problem at all! I haven't made any progress on this either, unfortunately; I'm happy to keep on pushing with it after GSoC officially finishes, though, so we can get it integrated into CodeWorld properly after we get through all the cabal problems.

I will be at ICFP next week; in fact, I'm writing this at the airport! It'd be great to meet you in person at some point, if you'll be around.

starsandspirals avatar Aug 16 '19 15:08 starsandspirals

Excellent! I'm leaving tomorrow night, and arriving Sunday morning. I look forward to seeing you there.

I am always happy to accept any collaboration on CodeWorld, but I want to be clear that you shouldn't carry forward GSoC obligations past the coding period. Luite is usually at ICFP, and maybe the three of us can find some time and solve this quickly. But if not, you should write a GSoC recap focusing on your GHC plugin running on non-GHCJS code, and show some examples of its use. That will be a successful project. The GHCJS and CodeWorld integration will still happen, but I will not consider you obligated to continue work on it.

cdsmith avatar Aug 16 '19 18:08 cdsmith