[GHC] #11999: expressing injectivity on functional dependencies gives orphan instances warnings

#11999: expressing injectivity on functional dependencies gives orphan instances warnings -------------------------------------+------------------------------------- Reporter: dredozubov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Class.hs {{{ {-# LANGUAGE DataKinds, FlexibleInstances, FunctionalDependencies, KindSignatures, MultiParamTypeClasses, TypeFamilies #-} module Class where class C a b | a -> b, b -> a }}} Lib.hs {{{ {-# LANGUAGE DataKinds, FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-} module Lib where import Class newtype Local = Local () instance C Local () }}} gives {{{ /Users/dr/workspace/broken-ophans-ghc/src/Lib.hs:10:1: warning: [-Worphans] Orphan instance: instance C Local () To avoid this move the instance declaration to the module of the class or of the type, or wrap the type with a newtype and declare the instance on the new type. }}} It seems weird to me and it is either a bug in the orphan instances checker or there is some fundamental aspect which i don't undestand. I've been able to reproduce this with 7.10.3 and 8-rc4. I've compiled a git repo with minimalistic example of this: [https://github.com/dredozubov/broken-instances-minimal] -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11999 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11999: expressing injectivity on functional dependencies gives orphan instances warnings -------------------------------------+------------------------------------- Reporter: dredozubov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by dredozubov): This code comment was brought to my attention on IRC: [https://ghc.haskell.org/trac/ghc/ticket/11999 ] It mentions this issue, but it still feels like a broken behavior to me. I'll leave it to the people more knowledgeable that me to decide if that's can be considered a bug. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11999#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#11999: expressing injectivity on functional dependencies gives orphan instances warnings -------------------------------------+------------------------------------- Reporter: dredozubov | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rahulmutt):
Note [When exactly is an instance decl an orphan?] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (see MkIface.instanceToIfaceInst, which implements this) Roughly speaking, an instance is an orphan if its head (after the =>) mentions nothing defined in this module.
Functional dependencies complicate the situation though. Consider
module M where { class C a b | a -> b }
and suppose we are compiling module X:
module X where import M data T = ... instance C Int T where ...
This instance is an orphan, because when compiling a third module Y we might get a constraint (C Int v), and we'd want to improve v to T. So we must make sure X's instances are loaded, even if we do not directly use anything from X.
This part of the note explains why your example would be considered an orphan instance. Otherwise you can define instances that may not be "seen" as intended. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11999#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC