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

Upstream Mac M1 Stack issue causing run-haskell to fail for Stack projects

Open dapritchard opened this issue 3 years ago • 0 comments

When I run run-haskell for a Stack project I'm seemingly getting many segmentation faults, followed by a GHCi prompt for a GHCi session that wasn't invoked for with the correct command-line arguments.

The text in the *haskell* buffer resulting from a call to run-haskell looks something like the following (there are dozens of segmentation fault messages that are left out). Note that GHCi isn't loaded with a particular package component, even though one was specified via the haskell-process-args-stack-ghci variable in the buffer from which run-haskell was invoked.

Process haskell segmentation fault: 11

<many more segmentation fault messages omitted>

Process haskell segmentation fault: 11

* * * * * * * *
It isn't yet possible to load multiple packages into GHCi in all cases - see
https://ghc.haskell.org/trac/ghc/ticket/10827
* * * * * * * *

Configuring GHCi with the following packages: using-quickcheck, validating-numbers-into-words
GHCi, version 9.0.2: https://www.haskell.org/ghc/  :? for help

I'm an M1 Mac user, and what I believe is causing the problem is an upstream Stack issue that affects M1 Macs as described in this Stack GitHub issue. For example, if I run

(make-comint "haskell" "stack" nil "ghci" "using-quickcheck")

then I get a single reported Process haskell segmentation fault: 11. But if I run

(make-comint "haskell" "bash" nil "-c" "stack ghci using-quickcheck")

then things work as expected.

As a workaround I'm currently using a modified version of inferior-haskell-start-process to run GHCi through Stack as follows.

(defun inferior-haskell-start-process--stack-workaround ()
  "Mimics `inferior-haskell-start-process' but using a workaround to get Stack to work."
  (let* ((command (haskell-program-name-with-args))
         (args-string (mapconcat #'shell-quote-argument command " ")))
    (when inferior-haskell-root-dir
      (setq default-directory inferior-haskell-root-dir))
    (setq inferior-haskell-buffer
          (make-comint "haskell" "bash" nil "-c" args-string))
    (with-current-buffer inferior-haskell-buffer
      (inferior-haskell-mode)
      (run-hooks 'inferior-haskell-hook))))

dapritchard avatar Nov 11 '22 17:11 dapritchard