Ticket #6026 (closed bug: fixed)

Opened 13 months ago

Last modified 6 months ago

Unboxed operators have wrong fixity

Reported by: benl Owned by: igloo
Priority: normal Milestone: 7.8.1
Component: libraries/base Version: 7.4.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect result at runtime Difficulty: Easy (less than 1 hour)
Test Case: T6026 Blocked By:
Blocking: Related Tickets:

Description

$ ghci -XMagicHash
$ :m GHC.Exts
> 1 + 2 * 3
7
> I# (1# +# 2# *# 3#)
9

Attachments

Change History

Changed 13 months ago by benl

I meant precedence, not fixity

Changed 13 months ago by simonpj

  • difficulty set to Unknown

Good point. Here's the deal.

  • LoadIface.ghcPrimIface gives the Iface data structure for GHC.Prim, which includes all primops.
  • You'll see that it give a fixity for seq, but not for any of the PrimOps. This is plainly wrong, as this ticket points out.
  • The wrong way to fix it is to add a long list of fixities to ghcPrimIface. Wrong because there are a lot of infix primops, and the list will change.
  • The right way to fix it is to allow prelude/primops.txt.pp to specify the fixity of a primop. There is a pattern to follow: the strictness or out_of_line fields. Then the program that processes primops.txt.pp can generate a function primOpFixity :: PrimOp -> Fixity, and ghcPrimIface can use that function to populate the fixity information.

Not clear how important this is... it's been this way for a long time. But yes, a useful task.

Simon

Changed 8 months ago by igloo

  • difficulty changed from Unknown to Easy (less than 1 hour)
  • milestone set to 7.8.1

Changed 6 months ago by michalt

Changed 6 months ago by michalt

  • status changed from new to patch

I've tried to follow the all the bullet points and everything seems to be working:

> ./inplace/bin/ghc-stage2 --interactive -XMagicHash
GHCi, version 7.7.20121113: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m +GHC.Exts
Prelude GHC.Exts> I# (1# +# 2# *# 3#)
7
Prelude GHC.Exts> D# (1.0## +## 2.0## *## 3.0##)
7.0
Prelude GHC.Exts> :i (+#)
(+#) :: Int# -> Int# -> Int#    -- Defined in `GHC.Prim'
infixl 6 +#
Prelude GHC.Exts> :i (+##)
(+##) :: Double# -> Double# -> Double#  -- Defined in `GHC.Prim'
infixl 6 +##

In genprimopcode I've created a new OptionFixity since it seemed that the other options didn't seem to fit that well.

Also, I've run validate and everything looks ok.

Changed 6 months ago by simonpj

  • owner set to igloo

Thank you michaelt!

Ian, can you pls review and commit? Thanks

Simon

Changed 6 months ago by michal.terepeta@…

commit 64efee6225ac18e54919d1690073fa2404a74a6c

Author: Michal Terepeta <michal.terepeta@gmail.com>
Date:   Mon Nov 12 21:31:32 2012 +0100

    Add fixity information to primops (ticket #6026)

 compiler/ghc.mk                 |    3 +++
 compiler/iface/LoadIface.lhs    |    6 ++++--
 compiler/prelude/PrimOp.lhs     |   15 +++++++++++++--
 compiler/prelude/primops.txt.pp |   24 ++++++++++++++++++++++++
 utils/genprimopcode/Lexer.x     |    5 +++++
 utils/genprimopcode/Main.hs     |   29 ++++++++++++++++++++++++++---
 utils/genprimopcode/Parser.y    |   13 +++++++++++++
 utils/genprimopcode/ParserM.hs  |    5 +++++
 utils/genprimopcode/Syntax.hs   |    9 +++++++++
 9 files changed, 102 insertions(+), 7 deletions(-)

Changed 6 months ago by igloo

  • status changed from patch to closed
  • testcase set to T6026
  • resolution set to fixed

Applied, thanks! I also added a test.

Note: See TracTickets for help on using tickets.