Skip to content

Support TemplateHaskell #1121

Closed
haskell/ghcide
#222

Description

@ndmitchell

Trying to synthesise one ticket that describes all the TH work. My understanding of the current state is:

  • If you have TH or ANN pragmas, and they all refer to code that is imported by packages or in this module, it works.
  • If you refer to other modules in this package it breaks, perhaps with haskell/ghcide#25.

The solution is likely to make sure we have compiled the dependencies to bytecode and send them at the linker before type checking a module that uses TH or ANN.

However, we don't have tests for the current state, and it works by luck rather than deliberately.

Activity

  1. cocreature commented on Sep 11, 2019

    @cocreature
    Contributor

    I have also seen some issue around async exceptions and TH which seemed to make GHC very unhappy (I don’t recall the precise error message).

  2. DavidEichmann commented on Sep 12, 2019

    @DavidEichmann

    I've noticed a huge slowdown when TH is enabled. After some searching I've noticed the folks at hie-engine ran into what looks like the same issue (HIE github issue), which was fixed in Infinisil/all-hies
    by dynamically linking HIE (infinisil/all-hies#3). That PR says dynamic linking may not be necessary in for ghc versions with a fix to this GHC issue.

  3. pwm commented on Oct 4, 2019

    @pwm

    Hi, anyone is in a position to estimate how much work this would entail? Since my team started using ghcide we can’t imagine going back to the stone age ever. You guys did an amazing job! On our end TH support seems to be the last big issue that’s in the way of full adoption.

  4. ndmitchell commented on Oct 4, 2019

    @ndmitchell
    CollaboratorAuthor

    My guess is you need to:

    • Figure out which modules require TH, nice and easy.
    • For those that do, first build all the dependencies to object code (moderate amount of work, probably < 100 lines, fits fairly well with the graph approach).
    • Then send that object code to the linker (dunno how hard this is, might have problems with state management).

    So probably not obviously hard, but I'd almost be surprised if something didn't get in your way.

  5. domenkozar commented on Dec 2, 2019

    @domenkozar
    Contributor

    @DavidEichmann in case you were using ghcide-nix, that has been fixed now.

  6. serras commented on Dec 4, 2019

    @serras
    Contributor

    I would like to tackle this issue, since out team uses TH in quite some places.
    Is there any further information that I can read to work on this?

  7. ndmitchell commented on Dec 4, 2019

    @ndmitchell
    CollaboratorAuthor

    None that I'm aware of @serras - but best of luck!

  8. serras commented on Dec 5, 2019

    @serras
    Contributor
  9. serras commented on Dec 5, 2019

    @serras
    Contributor

    I have started working on the issue at serras/ghcide@90c784b in a quite crude way, asking to compile all dependencies even if the file does not use Template Haskell.
    Now I get errors which look the ones in haskell/ghcide#212, even though now I am loading some bytecode:

    File:     ./src/B.hs
    Range:    1:0-100001:0
    Source:   typecheck
    Severity: DsError
    Message:
      Program error:
      ByteCodeLink.lookupCE
      During interactive linking, GHCi couldn't find the following symbol:
      A_a_closure
      This may be due to you not asking GHCi to load extra object files,
      archives or DLLs needed by your current session. Restart GHCi, specifying
      the missing library using the -L/path/to/object/dir and -lmissinglibname
      flags, or simply by naming the relevant files on the GHCi command line.
      Alternatively, this link failure might indicate a bug in GHCi.
      If you suspect the latter, please send a bug report to:
      [email protected]
    

    Is there any way I can check which rules are firing? At least I can be sure that the bytecode for A.hs is generated before continuing my investigation.

  10. cocreature commented on Dec 6, 2019

    @cocreature
    Contributor

    You can use shake profiling to figure out the rules, see https://github.com/digital-asset/ghcide/blob/master/src/Development/IDE/Types/Options.hs#L44 (I think this is not exposed via the CLI so you’ll have to set it in the code somewhere) but that’s more useful for benchmarking than for debugging imho. I would probably just use some printf statements in the rules.

  11. merijn commented on Dec 10, 2019

    @merijn

    I was testing out this PR and run into similar errors about a missing _closure despite said close being in the relevant library being loaded when I inspect it via nm. Is there a way I can see the ghci configuration ghcide is using to load things?

  12. domenkozar commented on Dec 11, 2019

    @domenkozar
    Contributor
  13. merijn commented on Dec 11, 2019

    @merijn

    Yeah, I'm seeing similar errors, and I have some suspicions but I'm not really sure enough how to debug ghcide to investigate further. Essentially, I seem to have both a static library (missing some symbols) and a dynamic library (not missing said symbols) in my dist-newstyle and ghcide seems to try to use the static one, but I'm not really sure why.

  14. merijn commented on Dec 11, 2019

    @merijn

    I'm trying to trick it into loading the dynamic library to see if that works, but that's not working :\

  15. cocreature commented on Dec 11, 2019

    @cocreature
    Contributor

    We don’t do anything explicit atm wtr to linking external libraries in our code. I was hoping that this just magically works™ if we setup the GHC API with the right flags but it looks like we need to figure out the right incantation.

  16. merijn commented on Dec 11, 2019

    @merijn

    I've been trying to find the right incantation with explicit -l/-L flags in hie.yaml, but so far no luck, but I've also going about it a bit blind since I don't actually know how ghcide sets up it's GHC session

  17. ndmitchell commented on Dec 12, 2019

    @ndmitchell
    CollaboratorAuthor

    Ghcide uses hie-bios to set up its session, which essentially dumps command line flags into a GHC session. If flags work in ghci, my experience is it usually works in ghcide too.

  18. merijn commented on Dec 12, 2019

    @merijn

    @ndmitchell I wish :)

    ghci seems perfectly happy to work with just .ghc.environment, but I'm seeing all sorts of weird missing symbol errors in ghcide that I can't quite explain. I don't mind digging a bit deeper trying to debug them, but I'm rather unsure/clueless on where to start.

  19. serras commented on Dec 12, 2019

    @serras
    Contributor

    @merijn you can have a look at hie-bios documentation and try to turn your current .ghc.environment configuration into a hie.yaml file.

  20. ndmitchell commented on Dec 12, 2019

    @ndmitchell
    CollaboratorAuthor

    @merijn yeah, .ghc.environment is entirely ignored by everything else, so you'll have to replicate that on the command line. FWIW, I turn off the GHC environment files because they cause lots of confusing behaviour with tools working differently in different places.

  21. merijn commented on Dec 12, 2019

    @merijn

    I was under the impression that ghcide used them to find dependencies? Because that seems to work fine in most of my simple-ish projects. I do have a hie.yaml to resolve the look source paths, but I'm always a bit mystified what else has to go in there.

  22. ndmitchell commented on Dec 13, 2019

    @ndmitchell
    CollaboratorAuthor

    @merijn nope, ghcide doesn't look at those files at all. It only uses cabal/stack as configured by hie-bios. In many cases cabal/stack will know the same information as those environment files.

  23. merijn commented on Dec 13, 2019

    @merijn

    Ah, so maybe that's where things go wrong, because in other projects I haven't had to use a hie.yaml to set things up! I'll start fiddling with hie-bios

  24. cocreature commented on Dec 13, 2019

    @cocreature
    Contributor

    As far as I know, we do pick up .ghc.environment files. The GHC API behaves like GHC itself in that it picks them up implicitly by default.

  25. ndmitchell commented on Dec 13, 2019

    @ndmitchell
    CollaboratorAuthor

    API's being influenced by random environment files scares me. The more I see about these environment files, the less I like them!

  26. transferred this issue fromhaskell/ghcideon Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions