Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Optimise build of Cabal library in Stage0 & StageH #233

Closed
snowleopard opened this issue Apr 30, 2016 · 2 comments
Closed

Optimise build of Cabal library in Stage0 & StageH #233

snowleopard opened this issue Apr 30, 2016 · 2 comments

Comments

@snowleopard
Copy link
Owner

snowleopard commented Apr 30, 2016

The current state of affairs is very inefficient:

  • We build Stage0 Cabal for ghc-pkg -- results go to _build/stage0/libraries/Cabal.
  • We also build parts of Cabal for Stage0 ghc-cabal -- results go to _build/stage0/utils/ghc-cabal. We may at some point get rid of ghc-cabal, but there is still a lot of work to be done Get rid of ghc-cabal and package-data.mk #18.
  • We also build parts of Cabal for Hadrian -- results go to _build/hadrian (we can call this StageH). See Switch to in-tree Cabal library #228 on switching to using in-tree Cabal library.

So we end up building big chunks of Cabal three times in Stage0 + StageH! Presumably, we could only do it once when we use the same GHC both for Stage0 and for StageH (i.e. for compiling Hadrian), which is likely to be the most common case.

@snowleopard
Copy link
Owner Author

Why does Hadrian currently require Cabal? We need to parse .cabal files for two reasons:

  1. To compute boot package constraints:
Cabal == 1.25.0.0
binary == 0.8.3.0
ghc-boot == 8.1
hoopl == 3.10.2.1
hpc == 0.6.0.3
template-haskell == 2.11.0.0
transformers == 0.5.2.0

Make build system does this using the following fragile code:

BOOT_PKG_CONSTRAINTS := \
    $(foreach d,$(PACKAGES_STAGE0),\
        $(foreach p,$(basename $(notdir $(wildcard libraries/$d/*.cabal))),\
            --constraint "$p == $(shell grep -i "^Version:" libraries/$d/$p.cabal | sed "s/[^0-9.]//g")"))
  1. To determine the order in which we need to configure packages (by extracting their dependencies from .cabal files). Make build system sequentialised things with the following hack:
# -------------------------------------------
# Note [Dependencies between package-data.mk files].

# We cannot run ghc-cabal to configure a package until we have
# configured and registered all of its dependencies.  So the following
# hack forces all the configure steps to happen in exactly the following order:
#
#  $(PACKAGES_STAGE1) ghc(stage2) $(PACKAGES_STAGE2)
#
# Ideally we should use the correct dependencies here to allow more
# parallelism, but we don't know the dependencies until we've
# generated the package-data.mk files.
define fixed_pkg_dep
libraries/$1/$2/package-data.mk : $$(fixed_pkg_prev)
fixed_pkg_prev:=libraries/$1/$2/package-data.mk
endef

ifneq "$(BINDIST)" "YES"
fixed_pkg_prev=
$(foreach pkg,$(PACKAGES_STAGE1),$(eval $(call fixed_pkg_dep,$(pkg),dist-install)))

@izgzhen izgzhen added this to Ideas & Research in GHC Transcendence Jul 18, 2017
@izgzhen izgzhen moved this from Ideas & Research to Performance in GHC Transcendence Jul 18, 2017
@snowleopard
Copy link
Owner Author

We no longer build ghc-cabal, so some duplication is gone. I think we can close this issue although there is still some scope for optimisation by sharing the build artefacts of Hadrian and Stage0 Cabal library.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

No branches or pull requests

1 participant