Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
19f20861
by Simon Peyton Jones at 2025-06-13T09:51:11-04:00
14 changed files:
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Solver/Default.hs
- compiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Solve.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Types/Evidence.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Instantiate.hs
- testsuite/tests/dependent/should_fail/T13135_simple.stderr
- + testsuite/tests/typecheck/should_compile/T25992.hs
- + testsuite/tests/typecheck/should_compile/T25992.stderr
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_fail/tcfail097.stderr
Changes:
| ... | ... | @@ -399,13 +399,6 @@ warnRedundantConstraints ctxt env info redundant_evs |
| 399 | 399 | | null redundant_evs
|
| 400 | 400 | = return ()
|
| 401 | 401 | |
| 402 | - -- Do not report redundant constraints for quantified constraints
|
|
| 403 | - -- See (RC4) in Note [Tracking redundant constraints]
|
|
| 404 | - -- Fortunately it is easy to spot implications constraints that arise
|
|
| 405 | - -- from quantified constraints, from their SkolInfo
|
|
| 406 | - | InstSkol (IsQC {}) _ <- info
|
|
| 407 | - = return ()
|
|
| 408 | - |
|
| 409 | 402 | | SigSkol user_ctxt _ _ <- info
|
| 410 | 403 | -- When dealing with a user-written type signature,
|
| 411 | 404 | -- we want to add "In the type signature for f".
|
| ... | ... | @@ -247,11 +247,11 @@ tryUnsatisfiableGivens wc = |
| 247 | 247 | ; solveAgainIf did_work final_wc }
|
| 248 | 248 | where
|
| 249 | 249 | go_wc (WC { wc_simple = wtds, wc_impl = impls, wc_errors = errs })
|
| 250 | - = do impls' <- mapMaybeBagM go_impl impls
|
|
| 250 | + = do impls' <- mapBagM go_impl impls
|
|
| 251 | 251 | return $ WC { wc_simple = wtds, wc_impl = impls', wc_errors = errs }
|
| 252 | 252 | go_impl impl
|
| 253 | 253 | | isSolvedStatus (ic_status impl)
|
| 254 | - = return $ Just impl
|
|
| 254 | + = return impl
|
|
| 255 | 255 | -- Is there a Given with type "Unsatisfiable msg"?
|
| 256 | 256 | -- If so, use it to solve all other Wanteds.
|
| 257 | 257 | | unsat_given:_ <- mapMaybe unsatisfiableEv_maybe (ic_given impl)
|
| ... | ... | @@ -271,24 +271,26 @@ unsatisfiableEv_maybe v = (v,) <$> isUnsatisfiableCt_maybe (idType v) |
| 271 | 271 | -- | We have an implication with an 'Unsatisfiable' Given; use that Given to
|
| 272 | 272 | -- solve all the other Wanted constraints, including those nested within
|
| 273 | 273 | -- deeper implications.
|
| 274 | -solveImplicationUsingUnsatGiven :: (EvVar, Type) -> Implication -> TcS (Maybe Implication)
|
|
| 274 | +solveImplicationUsingUnsatGiven :: (EvVar, Type) -> Implication -> TcS Implication
|
|
| 275 | 275 | solveImplicationUsingUnsatGiven
|
| 276 | 276 | unsat_given@(given_ev,_)
|
| 277 | - impl@(Implic { ic_wanted = wtd, ic_tclvl = tclvl, ic_binds = ev_binds_var, ic_need_inner = inner })
|
|
| 277 | + impl@(Implic { ic_wanted = wtd, ic_tclvl = tclvl, ic_binds = ev_binds_var
|
|
| 278 | + , ic_need_implic = inner })
|
|
| 278 | 279 | | isCoEvBindsVar ev_binds_var
|
| 279 | 280 | -- We can't use Unsatisfiable evidence in kinds.
|
| 280 | 281 | -- See Note [Coercion evidence only] in GHC.Tc.Types.Evidence.
|
| 281 | - = return $ Just impl
|
|
| 282 | + = return impl
|
|
| 282 | 283 | | otherwise
|
| 283 | 284 | = do { wcs <- nestImplicTcS ev_binds_var tclvl $ go_wc wtd
|
| 284 | 285 | ; setImplicationStatus $
|
| 285 | 286 | impl { ic_wanted = wcs
|
| 286 | - , ic_need_inner = inner `extendVarSet` given_ev } }
|
|
| 287 | + , ic_need_implic = inner `extendEvNeedSet` given_ev } }
|
|
| 288 | + -- Record that the Given is needed; I'm not certain why
|
|
| 287 | 289 | where
|
| 288 | 290 | go_wc :: WantedConstraints -> TcS WantedConstraints
|
| 289 | 291 | go_wc wc@(WC { wc_simple = wtds, wc_impl = impls })
|
| 290 | 292 | = do { mapBagM_ go_simple wtds
|
| 291 | - ; impls <- mapMaybeBagM (solveImplicationUsingUnsatGiven unsat_given) impls
|
|
| 293 | + ; impls <- mapBagM (solveImplicationUsingUnsatGiven unsat_given) impls
|
|
| 292 | 294 | ; return $ wc { wc_simple = emptyBag, wc_impl = impls } }
|
| 293 | 295 | go_simple :: Ct -> TcS ()
|
| 294 | 296 | go_simple ct = case ctEvidence ct of
|
| ... | ... | @@ -399,21 +401,21 @@ tryConstraintDefaulting wc |
| 399 | 401 | where
|
| 400 | 402 | go_wc :: WantedConstraints -> TcS WantedConstraints
|
| 401 | 403 | go_wc wc@(WC { wc_simple = simples, wc_impl = implics })
|
| 402 | - = do { simples' <- mapMaybeBagM go_simple simples
|
|
| 403 | - ; mb_implics <- mapMaybeBagM go_implic implics
|
|
| 404 | - ; return (wc { wc_simple = simples', wc_impl = mb_implics }) }
|
|
| 404 | + = do { simples' <- mapMaybeBagM go_simple simples
|
|
| 405 | + ; implics' <- mapBagM go_implic implics
|
|
| 406 | + ; return (wc { wc_simple = simples', wc_impl = implics' }) }
|
|
| 405 | 407 | |
| 406 | 408 | go_simple :: Ct -> TcS (Maybe Ct)
|
| 407 | 409 | go_simple ct = do { solved <- tryCtDefaultingStrategy ct
|
| 408 | 410 | ; if solved then return Nothing
|
| 409 | 411 | else return (Just ct) }
|
| 410 | 412 | |
| 411 | - go_implic :: Implication -> TcS (Maybe Implication)
|
|
| 413 | + go_implic :: Implication -> TcS Implication
|
|
| 412 | 414 | -- The Maybe is because solving the CallStack constraint
|
| 413 | 415 | -- may well allow us to discard the implication entirely
|
| 414 | 416 | go_implic implic
|
| 415 | 417 | | isSolvedStatus (ic_status implic)
|
| 416 | - = return (Just implic) -- Nothing to solve inside here
|
|
| 418 | + = return implic -- Nothing to solve inside here
|
|
| 417 | 419 | | otherwise
|
| 418 | 420 | = do { wanteds <- setEvBindsTcS (ic_binds implic) $
|
| 419 | 421 | -- defaultCallStack sets a binding, so
|
| ... | ... | @@ -2089,18 +2089,8 @@ solveOneFromTheOther. |
| 2089 | 2089 | (a) If both are GivenSCOrigin, choose the one that is unblocked if possible
|
| 2090 | 2090 | according to Note [Solving superclass constraints] in GHC.Tc.TyCl.Instance.
|
| 2091 | 2091 | |
| 2092 | - (b) Prefer constraints that are not superclass selections. Example:
|
|
| 2093 | - |
|
| 2094 | - f :: (Eq a, Ord a) => a -> Bool
|
|
| 2095 | - f x = x == x
|
|
| 2096 | - |
|
| 2097 | - Eager superclass expansion gives us two [G] Eq a constraints. We
|
|
| 2098 | - want to keep the one from the user-written Eq a, not the superclass
|
|
| 2099 | - selection. This means we report the Ord a as redundant with
|
|
| 2100 | - -Wredundant-constraints, not the Eq a.
|
|
| 2101 | - |
|
| 2102 | - Getting this wrong was #20602. See also
|
|
| 2103 | - Note [Tracking redundant constraints] in GHC.Tc.Solver.
|
|
| 2092 | + (b) Prefer constraints that are not superclass selections. See
|
|
| 2093 | + (TRC3) in Note [Tracking redundant constraints] in GHC.Tc.Solver.
|
|
| 2104 | 2094 | |
| 2105 | 2095 | (c) If both are GivenSCOrigin, chooose the one with the shallower
|
| 2106 | 2096 | superclass-selection depth, in the hope of identifying more correct
|
| ... | ... | @@ -42,6 +42,7 @@ import GHC.Types.Var( EvVar, tyVarKind ) |
| 42 | 42 | import GHC.Types.Var.Env
|
| 43 | 43 | import GHC.Types.Var.Set
|
| 44 | 44 | import GHC.Types.Basic ( IntWithInf, intGtLimit )
|
| 45 | +import GHC.Types.Unique.Set( nonDetStrictFoldUniqSet )
|
|
| 45 | 46 | |
| 46 | 47 | import GHC.Data.Bag
|
| 47 | 48 | |
| ... | ... | @@ -51,9 +52,10 @@ import GHC.Utils.Misc |
| 51 | 52 | |
| 52 | 53 | import GHC.Driver.Session
|
| 53 | 54 | |
| 54 | -import Data.List( deleteFirstsBy )
|
|
| 55 | 55 | |
| 56 | 56 | import Control.Monad
|
| 57 | + |
|
| 58 | +import Data.List( deleteFirstsBy )
|
|
| 57 | 59 | import Data.Foldable ( traverse_ )
|
| 58 | 60 | import Data.Maybe ( mapMaybe )
|
| 59 | 61 | import qualified Data.Semigroup as S
|
| ... | ... | @@ -277,10 +279,10 @@ solveNestedImplications implics |
| 277 | 279 | ; traceTcS "solveNestedImplications end }" $
|
| 278 | 280 | vcat [ text "unsolved_implics =" <+> ppr unsolved_implics ]
|
| 279 | 281 | |
| 280 | - ; return (catBagMaybes unsolved_implics) }
|
|
| 282 | + ; return unsolved_implics }
|
|
| 281 | 283 | |
| 282 | -solveImplication :: Implication -- Wanted
|
|
| 283 | - -> TcS (Maybe Implication) -- Simplified implication (empty or singleton)
|
|
| 284 | +solveImplication :: Implication -- Wanted
|
|
| 285 | + -> TcS Implication -- Simplified implication (empty or singleton)
|
|
| 284 | 286 | -- Precondition: The TcS monad contains an empty worklist and given-only inerts
|
| 285 | 287 | -- which after trying to solve this implication we must restore to their original value
|
| 286 | 288 | solveImplication imp@(Implic { ic_tclvl = tclvl
|
| ... | ... | @@ -290,7 +292,7 @@ solveImplication imp@(Implic { ic_tclvl = tclvl |
| 290 | 292 | , ic_info = info
|
| 291 | 293 | , ic_status = status })
|
| 292 | 294 | | isSolvedStatus status
|
| 293 | - = return (Just imp) -- Do nothing
|
|
| 295 | + = return imp -- Do nothing
|
|
| 294 | 296 | |
| 295 | 297 | | otherwise -- Even for IC_Insoluble it is worth doing more work
|
| 296 | 298 | -- The insoluble stuff might be in one sub-implication
|
| ... | ... | @@ -350,90 +352,63 @@ solveImplication imp@(Implic { ic_tclvl = tclvl |
| 350 | 352 | -}
|
| 351 | 353 | |
| 352 | 354 | ----------------------
|
| 353 | -setImplicationStatus :: Implication -> TcS (Maybe Implication)
|
|
| 355 | +setImplicationStatus :: Implication -> TcS Implication
|
|
| 354 | 356 | -- Finalise the implication returned from solveImplication,
|
| 355 | --- setting the ic_status field
|
|
| 357 | +-- * Set the ic_status field
|
|
| 358 | +-- * Prune unnecessary evidence bindings
|
|
| 359 | +-- * Prune unnecessary child implications
|
|
| 356 | 360 | -- Precondition: the ic_status field is not already IC_Solved
|
| 357 | --- Return Nothing if we can discard the implication altogether
|
|
| 358 | -setImplicationStatus implic@(Implic { ic_status = old_status
|
|
| 359 | - , ic_info = info
|
|
| 360 | - , ic_wanted = wc
|
|
| 361 | - , ic_given = givens })
|
|
| 362 | - | assertPpr (not (isSolvedStatus old_status)) (ppr info) $
|
|
| 361 | +setImplicationStatus implic@(Implic { ic_status = old_status
|
|
| 362 | + , ic_info = info
|
|
| 363 | + , ic_wanted = wc })
|
|
| 364 | + = assertPpr (not (isSolvedStatus old_status)) (ppr info) $
|
|
| 363 | 365 | -- Precondition: we only set the status if it is not already solved
|
| 364 | - not (isSolvedWC pruned_wc)
|
|
| 365 | - = do { traceTcS "setImplicationStatus(not-all-solved) {" (ppr implic)
|
|
| 366 | - |
|
| 367 | - ; implic <- neededEvVars implic
|
|
| 368 | - |
|
| 369 | - ; let new_status | insolubleWC pruned_wc = IC_Insoluble
|
|
| 370 | - | otherwise = IC_Unsolved
|
|
| 371 | - new_implic = implic { ic_status = new_status
|
|
| 372 | - , ic_wanted = pruned_wc }
|
|
| 373 | - |
|
| 374 | - ; traceTcS "setImplicationStatus(not-all-solved) }" (ppr new_implic)
|
|
| 375 | - |
|
| 376 | - ; return $ Just new_implic }
|
|
| 377 | - |
|
| 378 | - | otherwise -- Everything is solved
|
|
| 379 | - -- Set status to IC_Solved,
|
|
| 380 | - -- and compute the dead givens and outer needs
|
|
| 381 | - -- See Note [Tracking redundant constraints]
|
|
| 382 | - = do { traceTcS "setImplicationStatus(all-solved) {" (ppr implic)
|
|
| 383 | - |
|
| 384 | - ; implic@(Implic { ic_need_inner = need_inner
|
|
| 385 | - , ic_need_outer = need_outer }) <- neededEvVars implic
|
|
| 386 | - |
|
| 387 | - ; bad_telescope <- checkBadTelescope implic
|
|
| 388 | - |
|
| 389 | - ; let warn_givens = findUnnecessaryGivens info need_inner givens
|
|
| 390 | - |
|
| 391 | - discard_entire_implication -- Can we discard the entire implication?
|
|
| 392 | - = null warn_givens -- No warning from this implication
|
|
| 393 | - && not bad_telescope
|
|
| 394 | - && isEmptyWC pruned_wc -- No live children
|
|
| 395 | - && isEmptyVarSet need_outer -- No needed vars to pass up to parent
|
|
| 396 | - |
|
| 397 | - final_status
|
|
| 398 | - | bad_telescope = IC_BadTelescope
|
|
| 399 | - | otherwise = IC_Solved { ics_dead = warn_givens }
|
|
| 400 | - final_implic = implic { ic_status = final_status
|
|
| 401 | - , ic_wanted = pruned_wc }
|
|
| 402 | - |
|
| 403 | - ; traceTcS "setImplicationStatus(all-solved) }" $
|
|
| 404 | - vcat [ text "discard:" <+> ppr discard_entire_implication
|
|
| 405 | - , text "new_implic:" <+> ppr final_implic ]
|
|
| 406 | - |
|
| 407 | - ; return $ if discard_entire_implication
|
|
| 408 | - then Nothing
|
|
| 409 | - else Just final_implic }
|
|
| 410 | - where
|
|
| 411 | - WC { wc_simple = simples, wc_impl = implics, wc_errors = errs } = wc
|
|
| 412 | - |
|
| 413 | - pruned_implics = filterBag keep_me implics
|
|
| 414 | - pruned_wc = WC { wc_simple = simples
|
|
| 415 | - , wc_impl = pruned_implics
|
|
| 416 | - , wc_errors = errs } -- do not prune holes; these should be reported
|
|
| 417 | - |
|
| 418 | - keep_me :: Implication -> Bool
|
|
| 419 | - keep_me ic
|
|
| 420 | - | IC_Solved { ics_dead = dead_givens } <- ic_status ic
|
|
| 421 | - -- Fully solved
|
|
| 422 | - , null dead_givens -- No redundant givens to report
|
|
| 423 | - , isEmptyBag (wc_impl (ic_wanted ic))
|
|
| 424 | - -- And no children that might have things to report
|
|
| 425 | - = False -- Tnen we don't need to keep it
|
|
| 426 | - | otherwise
|
|
| 427 | - = True -- Otherwise, keep it
|
|
| 366 | + do { traceTcS "setImplicationStatus {" (ppr implic)
|
|
| 367 | + |
|
| 368 | + ; let solved = isSolvedWC wc
|
|
| 369 | + ; new_implic <- neededEvVars implic
|
|
| 370 | + ; bad_telescope <- if solved then checkBadTelescope implic
|
|
| 371 | + else return False
|
|
| 372 | + |
|
| 373 | + ; let new_status | insolubleWC wc = IC_Insoluble
|
|
| 374 | + | not solved = IC_Unsolved
|
|
| 375 | + | bad_telescope = IC_BadTelescope
|
|
| 376 | + | otherwise = IC_Solved { ics_dead = dead_givens }
|
|
| 377 | + dead_givens = findRedundantGivens new_implic
|
|
| 378 | + new_wc = pruneImplications wc
|
|
| 379 | + |
|
| 380 | + final_implic = new_implic { ic_status = new_status
|
|
| 381 | + , ic_wanted = new_wc }
|
|
| 382 | + |
|
| 383 | + ; traceTcS "setImplicationStatus }" (ppr final_implic)
|
|
| 384 | + ; return final_implic }
|
|
| 385 | + |
|
| 386 | +pruneImplications :: WantedConstraints -> WantedConstraints
|
|
| 387 | +-- We have now recorded the `ic_need` variables of the child
|
|
| 388 | +-- implications (in `ic_need_implics` of the parent) so we can
|
|
| 389 | +-- delete any unnecessary children.
|
|
| 390 | +pruneImplications wc@(WC { wc_impl = implics })
|
|
| 391 | + = wc { wc_impl = filterBag keep_me implics }
|
|
| 392 | + -- Do not prune holes; these should be reported
|
|
| 393 | + where
|
|
| 394 | + keep_me :: Implication -> Bool
|
|
| 395 | + keep_me (Implic { ic_status = status, ic_wanted = wanted })
|
|
| 396 | + | IC_Solved { ics_dead = dead_givens } <- status -- Fully solved
|
|
| 397 | + , null dead_givens -- No redundant givens to report
|
|
| 398 | + , isEmptyBag (wc_impl wanted) -- No children that might have things to report
|
|
| 399 | + = False
|
|
| 400 | + | otherwise
|
|
| 401 | + = True -- Otherwise, keep it
|
|
| 428 | 402 | |
| 429 | -findUnnecessaryGivens :: SkolemInfoAnon -> VarSet -> [EvVar] -> [EvVar]
|
|
| 430 | -findUnnecessaryGivens info need_inner givens
|
|
| 403 | +findRedundantGivens :: Implication -> [EvVar]
|
|
| 404 | +findRedundantGivens (Implic { ic_info = info, ic_need = need, ic_given = givens })
|
|
| 431 | 405 | | not (warnRedundantGivens info) -- Don't report redundant constraints at all
|
| 432 | - = []
|
|
| 406 | + = [] -- See (TRC4) of Note [Tracking redundant constraints]
|
|
| 433 | 407 | |
| 434 | 408 | | not (null unused_givens) -- Some givens are literally unused
|
| 435 | 409 | = unused_givens
|
| 436 | 410 | |
| 411 | + -- Only try this if unused_givens is empty: see (TRC2a)
|
|
| 437 | 412 | | otherwise -- All givens are used, but some might
|
| 438 | 413 | = redundant_givens -- still be redundant e.g. (Eq a, Ord a)
|
| 439 | 414 | |
| ... | ... | @@ -443,11 +418,13 @@ findUnnecessaryGivens info need_inner givens |
| 443 | 418 | |
| 444 | 419 | unused_givens = filterOut is_used givens
|
| 445 | 420 | |
| 421 | + needed_givens_ignoring_default_methods = ens_fvs need
|
|
| 446 | 422 | is_used given = is_type_error given
|
| 447 | - || given `elemVarSet` need_inner
|
|
| 423 | + || given `elemVarSet` needed_givens_ignoring_default_methods
|
|
| 448 | 424 | || (in_instance_decl && is_improving (idType given))
|
| 449 | 425 | |
| 450 | - minimal_givens = mkMinimalBySCs evVarPred givens
|
|
| 426 | + minimal_givens = mkMinimalBySCs evVarPred givens -- See (TRC2)
|
|
| 427 | + |
|
| 451 | 428 | is_minimal = (`elemVarSet` mkVarSet minimal_givens)
|
| 452 | 429 | redundant_givens
|
| 453 | 430 | | in_instance_decl = []
|
| ... | ... | @@ -459,6 +436,26 @@ findUnnecessaryGivens info need_inner givens |
| 459 | 436 | is_improving pred -- (transSuperClasses p) does not include p
|
| 460 | 437 | = any isImprovementPred (pred : transSuperClasses pred)
|
| 461 | 438 | |
| 439 | +warnRedundantGivens :: SkolemInfoAnon -> Bool
|
|
| 440 | +warnRedundantGivens (SigSkol ctxt _ _)
|
|
| 441 | + = case ctxt of
|
|
| 442 | + FunSigCtxt _ rrc -> reportRedundantConstraints rrc
|
|
| 443 | + ExprSigCtxt rrc -> reportRedundantConstraints rrc
|
|
| 444 | + _ -> False
|
|
| 445 | + |
|
| 446 | +warnRedundantGivens (InstSkol from _)
|
|
| 447 | + -- Do not report redundant constraints for quantified constraints
|
|
| 448 | + -- See (TRC4) in Note [Tracking redundant constraints]
|
|
| 449 | + -- Fortunately it is easy to spot implications constraints that arise
|
|
| 450 | + -- from quantified constraints, from their SkolInfo
|
|
| 451 | + = case from of
|
|
| 452 | + IsQC {} -> False
|
|
| 453 | + IsClsInst {} -> True
|
|
| 454 | + |
|
| 455 | + -- To think about: do we want to report redundant givens for
|
|
| 456 | + -- pattern synonyms, PatSynSigSkol? c.f #9953, comment:21.
|
|
| 457 | +warnRedundantGivens _ = False
|
|
| 458 | + |
|
| 462 | 459 | {- Note [Redundant constraints in instance decls]
|
| 463 | 460 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 464 | 461 | Instance declarations are special in two ways:
|
| ... | ... | @@ -510,21 +507,10 @@ checkBadTelescope (Implic { ic_info = info |
| 510 | 507 | | otherwise
|
| 511 | 508 | = go (later_skols `extendVarSet` one_skol) earlier_skols
|
| 512 | 509 | |
| 513 | -warnRedundantGivens :: SkolemInfoAnon -> Bool
|
|
| 514 | -warnRedundantGivens (SigSkol ctxt _ _)
|
|
| 515 | - = case ctxt of
|
|
| 516 | - FunSigCtxt _ rrc -> reportRedundantConstraints rrc
|
|
| 517 | - ExprSigCtxt rrc -> reportRedundantConstraints rrc
|
|
| 518 | - _ -> False
|
|
| 519 | - |
|
| 520 | - -- To think about: do we want to report redundant givens for
|
|
| 521 | - -- pattern synonyms, PatSynSigSkol? c.f #9953, comment:21.
|
|
| 522 | -warnRedundantGivens (InstSkol {}) = True
|
|
| 523 | -warnRedundantGivens _ = False
|
|
| 524 | - |
|
| 525 | 510 | neededEvVars :: Implication -> TcS Implication
|
| 526 | 511 | -- Find all the evidence variables that are "needed",
|
| 512 | +-- /and/ delete dead evidence bindings
|
|
| 513 | +--
|
|
| 527 | 514 | -- See Note [Tracking redundant constraints]
|
| 528 | 515 | -- See Note [Delete dead Given evidence bindings]
|
| 529 | 516 | --
|
| ... | ... | @@ -540,52 +526,93 @@ neededEvVars :: Implication -> TcS Implication |
| 540 | 526 | -- Then a2 is needed too
|
| 541 | 527 | --
|
| 542 | 528 | -- - Prune out all Given bindings that are not needed
|
| 543 | ---
|
|
| 544 | --- - From the 'needed' set, delete ev_bndrs, the binders of the
|
|
| 545 | --- evidence bindings, to give the final needed variables
|
|
| 546 | ---
|
|
| 547 | -neededEvVars implic@(Implic { ic_given = givens
|
|
| 548 | - , ic_binds = ev_binds_var
|
|
| 549 | - , ic_wanted = WC { wc_impl = implics }
|
|
| 550 | - , ic_need_inner = old_needs })
|
|
| 529 | + |
|
| 530 | +neededEvVars implic@(Implic { ic_info = info
|
|
| 531 | + , ic_binds = ev_binds_var
|
|
| 532 | + , ic_wanted = WC { wc_impl = implics }
|
|
| 533 | + , ic_need_implic = old_need_implic -- See (TRC1)
|
|
| 534 | + })
|
|
| 551 | 535 | = do { ev_binds <- TcS.getTcEvBindsMap ev_binds_var
|
| 552 | 536 | ; tcvs <- TcS.getTcEvTyCoVars ev_binds_var
|
| 553 | 537 | |
| 554 | - ; let seeds1 = foldr add_implic_seeds old_needs implics
|
|
| 555 | - seeds2 = nonDetStrictFoldEvBindMap add_wanted seeds1 ev_binds
|
|
| 556 | - -- It's OK to use a non-deterministic fold here
|
|
| 557 | - -- because add_wanted is commutative
|
|
| 558 | - seeds3 = seeds2 `unionVarSet` tcvs
|
|
| 559 | - need_inner = findNeededEvVars ev_binds seeds3
|
|
| 560 | - live_ev_binds = filterEvBindMap (needed_ev_bind need_inner) ev_binds
|
|
| 561 | - need_outer = varSetMinusEvBindMap need_inner live_ev_binds
|
|
| 562 | - `delVarSetList` givens
|
|
| 563 | - |
|
| 538 | + ; let -- Find the variables needed by `implics`
|
|
| 539 | + new_need_implic@(ENS { ens_dms = dm_seeds, ens_fvs = other_seeds })
|
|
| 540 | + = foldr add_implic old_need_implic implics
|
|
| 541 | + -- Start from old_need_implic! See (TRC1)
|
|
| 542 | + |
|
| 543 | + -- Get the variables needed by the solved bindings
|
|
| 544 | + -- (It's OK to use a non-deterministic fold here
|
|
| 545 | + -- because add_wanted is commutative.)
|
|
| 546 | + seeds_w = nonDetStrictFoldEvBindMap add_wanted tcvs ev_binds
|
|
| 547 | + |
|
| 548 | + need_ignoring_dms = findNeededGivenEvVars ev_binds (other_seeds `unionVarSet` seeds_w)
|
|
| 549 | + need_from_dms = findNeededGivenEvVars ev_binds dm_seeds
|
|
| 550 | + need_full = need_ignoring_dms `unionVarSet` need_from_dms
|
|
| 551 | + |
|
| 552 | + -- `need`: the Givens from outer scopes that are used in this implication
|
|
| 553 | + -- is_dm_skol: see (TRC5)
|
|
| 554 | + need | is_dm_skol info = ENS { ens_dms = trim ev_binds need_full
|
|
| 555 | + , ens_fvs = emptyVarSet }
|
|
| 556 | + | otherwise = ENS { ens_dms = trim ev_binds need_from_dms
|
|
| 557 | + , ens_fvs = trim ev_binds need_ignoring_dms }
|
|
| 558 | + |
|
| 559 | + -- Delete dead Given evidence bindings
|
|
| 560 | + -- See Note [Delete dead Given evidence bindings]
|
|
| 561 | + ; let live_ev_binds = filterEvBindMap (needed_ev_bind need_full) ev_binds
|
|
| 564 | 562 | ; TcS.setTcEvBindsMap ev_binds_var live_ev_binds
|
| 565 | - -- See Note [Delete dead Given evidence bindings]
|
|
| 566 | 563 | |
| 567 | 564 | ; traceTcS "neededEvVars" $
|
| 568 | - vcat [ text "old_needs:" <+> ppr old_needs
|
|
| 569 | - , text "seeds3:" <+> ppr seeds3
|
|
| 565 | + vcat [ text "old_need_implic:" <+> ppr old_need_implic
|
|
| 566 | + , text "new_need_implic:" <+> ppr new_need_implic
|
|
| 570 | 567 | , text "tcvs:" <+> ppr tcvs
|
| 568 | + , text "need_ignoring_dms:" <+> ppr need_ignoring_dms
|
|
| 569 | + , text "need_from_dms:" <+> ppr need_from_dms
|
|
| 570 | + , text "need:" <+> ppr need
|
|
| 571 | 571 | , text "ev_binds:" <+> ppr ev_binds
|
| 572 | 572 | , text "live_ev_binds:" <+> ppr live_ev_binds ]
|
| 573 | - |
|
| 574 | - ; return (implic { ic_need_inner = need_inner
|
|
| 575 | - , ic_need_outer = need_outer }) }
|
|
| 573 | + ; return (implic { ic_need = need
|
|
| 574 | + , ic_need_implic = new_need_implic }) }
|
|
| 576 | 575 | where
|
| 577 | - add_implic_seeds (Implic { ic_need_outer = needs }) acc
|
|
| 578 | - = needs `unionVarSet` acc
|
|
| 579 | - |
|
| 580 | - needed_ev_bind needed (EvBind { eb_lhs = ev_var
|
|
| 581 | - , eb_info = info })
|
|
| 582 | - | EvBindGiven{} <- info = ev_var `elemVarSet` needed
|
|
| 583 | - | otherwise = True -- Keep all wanted bindings
|
|
| 584 | - |
|
| 585 | - add_wanted :: EvBind -> VarSet -> VarSet
|
|
| 586 | - add_wanted (EvBind { eb_info = info, eb_rhs = rhs }) needs
|
|
| 587 | - | EvBindGiven{} <- info = needs -- Add the rhs vars of the Wanted bindings only
|
|
| 588 | - | otherwise = evVarsOfTerm rhs `unionVarSet` needs
|
|
| 576 | + trim :: EvBindMap -> VarSet -> VarSet
|
|
| 577 | + -- Delete variables bound by Givens or bindings
|
|
| 578 | + trim ev_binds needs = needs `varSetMinusEvBindMap` ev_binds
|
|
| 579 | + |
|
| 580 | + add_implic :: Implication -> EvNeedSet -> EvNeedSet
|
|
| 581 | + add_implic (Implic { ic_given = givens, ic_need = need }) acc
|
|
| 582 | + = (need `delGivensFromEvNeedSet` givens) `unionEvNeedSet` acc
|
|
| 583 | + |
|
| 584 | + needed_ev_bind needed (EvBind { eb_lhs = ev_var, eb_info = info })
|
|
| 585 | + | EvBindGiven{} <- info = ev_var `elemVarSet` needed
|
|
| 586 | + | otherwise = True -- Keep all wanted bindings
|
|
| 587 | + |
|
| 588 | + add_wanted :: EvBind -> VarSet -> VarSet
|
|
| 589 | + add_wanted (EvBind { eb_info = info, eb_rhs = rhs }) needs
|
|
| 590 | + | EvBindGiven{} <- info = needs -- Add the rhs vars of the Wanted bindings only
|
|
| 591 | + | otherwise = evVarsOfTerm rhs `unionVarSet` needs
|
|
| 592 | + |
|
| 593 | + is_dm_skol :: SkolemInfoAnon -> Bool
|
|
| 594 | + is_dm_skol (MethSkol _ is_dm) = is_dm
|
|
| 595 | + is_dm_skol _ = False
|
|
| 596 | + |
|
| 597 | +findNeededGivenEvVars :: EvBindMap -> VarSet -> VarSet
|
|
| 598 | +-- Find all the Given evidence needed by seeds,
|
|
| 599 | +-- looking transitively through bindings for Givens (only)
|
|
| 600 | +findNeededGivenEvVars ev_binds seeds
|
|
| 601 | + = transCloVarSet also_needs seeds
|
|
| 602 | + where
|
|
| 603 | + also_needs :: VarSet -> VarSet
|
|
| 604 | + also_needs needs = nonDetStrictFoldUniqSet add emptyVarSet needs
|
|
| 605 | + -- It's OK to use a non-deterministic fold here because we immediately
|
|
| 606 | + -- forget about the ordering by creating a set
|
|
| 607 | + |
|
| 608 | + add :: Var -> VarSet -> VarSet
|
|
| 609 | + add v needs
|
|
| 610 | + | Just ev_bind <- lookupEvBind ev_binds v
|
|
| 611 | + , EvBind { eb_info = EvBindGiven, eb_rhs = rhs } <- ev_bind
|
|
| 612 | + -- Look at Given bindings only
|
|
| 613 | + = evVarsOfTerm rhs `unionVarSet` needs
|
|
| 614 | + | otherwise
|
|
| 615 | + = needs
|
|
| 589 | 616 | |
| 590 | 617 | -------------------------------------------------
|
| 591 | 618 | simplifyDelayedErrors :: Bag DelayedError -> TcS (Bag DelayedError)
|
| ... | ... | @@ -707,117 +734,84 @@ in GHC.Tc.Gen.HsType. |
| 707 | 734 | |
| 708 | 735 | Note [Tracking redundant constraints]
|
| 709 | 736 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 710 | -With Opt_WarnRedundantConstraints, GHC can report which
|
|
| 711 | -constraints of a type signature (or instance declaration) are
|
|
| 712 | -redundant, and can be omitted. Here is an overview of how it
|
|
| 713 | -works.
|
|
| 714 | - |
|
| 715 | -This is all tested in typecheck/should_compile/T20602 (among
|
|
| 716 | -others).
|
|
| 717 | - |
|
| 718 | ------ What is a redundant constraint?
|
|
| 719 | - |
|
| 720 | -* The things that can be redundant are precisely the Given
|
|
| 721 | - constraints of an implication.
|
|
| 722 | - |
|
| 723 | -* A constraint can be redundant in two different ways:
|
|
| 724 | - a) It is not needed by the Wanted constraints covered by the
|
|
| 725 | - implication E.g.
|
|
| 726 | - f :: Eq a => a -> Bool
|
|
| 727 | - f x = True -- Equality not used
|
|
| 728 | - b) It is implied by other givens. E.g.
|
|
| 729 | - f :: (Eq a, Ord a) => blah -- Eq a unnecessary
|
|
| 730 | - g :: (Eq a, a~b, Eq b) => blah -- Either Eq a or Eq b unnecessary
|
|
| 731 | - |
|
| 732 | -* To find (a) we need to know which evidence bindings are 'wanted';
|
|
| 733 | - hence the eb_is_given field on an EvBind.
|
|
| 734 | - |
|
| 735 | -* To find (b), we use mkMinimalBySCs on the Givens to see if any
|
|
| 736 | - are unnecessary.
|
|
| 737 | - |
|
| 738 | ------ How tracking works
|
|
| 739 | - |
|
| 740 | -(RC1) When two Givens are the same, we drop the evidence for the one
|
|
| 741 | - that requires more superclass selectors. This is done
|
|
| 742 | - according to 2(c) of Note [Replacement vs keeping] in GHC.Tc.Solver.InertSet.
|
|
| 743 | - |
|
| 744 | -(RC2) The ic_need fields of an Implic records in-scope (given) evidence
|
|
| 745 | - variables bound by the context, that were needed to solve this
|
|
| 746 | - implication (so far). See the declaration of Implication.
|
|
| 747 | - |
|
| 748 | -(RC3) setImplicationStatus:
|
|
| 749 | - When the constraint solver finishes solving all the wanteds in
|
|
| 750 | - an implication, it sets its status to IC_Solved
|
|
| 751 | - |
|
| 752 | - - The ics_dead field, of IC_Solved, records the subset of this
|
|
| 753 | - implication's ic_given that are redundant (not needed).
|
|
| 754 | - |
|
| 755 | - - We compute which evidence variables are needed by an implication
|
|
| 756 | - in setImplicationStatus. A variable is needed if
|
|
| 757 | - a) it is free in the RHS of a Wanted EvBind,
|
|
| 758 | - b) it is free in the RHS of an EvBind whose LHS is needed, or
|
|
| 759 | - c) it is in the ics_need of a nested implication.
|
|
| 760 | - |
|
| 761 | - - After computing which variables are needed, we then look at the
|
|
| 762 | - remaining variables for internal redundancies. This is case (b)
|
|
| 763 | - from above. This is also done in setImplicationStatus.
|
|
| 764 | - Note that we only look for case (b) if case (a) shows up empty,
|
|
| 765 | - as exemplified below.
|
|
| 766 | - |
|
| 767 | - - We need to be careful not to discard an implication
|
|
| 768 | - prematurely, even one that is fully solved, because we might
|
|
| 769 | - thereby forget which variables it needs, and hence wrongly
|
|
| 770 | - report a constraint as redundant. But we can discard it once
|
|
| 771 | - its free vars have been incorporated into its parent; or if it
|
|
| 772 | - simply has no free vars. This careful discarding is also
|
|
| 773 | - handled in setImplicationStatus.
|
|
| 774 | - |
|
| 775 | -(RC4) We do not want to report redundant constraints for implications
|
|
| 776 | - that come from quantified constraints. Example #23323:
|
|
| 777 | - data T a
|
|
| 778 | - instance Show (T a) where ... -- No context!
|
|
| 779 | - foo :: forall f c. (forall a. c a => Show (f a)) => Proxy c -> f Int -> Int
|
|
| 780 | - bar = foo @T @Eq
|
|
| 781 | - |
|
| 782 | - The call to `foo` gives us
|
|
| 783 | - [W] d : (forall a. Eq a => Show (T a))
|
|
| 784 | - To solve this, GHC.Tc.Solver.Solve.solveForAll makes an implication constraint:
|
|
| 785 | - forall a. Eq a => [W] ds : Show (T a)
|
|
| 786 | - and because of the degnerate instance for `Show (T a)`, we don't need the `Eq a`
|
|
| 787 | - constraint. But we don't want to report it as redundant!
|
|
| 788 | - |
|
| 789 | -* Examples:
|
|
| 737 | +With Opt_WarnRedundantConstraints, GHC can report which constraints of a type
|
|
| 738 | +signature (or instance declaration) are redundant, and can be omitted. Here is
|
|
| 739 | +an overview of how it works.
|
|
| 790 | 740 | |
| 791 | - f, g, h :: (Eq a, Ord a) => a -> Bool
|
|
| 792 | - f x = x == x
|
|
| 793 | - g x = x > x
|
|
| 794 | - h x = x == x && x > x
|
|
| 741 | +This is all tested in typecheck/should_compile/T20602 (among others).
|
|
| 795 | 742 | |
| 796 | - All three will discover that they have two [G] Eq a constraints:
|
|
| 797 | - one as given and one extracted from the Ord a constraint. They will
|
|
| 798 | - both discard the latter, as noted above and in
|
|
| 799 | - Note [Replacement vs keeping] in GHC.Tc.Solver.InertSet.
|
|
| 743 | +How tracking works:
|
|
| 800 | 744 | |
| 801 | - The body of f uses the [G] Eq a, but not the [G] Ord a. It will
|
|
| 802 | - report a redundant Ord a using the logic for case (a).
|
|
| 745 | +* We maintain the `ic_need` field in an implication:
|
|
| 746 | + ic_need: the set of Given evidence variables that are needed somewhere
|
|
| 747 | + inside this implication; and are bound either by this implication
|
|
| 748 | + or by an enclosing one.
|
|
| 803 | 749 | |
| 804 | - The body of g uses the [G] Ord a, but not the [G] Eq a. It will
|
|
| 805 | - report a redundant Eq a using the logic for case (a).
|
|
| 750 | +* `setImplicationStatus` does all the work:
|
|
| 751 | + - When the constraint solver finishes solving all the wanteds in
|
|
| 752 | + an implication, it sets its status to IC_Solved
|
|
| 806 | 753 | |
| 807 | - The body of h uses both [G] Ord a and [G] Eq a. Case (a) will
|
|
| 808 | - thus come up with nothing redundant. But then, the case (b)
|
|
| 809 | - check will discover that Eq a is redundant and report this.
|
|
| 754 | + - `neededEvVars`: computes which evidence variables are needed by an
|
|
| 755 | + implication in `setImplicationStatus`. A variable is needed if
|
|
| 810 | 756 | |
| 811 | - If we did case (b) even when case (a) reports something, then
|
|
| 812 | - we would report both constraints as redundant for f, which is
|
|
| 813 | - terrible.
|
|
| 757 | + a) It is in the ic_need field of this implication, computed in
|
|
| 758 | + a previous call to `setImplicationStatus`; see (TRC1)
|
|
| 814 | 759 | |
| 815 | ------ Reporting redundant constraints
|
|
| 760 | + b) It is in the ics_need of a nested implication; see `add_implic`
|
|
| 761 | + in `neededEvVars`
|
|
| 762 | + |
|
| 763 | + c) It is free in the RHS of any /Wanted/ EvBind; each such binding
|
|
| 764 | + solves a Wanted, so we want them all. See `add_wanted` in
|
|
| 765 | + `neededEvVars`
|
|
| 766 | + |
|
| 767 | + d) It is free in the RHS of a /Given/ EvBind whose LHS is needed:
|
|
| 768 | + see `findNeededGivenEvVars` called from `neededEvVars`.
|
|
| 769 | + |
|
| 770 | + - Next, if the final status is IC_Solved, `setImplicationStatus` uses
|
|
| 771 | + `findRedundantGivens` to decide which of this implication's Givens
|
|
| 772 | + are redundant.
|
|
| 773 | + |
|
| 774 | + - It also uses `pruneImplications` to discard any now-unnecessary child
|
|
| 775 | + implications.
|
|
| 776 | + |
|
| 777 | +* GHC.Tc.Errors does the actual warning, in `warnRedundantConstraints`.
|
|
| 778 | + |
|
| 779 | + |
|
| 780 | +Wrinkles:
|
|
| 781 | + |
|
| 782 | +(TRC1) `pruneImplications` drops any sub-implications of an Implication
|
|
| 783 | + that are irrelevant for error reporting:
|
|
| 784 | + - no unsolved wanteds
|
|
| 785 | + - no sub-implications
|
|
| 786 | + - no redundant givens to report
|
|
| 787 | + But in doing so we must not lose track of the variables that those implications
|
|
| 788 | + needed! So we track the ic_needs of all child implications in `ic_need_implics`.
|
|
| 789 | + Crucially, this set includes things need by child implications that have been
|
|
| 790 | + discarded by `pruneImplications`.
|
|
| 791 | + |
|
| 792 | +(TRC2) A Given can be redundant because it is implied by other Givens
|
|
| 793 | + f :: (Eq a, Ord a) => blah -- Eq a unnecessary
|
|
| 794 | + g :: (Eq a, a~b, Eq b) => blah -- Either Eq a or Eq b unnecessary
|
|
| 795 | + We nail this by using `mkMinimalBySCs` in `findRedundantGivens`.
|
|
| 796 | + (TRC2a) But NOTE that we only attempt this mkMinimalBySCs stuff if all Givens
|
|
| 797 | + used by evidence bindings. Example:
|
|
| 798 | + f :: (Eq a, Ord a) => a -> Bool
|
|
| 799 | + f x = x == x
|
|
| 800 | + We report (Ord a) as unused because it is. But we must not also report (Eq a)
|
|
| 801 | + as unused because it is a superclass of Ord!
|
|
| 816 | 802 | |
| 817 | -* GHC.Tc.Errors does the actual warning, in warnRedundantConstraints.
|
|
| 803 | +(TRC3) When two Givens are the same, prefer one that does not involve superclass
|
|
| 804 | + selection, or more generally has shallower superclass-selection depth:
|
|
| 805 | + see 2(b,c) in Note [Replacement vs keeping] in GHC.Tc.Solver.InertSet.
|
|
| 806 | + e.g f :: (Eq a, Ord a) => a -> Bool
|
|
| 807 | + f x = x == x
|
|
| 808 | + Eager superclass expansion gives us two [G] Eq a constraints. We want to keep
|
|
| 809 | + the one from the user-written Eq a, not the superclass selection. This means
|
|
| 810 | + we report the Ord a as redundant with -Wredundant-constraints, not the Eq a.
|
|
| 811 | + Getting this wrong was #20602.
|
|
| 818 | 812 | |
| 819 | -* We don't report redundant givens for *every* implication; only
|
|
| 820 | - for those which reply True to GHC.Tc.Solver.warnRedundantGivens:
|
|
| 813 | +(TRC4) We don't compute redundant givens for *every* implication; only
|
|
| 814 | + for those which reply True to `warnRedundantGivens`:
|
|
| 821 | 815 | |
| 822 | 816 | - For example, in a class declaration, the default method *can*
|
| 823 | 817 | use the class constraint, but it certainly doesn't *have* to,
|
| ... | ... | @@ -836,9 +830,68 @@ others). |
| 836 | 830 | - GHC.Tc.Gen.Bind.tcSpecPrag
|
| 837 | 831 | - GHC.Tc.Gen.Bind.tcTySig
|
| 838 | 832 | |
| 839 | - This decision is taken in setImplicationStatus, rather than GHC.Tc.Errors
|
|
| 840 | - so that we can discard implication constraints that we don't need.
|
|
| 841 | - So ics_dead consists only of the *reportable* redundant givens.
|
|
| 833 | + - We do not want to report redundant constraints for implications
|
|
| 834 | + that come from quantified constraints. Example #23323:
|
|
| 835 | + data T a
|
|
| 836 | + instance Show (T a) where ... -- No context!
|
|
| 837 | + foo :: forall f c. (forall a. c a => Show (f a)) => Proxy c -> f Int -> Int
|
|
| 838 | + bar = foo @T @Eq
|
|
| 839 | + |
|
| 840 | + The call to `foo` gives us
|
|
| 841 | + [W] d : (forall a. Eq a => Show (T a))
|
|
| 842 | + To solve this, GHC.Tc.Solver.Solve.solveForAll makes an implication constraint:
|
|
| 843 | + forall a. Eq a => [W] ds : Show (T a)
|
|
| 844 | + and because of the degnerate instance for `Show (T a)`, we don't need the `Eq a`
|
|
| 845 | + constraint. But we don't want to report it as redundant!
|
|
| 846 | + |
|
| 847 | +(TRC5) Consider this (#25992), where `op2` has a default method
|
|
| 848 | + class C a where { op1, op2 :: a -> a
|
|
| 849 | + ; op2 = op1 . op1 }
|
|
| 850 | + instance C a => C [a] where
|
|
| 851 | + op1 x = x
|
|
| 852 | + |
|
| 853 | + Plainly the (C a) constraint is unused; but the expanded decl will look like
|
|
| 854 | + $dmop2 :: C a => a -> a
|
|
| 855 | + $dmop2 = op1 . op2
|
|
| 856 | + |
|
| 857 | + $fCList :: forall a. C a => C [a]
|
|
| 858 | + $fCList @a (d::C a) = MkC (\(x:a).x) ($dmop2 @a d)
|
|
| 859 | + |
|
| 860 | + Notice that `d` gets passed to `$dmop`: it is "needed". But it's only
|
|
| 861 | + /really/ needed if some /other/ method (in this case `op1`) uses it.
|
|
| 862 | + |
|
| 863 | + So, rather than one set of "needed Givens" we use `EvNeedSet` to track
|
|
| 864 | + a /pair/ of sets:
|
|
| 865 | + ens_dms: needed /only/ by default-method calls
|
|
| 866 | + ens_fvs: needed by something other than a default-method call
|
|
| 867 | + It's a bit of a palaver, but not really difficult.
|
|
| 868 | + All the logic is localised in `neededEvVars`.
|
|
| 869 | + |
|
| 870 | + |
|
| 871 | + |
|
| 872 | +----- Reporting redundant constraints
|
|
| 873 | + |
|
| 874 | + |
|
| 875 | +----- Examples
|
|
| 876 | + |
|
| 877 | + f, g, h :: (Eq a, Ord a) => a -> Bool
|
|
| 878 | + f x = x == x
|
|
| 879 | + g x = x > x
|
|
| 880 | + h x = x == x && x > x
|
|
| 881 | + |
|
| 882 | + All of f,g,h will discover that they have two [G] Eq a constraints: one as
|
|
| 883 | + given and one extracted from the Ord a constraint. They will both discard
|
|
| 884 | + the latter; see (TRC3).
|
|
| 885 | + |
|
| 886 | + The body of f uses the [G] Eq a, but not the [G] Ord a. It will report a
|
|
| 887 | + redundant Ord a.
|
|
| 888 | + |
|
| 889 | + The body of g uses the [G] Ord a, but not the [G] Eq a. It will report a
|
|
| 890 | + redundant Eq a.
|
|
| 891 | + |
|
| 892 | + The body of h uses both [G] Ord a and [G] Eq a; each is used in a solved
|
|
| 893 | + Wanted evidence binding. But (TRC2) kicks in and discovers the Eq a
|
|
| 894 | + is redundant.
|
|
| 842 | 895 | |
| 843 | 896 | ----- Shortcomings
|
| 844 | 897 | |
| ... | ... | @@ -1732,4 +1785,4 @@ solveCompletelyIfRequired ct (TcS thing_inside) |
| 1732 | 1785 | ; return $ Stop (ctEvidence ct) (text "Not fully solved; kept as inert:" <+> ppr ct)
|
| 1733 | 1786 | } }
|
| 1734 | 1787 | _notFullySolveMode ->
|
| 1735 | - thing_inside env |
|
| \ No newline at end of file | ||
| 1788 | + thing_inside env |
| ... | ... | @@ -495,7 +495,8 @@ tcClsInstDecl (L loc (ClsInstDecl { cid_ext = lwarn |
| 495 | 495 | do { dfun_ty <- tcHsClsInstType (InstDeclCtxt False) hs_ty
|
| 496 | 496 | ; let (tyvars, theta, clas, inst_tys) = tcSplitDFunTy dfun_ty
|
| 497 | 497 | -- NB: tcHsClsInstType does checkValidInstance
|
| 498 | - ; skol_info <- mkSkolemInfo (mkClsInstSkol clas inst_tys)
|
|
| 498 | + ; skol_info <- mkSkolemInfo (InstSkol IsClsInst pSizeZero)
|
|
| 499 | + -- pSizeZero: here the size part of InstSkol is irrelevant
|
|
| 499 | 500 | ; (subst, skol_tvs) <- tcInstSkolTyVars skol_info tyvars
|
| 500 | 501 | ; let tv_skol_prs = [ (tyVarName tv, skol_tv)
|
| 501 | 502 | | (tv, skol_tv) <- tyvars `zip` skol_tvs ]
|
| ... | ... | @@ -1816,7 +1817,7 @@ tcMethods :: SkolemInfoAnon -> DFunId -> Class |
| 1816 | 1817 | -> TcM ([Id], LHsBinds GhcTc, Bag Implication)
|
| 1817 | 1818 | -- The returned inst_meth_ids all have types starting
|
| 1818 | 1819 | -- forall tvs. theta => ...
|
| 1819 | -tcMethods skol_info dfun_id clas tyvars dfun_ev_vars inst_tys
|
|
| 1820 | +tcMethods _skol_info dfun_id clas tyvars dfun_ev_vars inst_tys
|
|
| 1820 | 1821 | dfun_ev_binds (spec_inst_prags, prag_fn) op_items
|
| 1821 | 1822 | (InstBindings { ib_binds = binds
|
| 1822 | 1823 | , ib_tyvars = lexical_tvs
|
| ... | ... | @@ -1852,7 +1853,7 @@ tcMethods skol_info dfun_id clas tyvars dfun_ev_vars inst_tys |
| 1852 | 1853 | tc_item :: ClassOpItem -> TcM (Id, LHsBind GhcTc, Maybe Implication)
|
| 1853 | 1854 | tc_item (sel_id, dm_info)
|
| 1854 | 1855 | | Just (user_bind, bndr_loc, prags) <- findMethodBind (idName sel_id) binds prag_fn
|
| 1855 | - = tcMethodBody skol_info clas tyvars dfun_ev_vars inst_tys
|
|
| 1856 | + = tcMethodBody False clas tyvars dfun_ev_vars inst_tys
|
|
| 1856 | 1857 | dfun_ev_binds is_derived hs_sig_fn
|
| 1857 | 1858 | spec_inst_prags prags
|
| 1858 | 1859 | sel_id user_bind bndr_loc
|
| ... | ... | @@ -1888,7 +1889,7 @@ tcMethods skol_info dfun_id clas tyvars dfun_ev_vars inst_tys |
| 1888 | 1889 | |
| 1889 | 1890 | Just (dm_name, dm_spec) ->
|
| 1890 | 1891 | do { (meth_bind, inline_prags) <- mkDefMethBind inst_loc dfun_id clas sel_id dm_name dm_spec
|
| 1891 | - ; tcMethodBody skol_info clas tyvars dfun_ev_vars inst_tys
|
|
| 1892 | + ; tcMethodBody True clas tyvars dfun_ev_vars inst_tys
|
|
| 1892 | 1893 | dfun_ev_binds is_derived hs_sig_fn
|
| 1893 | 1894 | spec_inst_prags inline_prags
|
| 1894 | 1895 | sel_id meth_bind inst_loc }
|
| ... | ... | @@ -2013,25 +2014,26 @@ Instead, we take the following approach: |
| 2013 | 2014 | -}
|
| 2014 | 2015 | |
| 2015 | 2016 | ------------------------
|
| 2016 | -tcMethodBody :: SkolemInfoAnon
|
|
| 2017 | +tcMethodBody :: Bool
|
|
| 2017 | 2018 | -> Class -> [TcTyVar] -> [EvVar] -> [TcType]
|
| 2018 | 2019 | -> TcEvBinds -> Bool
|
| 2019 | 2020 | -> HsSigFun
|
| 2020 | 2021 | -> [LTcSpecPrag] -> [LSig GhcRn]
|
| 2021 | 2022 | -> Id -> LHsBind GhcRn -> SrcSpan
|
| 2022 | 2023 | -> TcM (TcId, LHsBind GhcTc, Maybe Implication)
|
| 2023 | -tcMethodBody skol_info clas tyvars dfun_ev_vars inst_tys
|
|
| 2024 | +tcMethodBody is_def_meth clas tyvars dfun_ev_vars inst_tys
|
|
| 2024 | 2025 | dfun_ev_binds is_derived
|
| 2025 | 2026 | sig_fn spec_inst_prags prags
|
| 2026 | 2027 | sel_id (L bind_loc meth_bind) bndr_loc
|
| 2027 | 2028 | = add_meth_ctxt $
|
| 2028 | 2029 | do { traceTc "tcMethodBody" (ppr sel_id <+> ppr (idType sel_id) $$ ppr bndr_loc)
|
| 2030 | + ; let skol_info = MethSkol meth_name is_def_meth
|
|
| 2029 | 2031 | ; (global_meth_id, local_meth_id) <- setSrcSpan bndr_loc $
|
| 2030 | 2032 | mkMethIds clas tyvars dfun_ev_vars
|
| 2031 | 2033 | inst_tys sel_id
|
| 2032 | 2034 | |
| 2033 | 2035 | ; let lm_bind = meth_bind { fun_id = L (noAnnSrcSpan bndr_loc)
|
| 2034 | - (idName local_meth_id) }
|
|
| 2036 | + (idName local_meth_id) }
|
|
| 2035 | 2037 | -- Substitute the local_meth_name for the binder
|
| 2036 | 2038 | -- NB: the binding is always a FunBind
|
| 2037 | 2039 | |
| ... | ... | @@ -2042,7 +2044,7 @@ tcMethodBody skol_info clas tyvars dfun_ev_vars inst_tys |
| 2042 | 2044 | tcMethodBodyHelp sig_fn sel_id local_meth_id (L bind_loc lm_bind)
|
| 2043 | 2045 | |
| 2044 | 2046 | ; global_meth_id <- addInlinePrags global_meth_id prags
|
| 2045 | - ; spec_prags <- tcExtendIdEnv1 (idName sel_id) global_meth_id $
|
|
| 2047 | + ; spec_prags <- tcExtendIdEnv1 meth_name global_meth_id $
|
|
| 2046 | 2048 | -- tcExtendIdEnv1: tricky point: a SPECIALISE pragma in prags
|
| 2047 | 2049 | -- mentions sel_name but the pragma is really for global_meth_id.
|
| 2048 | 2050 | -- So we bind sel_name to global_meth_id, just in the pragmas.
|
| ... | ... | @@ -2071,6 +2073,8 @@ tcMethodBody skol_info clas tyvars dfun_ev_vars inst_tys |
| 2071 | 2073 | |
| 2072 | 2074 | ; return (global_meth_id, L bind_loc full_bind, Just meth_implic) }
|
| 2073 | 2075 | where
|
| 2076 | + meth_name = idName sel_id
|
|
| 2077 | + |
|
| 2074 | 2078 | -- For instance decls that come from deriving clauses
|
| 2075 | 2079 | -- we want to print out the full source code if there's an error
|
| 2076 | 2080 | -- because otherwise the user won't see the code at all
|
| ... | ... | @@ -67,6 +67,7 @@ module GHC.Tc.Types.Constraint ( |
| 67 | 67 | ImplicStatus(..), isInsolubleStatus, isSolvedStatus,
|
| 68 | 68 | UserGiven, getUserGivensFromImplics,
|
| 69 | 69 | HasGivenEqs(..), checkImplicationInvariants,
|
| 70 | + EvNeedSet(..), emptyEvNeedSet, unionEvNeedSet, extendEvNeedSet, delGivensFromEvNeedSet,
|
|
| 70 | 71 | |
| 71 | 72 | -- CtLocEnv
|
| 72 | 73 | CtLocEnv(..), setCtLocEnvLoc, setCtLocEnvLvl, getCtLocEnvLoc, getCtLocEnvLvl, ctLocEnvInGeneratedCode,
|
| ... | ... | @@ -1458,18 +1459,43 @@ data Implication |
| 1458 | 1459 | |
| 1459 | 1460 | -- The ic_need fields keep track of which Given evidence
|
| 1460 | 1461 | -- is used by this implication or its children
|
| 1461 | - -- NB: including stuff used by nested implications that have since
|
|
| 1462 | - -- been discarded
|
|
| 1463 | - -- See Note [Needed evidence variables]
|
|
| 1464 | - -- and (RC2) in Note [Tracking redundant constraints]a
|
|
| 1465 | - ic_need_inner :: VarSet, -- Includes all used Given evidence
|
|
| 1466 | - ic_need_outer :: VarSet, -- Includes only the free Given evidence
|
|
| 1467 | - -- i.e. ic_need_inner after deleting
|
|
| 1468 | - -- (a) givens (b) binders of ic_binds
|
|
| 1462 | + -- See Note [Tracking redundant constraints]
|
|
| 1463 | + -- NB: these sets include stuff used by fully-solved nested implications
|
|
| 1464 | + -- that have since been discarded
|
|
| 1465 | + ic_need :: EvNeedSet, -- All needed Given evidence, from this implication
|
|
| 1466 | + -- or outer ones
|
|
| 1467 | + -- That is, /after/ deleting the binders of ic_binds,
|
|
| 1468 | + -- but /before/ deleting ic_givens
|
|
| 1469 | + |
|
| 1470 | + ic_need_implic :: EvNeedSet, -- Union of of the ic_need of all implications in ic_wanted
|
|
| 1471 | + -- /including/ any fully-solved implications that have been
|
|
| 1472 | + -- discarded by `pruneImplications`. This discarding is why
|
|
| 1473 | + -- we need to keep this field in the first place.
|
|
| 1469 | 1474 | |
| 1470 | 1475 | ic_status :: ImplicStatus
|
| 1471 | 1476 | }
|
| 1472 | 1477 | |
| 1478 | +data EvNeedSet = ENS { ens_dms :: VarSet -- Needed only by default methods
|
|
| 1479 | + , ens_fvs :: VarSet -- Needed by things /other than/ default methods
|
|
| 1480 | + -- See (TRC5) in Note [Tracking redundant constraints]
|
|
| 1481 | + }
|
|
| 1482 | + |
|
| 1483 | +emptyEvNeedSet :: EvNeedSet
|
|
| 1484 | +emptyEvNeedSet = ENS { ens_dms = emptyVarSet, ens_fvs = emptyVarSet }
|
|
| 1485 | + |
|
| 1486 | +unionEvNeedSet :: EvNeedSet -> EvNeedSet -> EvNeedSet
|
|
| 1487 | +unionEvNeedSet (ENS { ens_dms = dm1, ens_fvs = fv1 })
|
|
| 1488 | + (ENS { ens_dms = dm2, ens_fvs = fv2 })
|
|
| 1489 | + = ENS { ens_dms = dm1 `unionVarSet` dm2, ens_fvs = fv1 `unionVarSet` fv2 }
|
|
| 1490 | + |
|
| 1491 | +extendEvNeedSet :: EvNeedSet -> Var -> EvNeedSet
|
|
| 1492 | +extendEvNeedSet ens@(ENS { ens_fvs = fvs }) v = ens { ens_fvs = fvs `extendVarSet` v }
|
|
| 1493 | + |
|
| 1494 | +delGivensFromEvNeedSet :: EvNeedSet -> [Var] -> EvNeedSet
|
|
| 1495 | +delGivensFromEvNeedSet (ENS { ens_dms = dms, ens_fvs = fvs }) givens
|
|
| 1496 | + = ENS { ens_dms = dms `delVarSetList` givens
|
|
| 1497 | + , ens_fvs = fvs `delVarSetList` givens }
|
|
| 1498 | + |
|
| 1473 | 1499 | implicationPrototype :: CtLocEnv -> Implication
|
| 1474 | 1500 | implicationPrototype ct_loc_env
|
| 1475 | 1501 | = Implic { -- These fields must be initialised
|
| ... | ... | @@ -1478,15 +1504,17 @@ implicationPrototype ct_loc_env |
| 1478 | 1504 | , ic_info = panic "newImplic:info"
|
| 1479 | 1505 | , ic_warn_inaccessible = panic "newImplic:warn_inaccessible"
|
| 1480 | 1506 | |
| 1481 | - , ic_env = ct_loc_env
|
|
| 1507 | + -- Given by caller
|
|
| 1508 | + , ic_env = ct_loc_env
|
|
| 1509 | + |
|
| 1482 | 1510 | -- The rest have sensible default values
|
| 1483 | - , ic_skols = []
|
|
| 1484 | - , ic_given = []
|
|
| 1485 | - , ic_wanted = emptyWC
|
|
| 1486 | - , ic_given_eqs = MaybeGivenEqs
|
|
| 1487 | - , ic_status = IC_Unsolved
|
|
| 1488 | - , ic_need_inner = emptyVarSet
|
|
| 1489 | - , ic_need_outer = emptyVarSet }
|
|
| 1511 | + , ic_skols = []
|
|
| 1512 | + , ic_given = []
|
|
| 1513 | + , ic_wanted = emptyWC
|
|
| 1514 | + , ic_given_eqs = MaybeGivenEqs
|
|
| 1515 | + , ic_status = IC_Unsolved
|
|
| 1516 | + , ic_need = emptyEvNeedSet
|
|
| 1517 | + , ic_need_implic = emptyEvNeedSet }
|
|
| 1490 | 1518 | |
| 1491 | 1519 | data ImplicStatus
|
| 1492 | 1520 | = IC_Solved -- All wanteds in the tree are solved, all the way down
|
| ... | ... | @@ -1562,7 +1590,7 @@ instance Outputable Implication where |
| 1562 | 1590 | , ic_given = given, ic_given_eqs = given_eqs
|
| 1563 | 1591 | , ic_wanted = wanted, ic_status = status
|
| 1564 | 1592 | , ic_binds = binds
|
| 1565 | - , ic_need_inner = need_in, ic_need_outer = need_out
|
|
| 1593 | + , ic_need = need, ic_need_implic = need_implic
|
|
| 1566 | 1594 | , ic_info = info })
|
| 1567 | 1595 | = hang (text "Implic" <+> lbrace)
|
| 1568 | 1596 | 2 (sep [ text "TcLevel =" <+> ppr tclvl
|
| ... | ... | @@ -1572,10 +1600,15 @@ instance Outputable Implication where |
| 1572 | 1600 | , hang (text "Given =") 2 (pprEvVars given)
|
| 1573 | 1601 | , hang (text "Wanted =") 2 (ppr wanted)
|
| 1574 | 1602 | , text "Binds =" <+> ppr binds
|
| 1575 | - , whenPprDebug (text "Needed inner =" <+> ppr need_in)
|
|
| 1576 | - , whenPprDebug (text "Needed outer =" <+> ppr need_out)
|
|
| 1603 | + , text "need =" <+> ppr need
|
|
| 1604 | + , text "need_implic =" <+> ppr need_implic
|
|
| 1577 | 1605 | , pprSkolInfo info ] <+> rbrace)
|
| 1578 | 1606 | |
| 1607 | +instance Outputable EvNeedSet where
|
|
| 1608 | + ppr (ENS { ens_dms = dms, ens_fvs = fvs })
|
|
| 1609 | + = text "ENS" <> braces (sep [text "ens_dms =" <+> ppr dms
|
|
| 1610 | + , text "ens_fvs =" <+> ppr fvs])
|
|
| 1611 | + |
|
| 1579 | 1612 | instance Outputable ImplicStatus where
|
| 1580 | 1613 | ppr IC_Insoluble = text "Insoluble"
|
| 1581 | 1614 | ppr IC_BadTelescope = text "Bad telescope"
|
| ... | ... | @@ -1663,18 +1696,6 @@ all at once, creating one implication constraint for the lot: |
| 1663 | 1696 | implication. TL;DR: an explicit forall should generate an implication
|
| 1664 | 1697 | quantified only over those explicitly quantified variables.
|
| 1665 | 1698 | |
| 1666 | -Note [Needed evidence variables]
|
|
| 1667 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1668 | -Th ic_need_evs field holds the free vars of ic_binds, and all the
|
|
| 1669 | -ic_binds in nested implications.
|
|
| 1670 | - |
|
| 1671 | - * Main purpose: if one of the ic_givens is not mentioned in here, it
|
|
| 1672 | - is redundant.
|
|
| 1673 | - |
|
| 1674 | - * solveImplication may drop an implication altogether if it has no
|
|
| 1675 | - remaining 'wanteds'. But we still track the free vars of its
|
|
| 1676 | - evidence binds, even though it has now disappeared.
|
|
| 1677 | - |
|
| 1678 | 1699 | Note [Shadowing in a constraint]
|
| 1679 | 1700 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1680 | 1701 | We assume NO SHADOWING in a constraint. Specifically
|
| ... | ... | @@ -2012,6 +2033,7 @@ checkSkolInfoAnon sk1 sk2 = go sk1 sk2 |
| 2012 | 2033 | go (TyConSkol f1 n1) (TyConSkol f2 n2) = f1==f2 && n1==n2
|
| 2013 | 2034 | go (DataConSkol n1) (DataConSkol n2) = n1==n2
|
| 2014 | 2035 | go (InstSkol {}) (InstSkol {}) = True
|
| 2036 | + go (MethSkol n1 d1) (MethSkol n2 d2) = n1==n2 && d1==d2
|
|
| 2015 | 2037 | go FamInstSkol FamInstSkol = True
|
| 2016 | 2038 | go BracketSkol BracketSkol = True
|
| 2017 | 2039 | go (RuleSkol n1) (RuleSkol n2) = n1==n2
|
| ... | ... | @@ -28,7 +28,7 @@ module GHC.Tc.Types.Evidence ( |
| 28 | 28 | -- * EvTerm (already a CoreExpr)
|
| 29 | 29 | EvTerm(..), EvExpr,
|
| 30 | 30 | evId, evCoercion, evCast, evDFunApp, evDataConApp, evSelector,
|
| 31 | - mkEvCast, evVarsOfTerm, mkEvScSelectors, evTypeable, findNeededEvVars,
|
|
| 31 | + mkEvCast, evVarsOfTerm, mkEvScSelectors, evTypeable,
|
|
| 32 | 32 | |
| 33 | 33 | evTermCoercion, evTermCoercion_maybe,
|
| 34 | 34 | EvCallStack(..),
|
| ... | ... | @@ -50,27 +50,30 @@ module GHC.Tc.Types.Evidence ( |
| 50 | 50 | |
| 51 | 51 | import GHC.Prelude
|
| 52 | 52 | |
| 53 | -import GHC.Types.Unique.DFM
|
|
| 54 | -import GHC.Types.Unique.FM
|
|
| 55 | -import GHC.Types.Var
|
|
| 56 | -import GHC.Types.Id( idScaledType )
|
|
| 53 | +import GHC.Tc.Utils.TcType
|
|
| 54 | + |
|
| 55 | +import GHC.Core
|
|
| 57 | 56 | import GHC.Core.Coercion.Axiom
|
| 58 | 57 | import GHC.Core.Coercion
|
| 59 | 58 | import GHC.Core.Ppr () -- Instance OutputableBndr TyVar
|
| 60 | -import GHC.Tc.Utils.TcType
|
|
| 59 | +import GHC.Core.Predicate
|
|
| 61 | 60 | import GHC.Core.Type
|
| 62 | 61 | import GHC.Core.TyCon
|
| 63 | 62 | import GHC.Core.DataCon ( DataCon, dataConWrapId )
|
| 64 | -import GHC.Builtin.Names
|
|
| 63 | +import GHC.Core.Class (Class, classSCSelId )
|
|
| 64 | +import GHC.Core.FVs ( exprSomeFreeVars )
|
|
| 65 | +import GHC.Core.InstEnv ( CanonicalEvidence(..) )
|
|
| 66 | + |
|
| 67 | +import GHC.Types.Unique.DFM
|
|
| 68 | +import GHC.Types.Unique.FM
|
|
| 69 | +import GHC.Types.Var
|
|
| 70 | +import GHC.Types.Name( isInternalName )
|
|
| 71 | +import GHC.Types.Id( idScaledType )
|
|
| 65 | 72 | import GHC.Types.Var.Env
|
| 66 | 73 | import GHC.Types.Var.Set
|
| 67 | -import GHC.Core.Predicate
|
|
| 68 | 74 | import GHC.Types.Basic
|
| 69 | 75 | |
| 70 | -import GHC.Core
|
|
| 71 | -import GHC.Core.Class (Class, classSCSelId )
|
|
| 72 | -import GHC.Core.FVs ( exprSomeFreeVars )
|
|
| 73 | -import GHC.Core.InstEnv ( CanonicalEvidence(..) )
|
|
| 76 | +import GHC.Builtin.Names
|
|
| 74 | 77 | |
| 75 | 78 | import GHC.Utils.Misc
|
| 76 | 79 | import GHC.Utils.Panic
|
| ... | ... | @@ -865,27 +868,13 @@ evTermCoercion tm = case evTermCoercion_maybe tm of |
| 865 | 868 | * *
|
| 866 | 869 | ********************************************************************* -}
|
| 867 | 870 | |
| 868 | -findNeededEvVars :: EvBindMap -> VarSet -> VarSet
|
|
| 869 | --- Find all the Given evidence needed by seeds,
|
|
| 870 | --- looking transitively through binds
|
|
| 871 | -findNeededEvVars ev_binds seeds
|
|
| 872 | - = transCloVarSet also_needs seeds
|
|
| 873 | - where
|
|
| 874 | - also_needs :: VarSet -> VarSet
|
|
| 875 | - also_needs needs = nonDetStrictFoldUniqSet add emptyVarSet needs
|
|
| 876 | - -- It's OK to use a non-deterministic fold here because we immediately
|
|
| 877 | - -- forget about the ordering by creating a set
|
|
| 878 | - |
|
| 879 | - add :: Var -> VarSet -> VarSet
|
|
| 880 | - add v needs
|
|
| 881 | - | Just ev_bind <- lookupEvBind ev_binds v
|
|
| 882 | - , EvBind { eb_info = EvBindGiven, eb_rhs = rhs } <- ev_bind
|
|
| 883 | - = evVarsOfTerm rhs `unionVarSet` needs
|
|
| 884 | - | otherwise
|
|
| 885 | - = needs
|
|
| 871 | +relevantEvVar :: Var -> Bool
|
|
| 872 | +-- Just returns /local/ free evidence variables; i.e ones with Internal Names
|
|
| 873 | +-- Top-level ones (DFuns, dictionary selectors and the like) don't count
|
|
| 874 | +relevantEvVar v = isInternalName (varName v)
|
|
| 886 | 875 | |
| 887 | 876 | evVarsOfTerm :: EvTerm -> VarSet
|
| 888 | -evVarsOfTerm (EvExpr e) = exprSomeFreeVars isEvVar e
|
|
| 877 | +evVarsOfTerm (EvExpr e) = exprSomeFreeVars relevantEvVar e
|
|
| 889 | 878 | evVarsOfTerm (EvTypeable _ ev) = evVarsOfTypeable ev
|
| 890 | 879 | evVarsOfTerm (EvFun {}) = emptyVarSet -- See Note [Free vars of EvFun]
|
| 891 | 880 |
| ... | ... | @@ -15,7 +15,7 @@ module GHC.Tc.Types.Origin ( |
| 15 | 15 | |
| 16 | 16 | -- * SkolemInfo
|
| 17 | 17 | SkolemInfo(..), SkolemInfoAnon(..), mkSkolemInfo, getSkolemInfo, pprSigSkolInfo, pprSkolInfo,
|
| 18 | - unkSkol, unkSkolAnon, mkClsInstSkol,
|
|
| 18 | + unkSkol, unkSkolAnon,
|
|
| 19 | 19 | |
| 20 | 20 | -- * CtOrigin
|
| 21 | 21 | CtOrigin(..), exprCtOrigin, lexprCtOrigin, matchesCtOrigin, grhssCtOrigin,
|
| ... | ... | @@ -58,7 +58,6 @@ import GHC.Hs |
| 58 | 58 | import GHC.Core.DataCon
|
| 59 | 59 | import GHC.Core.ConLike
|
| 60 | 60 | import GHC.Core.TyCon
|
| 61 | -import GHC.Core.Class
|
|
| 62 | 61 | import GHC.Core.InstEnv
|
| 63 | 62 | import GHC.Core.PatSyn
|
| 64 | 63 | import GHC.Core.Multiplicity ( scaledThing )
|
| ... | ... | @@ -288,6 +287,10 @@ data SkolemInfoAnon |
| 288 | 287 | ClsInstOrQC -- Whether class instance or quantified constraint
|
| 289 | 288 | PatersonSize -- Head has the given PatersonSize
|
| 290 | 289 | |
| 290 | + | MethSkol Name Bool -- Bound by the type of class method op
|
|
| 291 | + -- True <=> it's a default method
|
|
| 292 | + -- False <=> it's a user-written method
|
|
| 293 | + |
|
| 291 | 294 | | FamInstSkol -- Bound at a family instance decl
|
| 292 | 295 | | PatSkol -- An existential type variable bound by a pattern for
|
| 293 | 296 | ConLike -- a data constructor with an existential type.
|
| ... | ... | @@ -348,9 +351,6 @@ mkSkolemInfo sk_anon = do |
| 348 | 351 | getSkolemInfo :: SkolemInfo -> SkolemInfoAnon
|
| 349 | 352 | getSkolemInfo (SkolemInfo _ skol_anon) = skol_anon
|
| 350 | 353 | |
| 351 | -mkClsInstSkol :: Class -> [Type] -> SkolemInfoAnon
|
|
| 352 | -mkClsInstSkol cls tys = InstSkol IsClsInst (pSizeClassPred cls tys)
|
|
| 353 | - |
|
| 354 | 354 | instance Outputable SkolemInfo where
|
| 355 | 355 | ppr (SkolemInfo _ sk_info ) = ppr sk_info
|
| 356 | 356 | |
| ... | ... | @@ -369,6 +369,8 @@ pprSkolInfo (InstSkol IsClsInst sz) = vcat [ text "the instance declaration" |
| 369 | 369 | , whenPprDebug (braces (ppr sz)) ]
|
| 370 | 370 | pprSkolInfo (InstSkol (IsQC {}) sz) = vcat [ text "a quantified context"
|
| 371 | 371 | , whenPprDebug (braces (ppr sz)) ]
|
| 372 | +pprSkolInfo (MethSkol name d) = text "the" <+> ppWhen d (text "default")
|
|
| 373 | + <+> text "method declaration for" <+> ppr name
|
|
| 372 | 374 | pprSkolInfo FamInstSkol = text "a family instance declaration"
|
| 373 | 375 | pprSkolInfo BracketSkol = text "a Template Haskell bracket"
|
| 374 | 376 | pprSkolInfo (RuleSkol name) = text "the RULE" <+> pprRuleName name
|
| ... | ... | @@ -582,8 +582,11 @@ tcSkolDFunType dfun_ty |
| 582 | 582 | -- We instantiate the dfun_tyd with superSkolems.
|
| 583 | 583 | -- See Note [Subtle interaction of recursion and overlap]
|
| 584 | 584 | -- and Note [Super skolems: binding when looking up instances]
|
| 585 | - ; let inst_tys = substTys subst tys
|
|
| 586 | - skol_info_anon = mkClsInstSkol cls inst_tys }
|
|
| 585 | + ; let inst_tys = substTys subst tys
|
|
| 586 | + skol_info_anon = InstSkol IsClsInst (pSizeClassPred cls inst_tys)
|
|
| 587 | + -- We need to take the size of `inst_tys` (not `tys`) because
|
|
| 588 | + -- Paterson sizes mention the free type variables
|
|
| 589 | + }
|
|
| 587 | 590 | |
| 588 | 591 | ; let inst_theta = substTheta subst theta
|
| 589 | 592 | ; return (skol_info_anon, inst_tvs, inst_theta, cls, inst_tys) }
|
| 1 | - |
|
| 2 | 1 | T13135_simple.hs:34:11: error: [GHC-83865]
|
| 3 | - • Couldn't match type ‘SmartFun sig’ with ‘Bool’
|
|
| 2 | + • Couldn't match type ‘SmartFun sig1’ with ‘Bool’
|
|
| 4 | 3 | Expected: Int -> Bool
|
| 5 | - Actual: SmartFun (SigFun Int sig)
|
|
| 6 | - The type variable ‘sig’ is ambiguous
|
|
| 4 | + Actual: SmartFun (SigFun Int sig1)
|
|
| 5 | + The type variable ‘sig1’ is ambiguous
|
|
| 7 | 6 | • In the expression: smartSym
|
| 8 | 7 | In an equation for ‘problem’: problem = smartSym
|
| 8 | + |
| 1 | +{-# OPTIONS_GHC -Wredundant-constraints #-}
|
|
| 2 | + |
|
| 3 | +module T25992 where
|
|
| 4 | + |
|
| 5 | +data P a = P
|
|
| 6 | + |
|
| 7 | +instance Eq a => Semigroup (P a) where
|
|
| 8 | + P <> P = P |
| 1 | +T25992.hs:7:10: warning: [GHC-30606] [-Wredundant-constraints]
|
|
| 2 | + • Redundant constraint: Eq a
|
|
| 3 | + • In the instance declaration for ‘Semigroup (P a)’
|
|
| 4 | + |
| ... | ... | @@ -941,3 +941,4 @@ test('T25597', normal, compile, ['']) |
| 941 | 941 | test('T25960', normal, compile, [''])
|
| 942 | 942 | test('T26020', normal, compile, [''])
|
| 943 | 943 | test('T26020a', [extra_files(['T26020a_help.hs'])], multimod_compile, ['T26020a', '-v0'])
|
| 944 | +test('T25992', normal, compile, ['']) |
| ... | ... | @@ -7,8 +7,8 @@ tcfail097.hs:5:6: error: [GHC-39999] |
| 7 | 7 | The type variable ‘a0’ is ambiguous
|
| 8 | 8 | Potentially matching instances:
|
| 9 | 9 | instance Eq Ordering -- Defined in ‘GHC.Internal.Classes’
|
| 10 | - instance Eq a => Eq (Solo a) -- Defined in ‘GHC.Internal.Classes’
|
|
| 11 | - ...plus 22 others
|
|
| 10 | + instance Eq Integer -- Defined in ‘GHC.Internal.Bignum.Integer’
|
|
| 11 | + ...plus 23 others
|
|
| 12 | 12 | ...plus five instances involving out-of-scope types
|
| 13 | 13 | (use -fprint-potential-instances to see them all)
|
| 14 | 14 | • In the ambiguity check for ‘f’
|