DanielG / ghc-mod

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

ghc-modi check not consistent #275

Open rikvdkleij opened 10 years ago

rikvdkleij commented 10 years ago

ghc-modi version 4.1.3

I noticed in this project some inconsistent behavior of ghc-modi (ghc-mod is doing fine): https://github.com/rikvdkleij/Quicksort

To describe how to reproduce is difficult because it's not predictable. Try something like this: 1 - Make a syntax error in src/Quicksort.hs by removing space between module and Quicksort on first line (ghc-modi gives "parse error on input 'where'"). 2 - Check test/QuicksortSpec.hs, ghc-modi gives "File name does not match module........". 3 - Go back to src/Quicksort.hs. Fix it and check it. 4 - Check test/QuicksortSpec.hs. 5 - Repeat step 1. Now same error appears as for test/QuicksortSpec.hs in 2. (ghc-mod stil gives parse error)

Hope this helps.

Regards, Rik

rikvdkleij commented 10 years ago

I noticed it again with different files and different syntax error. It seems like last error is "hanging". Also restarting ghc-modi does not help.

rikvdkleij commented 10 years ago

Is this expected behavior of ghc-modi: check src/Quicksort.hs src/Quicksort.hs:11:1:Parse error: naked expression at top levelPerhaps you intended to use TemplateHaskell OK check src/Filter.hs src/Quicksort.hs:11:1:Parse error: naked expression at top levelPerhaps you intended to use TemplateHaskell OK

int3 commented 10 years ago

I've experienced a similar issue. It seems that ghc-modi doesn't show errors if a file is checked repeatedly unless its mtime changes between checks. And it also has a tendency to return unrelated results from old requests -- but only if the mtime of the files from the old request have changed.

kazu-yamamoto commented 10 years ago

ghc-modi uses cache. If mtime of a file is not changed, ghc-modi does not read it again. That's why ghc-modi is much faster than ghc-mod.

Emacs front-end modifies mtime of a target file before asking ghc-modi to check.

kazu-yamamoto commented 10 years ago

See: http://www.haskell.org/ghc/docs/latest/html/libraries/ghc-7.8.3/GHC.html#v:load

"This function implements the core of GHC's --make mode. It preprocesses, compiles and loads the specified modules, avoiding re-compilation wherever possible."

int3 commented 10 years ago

If ghc-modi is doing caching, then shouldn't it return the same errors for a file until its mtime gets updated? I'm saying that it's not returning any errors at all on subsequent checks. Specifically:

> check Foo.hs
Error: Foo.hs line 1 column 6 ...
> check Foo.hs
(nothing) -- I'd expected `Error: Foo.hs line 1 column 6 ...`

Also,

> check Foo.hs
Error: Foo.hs line 1 column 6 ...
> check Foo.hs
(nothing)
-- now, we update the `mtime` of Foo.hs.
> check Bar.hs
Error: Foo.hs line 1 column 6 ...
-- note that Bar.hs does not import Foo.hs

Let me know if you can't reproduce this, I can set up a full test case. My description above is from memory, but I'm pretty sure it's accurate.

kazu-yamamoto commented 10 years ago

You are right. The master branch now implements GhcMod monad. So, we can now have a state. Probably, we need to record mtime and errors in the state.

rikvdkleij commented 10 years ago

@kazu-yamamoto Can you give some estimation when you have fixed this issue? I have not (yet) enough Haskell experience to fix this issue. I would like to help with testing.

kazu-yamamoto commented 10 years ago

I'm waiting that @DanielG implements ErrorT stuff. #292

DanielG commented 10 years ago

Oh sorry I didn't know you were waiting on me otherwise I would've pushed this stuff sooner.

rikvdkleij commented 9 years ago

I noticed same behavior with info in ghc-modi.

DanielG commented 9 years ago

IIRC this should be fixed now @kazu-yamamoto removed the caching stuff from ghc-modi and the changes should have landed in 5.2.0.0 @rikvdkleij does this problem still happen with ghc-mod >= 5.2.0.0?

DanielG commented 9 years ago

Actually those changes already landed in v5.1.1.0.

rikvdkleij commented 9 years ago

Thanks! I will test asap.

rikvdkleij commented 9 years ago

Yes, it's fixed! Many thanks!

Btw, I noticed one time the old behavior but I can not reproduce it. So, I will close this issue.

rikvdkleij commented 9 years ago

Sorry, this issue is not solved yet.

Still notice problems. For example: 1- Running check first gives no problem (while it should because of syntax error) 2 - Give just an enter in Haskell file or ghc-mod info for a symbol 3 - Running check again gives expected error

DanielG commented 9 years ago

Is this still happening?

rikvdkleij commented 9 years ago

I switched to ghc-mod for check. Is there reason it should be solved in master? If so, I can switch back again :-)

DanielG commented 9 years ago

Ah ok, no rush then.

DanielG commented 9 years ago

Ok I think I finally understood what the problem is here, when we load a file again that used to have errors GHC doesn't emit those errors again because the file didn't change. Odd ghci manages to do the right think I don't think they store the error messages until the file actually changes there.

rikvdkleij commented 9 years ago

I do not know if it is related but I noticed with current master that for example a function name change is not picked up by ghc-mod check and also not by ghc-modi check. So I change a function name f to g in a module A (and also change function name in module B) and check gives error g not in scope in module B which uses function in module A.

rikvdkleij commented 8 years ago

@DanielG FYI, I noticed it's still a problem