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

run repl loading extra modules but not their dependencies #471

Closed
ghorn opened this issue Oct 29, 2018 · 4 comments
Closed

run repl loading extra modules but not their dependencies #471

ghorn opened this issue Oct 29, 2018 · 4 comments
Assignees

Comments

@ghorn
Copy link
Contributor

ghorn commented Oct 29, 2018

If I bazel run //:b-repl and //:b depends on //:a, ghci seems to load all the modules in //:a and //:b, but only the depencies of //:b. This then fails when it loads a module from //:a because it's missing some dependency of //:a that is not a dependency of //:b.

@Profpatsch Profpatsch added this to the REPL improvements milestone Jan 9, 2019
@SebastianKG SebastianKG self-assigned this Jan 14, 2019
@SebastianKG
Copy link
Contributor

I've attempted to reproduce this by modifying existing tests in this repository, but I haven't been able to. Please let me know if I'm not testing what you had intended. I changed four files, like so:

➡️ //test/binary-simple/BUILD

...

haskell_test(
    name = "binary-simple",
    srcs = ["Main.hs"],
    visibility = ["//visibility:public"],
    deps = [
      "//tests/binary-with-lib:lib", 
      "@hackage//:base"
    ],
)

...

➡️ //test/binary-simple/Main.hs

import Lib (value)

main = print value

➡️ //test/binary-with-lib/BUILD

...

haskell_library(
  name = "lib",
  srcs = glob(["src/*.hs"]),
  visibility = ["//visibility:public"],
  src_strip_prefix = "src",
  deps = [
    "@hackage//:text"
  ]
)

...

➡️ //test/binary-with-lib/src/Lib.hs

{-# LANGUAGE NoImplicitPrelude #-}

module Lib
  ( value
  ) where

import Data.Text (Text, pack)

value :: Text
value = pack "a string"

With all of these changes, I ran:

bazel run //tests/binary-simple:binary-simple@repl

The shell started up as expected, there were no errors. Then, I used :m Lib to load the library from the other package, and it loaded successfully, even though it uses text while the main package does not. I can successfully call the exported function.

Prelude Lib> value
"a string"

@ghorn
Copy link
Contributor Author

ghorn commented Mar 7, 2019

OK I have a reproduction of the issue. There are three haskell sources.

-- rh_ghci_bug_a/src/A/A.hs
module A.A ( a ) where

a :: ()
a = ()
-- rh_ghci_bug_bc/src/BC/B.hs
module BC.B ( b ) where

import A.A ( a )

b :: ()
b = a
-- rh_ghci_bug_bc/src/BC/C.hs
module BC.C ( c ) where

import BC.B ( b )

c :: ()
c = b

and two build files

# rh_ghci_bug_a/BUILD.bazel
package(default_visibility = ["//visibility:public"])

load(
    "@io_tweag_rules_haskell//haskell:haskell.bzl",
    "haskell_library",
)

haskell_library(
    name = "a",
    srcs = [
        "src/A/A.hs",
    ],
    src_strip_prefix = "src",
    deps = [
        "//ghc_pkgs:base",
    ],
)
package(default_visibility = ["//visibility:public"])

load(
    "@io_tweag_rules_haskell//haskell:haskell.bzl",
    "haskell_library",
)

haskell_library(
    name = "b",
    srcs = [
        "src/BC/B.hs",
    ],
    src_strip_prefix = "src",
    deps = [
        "//rh_ghci_bug_a:a",
        "//ghc_pkgs:base",
    ],
)

haskell_library(
    name = "c",
    srcs = [
        "src/BC/C.hs",
    ],
    src_strip_prefix = "src",
    deps = [
        ":b",
        # "//rh_ghci_bug_a:a", explicitly adding the transitive dependency fixes it
        "//ghc_pkgs:base",
    ],
)

the directory structure is:

$ tree rh_ghci_bug_*
rh_ghci_bug_a
├── BUILD.bazel
└── src
    └── A
        └── A.hs
rh_ghci_bug_bc
├── BUILD.bazel
└── src
    └── BC
        ├── B.hs
        └── C.hs

so C depends on B which depends on A.

bazel build //rh_ghci_bug_bc:c works fine but bazel run //rh_ghci_bug_bc:c-repl fails with:

[1 of 2] Compiling BC.B             ( rh_ghci_bug_bc/src/BC/B.hs, interpreted )

rh_ghci_bug_bc/src/BC/B.hs:5:1: error:
    Could not load module ‘A.A’
    It is a member of the hidden package ‘a’.
    You can run ‘:set -package a’ to expose it.
    (Note: this unloads all the modules in the current scope.)
    Use -v to see a list of the files searched for.
  |
5 | import A.A ( a )
  | ^^^^^^^^^^^^^^^^
Failed, no modules loaded.
Loaded GHCi configuration from bazel-out/k8-fastbuild/bin/rh_ghci_bug_bc/ghci-repl-script-c

I think the root cause is that ghci is loading B.hs as if it is in library //rh_ghci_bug_bc:c. The desired behavior is that B.hs is compiled as a separate library and ghci only loads modules in //rh_ghci_bug_bc:c.

aherrmann added a commit that referenced this issue Mar 11, 2019
aherrmann added a commit that referenced this issue Mar 11, 2019
```
bazel run //tests/repro/rh_ghci_bug_bc:c@repl
```

fails as expected.

```
bazel run //tests/repro/rh_ghci_bug_c:c_repl
```

succeeds.
aherrmann added a commit that referenced this issue Mar 12, 2019
aherrmann added a commit that referenced this issue Mar 14, 2019
aherrmann added a commit that referenced this issue Mar 14, 2019
@mboes mboes removed this from the REPL improvements milestone Apr 6, 2019
@Profpatsch
Copy link
Contributor

@aherrmann did your commit above solve this problem?

@aherrmann
Copy link
Member

@Profpatsch Yes, I think so. On current master this is part of the test suite and can be verified with

$ bazel run //tests/multi_repl:c_multi_repl
$ bazel run //tests/multi_repl:c_only_repl

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

No branches or pull requests

5 participants