
#15696: Derived Ord instance for enumerations with more than 8 elements seems to be incorrect -------------------------------------+------------------------------------- Reporter: mrkkrp | Owner: (none) Type: bug | Status: patch Priority: highest | Milestone: 8.6.2 Component: Compiler | Version: 8.6.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D5196 Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): OK, moving on to solutions. Your patch seems OK. But I wonder if `CorePrep` is the right place to do it. After all, some other STG manipulation might break it again. I think the right thing is for the code generator to do the job; that is, in effect implement `dataToTag#` properly. That is, in `StgCmmPrim`, in {{{ cgOpApp (StgPrimOp primop) args res_ty = do }}} add a special case for `DataToTagOp`, when we are compiling `dataToTag# x`. Then behave exactly as if we'd seen `case x of y -> dataToTag## y`, where by `dataToTag## y` I mean generate the code the looks in the info table. (We have that code here {{{ -- #define dataToTagzh(r,a) r=(GET_TAG(((StgClosure *)a)->header.info)) -- Note: argument may be tagged! emitPrimOp dflags [res] DataToTagOp [arg] = emitAssign (CmmLocal res) (getConstrTag dflags (cmmUntag dflags arg)) }}} ). And by "behave exactly as if we'd see case ..." I roughly mean call `StgCmmExpr.cgCase`. But that need some `alts` which we don't conveniently have. The easiest thing would be to take `-- the general case` equation for `cgCase` and split off the bit that does the eval, so that we can call it from `dataToTag#`. Doing this is not trivial, but it feels like the Right Thing, and will remove the magic from `dataToTag#`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15696#comment:37 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler