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

Support TemplateHaskell #222

Merged
merged 7 commits into from
Dec 10, 2019
Merged

Support TemplateHaskell #222

merged 7 commits into from
Dec 10, 2019

Conversation

serras
Copy link
Contributor

@serras serras commented Dec 6, 2019

This is a first attempt to fix #34. Right now, things seem to work fine, at least examples do! :)

There are a few things that might need additional attention:

  • Right now all modules are compiled to bytecode, because they might be needed in the future. Could we be more precise on this, to avoid having to generate all that code?
  • When a file is read by TemplateHaskell, it assumes that the current directory is the one in which ghcide is run. This is different from what Stack or Cabal do, because they assume the hs-source-dirs of the project is the current directory. This means files cannot be loaded correctly by TemplateHaskell splices in ghcide.

@digitalasset-cla
Copy link

digitalasset-cla commented Dec 6, 2019

CLA assistant check
All committers have signed the CLA.

@serras
Copy link
Contributor Author

serras commented Dec 6, 2019

About the two issues above:

  • I have implemented a simple check (the module uses TemplateHaskell or QuasiQuotes) to drive whether we need to compile all dependencies as bytecode.
  • The problem about the current directory seems to be solvable by using the new multi cradle from hie-bios. However, this is only available from version 0.3, which has not been released yet.

@cocreature
Copy link
Collaborator

Thanks a lot for the PR! I’ll have a detailed look at it next week but this looks great!

It would be awesome if we could get some testcases for this.

@serras
Copy link
Contributor Author

serras commented Dec 6, 2019

I have added a testcase based on the one for #212. However, something weird happens: loading such files in a command line works perfectly fine, but in the testcase runner loading times out.

@jinwoo
Copy link
Contributor

jinwoo commented Dec 6, 2019

Thanks, @serras for the fix! This is great.

Re: the test case timing out, what I figured out while writing the test cases in #212 and previous changes was that if your test case has no errors/warnings, there will be no diagnostics and your assertion code never runs. You need to intentionally add any error or warning, and assert that.

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.

Awesome, thanks a lot! I have one question about the global_uses_th_qq check and this needs to be refactored slightly to not break our use of ghcide in DAML. As mentioned in the inline comment, I am happy to handle that myself, just let me know what you prefer.

Thanks again!

packageState <- hscEnv <$> use_ GhcSession file
-- Figure out whether we need TemplateHaskell or QuasiQuotes support
let global_uses_th_qq = uses_th_qq $ hsc_dflags packageState
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was to take care of the case in which TemplateHaskell or QuasiQuotes is enabled at the package level, but not in the file itself (for example, if you add them as extensions in your .cabal file).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought that would still end up in the dflags of the file, is that not correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I am not sure about it. I guess we can always start with checking only the dflags of the file, and if it appears to be the case that sometimes we need to check other things, we just uncomment the code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good 👍

@@ -122,7 +123,7 @@ compileModule
:: HscEnv
-> [TcModuleResult]
-> TcModuleResult
-> IO ([FileDiagnostic], Maybe CoreModule)
-> IO ([FileDiagnostic], Maybe (CoreModule, TcModuleResult))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We use this function and the GenerateCore rule in DAML where generating bytecode doesn’t make sense (if it works at all) and would slow things down unnecessarily. I think the most sensible option here is to split this in two:

  1. GenerateCore can be changed to return CgGuts.
  2. We can add a new GenerateByteCode rule that depends on GenerateCore to get the CgGuts and then returns (CompiledByteCode, CgEntry).

I would probably just move the assembling of the HomeModInfo to the call site of this rule.

If you are fine with it, I’m also happy to do this change myself and push to your branch but if you want to give it a shot yourself you are more than welcome to!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer you to do it, because I might not get it 100% right. I'll give you push access in my repo so you can just push whenever you are done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Great, I’ll take care of it (hopefully tomorrow but definitely this week). I don’t think you need to give me access to your repo. The default on github is that you can push to the branch of a PR to your repo so unless you disabled that I should be all set.

@moritzkiefer-da moritzkiefer-da merged commit 481ca01 into haskell:master Dec 10, 2019
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* First attempt at TH support

* Update TcModuleResult when generating core

* Be a bit more cautious when asking for bytecode

* Check need for bytecode not only in source file itself, also in global information

* Add a test (based on haskell/ghcide#212)

* Fix test (thanks, @jinwoo)

* Split GenerateCore and GenerateByteCode
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* First attempt at TH support

* Update TcModuleResult when generating core

* Be a bit more cautious when asking for bytecode

* Check need for bytecode not only in source file itself, also in global information

* Add a test (based on haskell/ghcide#212)

* Fix test (thanks, @jinwoo)

* Split GenerateCore and GenerateByteCode
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
* First attempt at TH support

* Update TcModuleResult when generating core

* Be a bit more cautious when asking for bytecode

* Check need for bytecode not only in source file itself, also in global information

* Add a test (based on haskell/ghcide#212)

* Fix test (thanks, @jinwoo)

* Split GenerateCore and GenerateByteCode
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.

Support TemplateHaskell
5 participants