haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 209 forks source link

Error "target \8216+RTS\8217 is not a module name or a source file" in Atom #1725

Closed PaulJohnson closed 4 years ago

PaulJohnson commented 4 years ago

I've just upgraded to the latest HIE as part of a move to Stack lts-15.2. When I save a file in Atom (triggering HIE) I get the error message target \8216+RTS\8217 is not a module name or a source file in a red box at the top right.

I'm filing this as an HIE bug because it is HIE that has changed rather than the Atom plug-in.

fendor commented 4 years ago

Looks liek a HIE-bug. Do you have spaces in the filepath? If yes, this is a duplicate of #1669 and fixed in hie-bios, we just need a new release and bump versions.

PaulJohnson commented 4 years ago

There are no spaces in my filepaths.

\8216 and \8217 are the open and close single quote characters, so at a guess they got inserted around the +RTS by mistake somewhere instead of the ASCII single quote.

fendor commented 4 years ago

Can you share your project set-up a bit, and link logs of the execution? Some way to do that is by invoking hie-wrapper --debug . in the root of your project.

PaulJohnson commented 4 years ago

Here is the output of HIE. There is a lot of it, but a search for "not a module" will find the error message in question. hie.log.txt

I'm using Atom 1.45.0 with the following Haskell plugins:

atom-ide-ui 0.13.0 ide-haskell 2.4.1 ide-haskell-cabal 2.4.0 ide-haskell-hie 0.12.0 language-haskell 1.19.4

fendor commented 4 years ago

\8216 and \8217 are the open and close single quote characters, so at a guess they got inserted around the +RTS by mistake somewhere instead of the ASCII single quote.

IIRC, this is from GHC itself. For some reason, GHC thinks that +RTS is a target to compile...

Can not easily reproduce, can you provide a minimal project to play around with? Or just some project that produces this problem? Does the problem go away if you remove those +RTS entry from your .cabal or package.yaml file?

PaulJohnson commented 4 years ago

Does the problem go away if you remove those +RTS entry from your .cabal or package.yaml file?

Yes it does. I put them in some time ago to try to speed up compilation by giving the GHC garbage collector more room for manoeuvre.

fendor commented 4 years ago

What does your .cabal file look like with these option? Can you provide an example of this section?

PaulJohnson commented 4 years ago

I had

ghc-options: -Wall -j +RTS -A32m -RTS

in my .cabal file for the library section and each exec section.

fendor commented 4 years ago

Can reproduce on linux. Flag difference, output with hie.yaml

-fbuilding-cabal-package
-O0
-outputdir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-odir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-hidir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-stubdir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-i
-i/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-i/home/baldr/Documents/haskell/fprog/app
-i/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/autogen
-i/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/global-autogen
-I/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/autogen
-I/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/global-autogen
-I/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-optP-include
-optP/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/autogen/cabal_macros.h
-hide-all-packages
-Wmissing-home-modules
-no-user-package-db
-package-db
/home/baldr/.cabal/store/ghc-8.6.5/package.db
-package-db
/home/baldr/Documents/haskell/fprog/dist-newstyle/packagedb/ghc-8.6.5
-package-db
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/package.conf.inplace
-package-id
base-4.12.0.0
-package-id
fprog-0.1.0.0-inplace
-XHaskell2010
app/Main.hs
-Wall
-j
-rtsopts
-with-rtsopts=-N
-hide-all-packages

output without hie.yaml

-fbuilding-cabal-package
-O
-outputdir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-odir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-hidir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-stubdir
/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-i
-i/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-i/home/baldr/Documents/haskell/fprog/app
-i/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/autogen
-i/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/global-autogen
-I/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/autogen
-I/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/global-autogen
-I/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/fprog-tmp
-optP-include
-optP/home/baldr/Documents/haskell/fprog/dist-newstyle/build/x86_64-linux/ghc-8.6.5/fprog-0.1.0.0/x/fprog/build/fprog/autogen/cabal_macros.h
-hide-all-packages
-Wmissing-home-modules
-no-user-package-db
-package-db
/home/baldr/.cabal/store/ghc-8.6.5/package.db
-package-db
/home/baldr/Documents/haskell/fprog/dist-newstyle/packagedb/ghc-8.6.5
-package-id
base-4.12.0.0
-package-id
fprog-0.1.0.0-inplace
-XHaskell2010
-Wall
-j
+RTS
-A32m
-RTS
-threaded
-rtsopts
-with-rtsopts=-N
app/Main.hs

Note that the latter contains +RTS -A32m -RTS while the former does not. So, bug in the cabal-helper-helper implementation.

fendor commented 4 years ago

Potential work-around: Replace any occurrence of +RTS -A32m -RTS with -with-rtsopts=-A32m EDIT: If you already have an entry -with-rtsopts=... add another entry, dont try to merge them. If you try to merge them, it fails again, possibly another bug.

PaulJohnson commented 4 years ago

Side note: removing the -A32m means that Atom with HIE is now taking sane amounts of RAM. Telling GHC to allocate itself plenty of memory isn't a problem in batch mode, but it seems that it doesn't play well in HIE. I was seeing 20GB taken by my IDE. I just assumed it was inevitable for a large program under HIE.

fendor commented 4 years ago

Carried over from https://github.com/DanielG/cabal-helper/issues/101, the correct syntax is "-with-rtsopts=-A32m -T".

However, what were you actually trying to achieve with +RTS -A32m -RTS?

PaulJohnson commented 4 years ago

The intention is to make GHC run faster by increasing the allocation size for the GC, thereby reducing the number of garbage collections during compilation. This is recommended in a number of places, including this blog post.

Incidentally, -with-rtsopts is not the same thing. +RTS sets the run-time options for the current program (i.e. GHC), but -with-rtsopts is a flag for GHC which contains the run-time options for the generated executable.

fendor commented 4 years ago

In hie-bios, we explicitly strip RTS flags. I wonder why. EDIT: relevant issue: https://github.com/mpickering/hie-bios/issues/102 Another edit: Actually in that issue I recommended the same wrong suggestion about -with-rtsopts. Hopefully I will remember it now.

fendor commented 4 years ago

From irc discussion with @mpickering: HIE can not honor them because it is already too late when we get this options, the ghc session has already started, and we cant limit the used memory later. Therefore, the fix is to strip these options in cabal-helper-helper.

fendor commented 4 years ago

@PaulJohnson would you mind checking if this problem is gone?

PaulJohnson commented 4 years ago

Yup, seems to have nailed it, thanks.

fendor commented 4 years ago

Great news! However, please note that these flags dont do anything to the compiler used by HIE. So, it will have no impact on the memory used by HIE.