Skip to content

MicroHs (mhs 0.16.12.0) support for Cabal-syntax, Cabal, cabal-install-solver, and cabal-install (exe:cabal) - #533

Open
angerman wants to merge 17 commits into
stable-haskell/mergefrom
sh/microhs-cabal-install
Open

angerman wants to merge 17 commits into
stable-haskell/mergefrom
sh/microhs-cabal-install

Conversation

@angerman

@angerman angerman commented Nov 11, 2026 •

Copy link
Copy Markdown

Summary

This PR adds support for compiling the full 4-package closure (Cabal-syntax, Cabal, cabal-install-solver, and cabal-install / exe:cabal) with MicroHs (mhs 0.16.12.0) while keeping the GHC 9.14.1 build and test suite intact, grafted onto stable-haskell/merge (73d3ffda3e, the dual-compiler-aware --with-compiler / --with-build-compiler branch referenced by stable-haskell/ghc#200).

Key Changes

  1. Type-Family-Free & DataKinds-Free Core:

    • Replaced associated type Key a on IsNode in Distribution.Compat.Graph with a functional dependency class Ord k => IsNode k a | a -> k and parameterized Graph k a / GenericInstallPlan k ipkg srcpkg across Cabal-syntax, Cabal, cabal-install-solver, and cabal-install.
    • Replaced SymbolicPathX / PathLike type families in Distribution.Utils.Path with phantom-typed SymbolicPath from to and explicit FilePath/String path combinators.
    • Replaced closed type families (RightFlagsForPhase, SetupRunnerRes, InLibraryPhaseRes) and promoted DataKinds (SetupWrapperSpec, ExternalExe) in Distribution.Client.SetupWrapper and Distribution.Client.ProjectBuilding.UnpackedPackage with GADT-indexed SPostConfigurePhase flags result, InLibraryArgs lbi flags result, SetupRunnerArgs flags result, and WantedExternalExe result.
  2. POSIX C11 Shims & #ifdef __MHS__ Compatibility Seams:

    • Cabal-syntax/cbits/mhs_posix.{c,h}: POSIX stat/lstat/utimes/O_CREAT|O_EXCL helpers for Distribution.Compat.Directory.
    • Cabal/cbits/mhs_spawn.{c,h}: posix_spawnp(3) + waitpid(WNOHANG) process spawning for Distribution.Compat.Process.
    • Cabal/cbits/mhs_handle.{c,h}: MicroHs BFILE UTF-8 transducer detection, fseeko, and flock(2) (mhs_hLock/mhs_hUnlock).
    • cabal-install/cbits/mhs_sha256.{c,h}: One-shot SHA-256 via CommonCrypto (macOS) / OpenSSL libcrypto (POSIX).
    • Pure-Haskell .tar reader in Distribution.Client.Compat.Tar + external tar/gzip fallback under #ifdef __MHS__.
      -Pregenerated Distribution.Fields.Lexer (without alex -g unboxed Addr# primops) wired under if impl(mhs).
  3. MicroHs Typechecker & Desugarer Workarounds:

    • Explicit Functor/Foldable/Traversable/Eq/Ord/Show/Binary/NFData instances under #ifdef __MHS__ where MicroHs deriving hits tuple/constructor-scale limits (notably Extension/KnownExtension O(N²) deriving Ord).
    • Explicit type signatures on RecordWildCards bindings in let/where blocks (ProjectPlanning.hs) and unqualified field/constructor imports where MicroHs dsUpdateCase desugars record updates into case matches.
  4. CI Bootstrap Job & Artifact Upload (.github/workflows/bootstrap.yml + bootstrap/mhs/):

Verification

  • MicroHs 0.16.12.0:
    • Full 4-package closure (Cabal-syntax, Cabal, cabal-install-solver, cabal-install) compiles and links to exe:cabal (_build/artifacts/cabal, 5.9 MB, 33,784 top-level definitions).
    • cabal --version -> cabal-install version 3.19.0.0 (compiled using version 3.19.0.0 of the Cabal library)
    • cabal build --help exposes both -w / --with-compiler and -W / --with-build-compiler (dual-compiler awareness from 73d3ffda3e).
    • (cd Cabal-syntax && cabal check) -> No errors or warnings could be found in the package.
    • Cabal/tests/ProcessCaptureTests.hs (backend=mhs): T1–T7 all green.
  • GHC 9.14.1:
    • cabal build lib:Cabal-syntax lib:Cabal lib:hooks-exe lib:cabal-install-solver lib:cabal-install exe:cabal succeeds with 0 errors.

Cherry-pick of 23eefcaed (MicroHs support squashed) with conflicts
resolved: Stage->Machine renames applied to Machine.hs, HEAD's
dependency bounds and Machine/InMachine logic kept, MicroHs
compatibility changes (flag mhs stanzas, c-sources, ifdef __MHS__
guards, fundep IsNode instances, positional GADT constructors)
preserved. Verified with GHC 9.14.1 build of lib:Cabal-syntax,
lib:Cabal, lib:cabal-install-solver, lib:cabal-install and exe:cabal.
@angerman
angerman force-pushed the sh/microhs-cabal-install branch from e46621e to 1548a39 Compare November 12, 2026 00:42
@angerman
angerman changed the base branch from split/pr501x/10b-windows-tmp-retry to stable-haskell/merge November 12, 2026 00:42
@angerman angerman closed this Nov 12, 2026
@angerman angerman reopened this Nov 12, 2026
@angerman
angerman force-pushed the sh/microhs-cabal-install branch 7 times, most recently from 7b0cd18 to 6f191d4 Compare November 13, 2026 20:17
- Add bootstrap/mhs/build-cabal-mhs.sh, bootstrap/mhs/microhs-full.patch,
  and pure-Haskell shim packages (pretty-mhs, uri-mhs, binary-mhs,
  text-encoding-mhs) under bootstrap/mhs/shims/.
- Add bootstrap-mhs job to .github/workflows/bootstrap.yml to build
  cabal-install (exe:cabal) with MicroHs 0.16.12.0, run smoke tests and
  ProcessCaptureTests, and upload cabal-ubuntu-latest-mhs-0.16.12.0-bootstrapped
  via actions/upload-artifact@v7.
@angerman
angerman force-pushed the sh/microhs-cabal-install branch from 6f191d4 to b04f602 Compare November 13, 2026 20:26
Validate builds with -Werror. The local stage action discarded a
polymorphic put result, so -Wunused-do-bind failed Cabal-3.19 on every
GHC validate job and the Alpine static build.
Export the target-name helpers, drop two unused LogProgress imports,
and restore the Windows createTempDirectory path. The graft called
System.Posix.createDirectory on every non-MHS platform.
LogProgress.hang exists only under __MHS__, because MicroHs pretty
has no hang. Import it only there. Compat.Prelude already exports
Exception, when, and unless, so the extra imports failed -Werror.
GHC 9.14 rejects FileOrDir(..) under -Werror. The empty compatibility
datatype has no constructors, and neither hooks module uses the name.
The test library and custom-setup-tests import Compat.Directory and
Compat.Process, not the directory or process packages. GHC 9.6
-Wunused-packages rejects those direct dependencies.
cabal-install-solver and several test suites import
Distribution.Compat.Directory, not the directory package. GHC
-Wunused-packages rejects the direct dependency. integration-tests2
likewise only uses Compat.Process.
Validate -Werror rejected three cabal-install-solver imports. Machine.hs
kept the standard Prelude in scope, so Data.Foldable (Foldable) was unused
on GHC. Hide that Prelude, as the other solver modules do, so deriving
Foldable still sees the class on GHC and MicroHs.

OptionalStanza imported Structured, which Compat.Prelude already exports.
nominalStructure stays. PkgConfigDb imported mapM, which Traversable(..)
from the prelude already provides.
GHC 9.8.4 with cabal.validate.project (-Werror) failed the cabal-install
library, Cabal-tests, cabal-validate, and solver-benchmarks. Compat.Prelude
already exports the names those imports repeated. FileOrDir is an empty
datatype, so FileOrDir(..) is unused. directory and process are unused
where the code only imports Compat.Directory and Compat.Process. The
external setup runner now covers InLibraryArgs so -Wincomplete-patterns
is satisfied.
getStoreEntries listed the store root, so units under store/lib were never
reused. --offline then refused a cached remote package that still looked
configured. List the lib directories, and skip reuse when a dependency is
still configured instead of asserting.

Foreign libraries take their rpath from flibdir. Inplace v2-run also gets
rpaths relative to the component build directory.

Pin SetupHooks <.> to a Build file path so GHC 9.8+ accepts it, and update
the GenericPackageDescription and LocalBuildInfo structure hashes.
Baking the dist build directory into an executable RPATH lets runExe
find an internal dynamic library that was never installed (Cabal
haskell#4025). v2-run puts those directories on the loader path of the child
process instead: DYLD_LIBRARY_PATH on OSX, PATH on Windows, and
LD_LIBRARY_PATH elsewhere. An existing loader path is kept.

Skip the owner-execute round trip in the directory permissions test on
Windows. System.Directory does not report that bit for a file that is
not a program.
fourmolu 0.12 aligns the (++) with the (:) in progInvokeEnv.
v2-run executes the binary from its component build directory. The
install-relative $ORIGIN rpath to GHC's libHSbase does not resolve from
there, and the loader path only listed inplace build directories.
CmmSourcesDyn then failed to load libHSbase on Linux.

Pre-existing packages contribute libraryDynDirs, or libraryDirs when
that list is empty. Non-inplace elaborated packages contribute dynlibdir
and libdir. Inplace build directories stay off the executable RPATH.
MicroHs bootstrap failed in ProjectPlanning with "undefined value:
InstallDirs" at the data constructor. The last green MicroHs bootstrap
imported that constructor. Keeping only the field selectors makes
MicroHs reject the qualified record pattern. The pattern uses the
constructor directly, so GHC still treats the import as used.
findDependencyInStore stripped vowels on macOS to imitate
hashedInstalledPackageIdVeryShort. That id was removed, and macOS
store directories use the long id, which starts with the package
name. CopyHie, HaddockBuildDepends, and quickjump searched for
h-dpndncy, x, and ndf and missed hie-dependency, exe/lib, and indef.
MicroHs bootstrap failed while compiling Main with "undefined value:
NixStyleFlags" at the data constructor. CmdHaddockProject updates a
NixStyleFlags record, and MicroHs needs that constructor imported.
5ddda20 dropped it as unused for GHC. The pattern names the
constructor, so the import stays used.
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

Successfully merging this pull request may close these issues.

1 participant