[GHC] #5218: Add unpackCStringLen# to create Strings from string literals

GHC ghc-devs at haskell.org
Fri Apr 7 01:12:44 UTC 2017


#5218: Add unpackCStringLen# to create Strings from string literals
-------------------------------------+-------------------------------------
        Reporter:  tibbe             |                Owner:  thoughtpolice
            Type:  feature request   |               Status:  patch
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  7.0.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #5877 #10064      |  Differential Rev(s):  Phab:D2443
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by winter):

 > What is stopping these libraries from providing this mechanism currently
 using Addr# and primitive strings directly?

 The problem is that there's no way to cast `Addr#` into `ByteArray#`
 without copy, while unboxed vector(not storable) and text both want
 `ByteArray#`.

 > In general primitive strings are, as the name would suggest, primitive.
 I'm not sure forcing a heap object representation here is necessary nor
 prudent.

 I disagree. If we give string literal a proper compact representation, not
 only we cab save unnecessary copying during runtime, we can save code size
 in other ways.

 Consider if string literal now are `ByteArray#`s, we can use rules to
 simplify a UTF8 text type like `forall a. fromString (GHC.unpackCString#
 a) = UTF8 a`, that means we  can directly use constructor here instead of
 several calls. The same applys for unbox vectors using unboxed string
 literal and hexdecimal notation, which we have to use `fromList` and a
 real list now(which carrys a much larger overhead).

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/5218#comment:60>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list