Skip to content

Commit 48a8dfa

Browse files
authored
Merge pull request #6872 from phadej/issue-6377-add-cmm-test
Issue 6377 add cmm test
2 parents 2f3152c + 5341b25 commit 48a8dfa

File tree

15 files changed

+114
-51
lines changed

15 files changed

+114
-51
lines changed

cabal-install/Distribution/Client/CmdRun.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import Distribution.Client.CmdErrorMessages
3030
import Distribution.Client.TargetProblem
3131
( TargetProblem (..) )
3232

33-
import Distribution.Client.CmdRun.ClientRunFlags
34-
3533
import Distribution.Client.NixStyleOptions
3634
( NixStyleFlags (..), nixStyleOptions, defaultNixStyleFlags )
3735
import Distribution.Client.Setup
@@ -53,6 +51,8 @@ import Distribution.Simple.Utils
5351
import Distribution.Client.ProjectConfig
5452
( ProjectConfig(..), ProjectConfigShared(..)
5553
, withProjectOrGlobalConfig )
54+
import Distribution.Client.ProjectFlags
55+
( flagIgnoreProject )
5656
import Distribution.Client.ProjectPlanning
5757
( ElaboratedConfiguredPackage(..)
5858
, ElaboratedInstallPlan, binDirectoryFor )
@@ -110,7 +110,7 @@ import System.FilePath
110110
( (</>), isValid, isPathSeparator, takeExtension )
111111

112112

113-
runCommand :: CommandUI (NixStyleFlags ClientRunFlags)
113+
runCommand :: CommandUI (NixStyleFlags ())
114114
runCommand = CommandUI
115115
{ commandName = "v2-run"
116116
, commandSynopsis = "Run an executable."
@@ -146,8 +146,8 @@ runCommand = CommandUI
146146
++ " Build with '-O2' and run the program, passing it extra arguments.\n\n"
147147

148148
++ cmdCommonHelpTextNewBuildBeta
149-
, commandDefaultFlags = defaultNixStyleFlags defaultClientRunFlags
150-
, commandOptions = nixStyleOptions clientRunOptions
149+
, commandDefaultFlags = defaultNixStyleFlags ()
150+
, commandOptions = nixStyleOptions (const [])
151151
}
152152

153153
-- | The @run@ command runs a specified executable-like component, building it
@@ -158,8 +158,8 @@ runCommand = CommandUI
158158
-- For more details on how this works, see the module
159159
-- "Distribution.Client.ProjectOrchestration"
160160
--
161-
runAction :: NixStyleFlags ClientRunFlags -> [String] -> GlobalFlags -> IO ()
162-
runAction flags@NixStyleFlags {extraFlags=clientRunFlags, ..} targetStrings globalFlags = do
161+
runAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO ()
162+
runAction flags@NixStyleFlags {..} targetStrings globalFlags = do
163163
globalTmp <- getTemporaryDirectory
164164
tmpDir <- createTempDirectory globalTmp "cabal-repl."
165165

@@ -298,7 +298,7 @@ runAction flags@NixStyleFlags {extraFlags=clientRunFlags, ..} targetStrings glob
298298
handleDoesNotExist () (removeDirectoryRecursive tmpDir)
299299
where
300300
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
301-
ignoreProject = crunIgnoreProject clientRunFlags
301+
ignoreProject = flagIgnoreProject projectFlags
302302
cliConfig = commandLineFlagsToProjectConfig globalFlags flags mempty -- ClientInstallFlags, not needed here
303303
globalConfigFlag = projectConfigConfigFile (projectConfigShared cliConfig)
304304

cabal-install/Distribution/Client/CmdRun/ClientRunFlags.hs

Lines changed: 0 additions & 39 deletions
This file was deleted.

cabal-install/cabal-install.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ executable cabal
173173
Distribution.Client.CmdInstall.ClientInstallTargetSelector
174174
Distribution.Client.CmdRepl
175175
Distribution.Client.CmdRun
176-
Distribution.Client.CmdRun.ClientRunFlags
177176
Distribution.Client.CmdTest
178177
Distribution.Client.CmdLegacy
179178
Distribution.Client.CmdSdist

cabal-install/cabal-install.cabal.dev

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ library cabal-lib-client
165165
Distribution.Client.CmdInstall.ClientInstallTargetSelector
166166
Distribution.Client.CmdRepl
167167
Distribution.Client.CmdRun
168-
Distribution.Client.CmdRun.ClientRunFlags
169168
Distribution.Client.CmdTest
170169
Distribution.Client.CmdLegacy
171170
Distribution.Client.CmdSdist

cabal-install/cabal-install.cabal.prod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ executable cabal
173173
Distribution.Client.CmdInstall.ClientInstallTargetSelector
174174
Distribution.Client.CmdRepl
175175
Distribution.Client.CmdRun
176-
Distribution.Client.CmdRun.ClientRunFlags
177176
Distribution.Client.CmdTest
178177
Distribution.Client.CmdLegacy
179178
Distribution.Client.CmdSdist

cabal-install/cabal-install.cabal.zinza

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ Version: 3.3.0.0
109109
Distribution.Client.CmdInstall.ClientInstallTargetSelector
110110
Distribution.Client.CmdRepl
111111
Distribution.Client.CmdRun
112-
Distribution.Client.CmdRun.ClientRunFlags
113112
Distribution.Client.CmdTest
114113
Distribution.Client.CmdLegacy
115114
Distribution.Client.CmdSdist
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# cabal v2-run
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- cmmexperiment-0 (lib) (first run)
6+
- cmmexperiment-0 (exe:demo) (first run)
7+
Configuring library for cmmexperiment-0..
8+
Preprocessing library for cmmexperiment-0..
9+
Building library for cmmexperiment-0..
10+
Configuring executable 'demo' for cmmexperiment-0..
11+
Warning: The package has an extraneous version range for a dependency on an internal library: cmmexperiment >=0 && ==0. This version range includes the current package but isn't needed as the current package's library will always be used.
12+
Preprocessing executable 'demo' for cmmexperiment-0..
13+
Building executable 'demo' for cmmexperiment-0..
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
res <- cabal' "v2-run" ["demo"]
5+
assertOutputContains "= Post common block elimination =" res
6+
assertOutputContains "In Box we have 0x" res
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "Cmm.h"
2+
3+
aToMyWordzh (P_ clos)
4+
{
5+
return (clos);
6+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cabal-version: 3.0
2+
name: cmmexperiment
3+
version: 0
4+
build-type: Simple
5+
6+
-- This code is extracted form ghc-heap
7+
-- Copyright (c) 2012-2013, Joachim Breitner
8+
-- (and probably -2020 GHC Team)
9+
-- Under BSD-3-Clause
10+
11+
library
12+
default-language: Haskell2010
13+
hs-source-dirs: src
14+
build-depends: base
15+
exposed-modules: Demo
16+
17+
cmm-sources: cbits/HeapPrim.cmm
18+
if impl(ghc >=8.2)
19+
cmm-options: -ddump-cmm-verbose
20+
else
21+
cmm-options: -ddump-cmm
22+
23+
executable demo
24+
default-language: Haskell2010
25+
main-is: Main.hs
26+
hs-source-dirs: demo
27+
build-depends: base, cmmexperiment
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Main (main) where
2+
import Demo (main)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Setup configure
2+
Configuring cmmexperiment-0...
3+
# Setup build
4+
Preprocessing library for cmmexperiment-0..
5+
Building library for cmmexperiment-0..
6+
Preprocessing executable 'demo' for cmmexperiment-0..
7+
Building executable 'demo' for cmmexperiment-0..
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Test.Cabal.Prelude
2+
3+
main = setupTest $ do
4+
skipIf =<< ghcVersionIs (< mkVersion [7,8])
5+
setup "configure" []
6+
res <- setup' "build" []
7+
assertOutputContains "= Post common block elimination =" res
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE ForeignFunctionInterface #-}
3+
{-# LANGUAGE GHCForeignImportPrim #-}
4+
{-# LANGUAGE MagicHash #-}
5+
{-# LANGUAGE UnliftedFFITypes #-}
6+
module Demo (main) where
7+
8+
#include "MachDeps.h"
9+
10+
import Data.Bits
11+
import GHC.Exts
12+
import Numeric (showHex)
13+
14+
foreign import prim "aToMyWordzh" aToWord# :: Any -> Word#
15+
16+
tAG_MASK :: Int
17+
tAG_MASK = (1 `shift` TAG_BITS) - 1
18+
19+
data Box = Box Any
20+
21+
instance Show Box where
22+
showsPrec _ (Box a) rs =
23+
-- unsafePerformIO (print "↓" >> pClosure a) `seq`
24+
pad_out (showHex addr "") ++ (if tag>0 then "/" ++ show tag else "") ++ rs
25+
where
26+
ptr = W# (aToWord# a)
27+
tag = ptr .&. fromIntegral tAG_MASK -- ((1 `shiftL` TAG_BITS) -1)
28+
addr = ptr - tag
29+
pad_out ls = '0':'x':ls
30+
31+
asBox :: a -> Box
32+
asBox x = Box (unsafeCoerce# x)
33+
34+
main :: IO ()
35+
main = do
36+
let box = asBox "foobar"
37+
putStrLn $ "In Box we have " ++ show box

0 commit comments

Comments
 (0)