haskell-mode icon indicating copy to clipboard operation
haskell-mode copied to clipboard

haskell-process-get-repl-completions completely hangs Emacs if REPL is inside IO action

Open cobalamin opened this issue 8 years ago • 10 comments

I noticed this by using company-mode with the company-ghc backend. It's an easy way to reproduce this problem.

I have a hook to enable company-mode inside haskell-interactive-mode. It works great usually, but recently I've noticed that my entire Emacs sometimes freezes up. After some investigation, I noticed that this happens only when I'm inside an IO action and either waiting (company-mode by default triggers after a certain amount of time) or triggering the completion manually. A simple getLine is enough, but a forever $ putStrLn ... loop also works.

I don't think company-mode nor company-ghc are to blame here, since they seem to simply use haskell-process-get-repl-completions. I killed my GHC process and had a look at the log:

-> getLine
<- ghc: signal: 15

-> :complete repl "\nasd"
<- 0 0 "\n"

<- ghc: signal: 15
ghc: signal: 15

<- Leaving GHCi.
Leaving GHCi.

Event: "finished
"

Process reset.

(everything after ghc: signal 15 happens when I call kill <ghc-process-id> twice)

I noticed that this :complete repl ... call always occurs before REPL+Emacs start hanging. So I looked in my .emacs.d for files which send such a command, and haskell-process.el in haskell-mode showed up, specifically the haskell-process-get-repl-completions. And sure enough, when I insert a (debug) statement at the top of the function, I can see that this function is called when my problem would occur, and Emacs doesn't start hanging since it's not executing the rest.

This is possibly in some way related to https://github.com/haskell/haskell-mode/issues/871. However, I'm not in multiline mode. To make sure, I explicitly executed :unset +m before doing the same thing, and the problem still occurred.

Further info:

  • stack ghc -- --version: The Glorious Glasgow Haskell Compilation System, version 7.10.3
  • haskell-mode 20160518.945
  • M-x version: GNU Emacs 24.5.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21) of 2015-04-10 on builder10-9.porkrind.org
  • M-x eval-expression haskell-process-type: stack-ghci
  • stack --version: Version 1.0.4 x86_64

cobalamin avatar May 20 '16 07:05 cobalamin

Haskell mode uses singe REPL process for all tasks now. Hence, when you try to get completions while REPL is busy Emacs hangs. Same happens when REPL is in multiline mode (completion function hangs Emacs). So, basically REPL can handle only single action at a time. We discussed this issue few times, but no decision was made. The most terrible thing is that Haskell mode have Interactive mode and Inferior mode. I believe both of them serve for same purposes and must be merged into one non-blocking REPL backend. However they differ in details a bit and there is a lot of work to make things right. Personally I have no enough power right now to make any contributions.

geraldus avatar May 20 '16 11:05 geraldus

@geraldus Would using haskell-process-evaluating-p work in this case, at least to stop the hanging?

fice-t avatar May 28 '16 17:05 fice-t

@fice-t I don't know. Somebody have to test this.

geraldus avatar May 31 '16 11:05 geraldus

I tested it and it does detect it fine. Wrapping haskell-process-get-repl-completions in (if (haskell-process-evaluating-p process) nil ... seems to work. If it returned a special symbol (say 'evaluating) would that help the completion functions?

fice-t avatar Jun 01 '16 07:06 fice-t

Is there any workaround to make haskell-interactive-mode work with company-mode? I tried to use run this main function on haskell-interactive-mode, and it will hangs Emacs when I input every char . Forturnitly, C-g can make it restored to normal.

main = do
  input <- getLine
  putStrLn input

Eason0210 avatar Aug 05 '21 11:08 Eason0210

@Eason0210 same here, did you find any solution?

lastgosumatt avatar Dec 23 '21 14:12 lastgosumatt

@lastgosumatt The issue still exist. I use terminal to run such kind of code instead.

Eason0210 avatar Dec 24 '21 16:12 Eason0210

I tried to use corfu (a new completion front end) instead of company, It works well in haskell-interactive-mode.

Any one have some suggestions to fixed it, and make company work with haskell-interactive-mode?

Eason0210 avatar Jan 18 '22 02:01 Eason0210

same here, so the problem is company mode plu haskell-interactive-mode?

idhowardgj94 avatar Dec 29 '22 14:12 idhowardgj94

confirm that, work well if I close company mode.

idhowardgj94 avatar Dec 29 '22 14:12 idhowardgj94