Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#1145 closed merge (fixed)

class instance lost during re-export & packaging

Reported by: conal Owned by: igloo
Priority: normal Milestone: 6.6.1
Component: Compiler (Type checker) Version: 6.6
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The package TV defines an instance OFun (in module Interface.TV.OFun, source here) for a type class FunArr in the package DeepArrow. The module Interface.TV (source here) re-exports Interface.TV.OFun in its entirety.

When I compile a test program that imports Interface.TV, under ghc-6.6, the OFun instance of FunArr is not found. If the test module also says "import Interface.TV.OFun()", the instance is found. I get this behavior with ghc, ghc --make, and ghci.

The test program:

module Bug where

import Interface.TV.UI

-- Required to pick up the FunArr instance for OFun.  GHC bug?
import Interface.TV.OFun()

reverseT :: TV KIO (String -> String)
reverseT = tv (oTitle "reverse" defaultOut) reverse

revTwice :: TV KIO (String -> String)
revTwice = reverseT ->| reverseT

Test compile:

bash-3.2$ ghc -c Bug.hs
bash-3.2$ 

If I comment out the second import line, the problem surfaces:

ghc -c Bug.hs

Bug.hs:12:11:
    No instance for (FunArr ar (Output KIO))
      arising from use of `->|' at Bug.hs:12:11-31
    Possible fix:
      add an instance declaration for (FunArr ar (Output KIO))
    In the expression: reverseT ->| reverseT
    In the definition of `revTwice': revTwice = reverseT ->| reverseT
bash-3.2$ 

More details:

bash-3.2$ uname -a
CYGWIN_NT-5.1 Compy 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin

bash-3.2$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.6

bash-3.2$ ghc -v -c Bug.hs
Glasgow Haskell Compiler, Version 6.6, for Haskell 98, compiled by GHC version 6.6
Using package config file: c:\ghc\ghc-6.6\package.conf
wired-in package base mapped to base-2.0
wired-in package rts mapped to rts-1.0
wired-in package haskell98 mapped to haskell98-1.0
wired-in package template-haskell mapped to template-haskell-2.0
Hsc static flags: -static
Created temporary directory: c:/tmp/ghc3880_0
*** Checking old interface for main:Bug:
*** Parser:
*** Renamer/typechecker:

Bug.hs:12:11:
    No instance for (FunArr ar (Output KIO))
      arising from use of `->|' at Bug.hs:12:11-31
    Possible fix:
      add an instance declaration for (FunArr ar (Output KIO))
    In the expression: reverseT ->| reverseT
    In the definition of `revTwice': revTwice = reverseT ->| reverseT
*** Deleting temp files:
Deleting: c:/tmp/ghc3880_0/ghc3880_0.s
Warning: deleting non-existent c:/tmp/ghc3880_0/ghc3880_0.s
*** Deleting temp dirs:
Deleting: c:/tmp/ghc3880_0
bash-3.2$ 

Change History (8)

comment:1 Changed 7 years ago by igloo

  • Component changed from Compiler to Compiler (Type checker)
  • Milestone set to 6.6.1

Confirmed with 6.6; looks like some instances are getting lost.

It would be good to cut this down to a smaller case that we can put in the testsuite.

comment:2 Changed 7 years ago by simonpj

Conal,

Your comments say that the test program imports Interface.TV. But it doesn't; the test program you give imports Interface.TV.UI, and that module does not import Interface.TV.OFun.

So I'm not surprised at the behaviour you are seeing. Are you? GHC "sees" the instances in the transitive closure of the module import graph.

I'd try variations, only that means I have to install DeepArrow? etc, which I could do, but haven't yet.

Puzzled

Simon

comment:3 Changed 7 years ago by conal

My goof. The import should be just "Interface.TV" (without ".UI"). The new TV (version 2.0) only depends on the base, mtl & DeepArrow packages (no longer Phooey, which needs wxHaskell), so I guess you'd just need to install DeepArrow, which is small & easy. (The "UI" module is now GuiTV and re-exports "Interface.TV".)

The corrected Bug.hs:

module Bug where

import Interface.TV

-- Required to pick up the FunArr instance for OFun.  GHC bug?
import Interface.TV.OFun()

reverseT :: TV KIO (String -> String)
reverseT = tv (oTitle "reverse" defaultOut) reverse

revTwice :: TV KIO (String -> String)
revTwice = reverseT ->| reverseT

comment:4 Changed 7 years ago by simonpj

  • Type changed from bug to merge

Ok I've nailed this one. It was annoyingly tricky; to do with orphan instances in the presence of functional dependencies.

Ian: pls merge; but if the merge is not straightforward we could simply leave the fix out of 6.6.1; it's not critical.

I'm working on a test case.

Thanks for reporting this.

Simon

Wed Feb 21 16:30:47 GMT 2007 simonpj@…

  • Deal more correctly with orphan instances


Conal Eliott (Trac #1145) exposed a nasty flaw in the way in which
orphan instances are computed, when there are functional dependencies
in the class. It took me some time to figure out what was going on,
and led to more refactoring.


Briefly:


  • Elaborate comments about orphan-hood and versioning added to IfaceSyn?
  • The is_orph field vanishes from InstEnv?.Instance
  • Similarly ru_orph vanishes from CoreSyn?.CoreRule?
  • Orphan-hood is computed in MkIface?.instanceToIfaceInst, and

MkIface?.coreRuleToIfaceRule


Elsewhere just tidying up.


comment:5 Changed 7 years ago by igloo

  • Owner set to igloo

comment:6 Changed 7 years ago by igloo

  • Resolution set to fixed
  • Status changed from new to closed

I'm afraid the merge isn't trivial, so it's probably best to stick with the workaround (import the module directly) for 6.6.x.

I'm marking it as fixed as it's fixed in the HEAD.

Thanks

Ian

comment:7 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:8 Changed 6 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.