diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2021-07-22 11:41:08 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-07-27 12:03:00 -0400 |
commit | 9bf8d53012be8a36525e0917c67dc4b3deb033ee (patch) | |
tree | 9147945cb53350e51639bd1e6e8689fbb0e7f657 /testsuite/tests | |
parent | 6d2846f7e58ca4d78743b5735a8c34447694a5c5 (diff) | |
download | haskell-9bf8d53012be8a36525e0917c67dc4b3deb033ee.tar.gz |
Eliminate unnecessary unsafeEqualityProof
This patch addresses #20143, which wants to discard unused calls to
unsafeEqualityProof.
There are two parts:
* In exprOkForSideEffects, we want to know that unsafeEqualityProof
indeed terminates, without any exceptions etc
* But we can only discard the case if we know that the coercion
variable is not used, which means we have to gather accurate
occurrence info for CoVars. Previously OccurAnal only did a half
hearted job of doing so; this patch finishes the job.
See Note [Gather occurrences of coercion variables] in OccurAnal.
Because the occurrence analyser does more work, there is a small
compile-time cost but it's pretty small. The compiler perf tests
are usually 0.0% but occasionally up to 0.3% increase. I'm just
going to accept this -- gathering accurate occurrence information
really seems like the Right Thing to do.
There is an increase in `compile_time/peak_megabytes_allocated`, for
T11545, or around 14%; but I can't reproduce it on my machine (it's
the same before and after), and the peak-usage stats are vulnerable to
when exactly the GC takes place, so I'm just going to accept it.
Metric Increase:
T11545
Diffstat (limited to 'testsuite/tests')
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T20143.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/all.T | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/testsuite/tests/simplCore/should_compile/T20143.hs b/testsuite/tests/simplCore/should_compile/T20143.hs new file mode 100644 index 0000000000..d85f173954 --- /dev/null +++ b/testsuite/tests/simplCore/should_compile/T20143.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE ViewPatterns, GADTs #-} + +module T30243( getUL ) where + +import Data.Kind +import Unsafe.Coerce + +newtype AsUnitLoop a (b :: Type) (c :: Type) = UnsafeUL a + +data SafeUnitLoop a b c where + SafeUnitLoop :: !a -> SafeUnitLoop a () () + +mkSafeUnitLoop :: AsUnitLoop a b c -> SafeUnitLoop a b c +mkSafeUnitLoop (UnsafeUL a) = unsafeCoerce (SafeUnitLoop a) + +getUL :: AsUnitLoop a b c -> a +getUL (mkSafeUnitLoop -> SafeUnitLoop a) = a + +-- There should be no unsafeEqualityProof in the output +-- when compiled with -O diff --git a/testsuite/tests/simplCore/should_compile/all.T b/testsuite/tests/simplCore/should_compile/all.T index 2fe050e1ba..616a469746 100644 --- a/testsuite/tests/simplCore/should_compile/all.T +++ b/testsuite/tests/simplCore/should_compile/all.T @@ -368,3 +368,4 @@ test('T19780', normal, compile, ['-O2']) test('T19794', normal, compile, ['-O']) test('T19890', [ grep_errmsg(r'= T19890.foo1') ], compile, ['-O -ddump-simpl']) test('T20125', [ grep_errmsg(r'= T20125.MkT') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) +test('T20143', [ grep_errmsg(r'unsafeEqualityProof') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) |