Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .stan.toml
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,16 @@

# Anti-pattern: unsafe functions
[[ignore]]
id = "OBS-STAN-0212-5rtOmw-499:33"
id = "OBS-STAN-0212-5rtOmw-503:33"
# ✦ Description: Usage of unsafe functions breaks referential transparency
# ✦ Category: #Unsafe #AntiPattern
# ✦ File: src\Stack\Constants.hs
#
# 498 ┃
# 499 ┃ setupGhciShimCode = byteString $(do
# 500 ┃ path <- makeRelativeToProject "src/setup-shim/StackSetupShim.hs"
# 501 ┃ embedFile path)
# 502 ┃
# 503 ┃ setupGhciShimCode = byteString $(do
# 504 ┃ path <- makeRelativeToProject "src/setup-shim/StackSetupShim.hs"
# 505 ┃ embedFile path)
# 506 ┃

# Anti-pattern: unsafe functions
[[ignore]]
Expand Down
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Major changes:

Behavior changes:

* With GHC 9.4.1 or later, when building with profiling, Stack passes GHC's
`-fprof-late` flag (rather than `-fprof-auto`) and Cabal's
`--profiling-detail=none` and `--library-profiling-detail=none` options. Cost
centres are then inserted after optimisation, so the profile reflects the
optimised program. Existing profiling builds will be rebuilt.

Other enhancements:

* Consider Cabal 3.18 to be a tested library and remove warnings.
Expand Down
13 changes: 9 additions & 4 deletions src/Stack/Build/Source.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Distribution.Version ( mkVersion )
import qualified Pantry.SHA256 as SHA256
import Stack.Build.Cache ( tryGetBuildCache )
import Stack.Build.Haddock ( shouldHaddockDeps )
import Stack.Constants ( ghcSupportsProfLate )
import Stack.Package
( buildableBenchmarks, buildableExes, buildableTestSuites
, hasBuildableMainLibrary, resolvePackage
Expand Down Expand Up @@ -113,7 +114,6 @@ loadSourceMap targets boptsCli sma = do
bconfig <- view buildConfigL
let errsPackages = mapMaybe checkPackage packagesWithCliFlags
compiler = sma.compiler
ghcVersion = getGhcVersion compiler
buildOpts = bconfig.config.build
infoTableProfSupported = ghcVersion >= mkVersion [9, 2, 1]
infoTableProfUnsupportedWarning =
Expand Down Expand Up @@ -146,6 +146,7 @@ loadSourceMap targets boptsCli sma = do
, globalPkgs
}
where
ghcVersion = getGhcVersion sma.compiler
cliFlags = boptsCli.flags
targetsAndSmaDeps = targets.deps <> sma.deps
packagesWithCliFlags = mapMaybe maybeProjectWithCliFlags $ Map.toList cliFlags
Expand Down Expand Up @@ -212,6 +213,7 @@ loadSourceMap targets boptsCli sma = do
ghcOptions = generalGhcOptions
bconfig
boptsCli
ghcVersion
isTarget
isProjectPackage
isInfoTableProf
Expand Down Expand Up @@ -276,7 +278,7 @@ hashSourceMapData boptsCli sm = do
isInfoTableProf =
ghcVersion >= mkVersion [9, 2, 1] && bc.config.build.infoTableProf
bootGhcOpts =
map display (generalGhcOptions bc boptsCli False False isInfoTableProf)
map display (generalGhcOptions bc boptsCli ghcVersion False False isInfoTableProf)
hashedContent =
toLazyByteString $ compilerPath
<> compilerInfo
Expand Down Expand Up @@ -337,11 +339,12 @@ generalCabalConfigOpts bconfig boptsCli name isTarget isLocal = concat
generalGhcOptions ::
BuildConfig
-> BuildOptsCLI
-> Version
-> Bool
-> Bool
-> Bool
-> [Text]
generalGhcOptions bconfig boptsCli isTarget isLocal isInfoTableProf = concat
generalGhcOptions bconfig boptsCli ghcVersion isTarget isLocal isInfoTableProf = concat
[ Map.findWithDefault [] AGOEverything config.ghcOptionsByCat
, if isLocal
then Map.findWithDefault [] AGOLocals config.ghcOptionsByCat
Expand All @@ -351,7 +354,7 @@ generalGhcOptions bconfig boptsCli isTarget isLocal isInfoTableProf = concat
else []
, concat [["-fhpc"] | isLocal && bopts.testOpts.coverage]
, if bopts.libProfile || bopts.exeProfile
then ["-fprof-auto", "-fprof-cafs"]
then [costCentreInsertion, "-fprof-cafs"]
else []
, [ "-g" | not $ bopts.libStrip || bopts.exeStrip ]
, if isInfoTableProf
Expand All @@ -364,6 +367,8 @@ generalGhcOptions bconfig boptsCli isTarget isLocal isInfoTableProf = concat
where
bopts = config.build
config = view configL bconfig
costCentreInsertion =
if ghcSupportsProfLate ghcVersion then "-fprof-late" else "-fprof-auto"
includeExtraOptions =
case config.applyGhcOptions of
AGOTargets -> isTarget
Expand Down
14 changes: 9 additions & 5 deletions src/Stack/ConfigureOpts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import Path ( (</>), parseRelDir )
import Path.Extra ( toFilePathNoTrailingSep )
import Stack.Constants
( bindirSuffix, compilerOptionsCabalFlag, docDirSuffix
, relDirEtc, relDirLib, relDirLibexec, relDirShare
, ghcSupportsProfLate, relDirEtc, relDirLib, relDirLibexec
, relDirShare
)
import Stack.Prelude
import Stack.Types.BuildOpts ( BuildOpts (..) )
import Stack.Types.Compiler ( whichCompiler )
import Stack.Types.Compiler ( getGhcVersion, whichCompiler )
import Stack.Types.Config ( Config (..), HasConfig (..) )
import Stack.Types.ConfigureOpts
( BaseConfigOpts (..), ConfigureOpts (..)
Expand Down Expand Up @@ -123,10 +124,11 @@ configureOptsNonPathRelated ::
-> [String]
configureOptsNonPathRelated econfig bco deps isLocal package = concat
[ depOptions
, [ "--enable-library-profiling"
| bopts.libProfile || bopts.exeProfile
]
, ["--enable-library-profiling" | profiling]
, ["--enable-profiling" | bopts.exeProfile && isLocal]
, if profiling && ghcSupportsProfLate ghcVersion
then ["--profiling-detail=none", "--library-profiling-detail=none"]
else []
, ["--enable-split-objs" | bopts.splitObjs]
, [ "--disable-library-stripping"
| not $ bopts.libStrip || bopts.exeStrip
Expand Down Expand Up @@ -176,11 +178,13 @@ configureOptsNonPathRelated econfig bco deps isLocal package = concat
in concatMap (\x -> [compilerOptionsCabalFlag wc, T.unpack x]) newArgs

wc = view (actualCompilerVersionL . to whichCompiler) econfig
ghcVersion = view (actualCompilerVersionL . to getGhcVersion) econfig

hideSourcePaths = config.hideSourcePaths

config = view configL econfig
bopts = bco.buildOpts
profiling = bopts.libProfile || bopts.exeProfile
mapAndAppend fn = Map.foldrWithKey' (fmap (:) . fn)
-- Unioning atop defaults is needed so that all flags are specified with
-- --exact-configuration.
Expand Down
4 changes: 4 additions & 0 deletions src/Stack/Constants.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Stack.Constants
, defaultGlobalConfigPath
, platformVariantEnvVar
, compilerOptionsCabalFlag
, ghcSupportsProfLate
, ghcColorForceFlag
, minTerminalWidth
, maxTerminalWidth
Expand Down Expand Up @@ -357,6 +358,9 @@ platformVariantEnvVar = stackProgNameUpper ++ "_PLATFORM_VARIANT"
compilerOptionsCabalFlag :: WhichCompiler -> String
compilerOptionsCabalFlag Ghc = "--ghc-options"

ghcSupportsProfLate :: Version -> Bool
ghcSupportsProfLate ghcVersion = ghcVersion >= mkVersion [9, 4, 1]

-- | The flag to pass to GHC when we want to force its output to be
-- colorized.
ghcColorForceFlag :: String
Expand Down