diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2021-05-21 16:51:50 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-06-27 14:57:39 -0400 |
commit | eee498bfce3cce03ba1017b65d559c79d5c2eb60 (patch) | |
tree | d84aca47da56c7d90469412e090025527198bfc2 /testsuite/tests | |
parent | d7758da490db3cc662dbebdac4397b4b2c38d0f0 (diff) | |
download | haskell-eee498bfce3cce03ba1017b65d559c79d5c2eb60.tar.gz |
WorkWrap: Remove mkWWargs (#19874)
`mkWWargs`'s job was pushing casts inwards and doing eta expansion to match
the arity with the number of argument demands we w/w for.
Nowadays, we use the Simplifier to eta expand to arity. In fact, in recent years
we have even seen the eta expansion done by w/w as harmful, see Note [Don't eta
expand in w/w]. If a function hasn't enough manifest lambdas, don't w/w it!
What purpose does `mkWWargs` serve in this world? Not a great one, it turns out!
I could remove it by pulling some important bits,
notably Note [Freshen WW arguments] and Note [Join points and beta-redexes].
Result: We reuse the freshened binder names of the wrapper in the
worker where possible (see testuite changes), much nicer!
In order to avoid scoping errors due to lambda-bound unfoldings in worker
arguments, we zap those unfoldings now. In doing so, we fix #19766.
Fixes #19874.
Diffstat (limited to 'testsuite/tests')
14 files changed, 73 insertions, 53 deletions
diff --git a/testsuite/tests/simplCore/should_compile/T13143.stderr b/testsuite/tests/simplCore/should_compile/T13143.stderr index 87fbdd6213..c4c2db7462 100644 --- a/testsuite/tests/simplCore/should_compile/T13143.stderr +++ b/testsuite/tests/simplCore/should_compile/T13143.stderr @@ -70,15 +70,15 @@ T13143.$wg [InlPrag=[2], Occ=LoopBreaker] :: Bool -> Bool -> GHC.Prim.Int# -> GHC.Prim.Int# [GblId, Arity=3, Str=<1L><1L><L>, Unf=OtherCon []] T13143.$wg - = \ (w :: Bool) (w1 :: Bool) (ww :: GHC.Prim.Int#) -> - case w of { + = \ (ds :: Bool) (ds1 :: Bool) (ww :: GHC.Prim.Int#) -> + case ds of { False -> - case w1 of { + case ds1 of { False -> T13143.$wg GHC.Types.False GHC.Types.True ww; True -> GHC.Prim.+# ww 1# }; True -> - case w1 of { + case ds1 of { False -> T13143.$wg GHC.Types.True GHC.Types.True ww; True -> case lvl of wild2 { } } @@ -94,17 +94,17 @@ g [InlPrag=[2]] :: Bool -> Bool -> Int -> Int Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=3,unsat_ok=True,boring_ok=False) - Tmpl= \ (w [Occ=Once1] :: Bool) - (w1 [Occ=Once1] :: Bool) - (w2 [Occ=Once1!] :: Int) -> - case w2 of { GHC.Types.I# ww [Occ=Once1] -> - case T13143.$wg w w1 ww of ww1 [Occ=Once1] { __DEFAULT -> + Tmpl= \ (ds [Occ=Once1] :: Bool) + (ds1 [Occ=Once1] :: Bool) + (p [Occ=Once1!] :: Int) -> + case p of { GHC.Types.I# ww [Occ=Once1] -> + case T13143.$wg ds ds1 ww of ww1 [Occ=Once1] { __DEFAULT -> GHC.Types.I# ww1 } }}] -g = \ (w :: Bool) (w1 :: Bool) (w2 :: Int) -> - case w2 of { GHC.Types.I# ww -> - case T13143.$wg w w1 ww of ww1 { __DEFAULT -> GHC.Types.I# ww1 } +g = \ (ds :: Bool) (ds1 :: Bool) (p :: Int) -> + case p of { GHC.Types.I# ww -> + case T13143.$wg ds ds1 ww of ww1 { __DEFAULT -> GHC.Types.I# ww1 } } diff --git a/testsuite/tests/simplCore/should_compile/T15631.stdout b/testsuite/tests/simplCore/should_compile/T15631.stdout index e9e6a2bcab..ab181b58ed 100644 --- a/testsuite/tests/simplCore/should_compile/T15631.stdout +++ b/testsuite/tests/simplCore/should_compile/T15631.stdout @@ -1,7 +1,7 @@ case GHC.List.$wlenAcc - case GHC.List.$wlenAcc @a w 0# of ww1 { __DEFAULT -> - case GHC.List.reverse1 @a w (GHC.Types.[] @a) of { + case GHC.List.$wlenAcc @a xs 0# of ww1 { __DEFAULT -> + case GHC.List.reverse1 @a xs (GHC.Types.[] @a) of { [] -> case Foo.f1 @a of { GHC.Types.I# v1 -> GHC.Prim.+# ww1 v1 }; case GHC.List.$wlenAcc - case Foo.$wf @a w of ww [Occ=Once1] { __DEFAULT -> - case Foo.$wf @a w of ww { __DEFAULT -> GHC.Types.I# ww } + case Foo.$wf @a xs of ww [Occ=Once1] { __DEFAULT -> + case Foo.$wf @a xs of ww { __DEFAULT -> GHC.Types.I# ww } diff --git a/testsuite/tests/simplCore/should_compile/T18013.stderr b/testsuite/tests/simplCore/should_compile/T18013.stderr index 45f9900830..5c82b03c93 100644 --- a/testsuite/tests/simplCore/should_compile/T18013.stderr +++ b/testsuite/tests/simplCore/should_compile/T18013.stderr @@ -140,8 +140,8 @@ mapMaybeRule [InlPrag=[2]] Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=False) - Tmpl= \ (@a) (@b) (w [Occ=Once1!] :: Rule IO a b) -> - case w of { Rule @s ww ww1 [Occ=OnceL1!] -> + Tmpl= \ (@a) (@b) (f [Occ=Once1!] :: Rule IO a b) -> + case f of { Rule @s ww ww1 [Occ=OnceL1!] -> T18013a.Rule @IO @(Maybe a) @@ -176,8 +176,8 @@ mapMaybeRule [InlPrag=[2]] ~R# (s -> Maybe a -> IO (Result s (Maybe b)))) }}] mapMaybeRule - = \ (@a) (@b) (w :: Rule IO a b) -> - case w of { Rule @s ww ww1 -> + = \ (@a) (@b) (f :: Rule IO a b) -> + case f of { Rule @s ww ww1 -> let { lvl :: Result s (Maybe b) [LclId, Unf=OtherCon []] diff --git a/testsuite/tests/simplCore/should_compile/T19246.stderr b/testsuite/tests/simplCore/should_compile/T19246.stderr index 0c7894e56d..acfe1500b8 100644 --- a/testsuite/tests/simplCore/should_compile/T19246.stderr +++ b/testsuite/tests/simplCore/should_compile/T19246.stderr @@ -6,6 +6,6 @@ ==================== Tidy Core rules ==================== "SPEC f" [2] forall ($dOrd :: Ord Int). f @Int $dOrd = $sf "SPEC/T19246 $wf @Int" [2] - forall (w :: Ord Int). $wf @Int w = $s$wf + forall ($dOrd :: Ord Int). $wf @Int $dOrd = $s$wf diff --git a/testsuite/tests/simplCore/should_compile/T3717.stderr b/testsuite/tests/simplCore/should_compile/T3717.stderr index 6e8fe19294..bd6417b729 100644 --- a/testsuite/tests/simplCore/should_compile/T3717.stderr +++ b/testsuite/tests/simplCore/should_compile/T3717.stderr @@ -61,15 +61,15 @@ foo [InlPrag=[2]] :: Int -> Int Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=False) - Tmpl= \ (w [Occ=Once1!] :: Int) -> - case w of { GHC.Types.I# ww [Occ=Once1] -> + Tmpl= \ (ds [Occ=Once1!] :: Int) -> + case ds of { GHC.Types.I# ww [Occ=Once1] -> case T3717.$wfoo ww of ww1 [Occ=Once1] { __DEFAULT -> GHC.Types.I# ww1 } }}] foo - = \ (w :: Int) -> - case w of { GHC.Types.I# ww -> + = \ (ds :: Int) -> + case ds of { GHC.Types.I# ww -> case T3717.$wfoo ww of ww1 { __DEFAULT -> GHC.Types.I# ww1 } } diff --git a/testsuite/tests/simplCore/should_compile/T3772.stdout b/testsuite/tests/simplCore/should_compile/T3772.stdout index 5ead45f9c3..abf4b8db14 100644 --- a/testsuite/tests/simplCore/should_compile/T3772.stdout +++ b/testsuite/tests/simplCore/should_compile/T3772.stdout @@ -69,10 +69,10 @@ foo [InlPrag=[final]] :: Int -> () Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=False) - Tmpl= \ (w [Occ=Once1!] :: Int) -> - case w of { GHC.Types.I# ww [Occ=Once1] -> T3772.$wfoo ww }}] + Tmpl= \ (n [Occ=Once1!] :: Int) -> + case n of { GHC.Types.I# ww [Occ=Once1] -> T3772.$wfoo ww }}] foo - = \ (w :: Int) -> case w of { GHC.Types.I# ww -> T3772.$wfoo ww } + = \ (n :: Int) -> case n of { GHC.Types.I# ww -> T3772.$wfoo ww } diff --git a/testsuite/tests/simplCore/should_compile/T4908.stderr b/testsuite/tests/simplCore/should_compile/T4908.stderr index f8f9107485..afea396826 100644 --- a/testsuite/tests/simplCore/should_compile/T4908.stderr +++ b/testsuite/tests/simplCore/should_compile/T4908.stderr @@ -63,10 +63,10 @@ T4908.$wf [InlPrag=[2]] :: Int# -> (Int, Int) -> Bool Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [30 20] 101 20}] T4908.$wf - = \ (ww :: Int#) (w :: (Int, Int)) -> + = \ (ww :: Int#) (x :: (Int, Int)) -> case ww of ds { __DEFAULT -> - case w of { (a, b) -> + case x of { (a, b) -> case b of { I# ds1 -> case ds1 of ds2 { __DEFAULT -> T4908.f_$s$wf a ds2 (-# ds 1#); @@ -85,10 +85,10 @@ f [InlPrag=[2]] :: Int -> (Int, Int) -> Bool Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False) - Tmpl= \ (w [Occ=Once1!] :: Int) (w1 [Occ=Once1] :: (Int, Int)) -> - case w of { I# ww [Occ=Once1] -> T4908.$wf ww w1 }}] -f = \ (w :: Int) (w1 :: (Int, Int)) -> - case w of { I# ww -> T4908.$wf ww w1 } + Tmpl= \ (ds [Occ=Once1!] :: Int) (x [Occ=Once1] :: (Int, Int)) -> + case ds of { I# ww [Occ=Once1] -> T4908.$wf ww x }}] +f = \ (ds :: Int) (x :: (Int, Int)) -> + case ds of { I# ww -> T4908.$wf ww x } ------ Local rules for imported ids -------- diff --git a/testsuite/tests/simplCore/should_compile/T4930.stderr b/testsuite/tests/simplCore/should_compile/T4930.stderr index 3321809415..9da0009f84 100644 --- a/testsuite/tests/simplCore/should_compile/T4930.stderr +++ b/testsuite/tests/simplCore/should_compile/T4930.stderr @@ -61,15 +61,15 @@ foo [InlPrag=[2]] :: Int -> Int Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=False) - Tmpl= \ (w [Occ=Once1!] :: Int) -> - case w of { GHC.Types.I# ww [Occ=Once1] -> + Tmpl= \ (n [Occ=Once1!] :: Int) -> + case n of { GHC.Types.I# ww [Occ=Once1] -> case T4930.$wfoo ww of ww1 [Occ=Once1] { __DEFAULT -> GHC.Types.I# ww1 } }}] foo - = \ (w :: Int) -> - case w of { GHC.Types.I# ww -> + = \ (n :: Int) -> + case n of { GHC.Types.I# ww -> case T4930.$wfoo ww of ww1 { __DEFAULT -> GHC.Types.I# ww1 } } diff --git a/testsuite/tests/simplCore/should_compile/T5298.stdout b/testsuite/tests/simplCore/should_compile/T5298.stdout index 67b106c3be..661e893028 100644 --- a/testsuite/tests/simplCore/should_compile/T5298.stdout +++ b/testsuite/tests/simplCore/should_compile/T5298.stdout @@ -6,8 +6,8 @@ $wg 0# -> 1# } -- -g = \ w -> - case w of { I# ww -> case $wg ww of ww1 { __DEFAULT -> I# ww1 } } +g = \ ds -> + case ds of { I# ww -> case $wg ww of ww1 { __DEFAULT -> I# ww1 } } ------ Local rules for imported ids -------- diff --git a/testsuite/tests/simplCore/should_compile/T8331.stderr b/testsuite/tests/simplCore/should_compile/T8331.stderr index e84edead21..7219016651 100644 --- a/testsuite/tests/simplCore/should_compile/T8331.stderr +++ b/testsuite/tests/simplCore/should_compile/T8331.stderr @@ -16,7 +16,7 @@ ReaderT r (ST s) a -> ReaderT r (ST s) b -> ReaderT r (ST s) b)) "SPEC $c>> @(ST s) _" forall (@s) (@r) ($dMonad :: Monad (ST s)). - $fMonadReaderT_$c>> @(ST s) @r $dMonad + $fMonadReaderT1 @(ST s) @r $dMonad = $fMonadAbstractIOSTReaderT_$s$c>> @s @r "SPEC $cliftA2 @(ST s) _" forall (@s) (@r) ($dApplicative :: Applicative (ST s)). diff --git a/testsuite/tests/simplCore/should_compile/spec-inline.stderr b/testsuite/tests/simplCore/should_compile/spec-inline.stderr index 319eba03cb..2ba178e6bf 100644 --- a/testsuite/tests/simplCore/should_compile/spec-inline.stderr +++ b/testsuite/tests/simplCore/should_compile/spec-inline.stderr @@ -80,12 +80,12 @@ Roman.$wgo [InlPrag=[2]] :: Maybe Int -> Maybe Int -> GHC.Prim.Int# Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=IF_ARGS [61 30] 249 0}] Roman.$wgo - = \ (w :: Maybe Int) (w1 :: Maybe Int) -> - case w1 of { + = \ (u :: Maybe Int) (ds :: Maybe Int) -> + case ds of { Nothing -> case Roman.foo3 of wild1 { }; Just x -> case x of { GHC.Types.I# ipv -> - case w of { + case u of { Nothing -> Roman.foo_$s$wgo (GHC.Prim.*# 7# ipv) 10#; Just n -> case n of { GHC.Types.I# x2 -> @@ -116,14 +116,14 @@ Roman.foo_go [InlPrag=[2]] :: Maybe Int -> Maybe Int -> Int Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True, WorkFree=True, Expandable=True, Guidance=ALWAYS_IF(arity=2,unsat_ok=True,boring_ok=False) - Tmpl= \ (w [Occ=Once1] :: Maybe Int) - (w1 [Occ=Once1] :: Maybe Int) -> - case Roman.$wgo w w1 of ww [Occ=Once1] { __DEFAULT -> + Tmpl= \ (u [Occ=Once1] :: Maybe Int) + (ds [Occ=Once1] :: Maybe Int) -> + case Roman.$wgo u ds of ww [Occ=Once1] { __DEFAULT -> GHC.Types.I# ww }}] Roman.foo_go - = \ (w :: Maybe Int) (w1 :: Maybe Int) -> - case Roman.$wgo w w1 of ww { __DEFAULT -> GHC.Types.I# ww } + = \ (u :: Maybe Int) (ds :: Maybe Int) -> + case Roman.$wgo u ds of ww { __DEFAULT -> GHC.Types.I# ww } -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} Roman.foo2 :: Int diff --git a/testsuite/tests/stranal/should_compile/T16029.stdout b/testsuite/tests/stranal/should_compile/T16029.stdout index 2d1f2106f3..76bf2617fb 100644 --- a/testsuite/tests/stranal/should_compile/T16029.stdout +++ b/testsuite/tests/stranal/should_compile/T16029.stdout @@ -4,8 +4,8 @@ :: GHC.Prim.Int# -> GHC.Prim.Int# = \ (ww :: GHC.Prim.Int#) -> g2 [InlPrag=[2]] :: T -> Int -> Int - Tmpl= \ (w [Occ=Once1!] :: T) (w1 [Occ=Once1!] :: Int) -> - = \ (w :: T) (w1 :: Int) -> + Tmpl= \ (ds [Occ=Once1!] :: T) (ds1 [Occ=Once1!] :: Int) -> + = \ (ds :: T) (ds1 :: Int) -> g1 [InlPrag=[2]] :: S -> Int -> Int - Tmpl= \ (w [Occ=Once1!] :: S) (w1 [Occ=Once1!] :: Int) -> - = \ (w :: S) (w1 :: Int) -> + Tmpl= \ (ds [Occ=Once1!] :: S) (ds1 [Occ=Once1!] :: Int) -> + = \ (ds :: S) (ds1 :: Int) -> diff --git a/testsuite/tests/stranal/should_compile/T19766.hs b/testsuite/tests/stranal/should_compile/T19766.hs new file mode 100644 index 0000000000..1062c57cc1 --- /dev/null +++ b/testsuite/tests/stranal/should_compile/T19766.hs @@ -0,0 +1,19 @@ +{-# OPTIONS_GHC -O #-} + +module T19766 where + +data T a b = T !a !b + +data HasT = A (T Int Int) | B (T Int Int) + +getT :: HasT -> T Int Int +getT (A t) = t +getT (B t) = t + +f :: HasT -> [Int] +f ht = case getT ht of t@(T _ _) -> reverse $ reverse $ reverse $ reverse $ reverse $ reverse $ lookupGRE t 15 [1,2,3,4] +{-# NOINLINE f #-} + +lookupGRE :: T Int a -> Int -> [Int] -> [Int] +lookupGRE ~(T n _) !k xs = [ x | x <- xs, x+k == n ] +{-# NOINLINE lookupGRE #-} diff --git a/testsuite/tests/stranal/should_compile/all.T b/testsuite/tests/stranal/should_compile/all.T index f5ebbf289a..9a210ea165 100644 --- a/testsuite/tests/stranal/should_compile/all.T +++ b/testsuite/tests/stranal/should_compile/all.T @@ -66,6 +66,7 @@ test('T18894b', [ grep_errmsg(r'Arity=2') ], compile, ['-ddump-stranal -dsuppre test('T18982', [ grep_errmsg(r'\$w. .*Int#$') ], compile, ['-dppr-cols=1000 -ddump-simpl -dsuppress-idinfo -dsuppress-uniques']) test('T19180', normal, compile, ['']) +test('T19766', [ grep_errmsg(r'absentError') ], compile, ['-ddump-worker-wrapper']) test('T19849', normal, compile, ['']) test('T19882a', normal, compile, ['']) test('T19882b', normal, compile, ['']) |