DanielG / ghc-mod

Happy Haskell Hacking for editors. DEPRECATED
Other
677 stars 175 forks source link

ghc-mod takes a very long time to check a module using template haskell in a project depending on haskell-src-exts #950

Open expipiplus1 opened 5 years ago

expipiplus1 commented 5 years ago

Summary

In a project using haskell-src-exts as a transitive dependency ghc mod hangs 100% cpu usage when loading a file with quasi quotes or template haskell. On my machine this takes about

I have not tested with other large packages as dependencies.

To reproduce:

module Main where

main :: IO () main = pure 1

- `ghc-mod-test.cabal` 

name: ghc-mod-test version: 0.0.0 build-type: Simple

executable ghc-mod-test main-is: Main.hs build-depends: base , haskell-src-exts


- Run `ghc-mod browse Main.hs --verbose 7`
- Observe that ghc-mod hangs after printing `Target needs interpeter, switching to LinkInMemory/HscInterpreted. Perfectly normal if anything is using TemplateHaskell, QuasiQuotes or PatternSynonyms.` 

- Remove the `haskell-src-exts` line from `ghc-mod-test.cabal`
- Run `ghc-mod browse Main.hs --verbose 7`
- Observe that ghc-mod no longer hangs and correctly identifies the type error in `Main.hs`

## Versions

$ ghc-pkg list /nix/store/ynmnlayvwy7rcgqjgdqkik5cwnw4n8pg-ghc-8.6.4-with-packages/lib/ghc-8.6.4/package.conf.d Cabal-2.4.0.1 array-0.5.3.0 base-4.12.0.0 binary-0.8.6.0 bytestring-0.10.8.2 containers-0.6.0.1 deepseq-1.4.4.0 directory-1.3.3.0 filepath-1.4.2.1 ghc-8.6.4 ghc-boot-8.6.4 ghc-boot-th-8.6.4 ghc-compact-0.1.0.0 ghc-heap-8.6.4 ghc-prim-0.5.3 ghci-8.6.4 haskeline-0.7.4.3 haskell-src-exts-1.20.3 hpc-0.6.0.3 integer-gmp-1.0.2.0 libiserv-8.6.3 mtl-2.2.2 parsec-3.1.13.0 pretty-1.1.3.6 process-1.6.5.0 rts-1.0 stm-2.5.0.0 template-haskell-2.14.0.0 terminfo-0.4.1.2 text-1.2.3.1 time-1.8.0.2 transformers-0.5.6.2 unix-2.7.2.2 xhtml-3000.2.2.1

$ ghc-mod --version ghc-mod version 5.9.0.0 compiled by GHC 8.6.4

`d96119645c12905858468a98429f6a887330e7d9`

## ghc-mod's log:

info: Found Cabal project at: /home/j/projects/ghc-mod-test info: Using Cabal project at: /home/j/projects/ghc-mod-test DEBUG: setup configuration is out of date DEBUG: reconfiguring Cabal project Warning: The configure command is a part of the legacy v1 style of cabal usage.

Please switch to using either the new project style and the new-configure command or the legacy v1-configure alias as new-style projects will become the default in the next version of cabal-install. Please file a bug if you cannot replicate a working v1- use case with the new-style commands.

For more information, see: https://wiki.haskell.org/Cabal/NewBuild

Warning: ghc-mod-test.cabal:0:0: A package using section syntax must specify at least 'cabal-version: >= 1.2'. Warning: ghc-mod-test.cabal:0:0: A package using section syntax must specify at least 'cabal-version: >= 1.2'. DEBUG: reading cache: /home/j/projects/ghc-mod-test/dist/setup-config.ghc-mod.package-options DEBUG: regenerating cache: /home/j/projects/ghc-mod-test/dist/setup-config.ghc-mod.package-options (input data changed) DEBUG: writing memory cache: /home/j/projects/ghc-mod-test/dist/setup-config.ghc-mod.package-options DEBUG: reading cache: /home/j/projects/ghc-mod-test/dist/setup-config.ghc-mod.cabal-components DEBUG: regenerating cache: /home/j/projects/ghc-mod-test/dist/setup-config.ghc-mod.cabal-components (input data changed) DEBUG: writing memory cache: /home/j/projects/ghc-mod-test/dist/setup-config.ghc-mod.cabal-components DEBUG: resolveEntrypoint: ["-i","-idist/build/ghc-mod-test/ghc-mod-test-tmp","-i.","-idist/build/ghc-mod-test/autogen","-idist/build/global-autogen","-Idist/build/ghc-mod-test/autogen","-Idist/build/global-autogen","-Idist/build/ghc-mod-test/ghc-mod-test-tmp","-optP-include","-optPdist/build/ghc-mod-test/autogen/cabal_macros.h"] DEBUG: resolveEntrypoint: [] DEBUG: making sure autogen files exist DEBUG: autogen files out of sync DEBUG: writing Cabal autogen files DEBUG: reading cache: dist/setup-config.ghc-mod.resolved-components DEBUG: resolvedComponentsCache: files changed: none DEBUG: resolveGmComponent: ["-optP-include","-optPdist/build/autogen/cabal_macros.h"] DEBUG: resolveGmComponent: ["-i","-idist/build/ghc-mod-test/ghc-mod-test-tmp","-i.","-idist/build/ghc-mod-test/autogen","-idist/build/global-autogen","-Idist/build/ghc-mod-test/autogen","-Idist/build/global-autogen","-Idist/build/ghc-mod-test/ghc-mod-test-tmp","-optP-include","-optPdist/build/ghc-mod-test/autogen/cabal_macros.h","-XHaskell98","-optP-include","-optPdist/build/autogen/cabal_macros.h"] DEBUG: regenerating cache: dist/setup-config.ghc-mod.resolved-components (input data changed) DEBUG: writing memory cache: dist/setup-config.ghc-mod.resolved-components DEBUG: Could not find a component assignment, falling back to picking library component in cabal file. VOMIT: hide all packages(ignore .ghc.environment):: DontLoadGhcEnvironment VOMIT: Using the following mapped files: VOMIT: Using the following mapped files: VOMIT: Initializing GHC session with following options: "-fbuilding-cabal-package" "-O" "-outputdir" "dist/build/ghc-mod-test/ghc-mod-test-tmp" "-odir" "dist/build/ghc-mod-test/ghc-mod-test-tmp" "-hidir" "dist/build/ghc-mod-test/ghc-mod-test-tmp" "-stubdir" "dist/build/ghc-mod-test/ghc-mod-test-tmp" "-i" "-idist/build/ghc-mod-test/ghc-mod-test-tmp" "-i." "-idist/build/ghc-mod-test/autogen" "-idist/build/global-autogen" "-Idist/build/ghc-mod-test/autogen" "-Idist/build/global-autogen" "-Idist/build/ghc-mod-test/ghc-mod-test-tmp" "-optP-include" "-optPdist/build/ghc-mod-test/autogen/cabal_macros.h" "-hide-all-packages" "-Wmissing-home-modules" "-package-id" "base-4.12.0.0" "-package-id" "haskell-src-exts-1.20.3-2fryh11Yuz7lCtLeeIQn8" "-XHaskell98" "-Wno-missing-home-modules" "-O0" "-fno-warn-missing-home-modules" DEBUG: initSession: Session not initialized, creating new one VOMIT: Using the following targets: "Main.hs" DEBUG: loadTargets: Loading: Main.hs DEBUG: loadTargets: filterModSums: False info: loadTargets: Target needs interpeter, switching to LinkInMemory/HscInterpreted. Perfectly normal if anything is using TemplateHaskell, QuasiQuotes or PatternSynonyms. <<>>

Main.hs:6:13: error: • No instance for (Num ()) arising from the literal ‘1’ • In the first argument of ‘pure’, namely ‘1’ In the expression: pure 1 In an equation for ‘main’: main = pure 1 DEBUG: loadTargets: Loading done EXCEPTION: browse: Could not find module ‘Main.hs’ Use -v to see a list of the files searched for. /nix/store/wqrayxv60mxhyw5zmx0hhgj62qz3id58-ghc-mod-5.9.0.0/bin/ghc-mod brows 189.70s user 0.35s system 100% cpu 3:10.00 total

expipiplus1 commented 5 years ago

I get the same behavior with GHC-8.4.4 and GHC-8.2.2