summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
authornineonine <mail4chemik@gmail.com>2021-11-10 00:52:06 -0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-03-20 21:16:06 -0400
commitc842611fc72d987519cd9fab1c351135ae93665e (patch)
treeaa4365b4050a0733887a4d4f0291e6e9d52cc801 /testsuite
parentd45bb70178e044bc8b6e8215da7bc8ed0c95f2cb (diff)
downloadhaskell-c842611fc72d987519cd9fab1c351135ae93665e.tar.gz
Revamp derived Eq instance code generation (#17240)
This patch improves code generation for derived Eq instances. The idea is to use 'dataToTag' to evaluate both arguments. This allows to 'short-circuit' when tags do not match. Unfortunately, inner evals are still present when we branch on tags. This is due to the way 'dataToTag#' primop evaluates its argument in the code generator. #21207 was created to explore further optimizations. Metric Decrease: LargeRecord
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/deriving/should_compile/T17240.hs5
-rw-r--r--testsuite/tests/deriving/should_compile/T17240.stderr42
-rw-r--r--testsuite/tests/deriving/should_compile/all.T1
-rw-r--r--testsuite/tests/deriving/should_fail/drvfail011.stderr4
4 files changed, 50 insertions, 2 deletions
diff --git a/testsuite/tests/deriving/should_compile/T17240.hs b/testsuite/tests/deriving/should_compile/T17240.hs
new file mode 100644
index 0000000000..6b847c578a
--- /dev/null
+++ b/testsuite/tests/deriving/should_compile/T17240.hs
@@ -0,0 +1,5 @@
+module T17240 where
+
+data T = A | B Int | C Char | D Int deriving Eq
+
+data Nullary = X | Y | Z deriving Eq
diff --git a/testsuite/tests/deriving/should_compile/T17240.stderr b/testsuite/tests/deriving/should_compile/T17240.stderr
new file mode 100644
index 0000000000..cce538b59d
--- /dev/null
+++ b/testsuite/tests/deriving/should_compile/T17240.stderr
@@ -0,0 +1,42 @@
+
+==================== Derived instances ====================
+Derived class instances:
+ instance GHC.Classes.Eq T17240.Nullary where
+ (GHC.Classes.==) a b
+ = case (GHC.Prim.dataToTag# a) of
+ a#
+ -> case (GHC.Prim.dataToTag# b) of
+ b# -> (GHC.Prim.tagToEnum# (a# GHC.Prim.==# b#))
+
+ instance GHC.Classes.Eq T17240.T where
+ (GHC.Classes.==) a b
+ = case
+ (case (GHC.Prim.dataToTag# a) of
+ a# -> case (GHC.Prim.dataToTag# b) of b# -> a# GHC.Prim./=# b#)
+ of
+ 1# -> GHC.Types.False
+ _ -> case a of
+ (T17240.B a1)
+ -> case b of (T17240.B b1) -> ((a1 GHC.Classes.== b1))
+ (T17240.C a1)
+ -> case b of (T17240.C b1) -> ((a1 GHC.Classes.== b1))
+ (T17240.D a1)
+ -> case b of (T17240.D b1) -> ((a1 GHC.Classes.== b1))
+ _ -> GHC.Types.True
+
+
+Derived type family instances:
+
+
+
+==================== Filling in method body ====================
+GHC.Classes.Eq [T17240.Nullary]
+ GHC.Classes./= = GHC.Classes.$dm/= @(T17240.Nullary)
+
+
+
+==================== Filling in method body ====================
+GHC.Classes.Eq [T17240.T]
+ GHC.Classes./= = GHC.Classes.$dm/= @(T17240.T)
+
+
diff --git a/testsuite/tests/deriving/should_compile/all.T b/testsuite/tests/deriving/should_compile/all.T
index a33cb364c3..05f9e87dcb 100644
--- a/testsuite/tests/deriving/should_compile/all.T
+++ b/testsuite/tests/deriving/should_compile/all.T
@@ -122,6 +122,7 @@ test('T15831', normal, compile, [''])
test('T16179', normal, compile, [''])
test('T16341', normal, compile, [''])
test('T16518', normal, compile, [''])
+test('T17240', normal, compile, ['-ddump-deriv -dsuppress-uniques'])
test('T17324', normal, compile, [''])
test('T17339', normal, compile,
['-ddump-simpl -dsuppress-idinfo -dno-typeable-binds'])
diff --git a/testsuite/tests/deriving/should_fail/drvfail011.stderr b/testsuite/tests/deriving/should_fail/drvfail011.stderr
index d439bd03eb..5b26f5b575 100644
--- a/testsuite/tests/deriving/should_fail/drvfail011.stderr
+++ b/testsuite/tests/deriving/should_fail/drvfail011.stderr
@@ -3,8 +3,8 @@ drvfail011.hs:8:1: error:
• No instance for (Eq a) arising from a use of ‘==’
Possible fix: add (Eq a) to the context of the instance declaration
• In the expression: a1 == b1
- In an equation for ‘==’: (==) (T1 a1) (T1 b1) = ((a1 == b1))
+ In a case alternative: (T1 b1) -> ((a1 == b1))
+ In the expression: case b of (T1 b1) -> ((a1 == b1))
When typechecking the code for ‘==’
in a derived instance for ‘Eq (T a)’:
To see the code I am typechecking, use -ddump-deriv
- In the instance declaration for ‘Eq (T a)’