Skip to content

Instantly share code, notes, and snippets.

@9999years
Last active December 4, 2024 23:25
Show Gist options
  • Save 9999years/9ad5e0929c44b1908d66473cf66ddfc4 to your computer and use it in GitHub Desktop.
Save 9999years/9ad5e0929c44b1908d66473cf66ddfc4 to your computer and use it in GitHub Desktop.
Bisecting GHC
#!/usr/bin/env bash
set -ex
git clean -fdx
git reset --hard
git submodule deinit --all --force
git bisect reset ghc-9.8.1-release || true
git bisect start ghc-9.8.1-release ghc-9.7-start
# Note: The test script is kept in the parent directory of the GHC checkout so
# that it doesn't get deleted when we run `git clean -fdx`.
git bisect run ../test.sh
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ImplicitParams #-}
-- Reproducer for a GHC bug: https://gitlab.haskell.org/ghc/ghc/-/issues/25529
module Main where
import GHC.Stack (HasCallStack, CallStack, SrcLoc(srcLocStartLine, srcLocStartCol), callStack, getCallStack)
main :: IO ()
main =
let ?myImplicitParam = ()
in run action
action :: (HasCallStack, ?myImplicitParam :: ()) => IO ()
action = run $ pure ()
-- | Print the current call stack and then run an action.
run ::
(HasCallStack, ?myImplicitParam :: ()) =>
IO a ->
IO a
run action = do
let prettyCallStack = unlines $ map prettyCallStackEntry $ getCallStack callStack
prettyCallStackEntry (name, loc) =
name
<> ", called at "
<> show (srcLocStartLine loc)
<> ":"
<> show (srcLocStartCol loc)
putStrLn "============================================================"
putStrLn prettyCallStack
action
#!/usr/bin/env bash
# Log commands as we run them.
set -x
# Attempt to build GHC.
#
# If we can't build GHC, exit with 128. This will abort the entire `git bisect`
# instead of erroneously marking the commit as 'bad'.
#
# From `man git-bisect`:
# > Note that the script [...] should exit with code
# > 0 if the current source code is good/old, and exit with a code between 1
# > and 127 (inclusive), except 125, if the current source code is bad/new.
# >
# > Any other exit code will abort the bisect process. It should be noted that
# > a program that terminates via exit(-1) leaves $? = 255, (see the exit(3)
# > manual page), as the value is chopped with & 0377.
# 5 seconds:
# Reset the submodules if there's changes like generated files.
time git submodule update --init --force --recursive || exit 128
# Remove existing build products.
time rm -rf _build || exit 128
# Now we run the actual build process.
# See: https://gitlab.haskell.org/ghc/ghc/-/wikis/building/preparation
# 2 seconds:
time ./boot || exit 128
# 30 seconds:
time ./configure $CONFIGURE_ARGS || exit 128
# ~12 minutes (M1 Ultra, 20 cores, 64GB RAM), ~19 minutes (M2 Max, 12 cores, 32GB RAM):
time CABFLAGS=--allow-newer ./hadrian/build -j --flavour=Quick || exit 128
# Reset any modified files or checking out the next commit will fail:
time git reset --hard || exit 128
# Make sure we actually built a compiler:
if [[ ! -e _build/stage1/bin/runghc ]]
then
exit 128
fi
tmp=$(mktemp)
_build/stage1/bin/runghc "../Reproducer.hs" > "$tmp" || exit 128
# If the output doesn't contain 'action', the bug is present in this commit.
grep --quiet action "$tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment