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

Implement haskell_repl support for targets that have modules in them #1733

Merged
merged 13 commits into from
Jun 8, 2022

Conversation

googleson78
Copy link
Contributor

Fixes #1732

@googleson78
Copy link
Contributor Author

googleson78 commented Apr 28, 2022

TODO: tests

EDIT: I added one..?

@@ -548,6 +569,7 @@ def build_haskell_modules(
object files and the object files of their transitive module
dependencies. See Note [Narrowed Dependencies].
per_module_transitive_dyn_objects: like per_module_transitive_objects but for dyn_o files
repl_info: struct(source_files, boot_files, import_dirs, user_compile_flags)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this enough documentation? If not, how should I document the fields of the returned struct?

Copy link
Member

Choose a reason for hiding this comment

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

I would add some, to match the style of the doc for the other arguments. It looks you can indent it as it is done here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some docs here.

@@ -7,6 +7,7 @@ load(
)
load("//haskell:private/cc_libraries.bzl", "haskell_cc_libraries_aspect")

# TODO[GL] should we have repl_ghci_args here?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably not for now. Seems like something we can try to add later if a user wants it.

@googleson78 googleson78 force-pushed the 1732_repl-for-haskell-modules-targets branch from 205cb61 to 87ccbdf Compare May 4, 2022 12:06
Copy link
Contributor

@k1nkreet k1nkreet left a comment

Choose a reason for hiding this comment

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

Overall looks good to me

tests/haskell_module/repl/haskell_module_repl_test.go Outdated Show resolved Hide resolved
@googleson78
Copy link
Contributor Author

Now that #1731 is merged, I should take care of the import_dirs situation here (after rebasing).

@googleson78 googleson78 force-pushed the 1732_repl-for-haskell-modules-targets branch from 4e5b498 to 5dedb95 Compare May 13, 2022 13:05
@googleson78 googleson78 force-pushed the 1732_repl-for-haskell-modules-targets branch from 5dedb95 to 4cc50a1 Compare May 13, 2022 13:10
@pranaysashank
Copy link
Contributor

pranaysashank commented May 16, 2022

I just tested this PR on a local workspace with multiple packages, the repl target doesn't seem to build / include its dependencies.
Here is the workspace to test with https://github.com/pranaysashank/nd/tree/test-modules-repl

$ bazel run //package-b:package-b@repl
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
[1 of 2] Compiling PackageB.Mod2    ( package-b/src/PackageB/Mod2.hs, interpreted )

package-b/src/PackageB/Mod2.hs:4:1: error:
    Could not find module ‘PackageA.Mod2’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import qualified PackageA.Mod2
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
[1 of 2] Compiling PackageB.Mod2    ( package-b/src/PackageB/Mod2.hs, interpreted )

package-b/src/PackageB/Mod2.hs:4:1: error:
    Could not find module ‘PackageA.Mod2’
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import qualified PackageA.Mod2
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.

I guess this is still WIP, but this workspace could be useful for testing I suppose

@googleson78
Copy link
Contributor Author

Thanks a lot @pranaysashank. I'll look into it.

@googleson78
Copy link
Contributor Author

I just tried out your example repo and the repl starts up fine for me and loads modules, at least for package-a.

How are you running your repl?

Both bazel run //package-a:package-a@repl and defining an explicit haskell_repl target and doing bazel run //package-a:repl work for me.

@googleson78
Copy link
Contributor Author

Derp, I see. I'll look into why it doesn't work cross package.

@googleson78
Copy link
Contributor Author

Including your cross-library dependencies from package-a in the modules of the package-b haskell_library makes the repl work fine.

So this is either

  • an issue where we're not taking into account cross_library_deps somewhere for the repl target
  • a missing check to yell "things are missing from the modules attribute of your haskell_library"

Seeing as how the library builds without them included in there I assume it's the first one.

@pranaysashank
Copy link
Contributor

For the repl target, is it better to have behaviour similar to the normal build without modules attribute i.e. we build the cross package libraries that we depend on, instead of creating a repl with all the modules across packages.

Perhaps you're missing building narrowed_deps in the repl target.

@googleson78
Copy link
Contributor Author

After a lot of struggling with the "empty libs" mechanism, I managed to get your example working in my latest commit, 346cdd7, by propagating the repl aspect along narrowed_deps too.

I don't think this is the proper solution however, since this causes the repl target to rebuild all the modules in libraries specified in narrowed_deps, regardless if they are used.

@facundominguez can you offer some help here?

@googleson78
Copy link
Contributor Author

googleson78 commented May 26, 2022

TODO: I should also add your example as a test to the repo

EDIT: done

@googleson78
Copy link
Contributor Author

googleson78 commented May 26, 2022

After a short discussion with @facundominguez, it turns out it might not be possible or it might be rather complicated. I think it would be better to leave it as an open question for another issue, as something working slowly is better than not working at all.

haskell/repl.bzl Outdated
@@ -182,6 +182,7 @@ def _create_HaskellReplCollectInfo(target, ctx):

hs_info = target[HaskellInfo]

# TODO[GL]: do we need to also take into account narrowed_deps here, everywhere "deps" is checked?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

?

Copy link
Member

Choose a reason for hiding this comment

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

I would imagine it is necessary. To rehearse that we would need to add java dependencies to dependencies of Haskell libraries using modules.

@googleson78 googleson78 force-pushed the 1732_repl-for-haskell-modules-targets branch from e5c2025 to 90152f1 Compare May 27, 2022 09:09
@googleson78
Copy link
Contributor Author

googleson78 commented May 27, 2022

Re the run failures - one of them seems to be a flaky error the other one I'm not sure about - it passes locally 😿

@googleson78 googleson78 force-pushed the 1732_repl-for-haskell-modules-targets branch from e581c48 to 3f03379 Compare May 30, 2022 10:08
@facundominguez
Copy link
Member

The changes look good to me in intent, and given that the tests that have been added pass, the PR looks like a net improvement. I'm not versed in the aspects that get the repl working to foresee unknown issues.

The code that manages java and CC dependencies in libraries of narrowed_deps doesn't have a test yet. If you still have steam, it would be necessary to add such tests. Otherwise, just make a new issue to add them later.

@googleson78
Copy link
Contributor Author

Apart from the CC and java dependencies, it would also be nice to have tests for hie bios output. I'll try to add all three next week.

@googleson78
Copy link
Contributor Author

Actually, I can't seem to find tests for the normal repl usage with cc/java deps 😅 If they exist, can you point me to them? If not, I think we should leave this as a separate issue (add tests for both "normal" and module usage).

@facundominguez
Copy link
Member

@aherrmann is this good to merge?

Copy link
Member

@aherrmann aherrmann left a comment

Choose a reason for hiding this comment

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

Yes, that looks great. Thank you @googleson78!

@facundominguez facundominguez added the merge-queue merge on green CI label Jun 8, 2022
@mergify mergify bot merged commit d3caf0c into master Jun 8, 2022
@mergify mergify bot deleted the 1732_repl-for-haskell-modules-targets branch June 8, 2022 14:18
@mergify mergify bot removed the merge-queue merge on green CI label Jun 8, 2022
@googleson78
Copy link
Contributor Author

Opened #1756 and #1757

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.

Extend repl aspect to support haskell_module targets
6 participants