desugar: Ensure that a module's dep_orphs doesn't contain itself
ClosedPublic

Authored by bgamari on Aug 26 2017, 12:30 PM.

Details

Summary

Consider that we have two modules, A and B, both with hs-boot files,

  • A.hs contains a SOURCE import of B
  • B.hs-boot contains a SOURCE import of A
  • A.hs-boot declares an orphan instance
  • A.hs defines the orphan instance

In this case, B's dep_orphs will contain A due to its SOURCE import of A.
Consequently, A will contain itself in its imp_orphs due to its import of B.
This fact would end up being recorded in A's interface file. This would then
break the invariant asserted by calculateAvails that a module does not itself in
its dep_orphs. This was the cause of Trac #14128.

The solution is to remove self-references from imp_orphs when constructing
dep_orphs; we already did a similar thing for dep_mods. I believe we should do
the same for dep_finsts, although I'm treating this as a separate bug.

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
bgamari created this revision.Aug 26 2017, 12:30 PM
This revision was automatically updated to reflect the committed changes.
bgamari added a subscriber: ezyang.

@ezyang, how does this look to you?

ezyang edited edge metadata.Aug 29 2017, 7:55 PM

Well, this clearly fixes a bug, so I don't mind taking it. But I feel like we have similar logic for this (filter out self import) elsewhere in GHC, so I wonder if we've hit the root cause.