From 9372aaab0c869036689b9ec112bfbfd7d9cf43bf Mon Sep 17 00:00:00 2001 From: Matthew Craven <5086-clyring@users.noreply.gitlab.haskell.org> Date: Wed, 27 Apr 2022 17:06:40 -0400 Subject: Give the two T19569 tests different names --- testsuite/tests/lib/base/T19569.hs | 56 ---------------------- testsuite/tests/lib/base/T19569b.hs | 56 ++++++++++++++++++++++ testsuite/tests/lib/base/all.T | 2 +- testsuite/tests/simplCore/should_run/T19569.hs | 51 -------------------- testsuite/tests/simplCore/should_run/T19569.stdout | 1 - testsuite/tests/simplCore/should_run/T19569a.hs | 51 ++++++++++++++++++++ .../tests/simplCore/should_run/T19569a.stdout | 1 + testsuite/tests/simplCore/should_run/all.T | 2 +- 8 files changed, 110 insertions(+), 110 deletions(-) delete mode 100644 testsuite/tests/lib/base/T19569.hs create mode 100644 testsuite/tests/lib/base/T19569b.hs delete mode 100644 testsuite/tests/simplCore/should_run/T19569.hs delete mode 100644 testsuite/tests/simplCore/should_run/T19569.stdout create mode 100644 testsuite/tests/simplCore/should_run/T19569a.hs create mode 100644 testsuite/tests/simplCore/should_run/T19569a.stdout diff --git a/testsuite/tests/lib/base/T19569.hs b/testsuite/tests/lib/base/T19569.hs deleted file mode 100644 index 00f7c7367b..0000000000 --- a/testsuite/tests/lib/base/T19569.hs +++ /dev/null @@ -1,56 +0,0 @@ --- This program is meant to compare the bracketing produced by the --- actual implementation of (^) with the bracketing in the RHS of its --- rewrite rules for known small powers, and complains if they disagree. - -{-# OPTIONS_GHC -O -Wno-missing-methods #-} - -module Main where - -import Control.Monad -import Data.Typeable -import Numeric.Natural -import Text.Printf - -data MulTree = X | FromInteger Integer | Mul MulTree MulTree - deriving (Eq, Show) - -instance Num MulTree where - fromInteger = FromInteger - (*) = Mul - -opaquePow :: (Num a, Integral b) => a -> b -> a -{-# NOINLINE opaquePow #-} -opaquePow k e = k ^ e - -checkRules - :: forall expTy. (Integral expTy, Show expTy, Typeable expTy) - => expTy -> IO () -{-# INLINE checkRules #-} -checkRules _ = let - checkOne :: expTy -> IO () - {-# INLINE checkOne #-} - checkOne e = when (X ^ e /= opaquePow X e) (reportProblem (X ^ e) e) - reportProblem :: MulTree -> expTy -> IO () - reportProblem wrongVal e = do - printf "Problem with exponent (%s :: %s)\n" (show e) (show $ typeOf e) - printf " Expected: %s\n" (show $ opaquePow X e) - printf " Actual: %s\n" (show wrongVal) - in do - checkOne 0 - checkOne 1 - checkOne 2 - checkOne 3 - checkOne 4 - checkOne 5 - checkOne 6 - checkOne 7 - checkOne 8 - checkOne 9 - checkOne 10 - -main :: IO () -main = do - checkRules (0 :: Integer) - checkRules (0 :: Natural) - checkRules (0 :: Int) - checkRules (0 :: Word) diff --git a/testsuite/tests/lib/base/T19569b.hs b/testsuite/tests/lib/base/T19569b.hs new file mode 100644 index 0000000000..00f7c7367b --- /dev/null +++ b/testsuite/tests/lib/base/T19569b.hs @@ -0,0 +1,56 @@ +-- This program is meant to compare the bracketing produced by the +-- actual implementation of (^) with the bracketing in the RHS of its +-- rewrite rules for known small powers, and complains if they disagree. + +{-# OPTIONS_GHC -O -Wno-missing-methods #-} + +module Main where + +import Control.Monad +import Data.Typeable +import Numeric.Natural +import Text.Printf + +data MulTree = X | FromInteger Integer | Mul MulTree MulTree + deriving (Eq, Show) + +instance Num MulTree where + fromInteger = FromInteger + (*) = Mul + +opaquePow :: (Num a, Integral b) => a -> b -> a +{-# NOINLINE opaquePow #-} +opaquePow k e = k ^ e + +checkRules + :: forall expTy. (Integral expTy, Show expTy, Typeable expTy) + => expTy -> IO () +{-# INLINE checkRules #-} +checkRules _ = let + checkOne :: expTy -> IO () + {-# INLINE checkOne #-} + checkOne e = when (X ^ e /= opaquePow X e) (reportProblem (X ^ e) e) + reportProblem :: MulTree -> expTy -> IO () + reportProblem wrongVal e = do + printf "Problem with exponent (%s :: %s)\n" (show e) (show $ typeOf e) + printf " Expected: %s\n" (show $ opaquePow X e) + printf " Actual: %s\n" (show wrongVal) + in do + checkOne 0 + checkOne 1 + checkOne 2 + checkOne 3 + checkOne 4 + checkOne 5 + checkOne 6 + checkOne 7 + checkOne 8 + checkOne 9 + checkOne 10 + +main :: IO () +main = do + checkRules (0 :: Integer) + checkRules (0 :: Natural) + checkRules (0 :: Int) + checkRules (0 :: Word) diff --git a/testsuite/tests/lib/base/all.T b/testsuite/tests/lib/base/all.T index 8d88097a17..18c3f5814f 100644 --- a/testsuite/tests/lib/base/all.T +++ b/testsuite/tests/lib/base/all.T @@ -6,4 +6,4 @@ test('T17310', normal, compile, ['']) test('T19691', normal, compile, ['']) test('executablePath', extra_run_opts(config.os), compile_and_run, ['']) test('T17472', normal, compile_and_run, ['']) -test('T19569', normal, compile_and_run, ['']) +test('T19569b', normal, compile_and_run, ['']) diff --git a/testsuite/tests/simplCore/should_run/T19569.hs b/testsuite/tests/simplCore/should_run/T19569.hs deleted file mode 100644 index bffef2c6df..0000000000 --- a/testsuite/tests/simplCore/should_run/T19569.hs +++ /dev/null @@ -1,51 +0,0 @@ --- This is the integral benchmark from the nofib benchmark suite. --- In the past there have been issues with numeric stability for this benchmark (see #19569) --- so I added it to testsuite to catch such regressions in the future. - --- It might be acceptable for this test to fail if you make changes to the simplifier. But generally such a failure shouldn't be accepted without good reason. - --- The excessive whitespace is the result of running the original benchmark which was a .lhs file through unlit. - -module Main (integrate1D, main) where - -import System.Environment - -integrate1D :: Double -> Double -> (Double->Double) -> Double -integrate1D l u f = - let d = (u-l)/8.0 in - d * sum - [ (f l)*0.5, - f (l+d), - f (l+(2.0*d)), - f (l+(3.0*d)), - f (l+(4.0*d)), - f (u-(3.0*d)), - f (u-(2.0*d)), - f (u-d), - (f u)*0.5] - -integrate2D l1 u1 l2 u2 f = integrate1D l2 u2 - (\y->integrate1D l1 u1 - (\x->f x y)) - -zark u v = integrate2D 0.0 u 0.0 v (\x->(\y->x*y)) - --- type signature required for compilers lacking the monomorphism restriction -ints = [1.0..] :: [Double] -zarks = zipWith zark ints (map (2.0*) ints) -rtotals = head zarks : zipWith (+) (tail zarks) rtotals -rtotal n = rtotals!!n - -is = map (^4) ints -itotals = head is : zipWith (+) (tail is) itotals -itotal n = itotals!!n - -es = map (^2) (zipWith (-) rtotals itotals) -etotal n = sum (take n es) - --- The (analytical) result should be zero -main = do - [with_output,range] <- getArgs - if (read with_output) - then putStrLn $ show $ etotal $ read range - else seq (etotal $ read range) (putStrLn "Exact result hidden for lack of stability.\nPass 'True' as first argument to the benchmark if you want to view the computed output for testing purposes.") diff --git a/testsuite/tests/simplCore/should_run/T19569.stdout b/testsuite/tests/simplCore/should_run/T19569.stdout deleted file mode 100644 index 25a207288c..0000000000 --- a/testsuite/tests/simplCore/should_run/T19569.stdout +++ /dev/null @@ -1 +0,0 @@ -1.9105614312239304e29 diff --git a/testsuite/tests/simplCore/should_run/T19569a.hs b/testsuite/tests/simplCore/should_run/T19569a.hs new file mode 100644 index 0000000000..bffef2c6df --- /dev/null +++ b/testsuite/tests/simplCore/should_run/T19569a.hs @@ -0,0 +1,51 @@ +-- This is the integral benchmark from the nofib benchmark suite. +-- In the past there have been issues with numeric stability for this benchmark (see #19569) +-- so I added it to testsuite to catch such regressions in the future. + +-- It might be acceptable for this test to fail if you make changes to the simplifier. But generally such a failure shouldn't be accepted without good reason. + +-- The excessive whitespace is the result of running the original benchmark which was a .lhs file through unlit. + +module Main (integrate1D, main) where + +import System.Environment + +integrate1D :: Double -> Double -> (Double->Double) -> Double +integrate1D l u f = + let d = (u-l)/8.0 in + d * sum + [ (f l)*0.5, + f (l+d), + f (l+(2.0*d)), + f (l+(3.0*d)), + f (l+(4.0*d)), + f (u-(3.0*d)), + f (u-(2.0*d)), + f (u-d), + (f u)*0.5] + +integrate2D l1 u1 l2 u2 f = integrate1D l2 u2 + (\y->integrate1D l1 u1 + (\x->f x y)) + +zark u v = integrate2D 0.0 u 0.0 v (\x->(\y->x*y)) + +-- type signature required for compilers lacking the monomorphism restriction +ints = [1.0..] :: [Double] +zarks = zipWith zark ints (map (2.0*) ints) +rtotals = head zarks : zipWith (+) (tail zarks) rtotals +rtotal n = rtotals!!n + +is = map (^4) ints +itotals = head is : zipWith (+) (tail is) itotals +itotal n = itotals!!n + +es = map (^2) (zipWith (-) rtotals itotals) +etotal n = sum (take n es) + +-- The (analytical) result should be zero +main = do + [with_output,range] <- getArgs + if (read with_output) + then putStrLn $ show $ etotal $ read range + else seq (etotal $ read range) (putStrLn "Exact result hidden for lack of stability.\nPass 'True' as first argument to the benchmark if you want to view the computed output for testing purposes.") diff --git a/testsuite/tests/simplCore/should_run/T19569a.stdout b/testsuite/tests/simplCore/should_run/T19569a.stdout new file mode 100644 index 0000000000..25a207288c --- /dev/null +++ b/testsuite/tests/simplCore/should_run/T19569a.stdout @@ -0,0 +1 @@ +1.9105614312239304e29 diff --git a/testsuite/tests/simplCore/should_run/all.T b/testsuite/tests/simplCore/should_run/all.T index 34e7e2e386..52a1af40a8 100644 --- a/testsuite/tests/simplCore/should_run/all.T +++ b/testsuite/tests/simplCore/should_run/all.T @@ -97,7 +97,7 @@ test('NumConstantFolding16', normal, compile_and_run, ['']) test('NumConstantFolding32', normal, compile_and_run, ['']) test('NumConstantFolding', normal, compile_and_run, ['']) test('T19413', normal, compile_and_run, ['']) -test('T19569', [only_ways(['optasm']),extra_run_opts('True 1000000')], compile_and_run, ['-O2']) +test('T19569a', [only_ways(['optasm']),extra_run_opts('True 1000000')], compile_and_run, ['-O2']) test('T20203', normal, compile, ['-O -dsuppress-all -dsuppress-uniques -dno-typeable-binds -ddump-simpl']) test('T19313', normal, compile_and_run, ['']) test('UnliftedArgRule', normal, compile_and_run, ['']) -- cgit v1.2.1