-
-
-splitProductType :: String -> Type -> (TyCon, [Type], DataCon, [Type])
- -- For a tiresome reason, the type might not look like a product type
- -- This happens when compiling the compiler! The module Name
- -- imports {-# SOURCE #-} TyCon and Id
- -- data Name = Name NameSort Unique OccName Provenance
- -- data NameSort = WiredInId Module Id | ...
- -- So Name does not look recursive (because Id is imported via a hi-boot file,
- -- which says nothing about Id's rep) but actually it is, because Ids have Names.
- -- Modules that *import* Name have a more complete view, see that Name is recursive,
- -- and therefore that it isn't a ProductType. This conflicts with the CPR info
- -- in exports from Name that say "do CPR".
- --
- -- Arguably we should regard Name as a product anyway because it isn't recursive
- -- via products all the way... but we don't have that info to hand, and even if
- -- we did this case might *still* arise.
-
- --
- -- So we hack our way out for now, by trusting the pragma that said "do CPR"
- -- that means we can't use splitProductType_maybe
-
-splitProductType fname ty
- = case splitAlgTyConApp_maybe ty of
- Just (tycon, tycon_args, (con:other_cons))
- | null other_cons && not (isExistentialDataCon con)
- -> WARN( not (isProductTyCon tycon),
- text "splitProductType hack: I happened!" <+> ppr ty )
- (tycon, tycon_args, con, dataConArgTys con tycon_args)
-
- Nothing -> pprPanic (fname ++ ": not a product") (ppr ty)