| 31 | | * '''Representing integers'''. We stick to the `LitInteger` representation (which hides the concrete representation) as late as possible in the compiler. In particular, it's important that this representation is used in unfoldings in interface files, so that constant folding can happen on expressions that get inlined. We finally convert `LitInteger` to a proper core representation of Integer in [[GhcFile(compiler/coreSyn/CorePrep.lhs)]], which looks up the Id for `mkInteger` and uses it to build an expression like `mkInteger True [123, 456]` (where the `Bool` represents the sign, and the list of `Int`s are 31 bit chunks of the absolute value from lowest to highest). |
| | 31 | * '''Converting between Int and Integer'''. It's quite commonly the case that, after some inlining, we get something like `integerToInt (intToInteger i)`, which converts an `Int` to an `Integer` and back. This ''must'' optimise away. We do this by requiring that the `integer` package exposes |
| | 32 | {{{ |
| | 33 | smallInteger :: Int# -> Int |
| | 34 | }}} |
| | 35 | Now we can define `intToInteger` (or, more precisely, the `toInteger` method of the `Integral Int` instance in `GHC.Real` ) thus |
| | 36 | {{{ |
| | 37 | toInteger (I# i) = smallInteger i |
| | 38 | }}} |
| | 39 | And we have a RULE for `integerToInt (smallInteger i)`. |
| | 40 | |
| | 41 | * '''Representing integers'''. We stick to the `LitInteger` representation (which hides the concrete representation) as late as possible in the compiler. In particular, it's important that the `LitInteger` representation is used in unfoldings in interface files, so that constant folding can happen on expressions that get inlined. |
| | 42 | |
| | 43 | We finally convert `LitInteger` to a proper core representation of Integer in [[GhcFile(compiler/coreSyn/CorePrep.lhs)]], which looks up the Id for `mkInteger` and uses it to build an expression like `mkInteger True [123, 456]` (where the `Bool` represents the sign, and the list of `Int`s are 31 bit chunks of the absolute value from lowest to highest). |