Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Move session loading logic into ghcide library #697

Merged
merged 2 commits into from
Jul 27, 2020

Conversation

lukel97
Copy link
Collaborator

@lukel97 lukel97 commented Jul 14, 2020

This way haskell-language-server can reuse it without having to maintain two versions of this session setup code, which was getting quite tricky to maintain. Needs #693 and #696 merged first

@lukel97 lukel97 force-pushed the split-out-cradle-setup branch from a9a9aae to ce91422 Compare July 14, 2020 13:17
@jneira
Copy link
Member

jneira commented Jul 14, 2020

Some caveats of using a private lib:

  • It causes not deterministic build plan errors that forces you to delete the store partially or totally
  • Stack cradle cant handle them in a reliable way
  • Being a private lib, hls will not be able to use it (or am i missing something?)

Still this could be a preliminary step before convert it in a package, but the transition should be done asap, imo.

@lukel97 lukel97 force-pushed the split-out-cradle-setup branch from ce91422 to b2aa75a Compare July 14, 2020 16:30
@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 14, 2020

@jneira just before I read your comment I found out that I forgot to add the visibility: public field to the library! I've integrated it with haskell-language-server now but you're right, it was a bit of a pain and there are definitely some drawbacks. For one, I'm not sure if this works with ghc <8.8. Is there any reason why we can't just move this into ghcide itself?

@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 14, 2020

@jneira ok right off the bat haskell-language-server fails to build with stack build --stack-yaml=stack-8.6.5.yaml, stack 2.3.1 because it can't parse this bit of the cabal file:

  build-depends:
    , ghcide:ghcide-session-loader

@jneira
Copy link
Member

jneira commented Jul 14, 2020

Mmm i thought public libraries was not fully supported in cabal-install but the final pr has been recently merged, so it would need cabal-3.4 (and hoping not to hit more bugs). We will have to wait a while to have stack support.

@lukel97 lukel97 force-pushed the split-out-cradle-setup branch from f5cd1d3 to 899111d Compare July 15, 2020 11:33
@jneira
Copy link
Member

jneira commented Jul 15, 2020

@bubba what do you think about creating directly a new subpackage (ghcide-session-loader? ghcide-bios?) with the same contents as the public library?
Maybe it will no need separate the exe from the main lib in ghcide, as the subpackage would depend on the ghcide library and the ghicde executable will depend on its library and the subpackage.
It supposes more maintaining work but imo it will be more reliable.

@lukel97 lukel97 force-pushed the split-out-cradle-setup branch from 899111d to f9e3f1d Compare July 15, 2020 11:43
@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 15, 2020

@jneira I think a sub-package is probably overkill for just one module. With sub packages you need to be careful whenever you're making releases on hackage etc. so that you don't upload them in the wrong order. I always mess that up with haskell-lsp and haskell-lsp-types. I've moved it into just the ghcide library for now, with the one caveat being that loadSession just errors if the -fghc-lib flag is set

@jneira
Copy link
Member

jneira commented Jul 15, 2020

I think ghcide maintainers preferred to separate hie-bios from the ghcide main lib, to not leak it to daml.
Although maybe they could confirm if it is so.

@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 15, 2020

@jneira ah if thats the case then, then we might not have much choice

@jneira
Copy link
Member

jneira commented Jul 15, 2020

@bubba Other alternative would be move the ghc session logic to hls and remove the exe part from ghcide entirely, letting it be a pure lib 😄

@pepeiborra
Copy link
Collaborator

@bubba @jneira Can you enumerate all the options and their tradeoffs? Things to consider:

  • testability
  • minimal dependencies in the ghcide Library stanza
  • compatibility with tools and IDEs

Hopefully making it easy for the code owners (@digitalasset @cocreature) to pick one.

@cocreature
Copy link
Collaborator

Other alternative would be move the ghc session logic to hls and remove the exe part from ghcide entirely, letting it be a pure lib smile

That breaks all tests we currently have.

I think ghcide maintainers preferred to separate hie-bios from the ghcide main lib, to not leak it to daml.
Although maybe they could confirm if it is so.

Yes, we need to be able to build ghcide (the library) without a dependency on any Haskell build tool stuff which includes hie-bios.

What could work is to just hide the session stuff and the dependency on hie-bios behind a cabal flag.

@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 15, 2020

Approach Pros Cons
Move loadSession into lib:ghcide Simple ghcide needs to be independent of haskell stuff so no hie-bios: No dice
Move loadSession into sublibrary All in the one package Really dubious stack support
Move loadSession into new package Works with all stack/cabal versions More release churn. Now have a circular dependency on exe:ghcide -> lib:ghcide-session-loader -> lib:ghcide, so exe:ghcide might also need split out into another package
Hide behind a cabal flag All in the one package No good way of specifying cabal flags for dependencies directly in .cabal files. Will need to use cabal.project in haskell-language-server

@cocreature
Copy link
Collaborator

cabal flags have a default. Apart from DAML nobody cares about being able to disable this so the sane option is to include it by default. We could even just reuse the ghc-lib flag here. Then apart from DAML nobody has to specify the flag and it’s not really an issue that you cannot specify flags for your build-depends in your cabal file.

@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 15, 2020

@cocreature I was thinking that as well, if the default was to include hie-bios/the session loader then haskell-language-server might still be able to get uploaded to hackage eventually. I'm happy to try out this option

@jneira
Copy link
Member

jneira commented Jul 15, 2020

Now have a circular dependency on exe:ghcide -> lib:ghcide-session-loader -> lib:ghcide, so exe:ghcide might also need split out into another package

I think there would not be such circularity cause one package depends on the lib of the another one, no on its executables (they are private for dependency management purpose).
The advantage would be it works out of the box with all stack/cabal versions and the separation is cleaner (maybe too much), only one small independent component will be more reliable, in general. Also it would make impossible to introduce dependencies from other ghcide lib modules to the session loader.

That said, agree a cabal flag with the default value would be the best option. Not sure about how can it affect the ghcide executable, it will be no buildable with the session loader disabled (so maybe simply mark it as buildable: false for the chosen flag would suffice).

@lukel97 lukel97 force-pushed the split-out-cradle-setup branch from f9e3f1d to cce9b29 Compare July 15, 2020 12:46
@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 15, 2020

I think there would not be such circularity cause one package depends on the lib of the another one, no on its executables (they are private for dependency management purpose).

I didn't realise stack/cabal could handle that!

@cocreature @jneira for now I've just reused the ghc-lib flag which I was already using as a check. The ghcide executable has buildable: False when this is turned on anyway so there shouldn't be any difference

ghcide.cabal Outdated Show resolved Hide resolved
@lukel97 lukel97 force-pushed the split-out-cradle-setup branch 2 times, most recently from f1e85e1 to e2809d5 Compare July 16, 2020 11:19
This way haskell-language-server can also reuse this logic.
Note that this sublibrary is public so it requires cabal-version: 3.0
Part of the work towards #478
@lukel97 lukel97 force-pushed the split-out-cradle-setup branch from e2809d5 to f6880a5 Compare July 20, 2020 11:43
@lukel97 lukel97 force-pushed the split-out-cradle-setup branch 2 times, most recently from da6000b to 16a85ae Compare July 20, 2020 11:52
@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 20, 2020

Argh this module fails to build only on windows when building with stack and ghc-8.10. Window + cabal + ghc-8.10 seems fine. Not exactly sure what's causing it

@lukel97
Copy link
Collaborator Author

lukel97 commented Jul 20, 2020

Looks like the template-haskell bit used to generate the GhcVersionChecker is the culprit. Maybe that stuff does need moved back out into a separate module

@lukel97 lukel97 force-pushed the split-out-cradle-setup branch 7 times, most recently from efbfa13 to e1fcb75 Compare July 20, 2020 22:44
Sublibraries do not seem to play well. Hide this behind the ghc-lib flag
so that the Haskell specific hie-bios stuff can be disabled

Note that we need to put the template-haskell part of this module into a
separate module because of an access exception when compiling with
Stack, GHC 8.10.1 and Windows.
@lukel97 lukel97 force-pushed the split-out-cradle-setup branch from e1fcb75 to e04f298 Compare July 21, 2020 10:59
@lukel97 lukel97 changed the title Split out cradle loading logic into new library Move session loading logic into ghcide library Jul 21, 2020
Copy link
Collaborator

@cocreature cocreature left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @bubba, thank you very much!

@cocreature cocreature closed this Jul 27, 2020
@cocreature cocreature reopened this Jul 27, 2020
@cocreature cocreature merged commit 4121937 into haskell:master Jul 27, 2020
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Split out the session loading logic into a sublibrary

This way haskell-language-server can also reuse this logic.
Note that this sublibrary is public so it requires cabal-version: 3.0
Part of the work towards haskell/ghcide#478

* Move Development.IDE.Session into ghcide itself

Sublibraries do not seem to play well. Hide this behind the ghc-lib flag
so that the Haskell specific hie-bios stuff can be disabled

Note that we need to put the template-haskell part of this module into a
separate module because of an access exception when compiling with
Stack, GHC 8.10.1 and Windows.
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Split out the session loading logic into a sublibrary

This way haskell-language-server can also reuse this logic.
Note that this sublibrary is public so it requires cabal-version: 3.0
Part of the work towards haskell/ghcide#478

* Move Development.IDE.Session into ghcide itself

Sublibraries do not seem to play well. Hide this behind the ghc-lib flag
so that the Haskell specific hie-bios stuff can be disabled

Note that we need to put the template-haskell part of this module into a
separate module because of an access exception when compiling with
Stack, GHC 8.10.1 and Windows.
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* Split out the session loading logic into a sublibrary

This way haskell-language-server can also reuse this logic.
Note that this sublibrary is public so it requires cabal-version: 3.0
Part of the work towards haskell/ghcide#478

* Move Development.IDE.Session into ghcide itself

Sublibraries do not seem to play well. Hide this behind the ghc-lib flag
so that the Haskell specific hie-bios stuff can be disabled

Note that we need to put the template-haskell part of this module into a
separate module because of an access exception when compiling with
Stack, GHC 8.10.1 and Windows.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants