Repository navigation
Closed
Labels
Description
Describe the bug
I have the following cabal file:
cabal-version: 2.0
name: unpacked-example
version: 0.1.0.0
build-type: Simple
library example
default-language: Haskell2010
hs-source-dirs: example
exposed-modules: Int
build-depends: base
executable unpacked-set-example
default-language: Haskell2010
main-is: example/Main.hs
build-depends: base, unpacked-containers, example
mixins: unpacked-containers (Set as Int.Set) requires (Key as Int)
And the following source files:
$ cat example/Int.hs
module Int where
type Key = Int
$ cat example/Main.hs
module Main where
import Int.Set
ten :: Set
ten = fromList [1..10]
main :: IO ()
main = print ten
I can't build it and cannot figure out what is wrong. Here is the cabal build message:
$ cabal v2-build
Build profile: -w ghc-8.8.3 -O1
In order, the following will be built (use -v for more details):
- unpacked-containers-0 (lib with Key=unpacked-example-0.1.0.0-inplace-example:Int) (requires build)
- unpacked-example-0.1.0.0 (exe:unpacked-set-example) (first run)
Starting unpacked-containers-0 (lib)
Failed to build unpacked-containers-0. The failure occurred during the
configure step.
Build log (
/Users/harendra/.cabal/logs/ghc-8.8.3/npckd-cntnrs-0-8f491d38+B2PfsuvwtufFrJw0XqUoXM.log
):
Configuring library instantiated with
Key = unpacked-example-0.1.0.0-inplace-example:Int
for unpacked-containers-0..
Warning: The package has an extraneous version range for a dependency on an
internal library: unpacked-containers -any && ==0. This version range includes
the current package but isn't needed as the current package's library will
always be used.
Error:
The following packages are broken because other packages they depend on are missing. These broken packages must be rebuilt before they can be used.
planned package unpacked-containers-0 is broken due to missing package unpacked-example-0.1.0.0-inplace-example
cabal: Failed to build unpacked-containers-0 (which is required by
exe:unpacked-set-example from unpacked-example-0.1.0.0). See the build log
above for details.
To Reproduce
Steps to reproduce the behavior:
Run cabal v2-build with above configuration.
Expected behavior
cabal build should succeed or print a message which can clearly pinpoint what is wrong. I tried going through the docs as well, but could not figure out what is wrong here. Did many trial and errors as well, but no luck with compiling this example.
System information
- Operating system: Mac OSX
- cabal version: 3.2
- ghc version: 8.8.3
Activity
phadej commentedon May 22, 2020
There is #6005 which mentions problems with
unpacked-containers, but it's marked as fixed. cc @ezyangharendra-kumar commentedon May 25, 2020
This has stalled my work, I would like to know if there is a workaround, how can I use unpacked-containers in my project?
ezyang commentedon May 26, 2020
I agree this looks pretty similar to #6317 but given the cabal and ghc versions quoted in this ticket you should have this fix already.
ezyang commentedon May 26, 2020
@harendra-kumar do you think you would have time to do a bisect for this problem?
harendra-kumar commentedon May 28, 2020
@ezyang I can try, what do you suggest? Maybe, I can try running cabal at the commit right after that fix.
harendra-kumar commentedon May 28, 2020
I built cabal at the commit in that PR and it still fails with the same error. I tried with ghc-8.6.5 as well, but no luck.
The example I am building is exactly copied from the unpacked-containers package. Surprisingly, when I build unpacked-containers package itself which contains this example, it builds perfectly well. But this example which uses unpacked-containers as a dependency does not build.
Based on the above, I guessed that if I add
unpacked-containersto mycabal.projectit might work and it worked! The problem seems to occur only when it is used as an external dependency.ezyang commentedon May 28, 2020
Yeah, sounds like I didn't manage to completely nail it in that PR then. Please use this workaround for now, I'll take a look this weekend.
Mikolaj commentedon May 8, 2021
@harendra-kumar: thank you again for reporting this; just in case: does the bug persist? [edit: and with which cabal version?]
example for cabal bug 6835
danidiaz commentedon May 27, 2021
I've encountered the same problem with my moo-nad package. To reproduce:
The code that emits the error is in
Cabal/Distribution/Backpack/Configure.hs, the functiontoComponentLocalBuildInfos. Which seems to create aGraph (Either InstalledPackageInfo ReadyComponent)which according to the comments is:So it seems that the graph is made of already compiled and installed external packages (from the store?) or
ReadyComponents that can be compiled (should the products of compilation go in the store as well?)In my case, the "keys" in the graph, along with their dependencies, are:
In particular, the "fully instantiated"
ReadyComponentmoo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e+L8yXyvV74rTHJagYNPv9JNdepends on the local compilation unitmoo-oops-0.1.0.2-inplace-example-impl-x, but that unit doesn't have its own node in the graph, and that triggers the error.Also, in the full entry for
moo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e+L8yXyvV74rTHJagYNPv9JN, if we look at the fieldinstc_insts_depsthat contains detailed descriptions about the dependencies, we findSo it seems the bug happens earlier. Perhaps the graph should have an entry for
moo-oops-0.1.0.2-inplace-example-impl-x, and it should be "munged" correctly. However, it's an inplace unit. Does it really belong to this graph, which seems to be for "external" dependencies?Mikolaj commentedon May 27, 2021
@danidiaz: thank you for the report. I see GHC is 9.0. Is cabal 3.4? Do you get the same error with current master branch of cabal?
Could anybody reproduce, please?
danidiaz commentedon May 27, 2021
I'm using GHC 9.0.1 and cabal 3.4. I'm having trouble compiling the current
masterbranch, so I didn't try with it.Mikolaj commentedon May 27, 2021
Thank you for the details. Master branch should compile fine, so feel free to open an issue if it doesn't. Or if I can help otherwise, please elaborate here.
harendra-kumar commentedon May 28, 2021
@Mikolaj the original example I gave above is pretty simple and quick to reproduce. I tried it again with cabal built from the master branch but it failed with the same message.
4 remaining items
danidiaz commentedon May 29, 2021
So it seems that cabal-install generates a nice
dist-newstyle/cache/plan.jsonfile with the build plan. I wish I had known this earlier. The plan doesn't seem to show which which implementation libraries are used for each "fully instantiated" component, though.Mikolaj commentedon May 29, 2021
Indeed,
git grep plan.jsonshows thatplan.jsonis never mentioned in cabal docs except inPerhaps it would make sense to add it, e.g., wherever 'build plan' appears in docs:
Regarding
plan.jsonbeing faulty and it either reflecting or not some problems inside cabal's internal build plan, there is a comment incabal-install/src/Distribution/Client/ProjectPlanOutput.hsthat may be relevant, but I don't know what it means exactly:danidiaz commentedon May 30, 2021
Judging from comments in the code, an "improved" plan is one for which package references have info about the actual locations in the store:
I don't think plan.json is faulty, it's just that it doesn't show everything I need. I (hackishly) tweaked the
elaboratedPackageToJfunction to show additional stuff relevant to this bug:Then I searched in the generated
plan.jsonfor a package id of the formmoo-nad-0.1.0.2-stuff+someohterstuff. The+in package ids seems to identify components that are "instantiated" from an indefinite component likemoo-nad-0.1.0.2-stuffplus some implementation library.For my buggy case, I have:
So it seems that the package db stacks are set up incorrectly, there's no local package database. The instantiation with
Moofrommoo-nad-x-0.1.0.2-inplace-example-impl-xseems to be correct though.For my happy case, I have:
danidiaz commentedon May 30, 2021
The function
writePlanExternalRepresentationthat writesplan.jsonis called toward the end of the top-level functionDistribution.Client.Project.Planning.rebuildInstallPlan. Before that, the rebuild function callsphaseElaboratePlan, which does two things:Call
elaborateInstallPlan, which creates a preliminary version of the elaborated plan.The decision to put a compilation unit into the Cabal store or into
dist-newstyleis done here, with the help of theshouldBuildInplaceOnlyfunction. The choice affectselabBuildStyle,buildAndRegisterDbsandpkgInstalledId.However, this preliminary version of the plan doesn't include compilation units that are the "instantiated" form of indefinite components. As one comment says:
Call
instantiateInstallPlan, that adds the instantiated packages to the plan returned byelaborateInstallPlan.For example, in my case the verbose log output shows the lines:
If we move the logging statement
to before the call to
instantiateInstallPlan,moo-nad-0.1.0.2-inplace+CXHgquAbAM34wnUHImMH6rceases to appear.The problem seems to be that
instantiateInstallPlan(more preciselyinstantiateComponent) always preserves the global/local choices made duringelaborateInstallPlan. But even if an indefinite component is global, if the implementation is local the instantiated package should be local.instantiateInstallPlanneeds to take that into account.ezyang commentedon May 31, 2021
Thanks for this work, @danidiaz, I think I agree with your diagnosis of the situation. Need to adjust instantiateInstallPlan to turn instantiated packages into local ones if any of the packages it is instantiated with is local. Might require some surgery at the code here though...
ezyang commentedon May 31, 2021
Here is a crappy patch which makes moo-nad-x successfully compile. However, it does so by ALWAYS putting instantiated packages in the inplace store.
ezyang commentedon May 31, 2021
I have a substantially working patch but it is somewhat involved, will submit soon.
Fix #6835
danidiaz commentedon May 31, 2021
@ezyang Thanks!
If you don't mind, I have a few questions about the fields
elabInstantiatedWith,elabLinkedInstantiatedWithandelabModuleShapeof the datatypeElaboratedConfiguredPackage, in order to better understand Backpack's implementation.elabInstantiatedWith, are they always a subset of the keys inelabLinkedInstantiatedWith? Do they correspond to those signatures which have already been "filled" with modules of a concrete compilation unit?OpenModulevalues inelabLinkedInstantiatedWithalwaysOpenModuleVars, or perhaps they don't need to be?modShapeRequiresfield ofelabModuleShapealways equal to the set of keys inelabLinkedInstantiatedWith?ezyang commentedon May 31, 2021
As a reminder, here are the types of the two fields in question:
Module are modules that are fully instantiated and thus opaque, whereas OpenModules maintain the inner structure of instantiations and so you can substitute over them when you instantiate them.
So, the data flow here, is elabLinkedInstantiatedWith is initially populated after mix-in linking (e.g., we've resolved a plain old
build-depends: pinto a more specific dependency with all the holes explicitly specified, e.g.,p[H=<H>, Data.Map=containers:Data.Map]), and then elabInstantiatedWith is populated after instantiation has occurred (e.g., we instantiated p to remove the hole). So in fact the keys between elabInstantiatedWith and elabLinkedInstantiatedWith are exactly the same.As an example, suppose you have a unit
p[H=<H>]and you are looking at the plan package that corresponds to it having been instantiated to bep[H=q:H]. Then:Note that, somewhat confusingly, elabLinkedInstantiatedWith isn't really used in any really serious way; it's only nontrivial use is
This is because the instantiation of a unit can be inferred from its contextual use, as any reference to a unit is obligated to list all the things it depends on. In other words, pay attention to compLinkedLibDependencies, that's the important field from mixin linking!
Yes, they have to be. There is only one place elabLinkedInstantiatedWith is filled
and
lc_instsis defined to be:But remember what I said above, which is that we aren't really using the structure of elabLinkedInstantiatedWith in a nontrivial way.
Yes.
Merge pull request #7413 from haskell/T6358
harendra-kumar commentedon Jun 5, 2021
I am able to compile my example successfully. Thanks everyone!
Fix #6835
Fix #6835