
#12670: Representation polymorphism validity check is too strict -------------------------------------+------------------------------------- Reporter: bgamari | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Compiler (Type | Version: 8.0.1 checker) | Resolution: | Keywords: typeable 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 bgamari): Well, I'm not quite sure that is sufficient; afterall the kind of `a` in the above example indeed has the form `TYPE blah`. Rather, it seems like we need some way of determining whether a particular `RuntimeRep` variable affects the runtime representation of a type. It would seem at first glance that given a function type, e.g. `a -> b`, we would want to check that the kinds of `a` and `b` both have no free `RuntimeRep` variables. I suspect this is the only check necessary. We can assume that applications of any other tycon to `RuntimeRep` variables is safe since the type has already been subject to the `checkForRepresentationPolymorphism` check. Consequently, we have already determined that none of the type's type arguments will affect its representation and therefore any well-kinded application is safe. Therefore, I propose that `checkForRepresentationPolymorphism` is simply the following, {{{#!hs checkForRepresentationPolymorphism :: SDoc -> Type -> TcM () checkForRepresentationPolymorphism extra ty | Just (tc, tys) <- splitTyConApp_maybe ty , isUnboxedTupleTyCon tc || isUnboxedSumTyCon tc = mapM_ (checkForRepresentationPolymorphism extra) (dropRuntimeRepArgs tys) | tuple_rep || sum_rep = {- fail -} | (args, res) <- splitFunTys ty , not $ all is_safe_arrow_argument (res:args) = {- fail -} | otherwise = return () where tuple_rep = runtime_rep `eqType` unboxedTupleRepDataConTy sum_rep = runtime_rep `eqType` unboxedSumRepDataConTy tuple_or_sum = text (if tuple_rep then "tuple" else "sum") ki = typeKind ty runtime_rep = getRuntimeRepFromKind "check_type" ki is_safe_arrow_argument = isEmptyVarSet . tyCoVarsOfType . getRuntimeRepFromKind "check_type" . typeKind }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/12670#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler