[commit: ghc] master: Include the instances of associated types in the "extras" of a class (3bf0520)
Simon Peyton Jones
simonpj at microsoft.com
Wed Aug 3 08:47:33 CEST 2011
Repository : ssh://darcs.haskell.org//srv/darcs/ghc
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/3bf0520aea5acbecb83dcc0fc722c79ce9f5723c
>---------------------------------------------------------------
commit 3bf0520aea5acbecb83dcc0fc722c79ce9f5723c
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date: Wed Aug 3 07:46:50 2011 +0100
Include the instances of associated types in the "extras" of a class
This fixes Trac #5147, which was going wrong because
the class ABI fingerprint wasn't changing when we added
or removed a Show instance to the associated type.
>---------------------------------------------------------------
compiler/iface/IfaceSyn.lhs | 8 ++++++++
compiler/iface/MkIface.lhs | 24 ++++++++++++++++++++----
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/compiler/iface/IfaceSyn.lhs b/compiler/iface/IfaceSyn.lhs
index 8ca6b39..b5da626 100644
--- a/compiler/iface/IfaceSyn.lhs
+++ b/compiler/iface/IfaceSyn.lhs
@@ -282,6 +282,14 @@ Note [Orphans]: the ifInstOrph and ifRuleOrph fields
If a module contains any "orphans", then its interface file is read
regardless, so that its instances are not missed.
+ - If an instance is an orphan its ifInstOprh field is Nothing
+ Otherwise ifInstOrph is (Just n) where n is the Name of a
+ local class or tycon that witnesses its non-orphan-hood.
+ This computation is done by MkIface.instanceToIfaceInst
+
+ - Similarly for ifRuleOrph
+ The computation is done by MkIface.coreRuleToIfaceRule
+
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
diff --git a/compiler/iface/MkIface.lhs b/compiler/iface/MkIface.lhs
index a72ed4e..fcf7c31 100644
--- a/compiler/iface/MkIface.lhs
+++ b/compiler/iface/MkIface.lhs
@@ -650,9 +650,22 @@ type IfaceDeclABI = (Module, IfaceDecl, IfaceDeclExtras)
data IfaceDeclExtras
= IfaceIdExtras Fixity [IfaceRule]
- | IfaceDataExtras Fixity [IfaceInstABI] [(Fixity,[IfaceRule])]
- | IfaceClassExtras Fixity [IfaceInstABI] [(Fixity,[IfaceRule])]
+
+ | IfaceDataExtras
+ Fixity -- Fixity of the tycon itself
+ [IfaceInstABI] -- Local instances of this tycon
+ -- See Note [Orphans] in IfaceSyn
+ [(Fixity,[IfaceRule])] -- For each construcotr, fixity and RULES
+
+ | IfaceClassExtras
+ Fixity -- Fixity of the class itself
+ [IfaceInstABI] -- Local instances of this class *or*
+ -- of its associated data types
+ -- See Note [Orphans] in IfaceSyn
+ [(Fixity,[IfaceRule])] -- For each class method, fixity and RULES
+
| IfaceSynExtras Fixity
+
| IfaceOtherDeclExtras
abiDecl :: IfaceDeclABI -> IfaceDecl
@@ -727,9 +740,12 @@ declExtras fix_fn rule_env inst_env decl
IfaceDataExtras (fix_fn n)
(map ifDFun $ lookupOccEnvL inst_env n)
(map (id_extras . ifConOcc) (visibleIfConDecls cons))
- IfaceClass{ifSigs=sigs} ->
+ IfaceClass{ifSigs=sigs, ifATs=ats} ->
IfaceClassExtras (fix_fn n)
- (map ifDFun $ lookupOccEnvL inst_env n)
+ (map ifDFun $ (concatMap (lookupOccEnvL inst_env . ifName) ats)
+ ++ lookupOccEnvL inst_env n)
+ -- Include instances of the associated types
+ -- as well as instances of the class (Trac #5147)
[id_extras op | IfaceClassOp op _ _ <- sigs]
IfaceSyn{} -> IfaceSynExtras (fix_fn n)
_other -> IfaceOtherDeclExtras
More information about the Cvs-ghc
mailing list