diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2020-09-08 19:25:11 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-09-15 15:19:44 -0400 |
commit | c7182a5c67fe8b5bd256cb8eb805562636853ea2 (patch) | |
tree | 6e9f04053559df514b8deab624bb9491fae27f27 /testsuite/tests | |
parent | 8610bcbeb11b898f85f228b755fa8421b5ae3e34 (diff) | |
download | haskell-c7182a5c67fe8b5bd256cb8eb805562636853ea2.tar.gz |
Care with implicit-parameter superclasses
Two bugs, #18627 and #18649, had the same cause: we were not
account for the fact that a constaint tuple might hide an implicit
parameter.
The solution is not hard: look for implicit parameters in
superclasses. See Note [Local implicit parameters] in
GHC.Core.Predicate.
Then we use this new function in two places
* The "short-cut solver" in GHC.Tc.Solver.Interact.shortCutSolver
which simply didn't handle implicit parameters properly at all.
This fixes #18627
* The specialiser, which should not specialise on implicit parameters
This fixes #18649
There are some lingering worries (see Note [Local implicit
parameters]) but things are much better.
Diffstat (limited to 'testsuite/tests')
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T18649.hs | 26 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/T18649.stderr | 4 | ||||
-rw-r--r-- | testsuite/tests/simplCore/should_compile/all.T | 4 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_run/T18627.hs | 16 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_run/T18627.stdout | 1 | ||||
-rwxr-xr-x | testsuite/tests/typecheck/should_run/all.T | 1 |
6 files changed, 52 insertions, 0 deletions
diff --git a/testsuite/tests/simplCore/should_compile/T18649.hs b/testsuite/tests/simplCore/should_compile/T18649.hs new file mode 100644 index 0000000000..de8b59bf86 --- /dev/null +++ b/testsuite/tests/simplCore/should_compile/T18649.hs @@ -0,0 +1,26 @@ +{-# LANGUAGE ImplicitParams #-} +{-# LANGUAGE ConstraintKinds #-} +{-# LANGUAGE FlexibleContexts #-} + +module Test where + +import Prelude + +type Hidden a = + ( ?enable :: a + , Eq a -- removing this "fixes" the issue + ) + +{-# NOINLINE a #-} +a :: Hidden Bool => Integer -> Bool +a _ = ?enable + +system :: Hidden Bool => Bool +system = a 0 + +topEntity :: Bool -> Bool +topEntity ena = let ?enable = ena + in system + +someVar = let ?enable = True + in system diff --git a/testsuite/tests/simplCore/should_compile/T18649.stderr b/testsuite/tests/simplCore/should_compile/T18649.stderr new file mode 100644 index 0000000000..079367fbee --- /dev/null +++ b/testsuite/tests/simplCore/should_compile/T18649.stderr @@ -0,0 +1,4 @@ + +==================== Tidy Core rules ==================== + + diff --git a/testsuite/tests/simplCore/should_compile/all.T b/testsuite/tests/simplCore/should_compile/all.T index 771798ee18..d377cfd06b 100644 --- a/testsuite/tests/simplCore/should_compile/all.T +++ b/testsuite/tests/simplCore/should_compile/all.T @@ -333,3 +333,7 @@ test('T18347', normal, compile, ['-dcore-lint -O']) test('T18355', [ grep_errmsg(r'OneShot') ], compile, ['-O -ddump-simpl -dsuppress-uniques']) test('T18399', normal, compile, ['-dcore-lint -O']) test('T18589', normal, compile, ['-dcore-lint -O']) + +# T18649 should /not/ generate a specialisation rule +test('T18649', normal, compile, ['-O -ddump-rules -Wno-simplifiable-class-constraints']) + diff --git a/testsuite/tests/typecheck/should_run/T18627.hs b/testsuite/tests/typecheck/should_run/T18627.hs new file mode 100644 index 0000000000..22dd87c83a --- /dev/null +++ b/testsuite/tests/typecheck/should_run/T18627.hs @@ -0,0 +1,16 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE ImplicitParams #-} +{-# LANGUAGE MultiParamTypeClasses #-} +module Main where + +import GHC.Classes + +instance IP "x" Int where + ip = 21 + +baz :: (?x :: Int) => Int +baz = ?x + +main :: IO () +main = let ?x = 42 + in print baz diff --git a/testsuite/tests/typecheck/should_run/T18627.stdout b/testsuite/tests/typecheck/should_run/T18627.stdout new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/testsuite/tests/typecheck/should_run/T18627.stdout @@ -0,0 +1 @@ +42 diff --git a/testsuite/tests/typecheck/should_run/all.T b/testsuite/tests/typecheck/should_run/all.T index 5afc7e3725..f69cc71352 100755 --- a/testsuite/tests/typecheck/should_run/all.T +++ b/testsuite/tests/typecheck/should_run/all.T @@ -146,3 +146,4 @@ test('UnliftedNewtypesDependentFamilyRun', normal, compile_and_run, ['']) test('UnliftedNewtypesIdentityRun', normal, compile_and_run, ['']) test('UnliftedNewtypesCoerceRun', normal, compile_and_run, ['']) test('T17104', normal, compile_and_run, ['']) +test('T18627', normal, compile_and_run, ['-O']) # Optimisation shows up the bug |