diff options
author | Joachim Breitner <mail@joachim-breitner.de> | 2017-04-09 19:40:02 -0400 |
---|---|---|
committer | Joachim Breitner <mail@joachim-breitner.de> | 2017-04-10 10:12:39 -0400 |
commit | b55f310d06b8d3988d40aaccc0ff13601ee52b84 (patch) | |
tree | f032490d14cb2c4a03f3a9b97456c16b1df5cd7c /testsuite/tests/simplStg | |
parent | 87377f74eec1567af741737b4b9034d06e3f0698 (diff) | |
download | haskell-b55f310d06b8d3988d40aaccc0ff13601ee52b84.tar.gz |
StgCse: Do not re-use trivial case scrutinees
as they might be marked as one-shot, and suddenly we’d evaluate them
multiple times. This came up in #13536 (test cases included).
The solution was layed out by SPJ in ticket:13536#comment:12.
Differential Revision: https://phabricator.haskell.org/D3437
Diffstat (limited to 'testsuite/tests/simplStg')
-rw-r--r-- | testsuite/tests/simplStg/should_run/T13536.hs | 17 | ||||
-rw-r--r-- | testsuite/tests/simplStg/should_run/T13536.stderr | 1 | ||||
-rw-r--r-- | testsuite/tests/simplStg/should_run/T13536.stdout | 1 | ||||
-rw-r--r-- | testsuite/tests/simplStg/should_run/all.T | 1 |
4 files changed, 20 insertions, 0 deletions
diff --git a/testsuite/tests/simplStg/should_run/T13536.hs b/testsuite/tests/simplStg/should_run/T13536.hs new file mode 100644 index 0000000000..cf70f46163 --- /dev/null +++ b/testsuite/tests/simplStg/should_run/T13536.hs @@ -0,0 +1,17 @@ +import Debug.Trace + +newtype Id a = Id a + + +unId True _ = Nothing -- make lazy +unId False (Just (Id x)) = (Just x) +unId False Nothing = Nothing +{-# NOINLINE unId #-} + +val n = trace "evalued once, as it should" (Just (Id n)) +{-# NOINLINE val #-} + +foo b n = unId b (val n) +{-# NOINLINE foo #-} + +main = print (foo False 1) diff --git a/testsuite/tests/simplStg/should_run/T13536.stderr b/testsuite/tests/simplStg/should_run/T13536.stderr new file mode 100644 index 0000000000..638b7f82c1 --- /dev/null +++ b/testsuite/tests/simplStg/should_run/T13536.stderr @@ -0,0 +1 @@ +evalued once, as it should diff --git a/testsuite/tests/simplStg/should_run/T13536.stdout b/testsuite/tests/simplStg/should_run/T13536.stdout new file mode 100644 index 0000000000..f8e0357378 --- /dev/null +++ b/testsuite/tests/simplStg/should_run/T13536.stdout @@ -0,0 +1 @@ +Just 1 diff --git a/testsuite/tests/simplStg/should_run/all.T b/testsuite/tests/simplStg/should_run/all.T index 3d4f4a3763..b24da84ef2 100644 --- a/testsuite/tests/simplStg/should_run/all.T +++ b/testsuite/tests/simplStg/should_run/all.T @@ -10,3 +10,4 @@ def f( name, opts ): setTestOpts(f) test('T9291', normal, compile_and_run, ['']) +test('T13536', normal, compile_and_run, ['']) |