Second go at fixing #9061
Second go at fixing #9061

My first attempt introduce a bug in -fprint-minimal-imports, but
fortunately a regression test caught it.

(cherry picked from commit 5b73dc5fda1941d51827ea72614782c10a355a3d)

hferreiro/replay,lukexi/ghc-7.8-arm64,lukexi/ghc-7.8-arm64,lukexi/ghc-7.8-arm64,lukexi/ghc-7.8-arm64,lukexi/ghc-7.8-arm64,hferreiro/replay,hferreiro/replay,hferreiro/replay,hferreiro/replay,hferreiro/replay,hferreiro/replay