Skip to content

Unable to build with backpack modules from unpacked-containers package #6835

Closed

Description

@harendra-kumar

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

  1. phadej commented on May 22, 2020

    @phadej
    Collaborator

    There is #6005 which mentions problems with unpacked-containers, but it's marked as fixed. cc @ezyang

  2. harendra-kumar commented on May 25, 2020

    @harendra-kumar
    Author

    This has stalled my work, I would like to know if there is a workaround, how can I use unpacked-containers in my project?

  3. ezyang commented on May 26, 2020

    @ezyang
    Contributor

    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.

  4. ezyang commented on May 26, 2020

    @ezyang
    Contributor

    @harendra-kumar do you think you would have time to do a bisect for this problem?

  5. harendra-kumar commented on May 28, 2020

    @harendra-kumar
    Author

    @ezyang I can try, what do you suggest? Maybe, I can try running cabal at the commit right after that fix.

  6. harendra-kumar commented on May 28, 2020

    @harendra-kumar
    Author

    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-containers to my cabal.project it might work and it worked! The problem seems to occur only when it is used as an external dependency.

    $ cat cabal.project 
    packages:., ../unpacked-containers/unpacked-containers
    
  7. ezyang commented on May 28, 2020

    @ezyang
    Contributor

    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.

  8. Mikolaj commented on May 8, 2021

    @Mikolaj
    Member

    @harendra-kumar: thank you again for reporting this; just in case: does the bug persist? [edit: and with which cabal version?]

  9. added a commit that references this issue on May 27, 2021
  10. danidiaz commented on May 27, 2021

    @danidiaz
    Collaborator

    I've encountered the same problem with my moo-nad package. To reproduce:

    git clone --branch cabal_bug_6835 https://github.com/danidiaz/moo-nad.git moo-nad-x
    cd moo-nad-x/
    cabal test
    

    The code that emits the error is in Cabal/Distribution/Backpack/Configure.hs, the function toComponentLocalBuildInfos. Which seems to create a Graph (Either InstalledPackageInfo ReadyComponent) which according to the comments is:

    -- The database of transitively reachable installed packages that the
    -- external components the package (as a whole) depends on.

    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:

    For node UnitId "base-4.15.0.0" the deps are [UnitId "ghc-bignum-1.0",UnitId "ghc-prim-0.7.0",UnitId "rts"]
    For node UnitId "dep-t-0.4.4.0-91bfa4959ff60e0ce747ecfe782ff084cc3879da25a778ac219d4d5ff0aa0684" the deps are [UnitId "base-4.15.0.0",UnitId "mtl-2.2.2",UnitId "transformers-0.5.6.2",UnitId "unliftio-core-0.2.0.1-eddc7cf14ccd70f3513c556621fa675e3ed0579117262a3d9447d71c1c729978"]
    For node UnitId "ghc-bignum-1.0" the deps are [UnitId "ghc-prim-0.7.0"]
    For node UnitId "ghc-prim-0.7.0" the deps are [UnitId "rts"]
    For node UnitId "moo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e" the deps are [UnitId "base-4.15.0.0",UnitId "dep-t-0.4.4.0-91bfa4959ff60e0ce747ecfe782ff084cc3879da25a778ac219d4d5ff0aa0684",UnitId "mtl-2.2.2"]
    For node (this is the only ReadyComponent, the other are InstalledPackageInfo) UnitId "moo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e+L8yXyvV74rTHJagYNPv9JN" the deps are [UnitId "moo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e",UnitId "base-4.15.0.0",UnitId "dep-t-0.4.4.0-91bfa4959ff60e0ce747ecfe782ff084cc3879da25a778ac219d4d5ff0aa0684",UnitId "mtl-2.2.2",UnitId "moo-oops-0.1.0.2-inplace-example-impl-x"]
    For node UnitId "mtl-2.2.2" the deps are [UnitId "base-4.15.0.0",UnitId "transformers-0.5.6.2"]
    For node UnitId "rts" the deps are []
    For node UnitId "transformers-0.5.6.2" the deps are [UnitId "base-4.15.0.0"]
    For node UnitId "unliftio-core-0.2.0.1-eddc7cf14ccd70f3513c556621fa675e3ed0579117262a3d9447d71c1c729978" the deps are [UnitId "base-4.15.0.0",UnitId "transformers-0.5.6.2"]
    

    In particular, the "fully instantiated" ReadyComponent moo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e+L8yXyvV74rTHJagYNPv9JN depends on the local compilation unit moo-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 field instc_insts_deps that contains detailed descriptions about the dependencies, we find

    instc_insts_deps = [(UnitId "moo-oops-0.1.0.2-inplace-example-impl-x",MungedPackageId {mungedName = MungedPackageName (PackageName "nonexistent-package-this-is-a-cabal-bug")

    So 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?

  11. Mikolaj commented on May 27, 2021

    @Mikolaj
    Member

    @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?

  12. danidiaz commented on May 27, 2021

    @danidiaz
    Collaborator

    I'm using GHC 9.0.1 and cabal 3.4. I'm having trouble compiling the current master branch, so I didn't try with it.

  13. Mikolaj commented on May 27, 2021

    @Mikolaj
    Member

    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.

  14. harendra-kumar commented on May 28, 2021

    @harendra-kumar
    Author

    @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.

    $ ~/.cabal/bin/cabal --version
    cabal-install version 3.5
    compiled using version 3.5.0.0 of the Cabal library
    
    $ ghc --version
    The Glorious Glasgow Haskell Compilation System, version 8.8.3
    
    $ ~/.cabal/bin/cabal build
    ...
    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:utils >=0 && ==0,
    unpacked-containers:{unpacked-containers, example} (>=0 && >=0) && ==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). The failure occurred
    during the configure step.
    
  15. 4 remaining items

  16. danidiaz commented on May 29, 2021

    @danidiaz
    Collaborator

    So it seems that cabal-install generates a nice dist-newstyle/cache/plan.json file 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.

  17. Mikolaj commented on May 29, 2021

    @Mikolaj
    Member

    Indeed, git grep plan.json shows that plan.json is never mentioned in cabal docs except in

    doc/nix-local-build.rst:``plan.json`` (JSON)
    doc/nix-local-build.rst-    A JSON serialization of the computed install plan intended
    doc/nix-local-build.rst-    for integrating ``cabal`` with external tooling.
    doc/nix-local-build.rst-    The `cabal-plan <http://hackage.haskell.org/package/cabal-plan>`__
    doc/nix-local-build.rst:    package provides a library for parsing ``plan.json`` files into a
    doc/nix-local-build.rst-    Haskell data structure as well as an example tool showing possible
    doc/nix-local-build.rst-    applications.
    

    Perhaps it would make sense to add it, e.g., wherever 'build plan' appears in docs:

    doc/cabal-package.rst:       resolved within the same configuration of the package in the build plan.
    doc/cabal-project.rst:   aware of in a build plan. If you wish to restrict the build plan to
    

    Regarding plan.json being faulty and it either reflecting or not some problems inside cabal's internal build plan, there is a comment in cabal-install/src/Distribution/Client/ProjectPlanOutput.hs that may be relevant, but I don't know what it means exactly:

    -- Note that the plan.json currently only uses the elaborated plan,
    -- not the improved plan. So we will not get the Installed state for
    -- that case, but the code supports it in case we want to use this
    -- later in some use case where we want the status of the build.
    
  18. danidiaz commented on May 30, 2021

    @danidiaz
    Collaborator

    Judging from comments in the code, an "improved" plan is one for which package references have info about the actual locations in the store:

    Two variants of the install plan are returned: with and without packages from the store. That is, the "improved" plan where source packages are replaced by pre-existing installed packages from the store (when their ids match), and also the original elaborated plan which uses primarily source packages.

    Update the files we maintain that reflect our current build environment. In particular we maintain a JSON representation of the elaborated install plan (but not the improved plan since that reflects the state of the build rather than just the input environment).

    Improve the elaborated install plan. The elaborated plan consists mostly of source packages (with full nix-style hashed ids). Where corresponding installed packages already exist in the store, replace them in the plan.

    The improved plan changes each time we install something, whereas the underlying elaborated plan only changes when input config changes, so it's worth caching them separately.

    I don't think plan.json is faulty, it's just that it doesn't show everything I need. I (hackishly) tweaked the elaboratedPackageToJ function to show additional stuff relevant to this bug:

    , "build-style" J..= J.String (show (elabBuildStyle elab))  
    , "canonical" J..= J.String (show (elabIsCanonical elab))    
    , "module-shape" J..=  J.String (show (elabModuleShape elab))  
    , "instantiatied-with" J..=  J.String (show (elabInstantiatedWith elab))
    , "linked-instantiatied-with" J..=  J.String (show (elabLinkedInstantiatedWith elab))
    , "setup-package-db-stack" J..=  J.String (show (elabSetupPackageDBStack elab)) 
    , "build-package-db-stack" J..=  J.String (show (elabBuildPackageDBStack elab)) 
    , "register-package-db-stack" J..=  J.String (show (elabRegisterPackageDBStack elab))  
    , "local-to-project" J..=  J.String (show (elabLocalToProject elab)) 
    

    Then I searched in the generated plan.json for a package id of the form moo-nad-0.1.0.2-stuff+someohterstuff. The + in package ids seems to identify components that are "instantiated" from an indefinite component like moo-nad-0.1.0.2-stuff plus some implementation library.

    For my buggy case, I have:

      {
          "type": "configured",
          "id": "moo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e+CXHgquAbAM34wnUHImMH6r",
          "pkg-name": "moo-nad",
          "pkg-version": "0.1.0.2",
          "build-style": "BuildAndInstall",
          "canonical": "False",
          "module-shape": "ModuleShape {modShapeProvides = fromList [(ModuleName \"Moo.Prelude\",OpenModule (IndefFullUnitId (ComponentId \"moo-nad-0.1.0.2-136596e5d30785f22eda9db329422a145f8a7b99b9390088a3356b95680ad70e\") (fromList [(ModuleName \"Moo\",OpenModuleVar (ModuleName \"Moo\"))])) (ModuleName \"Moo.Prelude\"))], modShapeRequires = fromList [ModuleName \"Moo\"]}",
          "instantiatied-with": "fromList [(ModuleName \"Moo\",Module (DefUnitId {unDefUnitId = UnitId \"moo-nad-x-0.1.0.2-inplace-example-impl-x\"}) (ModuleName \"Moo\"))]",
          "linked-instantiatied-with": "fromList [(ModuleName \"Moo\",OpenModuleVar (ModuleName \"Moo\"))]",
          "setup-package-db-stack": "[GlobalPackageDB,SpecificPackageDB \"/home/daniel/.cabal/store/ghc-9.0.1/package.db\"]",
          "build-package-db-stack": "[GlobalPackageDB,SpecificPackageDB \"/home/daniel/.cabal/store/ghc-9.0.1/package.db\"]",
          "register-package-db-stack": "[GlobalPackageDB,SpecificPackageDB \"/home/daniel/.cabal/store/ghc-9.0.1/package.db\"]",
          "local-to-project": "False",
          "flags": {
            
          },
          "style": "global",
          "pkg-src": {
            "type": "repo-tar",
            "repo": {
              "type": "secure-repo",
              "uri": "http://hackage.haskell.org/"
            }
          },
          "pkg-cabal-sha256": "a2576f6a42dd26ce59cd926e167bab2fba5b9ca66d405324ca4bc6bd3486fa8b",
          "pkg-src-sha256": "75e5d1f04f73cbf8d060f4ca86f97e8d2c332e99b0121fd235eaaae337a1fe04",
          "depends": [
            "base-4.15.0.0",
            "dep-t-0.4.4.0-91bfa4959ff60e0ce747ecfe782ff084cc3879da25a778ac219d4d5ff0aa0684",
            "mtl-2.2.2"
          ],
          "exe-depends": [
            
          ],
          "component-name": "lib"
        },
    

    So it seems that the package db stacks are set up incorrectly, there's no local package database. The instantiation with Moo from moo-nad-x-0.1.0.2-inplace-example-impl-x seems to be correct though.

    For my happy case, I have:

        {
          "type": "configured",
          "id": "moo-nad-0.1.0.2-inplace+CXHgquAbAM34wnUHImMH6r",
          "pkg-name": "moo-nad",
          "pkg-version": "0.1.0.2",
          "build-style": "BuildInplaceOnly",
          "canonical": "False",
          "module-shape": "ModuleShape {modShapeProvides = fromList [(ModuleName \"Moo.Prelude\",OpenModule (IndefFullUnitId (ComponentId \"moo-nad-0.1.0.2-inplace\") (fromList [(ModuleName \"Moo\",OpenModuleVar (ModuleName \"Moo\"))])) (ModuleName \"Moo.Prelude\"))], modShapeRequires = fromList [ModuleName \"Moo\"]}",
          "instantiatied-with": "fromList [(ModuleName \"Moo\",Module (DefUnitId {unDefUnitId = UnitId \"moo-nad-x-0.1.0.2-inplace-example-impl-x\"}) (ModuleName \"Moo\"))]",
          "linked-instantiatied-with": "fromList [(ModuleName \"Moo\",OpenModuleVar (ModuleName \"Moo\"))]",
          "setup-package-db-stack": "[GlobalPackageDB,SpecificPackageDB \"/home/daniel/.cabal/store/ghc-9.0.1/package.db\",SpecificPackageDB \"/home/daniel/hs/moo-good/dist-newstyle/packagedb/ghc-9.0.1\"]",
          "build-package-db-stack": "[GlobalPackageDB,SpecificPackageDB \"/home/daniel/.cabal/store/ghc-9.0.1/package.db\",SpecificPackageDB \"/home/daniel/hs/moo-good/dist-newstyle/packagedb/ghc-9.0.1\"]",
          "register-package-db-stack": "[GlobalPackageDB,SpecificPackageDB \"/home/daniel/.cabal/store/ghc-9.0.1/package.db\",SpecificPackageDB \"/home/daniel/hs/moo-good/dist-newstyle/packagedb/ghc-9.0.1\"]",
          "local-to-project": "True",
          "flags": {
            
          },
          "style": "local",
          "pkg-src": {
            "type": "local",
            "path": "/home/daniel/hs/moo-good/moo-nad"
          },
          "dist-dir": "/home/daniel/hs/moo-good/dist-newstyle/build/x86_64-linux/ghc-9.0.1/moo-nad-0.1.0.2/moo-nad-0.1.0.2-inplace+CXHgquAbAM34wnUHImMH6r",
          "depends": [
            "base-4.15.0.0",
            "dep-t-0.4.4.0-91bfa4959ff60e0ce747ecfe782ff084cc3879da25a778ac219d4d5ff0aa0684",
            "mtl-2.2.2"
          ],
          "exe-depends": [
            
          ],
          "component-name": "lib"
        },
    
  19. danidiaz commented on May 30, 2021

    @danidiaz
    Collaborator

    The function writePlanExternalRepresentation that writes plan.json is called toward the end of the top-level function Distribution.Client.Project.Planning.rebuildInstallPlan. Before that, the rebuild function calls phaseElaboratePlan, 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-newstyle is done here, with the help of the shouldBuildInplaceOnly function. The choice affects elabBuildStyle, buildAndRegisterDbs and pkgInstalledId.

      However, this preliminary version of the plan doesn't include compilation units that are the "instantiated" form of indefinite components. As one comment says:

      -- NB: We don't INSTANTIATE packages at this point. That's
      -- a post-pass. This makes it simpler to compute dependencies.

    • Call instantiateInstallPlan, that adds the instantiated packages to the plan returned by elaborateInstallPlan.

    For example, in my case the verbose log output shows the lines:

    Elaborating the install plan...
    ...
    Configured moo-nad-0.1.0.2 (moo-nad-0.1.0.2-inplace+CXHgquAbAM34wnUHImMH6r)
        moo-nad-0.1.0.2-inplace
        base-4.15.0.0
        dep-t-0.4.4.0-91bfa4959ff60e0ce747ecfe782ff084cc3879da25a778ac219d4d5ff0aa0684
        mtl-2.2.2
        moo-nad-x-0.1.0.2-inplace-example-impl-x
    

    If we move the logging statement

       liftIO $ debugNoWrap verbosity (InstallPlan.showInstallPlan instantiatedPlan) 
    

    to before the call to instantiateInstallPlan, moo-nad-0.1.0.2-inplace+CXHgquAbAM34wnUHImMH6r ceases to appear.

    The problem seems to be that instantiateInstallPlan (more precisely instantiateComponent) always preserves the global/local choices made during elaborateInstallPlan. But even if an indefinite component is global, if the implementation is local the instantiated package should be local. instantiateInstallPlan needs to take that into account.

  20. ezyang commented on May 31, 2021

    @ezyang
    Contributor

    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...

  21. ezyang commented on May 31, 2021

    @ezyang
    Contributor

    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.

    diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs
    index 862a1deca..bca4c357d 100644
    --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs
    +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs
    @@ -663,7 +663,9 @@ rebuildInstallPlan verbosity
                       defaultInstallDirs
                       elaboratedShared
                       elaboratedPlan
    -        liftIO $ debugNoWrap verbosity (InstallPlan.showInstallPlan instantiatedPlan)
    +        liftIO $ notice verbosity "--- Instantiated plan:"
    +        liftIO $ noticeNoWrap verbosity (InstallPlan.showInstallPlan instantiatedPlan)
    +        liftIO $ notice verbosity "---"
             return (instantiatedPlan, elaboratedShared)
           where
             withRepoCtx = projectConfigWithSolverRepoContext verbosity
    @@ -1797,6 +1799,10 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
               elabSetupScriptStyle elabPkgDescription libDepGraph deps0
             elabSetupPackageDBStack    = buildAndRegisterDbs
     
    +        elabInplaceBuildPackageDBStack = inplacePackageDbs
    +        elabInplaceRegisterPackageDBStack = inplacePackageDbs
    +        elabInplaceSetupPackageDBStack = inplacePackageDbs
    +
             buildAndRegisterDbs
               | shouldBuildInplaceOnly pkg = inplacePackageDbs
               | otherwise                  = storePackageDbs
    @@ -2188,7 +2194,11 @@ instantiateInstallPlan storeDirLayout defaultInstallDirs elaboratedShared plan =
                         elabInstallDirs = computeInstallDirs storeDirLayout
                                                              defaultInstallDirs
                                                              elaboratedShared
    -                                                         elab1
    +                                                         elab1,
    +                    elabBuildStyle = BuildInplaceOnly,
    +                    elabBuildPackageDBStack = elabInplaceBuildPackageDBStack elab1,
    +                    elabRegisterPackageDBStack = elabInplaceRegisterPackageDBStack elab1,
    +                    elabSetupPackageDBStack = elabInplaceSetupPackageDBStack elab1
                       }
                 return $ InstallPlan.Configured elab
               _ -> return planpkg
    diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs b/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs
    index c3e920f3e..57dfb2450 100644
    --- a/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs
    +++ b/cabal-install/src/Distribution/Client/ProjectPlanning/Types.hs
    @@ -237,6 +237,10 @@ data ElaboratedConfiguredPackage
            elabBuildPackageDBStack    :: PackageDBStack,
            elabRegisterPackageDBStack :: PackageDBStack,
     
    +       elabInplaceSetupPackageDBStack    :: PackageDBStack,
    +       elabInplaceBuildPackageDBStack    :: PackageDBStack,
    +       elabInplaceRegisterPackageDBStack :: PackageDBStack,
    +
            elabPkgDescriptionOverride  :: Maybe CabalFileText,
     
            -- TODO: make per-component variants of these flags
    
    
  22. ezyang commented on May 31, 2021

    @ezyang
    Contributor

    I have a substantially working patch but it is somewhat involved, will submit soon.

  23. added a commit that references this issue on May 31, 2021
    823e894
  24. danidiaz commented on May 31, 2021

    @danidiaz
    Collaborator

    @ezyang Thanks!

    If you don't mind, I have a few questions about the fields elabInstantiatedWith, elabLinkedInstantiatedWith and elabModuleShape of the datatype ElaboratedConfiguredPackage, in order to better understand Backpack's implementation.

    • the keys in elabInstantiatedWith, are they always a subset of the keys in elabLinkedInstantiatedWith? Do they correspond to those signatures which have already been "filled" with modules of a concrete compilation unit?
    • are the OpenModule values in elabLinkedInstantiatedWith always OpenModuleVars, or perhaps they don't need to be?
    • is the modShapeRequires field of elabModuleShape always equal to the set of keys in elabLinkedInstantiatedWith?
  25. ezyang commented on May 31, 2021

    @ezyang
    Contributor

    the keys in elabInstantiatedWith, are they always a subset of the keys in elabLinkedInstantiatedWith? Do they correspond to those signatures which have already been "filled" with modules of a concrete compilation unit?

    As a reminder, here are the types of the two fields in question:

           elabInstantiatedWith :: Map ModuleName Module,
           elabLinkedInstantiatedWith :: Map ModuleName OpenModule,
    

    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: p into 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 be p[H=q:H]. Then:

    elabLinkedInstantiatedWith = Map.fromList [("H", OpenModuleVar "H")]
    elabInstantiatedWith = Map.fromList [("H", Module "q" "H")]
    

    Note that, somewhat confusingly, elabLinkedInstantiatedWith isn't really used in any really serious way; it's only nontrivial use is

                    InstallPlan.Configured elab
                        | not (Map.null (elabLinkedInstantiatedWith elab))
                        -> indefiniteUnitId (elabComponentId elab)
                            >> return ()
    

    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!

    are the OpenModule values in elabLinkedInstantiatedWith always OpenModuleVars, or perhaps they don't need to be?

    Yes, they have to be. There is only one place elabLinkedInstantiatedWith is filled

                        elabLinkedInstantiatedWith = Map.fromList (lc_insts lc),
    

    and lc_insts is defined to be:

    -- | The instantiation of 'lc_uid'; this always has the invariant
    -- that it is a mapping from a module name @A@ to @<A>@ (the hole A).
    lc_insts :: LinkedComponent -> [(ModuleName, OpenModule)]
    lc_insts lc = [ (req, OpenModuleVar req)
                  | req <- Set.toList (modShapeRequires (lc_shape lc)) ]
    

    But remember what I said above, which is that we aren't really using the structure of elabLinkedInstantiatedWith in a nontrivial way.

    is the modShapeRequires field of elabModuleShape always equal to the set of keys in elabLinkedInstantiatedWith?

    Yes.

  26. added a commit that references this issue on Jun 3, 2021
    873216f
  27. harendra-kumar commented on Jun 5, 2021

    @harendra-kumar
    Author

    I am able to compile my example successfully. Thanks everyone!

  28. added a commit that references this issue on Jun 5, 2021
    a4d3569
  29. added a commit that references this issue on Jun 6, 2021
    35aa1fa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions