From 74311e10bbb6ced9cd3093c8949f2535a715d8f6 Mon Sep 17 00:00:00 2001 From: Sebastian Graf Date: Thu, 20 Feb 2020 16:48:16 +0100 Subject: PmCheck: Implement Long-distance information with Covered sets Consider ```hs data T = A | B | C f :: T -> Int f A = 1 f x = case x of A -> 2 B -> 3 C -> 4 ``` Clearly, the RHS returning 2 is redundant. But we don't currently see that, because our approximation to the covered set of the inner case expression just picks up the positive information from surrounding pattern matches. It lacks the context sensivity that `x` can't be `A` anymore! Therefore, we adopt the conceptually and practically superior approach of reusing the covered set of a particular GRHS from an outer pattern match. In this case, we begin checking the `case` expression with the covered set of `f`s second clause, which encodes the information that `x` can't be `A` anymore. After this MR, we will successfully warn about the RHS returning 2 being redundant. Perhaps surprisingly, this was a great simplification to the code of both the coverage checker and the desugarer. Found a redundant case alternative in `unix` submodule, so we have to bump it with a fix. Metric Decrease: T12227 --- compiler/typecheck/TcRnTypes.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'compiler/typecheck') diff --git a/compiler/typecheck/TcRnTypes.hs b/compiler/typecheck/TcRnTypes.hs index e9da98379c..856dfa7f14 100644 --- a/compiler/typecheck/TcRnTypes.hs +++ b/compiler/typecheck/TcRnTypes.hs @@ -99,7 +99,7 @@ import TcOrigin import Annotations import InstEnv import FamInstEnv -import {-# SOURCE #-} GHC.HsToCore.PmCheck.Types (Delta) +import {-# SOURCE #-} GHC.HsToCore.PmCheck.Types (Deltas) import IOEnv import RdrName import Name @@ -317,9 +317,9 @@ data DsLclEnv = DsLclEnv { dsl_loc :: RealSrcSpan, -- To put in pattern-matching error msgs -- See Note [Note [Type and Term Equality Propagation] in Check.hs - -- The oracle state Delta is augmented as we walk inwards, - -- through each pattern match in turn - dsl_delta :: Delta + -- The set of reaching values Deltas is augmented as we walk inwards, + -- refined through each pattern match in turn + dsl_deltas :: Deltas } -- Inside [| |] brackets, the desugarer looks -- cgit v1.2.1