Skip to content

Issue 6377 add cmm test #6872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2020
Merged
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
16 changes: 8 additions & 8 deletions cabal-install/Distribution/Client/CmdRun.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import Distribution.Client.CmdErrorMessages
import Distribution.Client.TargetProblem
( TargetProblem (..) )

import Distribution.Client.CmdRun.ClientRunFlags

import Distribution.Client.NixStyleOptions
( NixStyleFlags (..), nixStyleOptions, defaultNixStyleFlags )
import Distribution.Client.Setup
Expand All @@ -53,6 +51,8 @@ import Distribution.Simple.Utils
import Distribution.Client.ProjectConfig
( ProjectConfig(..), ProjectConfigShared(..)
, withProjectOrGlobalConfig )
import Distribution.Client.ProjectFlags
( flagIgnoreProject )
import Distribution.Client.ProjectPlanning
( ElaboratedConfiguredPackage(..)
, ElaboratedInstallPlan, binDirectoryFor )
Expand Down Expand Up @@ -110,7 +110,7 @@ import System.FilePath
( (</>), isValid, isPathSeparator, takeExtension )


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

++ cmdCommonHelpTextNewBuildBeta
, commandDefaultFlags = defaultNixStyleFlags defaultClientRunFlags
, commandOptions = nixStyleOptions clientRunOptions
, commandDefaultFlags = defaultNixStyleFlags ()
, commandOptions = nixStyleOptions (const [])
}

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

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

Expand Down
39 changes: 0 additions & 39 deletions cabal-install/Distribution/Client/CmdRun/ClientRunFlags.hs

This file was deleted.

1 change: 0 additions & 1 deletion cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ executable cabal
Distribution.Client.CmdInstall.ClientInstallTargetSelector
Distribution.Client.CmdRepl
Distribution.Client.CmdRun
Distribution.Client.CmdRun.ClientRunFlags
Distribution.Client.CmdTest
Distribution.Client.CmdLegacy
Distribution.Client.CmdSdist
Expand Down
1 change: 0 additions & 1 deletion cabal-install/cabal-install.cabal.dev
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ library cabal-lib-client
Distribution.Client.CmdInstall.ClientInstallTargetSelector
Distribution.Client.CmdRepl
Distribution.Client.CmdRun
Distribution.Client.CmdRun.ClientRunFlags
Distribution.Client.CmdTest
Distribution.Client.CmdLegacy
Distribution.Client.CmdSdist
Expand Down
1 change: 0 additions & 1 deletion cabal-install/cabal-install.cabal.prod
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ executable cabal
Distribution.Client.CmdInstall.ClientInstallTargetSelector
Distribution.Client.CmdRepl
Distribution.Client.CmdRun
Distribution.Client.CmdRun.ClientRunFlags
Distribution.Client.CmdTest
Distribution.Client.CmdLegacy
Distribution.Client.CmdSdist
Expand Down
1 change: 0 additions & 1 deletion cabal-install/cabal-install.cabal.zinza
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ Version: 3.3.0.0
Distribution.Client.CmdInstall.ClientInstallTargetSelector
Distribution.Client.CmdRepl
Distribution.Client.CmdRun
Distribution.Client.CmdRun.ClientRunFlags
Distribution.Client.CmdTest
Distribution.Client.CmdLegacy
Distribution.Client.CmdSdist
Expand Down
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# cabal v2-run
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- cmmexperiment-0 (lib) (first run)
- cmmexperiment-0 (exe:demo) (first run)
Configuring library for cmmexperiment-0..
Preprocessing library for cmmexperiment-0..
Building library for cmmexperiment-0..
Configuring executable 'demo' for cmmexperiment-0..
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.
Preprocessing executable 'demo' for cmmexperiment-0..
Building executable 'demo' for cmmexperiment-0..
1 change: 1 addition & 0 deletions cabal-testsuite/PackageTests/CmmSources/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude

main = cabalTest $ do
res <- cabal' "v2-run" ["demo"]
assertOutputContains "= Post common block elimination =" res
assertOutputContains "In Box we have 0x" res
6 changes: 6 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/cbits/HeapPrim.cmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Cmm.h"

aToMyWordzh (P_ clos)
{
return (clos);
}
27 changes: 27 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/cmmexperiment.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cabal-version: 3.0
name: cmmexperiment
version: 0
build-type: Simple

-- This code is extracted form ghc-heap
-- Copyright (c) 2012-2013, Joachim Breitner
-- (and probably -2020 GHC Team)
-- Under BSD-3-Clause

library
default-language: Haskell2010
hs-source-dirs: src
build-depends: base
exposed-modules: Demo

cmm-sources: cbits/HeapPrim.cmm
if impl(ghc >=8.2)
cmm-options: -ddump-cmm-verbose
else
cmm-options: -ddump-cmm

executable demo
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: demo
build-depends: base, cmmexperiment
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/demo/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Main (main) where
import Demo (main)
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/setup.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Setup configure
Configuring cmmexperiment-0...
# Setup build
Preprocessing library for cmmexperiment-0..
Building library for cmmexperiment-0..
Preprocessing executable 'demo' for cmmexperiment-0..
Building executable 'demo' for cmmexperiment-0..
7 changes: 7 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude

main = setupTest $ do
skipIf =<< ghcVersionIs (< mkVersion [7,8])
setup "configure" []
res <- setup' "build" []
assertOutputContains "= Post common block elimination =" res
37 changes: 37 additions & 0 deletions cabal-testsuite/PackageTests/CmmSources/src/Demo.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnliftedFFITypes #-}
module Demo (main) where

#include "MachDeps.h"

import Data.Bits
import GHC.Exts
import Numeric (showHex)

foreign import prim "aToMyWordzh" aToWord# :: Any -> Word#

tAG_MASK :: Int
tAG_MASK = (1 `shift` TAG_BITS) - 1

data Box = Box Any

instance Show Box where
showsPrec _ (Box a) rs =
-- unsafePerformIO (print "↓" >> pClosure a) `seq`
pad_out (showHex addr "") ++ (if tag>0 then "/" ++ show tag else "") ++ rs
where
ptr = W# (aToWord# a)
tag = ptr .&. fromIntegral tAG_MASK -- ((1 `shiftL` TAG_BITS) -1)
addr = ptr - tag
pad_out ls = '0':'x':ls

asBox :: a -> Box
asBox x = Box (unsafeCoerce# x)

main :: IO ()
main = do
let box = asBox "foobar"
putStrLn $ "In Box we have " ++ show box