Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Find the libdir directory of ghc at run-time #1496

Merged
merged 7 commits into from Dec 29, 2019

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented Dec 23, 2019

Fixes #1495

Finds the libdir directory of the appropriate ghc version at run-time.
Introduces the isCabalCradle predicate to complement the isStackCradle

  • Documentation is missing.
  • getProjectGhcVersion can be expressed with execProjectGhc

While it works in manual test-cases I have the following considerations:

  • Cradle initialisation happens in too many places. At least the one in "NotInitialized" can be skipped, imo.
  • We might select the wrong ghc version in certain circumstances.
  • I dont know what happens if the system lib dir is Nothing

mGhcPath <- getProjectGhcPath crdl
case mGhcPath of
Nothing -> return Nothing
Just ghcPath -> catch (Just <$> tryCommand (ghcPath ++ " --print-libdir")) $ \(_ :: IOException) -> return Nothing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching and discarding the exception is probably a bad thing.

At the very least we should log something on failure.

Is the the exception that would be thrown if GHC is not installed? Do we report it gracefully elsewhere if that is the case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, not yet. Not sure how to properly report it, since it is executed before the server is actually started, e.g. When we start the GHC thread

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should re-look at this startup sequencing, and launch the various processes once the initialize message comes in, while processing it.

That way we can determine the cradle according to the passed-in project root, and we have a way to report errors. The spec says we are not to process anything before initialization is complete anyway, so it is an appropriate place to do it.

cc @bubba @mpickering

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think the LSP server should be bootstrapped before the dispatcher. And while we're at it, we should provide an easier way to log/show these messages via LSP. Presumably some sort of transformer stack hierarchy:

IO a < LspM a < IdeM a < IdeGhcM a

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And perhaps we should rename onStartup to onInitialize, and make it clear where in the server life cycle it operates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so that is actuallly fine as-is? Just need to refactor when the cradle is loaded?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this change should also resolve haskell/vscode-haskell#164

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely. For hie-bios multi-cradles, also #1490 needs to be resolved.

@fendor fendor force-pushed the dont-depend-on-ghc-at-run-time branch from 862da6b to 536edec Compare December 23, 2019 21:10
@lukel97 lukel97 added this to In progress in Dec 2019 Release via automation Dec 24, 2019
mGhcPath <- getProjectGhcPath crdl
case mGhcPath of
Nothing -> return Nothing
Just ghcPath -> catch (Just <$> tryCommand (ghcPath ++ " --print-libdir")) $ \(_ :: IOException) -> return Nothing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think the LSP server should be bootstrapped before the dispatcher. And while we're at it, we should provide an easier way to log/show these messages via LSP. Presumably some sort of transformer stack hierarchy:

IO a < LspM a < IdeM a < IdeGhcM a

.circleci/config.yml Outdated Show resolved Hide resolved
@fendor fendor requested review from alanz and lukel97 December 27, 2019 12:25
src/Haskell/Ide/Engine/Server.hs Outdated Show resolved Hide resolved
src/Haskell/Ide/Engine/Server.hs Outdated Show resolved Hide resolved
test/functional/HieBiosSpec.hs Outdated Show resolved Hide resolved
test/functional/HieBiosSpec.hs Outdated Show resolved Hide resolved
@fendor fendor force-pushed the dont-depend-on-ghc-at-run-time branch from bb361f6 to 61f9391 Compare December 27, 2019 13:34
@fendor fendor changed the title WIP: Find the libdir directory of ghc at run-time Find the libdir directory of ghc at run-time Dec 27, 2019
@fendor fendor force-pushed the dont-depend-on-ghc-at-run-time branch 9 times, most recently from ad9e3a5 to fe25526 Compare December 28, 2019 18:07
@fendor fendor force-pushed the dont-depend-on-ghc-at-run-time branch from fe25526 to 21f894a Compare December 28, 2019 18:08
hie-plugin-api/Haskell/Ide/Engine/Cradle.hs Outdated Show resolved Hide resolved
hie-plugin-api/Haskell/Ide/Engine/Cradle.hs Outdated Show resolved Hide resolved
src/Haskell/Ide/Engine/Scheduler.hs Show resolved Hide resolved
src/Haskell/Ide/Engine/Version.hs Outdated Show resolved Hide resolved
@fendor
Copy link
Collaborator Author

fendor commented Dec 29, 2019

@bubba thanks for fixing the tests!
PR is ready for merge, waiting for some reviews now.

Comment on lines +194 to +212
flip labelThread "scheduler" =<<
(forkIO (
Scheduler.runScheduler scheduler errorHandler callbackHandler (Just lf) mcradle
`E.catch` \(e :: E.SomeException) ->
(errorm $ "Scheduler thread exited unexpectedly: " ++ show e)
))
flip labelThread "reactor" =<<
(forkIO (
reactorFunc
`E.catch` \(e :: E.SomeException) ->
(errorm $ "Reactor thread exited unexpectedly: " ++ show e)
))
flip labelThread "diagnostics" =<<
(forkIO (
diagnosticsQueue tr
`E.catch` \(e :: E.SomeException) ->
(errorm $ "Diagnostic thread exited unexpectedly: " ++ show e)
))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some future date we should go back to launching these threads with race rather than forkIO, so if one does die, we know immediately, and can see something in the log. With this setup it can still limp along.

@alanz alanz merged commit 310450e into haskell:master Dec 29, 2019
Dec 2019 Release automation moved this from In progress to Done Dec 29, 2019
alanz added a commit to alanz/haskell-ide-engine that referenced this pull request Dec 29, 2019
alanz added a commit that referenced this pull request Dec 29, 2019
Adapt GhcModPluginSpec after merge of #1496
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

HIE crashes if there is no "ghc" on the path with explicit stack config
3 participants