diff options
author | Simon Peyton Jones <simon.peytonjones@gmail.com> | 2023-01-19 08:59:18 +0000 |
---|---|---|
committer | Simon Peyton Jones <simon.peytonjones@gmail.com> | 2023-01-20 08:34:01 +0000 |
commit | 0ff665690e989f58a46df19e6fcbd35cb80eb0e8 (patch) | |
tree | a9f59bc015b63de6e8f887a31fc654dc9f0ccb67 | |
parent | 14b5982a3aea351e4b01c5804ebd4d4629ba6bab (diff) | |
download | haskell-0ff665690e989f58a46df19e6fcbd35cb80eb0e8.tar.gz |
Fix #22742wip/T22742
runtimeRepLevity_maybe was panicing unnecessarily; and
the error printing code made use of the case when it should
return Nothing rather than panicing.
For some bizarre reason perf/compiler/T21839r shows a 10% bump in runtime
peak-megagbytes-used, on a single architecture (alpine). See !9753 for
commentary, but I'm going to accept it.
Metric Increase:
T21839r
-rw-r--r-- | compiler/GHC/Core/Type.hs | 11 | ||||
-rw-r--r-- | testsuite/tests/polykinds/T22742.hs | 8 | ||||
-rw-r--r-- | testsuite/tests/polykinds/T22742.stderr | 6 | ||||
-rw-r--r-- | testsuite/tests/polykinds/all.T | 1 |
4 files changed, 22 insertions, 4 deletions
diff --git a/compiler/GHC/Core/Type.hs b/compiler/GHC/Core/Type.hs index 81b0f1e31b..9e0d95b0d9 100644 --- a/compiler/GHC/Core/Type.hs +++ b/compiler/GHC/Core/Type.hs @@ -686,8 +686,8 @@ kindBoxedRepLevity_maybe ty -- * False of type variables, type family applications, -- and of other reps such as @IntRep :: RuntimeRep@. isLiftedRuntimeRep :: RuntimeRepType -> Bool -isLiftedRuntimeRep rep = - runtimeRepLevity_maybe rep == Just Lifted +isLiftedRuntimeRep rep + = runtimeRepLevity_maybe rep == Just Lifted -- | Check whether a type of kind 'RuntimeRep' is unlifted. -- @@ -779,7 +779,8 @@ isBoxedRuntimeRep_maybe rep | otherwise = Nothing --- | Check whether a type of kind 'RuntimeRep' is lifted, unlifted, or unknown. +-- | Check whether a type (usually of kind 'RuntimeRep') is lifted, unlifted, +-- or unknown. Returns Nothing if the type isn't of kind 'RuntimeRep'. -- -- `runtimeRepLevity_maybe rr` returns: -- @@ -793,7 +794,9 @@ runtimeRepLevity_maybe rep if (rr_tc `hasKey` boxedRepDataConKey) then case args of [lev] -> levityType_maybe lev - _ -> pprPanic "runtimeRepLevity_maybe" (ppr rep) + _ -> Nothing -- Type isn't of kind RuntimeRep + -- The latter case happens via the call to isLiftedRuntimeRep + -- in GHC.Tc.Errors.Ppr.pprMisMatchMsg (#22742) else Just Unlifted -- Avoid searching all the unlifted RuntimeRep type cons -- In the RuntimeRep data type, only LiftedRep is lifted diff --git a/testsuite/tests/polykinds/T22742.hs b/testsuite/tests/polykinds/T22742.hs new file mode 100644 index 0000000000..d24164156b --- /dev/null +++ b/testsuite/tests/polykinds/T22742.hs @@ -0,0 +1,8 @@ +module T22742 where + +import GHC.Exts (TYPE) + +data T (a :: TYPE r) = MkT + +f :: T @(f a b) () -> () +f MkT = () diff --git a/testsuite/tests/polykinds/T22742.stderr b/testsuite/tests/polykinds/T22742.stderr new file mode 100644 index 0000000000..93d5f235a6 --- /dev/null +++ b/testsuite/tests/polykinds/T22742.stderr @@ -0,0 +1,6 @@ + +T22742.hs:7:17: error: [GHC-83865] + • Couldn't match kind ‘GHC.Types.BoxedRep’ with ‘f a’ + Expected kind ‘TYPE (f a b)’, but ‘()’ has kind ‘*’ + • In the second argument of ‘T’, namely ‘()’ + In the type signature: f :: T @(f a b) () -> () diff --git a/testsuite/tests/polykinds/all.T b/testsuite/tests/polykinds/all.T index b23e76c025..a73508858c 100644 --- a/testsuite/tests/polykinds/all.T +++ b/testsuite/tests/polykinds/all.T @@ -242,3 +242,4 @@ test('T19739d', normal, compile, ['']) test('T22379a', normal, compile, ['']) test('T22379b', normal, compile, ['']) test('T22743', normal, compile_fail, ['']) +test('T22742', normal, compile_fail, ['']) |