tek / incipit

A Prelude for Polysemy
1 stars 0 forks source link

How to hide Prelude? #1

Open adlaika opened 2 years ago

adlaika commented 2 years ago

After seeing the following error trying to stack build a project that relies on polysemy-conc (and thus on incipit-core)...

unix-time              > configure
unix-time              > [1 of 2] Compiling Main             ( /private/var/folders/5t/7vlbcgyd6_73wtq7gjx35g3r0000gn/T/stack-3ae17c9d728419f4/unix-time-0.4.7/Setup.hs, /private/var/folders/5t/7vlbcgyd6_73wtq7gjx35g3r0000gn/T/stack-3ae17c9d728419f4/unix-time-0.4.7/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup/Main.o )
unix-time              >
unix-time              > /private/var/folders/5t/7vlbcgyd6_73wtq7gjx35g3r0000gn/T/stack-3ae17c9d728419f4/unix-time-0.4.7/Setup.hs:1:8: error:
unix-time              >     Ambiguous module name ‘Prelude’:
unix-time              >       it was found in multiple packages:
unix-time              >       base-4.15.1.0 incipit-base-0.2.0.0 incipit-core-0.2.0.0
unix-time              >   |
unix-time              > 1 | module Main (main) where
unix-time              >   |        ^^^^
Progress 1/15

--  While building package unix-time-0.4.7 (scroll up to its section to see the error) using:
      /Users/adlai/.stack/programs/aarch64-osx/ghc-9.0.2/bin/ghc-9.0.2 --make -odir /private/var/folders/5t/7vlbcgyd6_73wtq7gjx35g3r0000gn/T/stack-3ae17c9d728419f4/unix-time-0.4.7/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup -hidir /private/var/folders/5t/7vlbcgyd6_73wtq7gjx35g3r0000gn/T/stack-3ae17c9d728419f4/unix-time-0.4.7/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup -i -i. -package=Cabal-3.4.1.0 -clear-package-db -global-package-db -package-db=/Users/adlai/.stack/snapshots/aarch64-osx/4e2abd3a1f3c6ee84ca3952d068f82fc24a4e1b9a3ccaae9959e1791b6a5f81b/9.0.2/pkgdb /private/var/folders/5t/7vlbcgyd6_73wtq7gjx35g3r0000gn/T/stack-3ae17c9d728419f4/unix-time-0.4.7/Setup.hs /Users/adlai/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -main-is StackSetupShim.mainOverride -o /private/var/folders/5t/7vlbcgyd6_73wtq7gjx35g3r0000gn/T/stack-3ae17c9d728419f4/unix-time-0.4.7/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup/setup -threaded
    Process exited with code: ExitFailure 1

...I tried the README's suggestion in package.yaml's dependencies block:

- name: base 
    version: '>= 4.14.1.0'
    mixin:
      - hiding (Prelude)

However, I'm still getting the same error. Is there something I'm missing? Thanks!

tek commented 2 years ago

I've seen someone else have this exact problem, also happening during build of unix-time. I tried to reproduce with their test case but the issue didn't occur. It looks like Stack is adding the extra-depends of the main project to the dependencies of unix-time.

Have you tried wiping ~/.stack or ~/.cabal?

tek commented 2 years ago

oh and which stack version are you using?

adlaika commented 2 years ago

oh and which stack version are you using?

2.7.5

tek commented 2 years ago

https://github.com/qwbarch/ambiguous-prelude

this is the reproducer of the other reporter of this bug, can you verify it happens for you there as well?

tek commented 2 years ago

just tried again, stack 2.7.5, clean cache. built successfully

adlaika commented 2 years ago

https://github.com/qwbarch/ambiguous-prelude

this is the reproducer of the other reporter of this bug, can you verify it happens for you there as well?

I was able to build this project successfully (after accounting for a Mac M1 specific problem that I'm 99% sure is unrelated).

adlaika commented 2 years ago

Attempting with the same LTS as my project.

tek commented 2 years ago

huh!

@qwbarch was using a Debian VM, so it's definitely unrelated to MacOS

tek commented 2 years ago

do you have a repo I can try?

adlaika commented 2 years ago

I've seen someone else have this exact problem, also happening during build of unix-time. I tried to reproduce with their test case but the issue didn't occur. It looks like Stack is adding the extra-depends of the main project to the dependencies of unix-time.

Have you tried wiping ~/.stack or ~/.cabal?

Haven't tried this yet, but I did stack clean && stack purge at least once.

adlaika commented 2 years ago

do you have a repo I can try?

I'll try to get you a minimal example after lunch.

adlaika commented 2 years ago

Attempting with the same LTS as my project.

This worked as well.

tek commented 2 years ago

I found this: https://github.com/commercialhaskell/stack/issues/5414

tek commented 2 years ago

might be worth trying:

$ rm -rf ~/.stack/snapshots/...
$ rm -rf .stack-work
$ stack build unix-time
$ stack build
tek commented 2 years ago

:sweat_smile: Stack's hermeticity appears to be severely lacking, I guess :slightly_smiling_face:

adlaika commented 2 years ago

Yeah, looks like that worked--build is well past that point now. Had to do it again for network.

tek commented 2 years ago

oh wow. that's also the package that failed in the linked issue

tek commented 2 years ago

very curious, given that alternative preludes aren't exactly an exotic concept. wonder if Relude et al. are doing something to prevent that

adlaika commented 2 years ago

very curious, given that alternative preludes aren't exactly an exotic concept. wonder if Relude et al. are doing something to prevent that

we use classy-prelude, which exports ClassyPrelude instead.

tek commented 2 years ago

oh right

adlaika commented 2 years ago

So...now I'm getting:

➜ stack build
Building all executables for `nauvoo' once. After a successful build of all of them, only specified executables will be rebuilt.
nauvoo> build (lib + exe)
Preprocessing library for nauvoo-0.0.0.1..
Building library for nauvoo-0.0.0.1..
[ 15 of 198] Compiling Paths_nauvoo

/Users/adlai/gits/astro/nauvoo/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/build/autogen/Paths_nauvoo.hs:41:53: error:
    Variable not in scope: return :: FilePath -> IO String
   |
41 | getBinDir = catchIO (getEnv "nauvoo_bindir") (\_ -> return bindir)
   |                                                     ^^^^^^

/Users/adlai/gits/astro/nauvoo/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/build/autogen/Paths_nauvoo.hs:42:53: error:
    Variable not in scope: return :: FilePath -> IO String
   |
42 | getLibDir = catchIO (getEnv "nauvoo_libdir") (\_ -> return libdir)
   |                                                     ^^^^^^

/Users/adlai/gits/astro/nauvoo/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/build/autogen/Paths_nauvoo.hs:43:59: error:
    Variable not in scope: return :: FilePath -> IO String
   |
43 | getDynLibDir = catchIO (getEnv "nauvoo_dynlibdir") (\_ -> return dynlibdir)
   |                                                           ^^^^^^

/Users/adlai/gits/astro/nauvoo/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/build/autogen/Paths_nauvoo.hs:44:55: error:
    Variable not in scope: return :: FilePath -> IO String
   |
44 | getDataDir = catchIO (getEnv "nauvoo_datadir") (\_ -> return datadir)
   |                                                       ^^^^^^

/Users/adlai/gits/astro/nauvoo/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/build/autogen/Paths_nauvoo.hs:45:61: error:
    Variable not in scope: return :: FilePath -> IO String
   |
45 | getLibexecDir = catchIO (getEnv "nauvoo_libexecdir") (\_ -> return libexecdir)
   |                                                             ^^^^^^

/Users/adlai/gits/astro/nauvoo/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/build/autogen/Paths_nauvoo.hs:46:61: error:
    Variable not in scope: return :: FilePath -> IO String
   |
46 | getSysconfDir = catchIO (getEnv "nauvoo_sysconfdir") (\_ -> return sysconfdir)
   |                                                             ^^^^^^

/Users/adlai/gits/astro/nauvoo/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/build/autogen/Paths_nauvoo.hs:51:3: error:
    Variable not in scope: return :: [Char] -> IO FilePath
   |
51 |   return (dir ++ "/" ++ name)
   |   ^^^^^^

--  While building package nauvoo-0.0.0.1 (scroll up to its section to see the error) using:
      /Users/adlai/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.4.1.0 build lib:nauvoo exe:nauvoo exe:nauvoo-integration --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

...which I assume is the result of not having some Prelude in scope somewhere?

adlaika commented 2 years ago

but perhaps is unrelated?

tek commented 2 years ago

are you using Incipit as your prelude explicitly, i.e. specifying hiding (Prelude) for base?

tek commented 2 years ago

I'm not suggesting you do that, but if so, you might want to disable the Paths_nauvoo module with

  when:
    condition: false
    generated-other-modules:
      - Paths_nauvoo

in your hpack file

tek commented 2 years ago

this is a more general issue, discussed frequently on the cabal issue tracker, like here: https://github.com/haskell/cabal/issues/7761

tek commented 2 years ago

oh right, you're using classy-prelude. that should apply for that as well, I think

adlaika commented 2 years ago

I'm not suggesting you do that, but if so, you might want to disable the Paths_nauvoo module with

  when:
    condition: false
    generated-other-modules:
      - Paths_nauvoo

in your hpack file

No luck with either this or the solution from #7761:

library paths-nauvoo
  default-language: Haskell2010
  build-depends: base
  autogen-modules: Paths_nauvoo
  exposed-modules: Paths_nauvoo
library
...
  build-depends:
    ...
    , paths-nauvoo
...

Is it necessary to wipe ~/.stack and ~/.cabal between every attempt?

tek commented 2 years ago

no, this problem should be local to your project. let's first establish the circumstances – did I understand correctly that you're using classy-prelude, with something like

dependencies:
  - name: base
    mixin: (hiding Prelude)
  - name: classy-prelude
    mixin: (ClassyPrelude as Prelude)

Also, nauvoo is the project you're working on, not a dep?

If so, return appears to be exported by ClassyPrelude, which suggests that there is another weird interaction with incipit caused by stack. If that's the case, I'd definitely have to reevaluate the utility of providing a convienence Prelude module here.

tek commented 2 years ago

still strange that this only surfaces for the Paths module though.

tek commented 2 years ago

btw my hack for hiding Paths has to be added to both the library and all executables and tests. you can verify that it works if there is no mention of Paths in the generated nauvoo.cabal

adlaika commented 2 years ago

Sorry, I wasn't clear--we don't use a mixin for classy-prelude. We just import ClassyPrelude where needed.

tek commented 2 years ago

ok, that should have the same effect

adlaika commented 2 years ago

And yes--nauvoo is our project.

adlaika commented 2 years ago

btw my hack for hiding Paths has to be added to both the library and all executables and tests. you can verify that it works if there is no mention of Paths in the generated nauvoo.cabal

I'll try this.

tek commented 2 years ago

oh, you import ClassyPrelude when needed? as in, you still use Prelude from base by default?

adlaika commented 2 years ago

As far as I can tell, there's no mention of Paths in our nauvoo.cabal. That makes sense, since I actually generated it via hpack with

dependencies:
...
  - paths-nauvoo

verbatim: |
  library paths-nauvoo
    default-language: Haskell2010
    build-depends: base
    autogen-modules: Paths_nauvoo
    exposed-modules: Paths_nauvoo

...then library, executable, and tests all depend on the top-level dependencies

adlaika commented 2 years ago

oh, you import ClassyPrelude when needed? as in, you still use Prelude from base by default?

No, we use NoImplicitPrelude.

adlaika commented 2 years ago

(thank you for your time and patience, btw! really appreciate it :) )

tek commented 2 years ago

I see. so the default-visible Prelude used by Paths should definitely be from base. In any case, this is pretty bad UX, I will release a new version of all the packages without an exported Prelude in incipit-*. Might take a few days though :)

tek commented 2 years ago

and thank you for the valuable feedback :smile:

adlaika commented 2 years ago

That's awesome! Once polysemy-conc uses the new version, that'll solve our problem :)

tek commented 2 years ago

I just noticed the file /home/tek/.ghc/x86_64-linux-9.0.2/environments/default, seems to be generated by stack and contains a few package ids. That might be the source of the contamination.

adlaika commented 2 years ago

hmm. my ~/.ghc/ folder is empty. Maybe because I use ghcup?

tek commented 2 years ago

might be!

adlaika commented 2 years ago

As far as I can tell, my ~/.ghcup doesn't contain any equivalent to /home/tek/.ghc/x86_64-linux-9.0.2/environments/default

tek commented 2 years ago

@adlaika FYI all the libs have been released!

adlaika commented 2 years ago

Wow, quick! You rock, thanks so much for all the help :)

tek commented 2 years ago

please yell if anything still behaves unexpectedly!

adlaika commented 2 years ago

Will do--I'm out of town this weekend, but I'll give it a shot on Monday.

On Sat, Jun 11, 2022, 11:50 AM Torsten Schmits @.***> wrote:

please yell if anything still behaves unexpectedly!

— Reply to this email directly, view it on GitHub https://github.com/tek/incipit/issues/1#issuecomment-1152980397, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB7APJAM6QWX66ZKSZNSOLVOTNV5ANCNFSM5YOVRTVQ . You are receiving this because you were mentioned.Message ID: @.***>