Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add da-hls helper #13853

Merged
merged 5 commits into from
May 12, 2022
Merged

Add da-hls helper #13853

merged 5 commits into from
May 12, 2022

Conversation

akrmn
Copy link
Contributor

@akrmn akrmn commented May 11, 2022

current status

@hls-exe//haskell-language-server builds successfully, and using da-hls as the language server executable works fine for //compiler/damlc:damlc@ghci and its dependencies. That is, it doesn't work for test files yet. A crude way to work around this is to change //compiler/damlc:damlc@ghci in .hie-bios to the bazel target that includes the file of interest. I think the approach mentioned in tweag/rules_haskell#1489 might allow us to have a working hls for any .hs file in the repo without changing .hie-bios, but I'd rather do that later in a separate PR.

The linker errors from earlier are sidestepped by simply removing the following lines from the output of .hie-bios,

-Lbazel-out/darwin-opt/bin/external/com_github_madler_zlib/_ghc_pic_a
-Lbazel-out/darwin-opt/bin/external/grpc_haskell_core_cbits
-lmerged_cbits

I'm not sure how to justify it but it seems to work. My guess is that attempting to run code that uses these libs, for instance by calling a function from zlib in an hls-eval-plugin comment (-- >>>), will crash the server, but that's unlikely compared to the other hls use cases.

Finally, I managed to fix the Could not find module errors by using src_strip_prefix in da_haskell_librarys to remove any prefixes (e.g. src or lib).

previously

@hls-exe//haskell-language-server builds successfully, but actually using da-hls as the language server executable results in a bunch of errors like this one:

Unexpected usage error
User-specified static library could not be loaded (bazel-out/darwin-opt/bin/external/com_github_madler_zlib/_ghc_pic_a/libz.a)
Loading static libraries is not supported in this configuration.
Try using a dynamic library instead.

I tried defining a cc_library libz-dyn in 3rdparty/c/zlib.BUILD, identical to libz except with linkstatic = False, while removing the line

-Lbazel-out/darwin-opt/bin/external/com_github_madler_zlib/_ghc_pic_a

from the output of .hie-bios, but then the errors referred to libmerged_cbits.a:

Unexpected usage error
User-specified static library could not be loaded (bazel-out/darwin-opt/bin/external/grpc_haskell_core_cbits/libmerged_cbits.a)
Loading static libraries is not supported in this configuration.
Try using a dynamic library instead.

I tried to exclude those by removing the following lines from the output of .hie-bios,

-Lbazel-out/darwin-opt/bin/external/grpc_haskell_core_cbits
-lmerged_cbits

After that, all the remaining errors are bogus Could not find module errors for modules which do exist. At first I thought this was related to generated .hs files, for instance Com.Daml.DamlLfDev.DamlLf1, but that one is fine. The problem seems to be with some modules that import other modules from the same package; modules that only import modules from other packages work fine. Still, there does seem to be a relation with the generated modules because packages without generated module appear to work entirely. In turn, that's probably an effect of just dropping the libraries, but I don't know how to force hls to use them dynamically.

@akrmn akrmn requested a review from cocreature May 11, 2022 10:41
dev-env/bin/da-ghcide Outdated Show resolved Hide resolved
stack-snapshot.yaml Outdated Show resolved Hide resolved
@akrmn akrmn marked this pull request as ready for review May 11, 2022 11:01
@akrmn akrmn requested a review from garyverhaegen-da as a code owner May 11, 2022 11:01
@cocreature
Copy link
Contributor

Still, there does seem to be a relation with the generated modules because packages

Maybe try playing around with experimental_from_binary for the generated packages https://api.haskell.build/haskell/defs.html#haskell_repl

@akrmn akrmn changed the title [WIP] Add da-hls helper Add da-hls helper May 11, 2022
@akrmn akrmn requested a review from a team May 11, 2022 13:37
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Thanks, I'd really like to see this working!

Copy link
Collaborator

@remyhaemmerle-da remyhaemmerle-da left a comment

Choose a reason for hiding this comment

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

Look reasonable.

@akrmn akrmn merged commit ad123f9 into main May 12, 2022
@akrmn akrmn deleted the hls branch May 12, 2022 08:53
Copy link
Contributor

@sofiafaro-da sofiafaro-da left a comment

Choose a reason for hiding this comment

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

Great work, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants