-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault when encountering a TemplateHaskell splice #800
Comments
Another workaround is to use |
Fencing the splice with a preprocessor directive (and enabling version :: Version
#ifdef __GHCIDE__
version = "0"
#else
version = $(fromPackage)
#endif Do you want a backtrace from when it segfaults? I've not had much success getting GDB to play nice with GHC but I'll give it a try if you want. |
If it's easy then sure, but I'm not sure if anyone is likely to look at it. TH related things aren't our strong spot. |
Is this reproducible @afcowie ? |
@mpickering yes, very reproducible. I only have one Template Haskell splice in my collection of projects—only time I've ever written TH code—but I hazard a guess any Template Haskell splice would trigger this. (this is to say I have three separate projects doing this in one file each and ghcide segfaults with all of them) |
Template Haskell does generally work so I think it is probably something specific to do with this splice. |
|
For fascinating reasons the **ghcide** Language Server Protocol server crashes when faced with a Template Haskell splice. Guard the code snippet which gets the application version from the package metadata with a CPP directive so we can open this source file in VS Code without it killing the IDE. Upstream issue is https://github.com/digital-asset/ghcide/issues/444
@mpickering I'm sorry you find our code excessively dodgy. We've avoided TemplateHaskell for years, seems to cause more problems that its worth but worked for us in this case. I'll try your suggestion. |
@mpickering No, changing to |
@afcowie Can you produce a standalone repo with a |
This builds against `lts-15.0` with GHC 8.8.2; unfortunately **ghcide** segfaults when checking it for errors. Demonstrates https://github.com/digital-asset/ghcide/issues/444 as requested by @mpickering whose help we hugely appreciate.
@mpickering done. If you clone https://github.com/afcowie/hello/tree/ghcide-issue-444 you will get a essentially bare repository with a single program that demonstrates the problem.
however
I should note that this is with GHC 8.8.2 so you'll need the a version of ghcide built against that, as I understand it. The problem was exhibited with earlier versions of GHC. If you're using Stack but GHC 8.6.5, say, you can use: resolver: lts-14.27
extra-deps:
- core-text-0.2.3.3
- core-data-0.2.1.5
- core-program-0.2.4.2 and get the same demonstration. |
The segfault is coming from calling |
The |
To further deepen the mystery, if I add |
@hvr This is extraordinary debugging work by @mpickering. If you look at the Haskell source for HelloMain.hs in Matt's Gist he worked down to a very minimal example. Do you think you might have any insight about what's happening here? Amazing bug, really. |
@mpickering @afcowie I tried to reproduce this by cloning the gist (fixing up the .cabal file) and PS: Does this bug-repro really need |
@hvr I couldn't reproduce it with a normal GHC executable, only when using Btw, I never said this in the issue but the segfault only happens if the string is at least 16 bytes long. Strings under 16 bytes seem to work. |
@mpickering well, I tried with ghcide too and still wasn't able to reproduce:
|
Bummer. Thanks for trying @hvr. I just tried with Matt's minimal example and it still segfaults the same way. |
@afcowie @hvr I am using NixOS, what about your Andrew? Perhaps I should try with a different C compiler? |
I just tried the example again with 8.8.1 and it worked, are you building a recent commit from master @afcowie ? |
@mpickering Fedora 31 Linux on an Intel i9; GHC 8.8.3 as specified by the |
@afcowie if you're using ghcide-nix, try uncommenting https://github.com/cachix/ghcide-nix/blob/master/nix/default.nix#L19 and check if that fixes it. |
I have had some odd behaviours with |
So I did a full from scratch re-installation of all the Haskell infrastructure, and unfortunately the problem endures. |
Maybe this one is fixed by haskell/ghcide#836? @istathar could you give a try, please? |
@jneira alas. I just tried it with ghcide from 'master' and I'm afraid to report that when I remove the
|
I'm also getting this error with a Stack project on Linux (no Nix), initialized with |
I'm also running into this with a cabal project on MacOS. The specific thing that's causing it for me is a typed TH quotation. Using GHC 8.10.2 and HLS 0.9.0. I can provide more information if it may help lead to a fix! |
@FinleyMcIlwaine That is probably unrelated to this problem. Please make a new ticket. |
I'm running into a segfault problem as well using postgresql-typed's template haskell. Tried with GHC 8.8.4, 8.10.2 and 8.10.4. |
Yeah it does not use ghcide, comparing with intellij could be a investigation path, thanks |
Just chiming in to say I get segfaults as well, only with template haskell on (specifically, quasiquotes from the path library). Although in my case, it only happens inside a nix-shell. (GHC 8.10.4, on WSL2+Fedora) |
I got this same problem and the only way I got to make it work was running |
Hi, I got the same problem with HLS 1.3.0.0 and GHC 8.8.4. |
+1
This one is related to file-embed library usage. Plain vanilla usage works: $(makeRelativeToProject` "<relative-path-to-file>" >>= embedStringFile) ... but this helper causes issues (I guess at the call-site): includeFile :: FilePath -> Q Exp
includeFile = makeRelativeToProject >=> embedStringFile This was a quick hack to mitigate #481. So I am not sure if it is separate from #481, but thought I should report. Also, in the past, I experienced issues with quasiquotes from the |
I'm running what I suspect might be this problem when trying to use HLS and VS Code on Wasp's Haskell component. The symptoms I see in VS Code are a crash loop, similar to #1297, with no errors reported from the server in the VS Code output. When I run HLS 1.4.0 from an isolated install (installed with I tried to replicate by building from source; I cloned this repo, and checked out the 1.4.0 tag. Building with Stack with or without debug symbols, with or without optimization, I wasn't able to replicate the issue; running the built executable against waspc ran to completion successfully every time. I tried:
I haven't tried building from source with Cabal yet. I don't know if there are any other options/flags I should use to replicate what's used for the binary fetched by |
@DylanSp many thanks for the detailed update and for trying reproduce the problem. |
@jneira My OS is Linux Mint 18, based on Ubuntu 16.04, running on x64. It's entirely possible that something's weird with linking with local libraries; I had errors building an unrelated Haskell project due to GHC 8.10.7/base 4.10.3.0 wanting a newer |
Tried building HLS from source with
Will try using a Docker container to build against a more recent libc. |
The prebuilt binary is being built with ubuntu 18 so it seems is could be related, other issues about crashes with TH are not reproduced building hls from source so i think they are related: |
I was able to reproduce the core dump when installing the prebuilt HLS binary in an Ubuntu 18.04 container. I tried building HLS from source in an 18.04 container as well; that ran successfully to completion. This C assertion failure fired after HLS finished analyzing everything:
https://gist.github.com/DylanSp/aea8643a19e883a19f974e652aada853 can reproduce the error.
|
After further investigation, I was able to get the same assertion failure with HLS built from source, in both Ubuntu 18.04 and 20.04 environments. The problem seems to be related to the prebuilt HLS binary using static linking; the problem didn't occur when HLS was built without the |
@DylanSp many thanks for the anaylisis and reproduction, so we could state that building from source with dynamic linking seems to workaround the issue (as other ones): if any of reporters can reproduce it with that setup, please update the issue, thanks! |
@jneira No problem; glad I can help by suggesting a workaround, and I hope with my info you can track down the root cause. |
This issue was really useful to make progress on diagnostic template haskell related problems, thanks very much all for the effort put in investigations and reproductions. |
I hate to say it but I think we need to re-open this (cc @jneira). I'm hitting the segfaut again, with haskell-language-server-1.5.1-linux-8.10.7 ; command-line build with (in our case
|
I am gonna close this issue as all compiler crashes seems to have the same root cause:
If any of you think the issue should not be included generically feel free to reopen it (with a brief explanation if possible) |
We've had ghcide crashing, and the editor trying to reload it leads to a tight loop that the editor can't escape. Trying the ghcide binary from the command-line in test mode leads to a segfault:
This is triggered when using TemplateHaskell. We have a splice
fromPackage :: Q Exp
which returns some metadata from the project's .cabal file:removing this definition from the source file (in this case RenderMain.hs lines 13-14) allows the ghcide binary to complete its test run:
I had earlier speculated that QuasiQuotes were to blame, but the file checks ok with those
[quote| ... |]
blocks still in the file.Other files in the project load and check fine, so long as you avoid having the problematic file open in an editor tab you can avoid the crash. Not ideal, but at least a workaround.
The text was updated successfully, but these errors were encountered: