[Issue 4850] std.conv.to isn't pure

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 9 08:45:13 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=4850


kennytm at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm at gmail.com


--- Comment #1 from kennytm at gmail.com 2011-06-09 08:40:34 PDT ---
std.conv.to is not pure due to the following function and bugs. The conversions
which trigger them are listed below.

1. std.array.appender
     - array -> string
     - AA -> string
     - struct -> string
2. memcpy
     - void[] -> string
3. std.exception.enforce  (bug 5750)
     - void[] -> string
     - integer & radix -> string
4. the .toString member method is not necessarily pure
     - class/struct -> string
5. std.conv.to itself is not pure
     - array -> string
     - AA -> string
     - struct -> string
     - enum -> string
     - typedef -> string
     - bool -> string
     - array -> array
     - AA -> AA
     - integer -> string
     - floating -> string
     - pointer -> string
6. std.conv.parseString
     - string -> string
7. the .to!T member template method is not necessarily pure
     - class -> any
8. std.conv.ConvOverflowException.raise (bug 3269, should have been fixed)
     - numeric -> numeric
9. 'pure nested function '__foreachbody2115' cannot access mutable data
'first'' (bug 5635).
10. core.memory.GC.malloc (why not use 'new Char[x]'?)
     - uint/ulong -> string
11. sprintf
     - [i,c]double/real -> string

std.conv.parseString is not 'pure' because convError and parse are not 'pure'.
convError is not 'pure' because it uses to!string. parse is not pure due to the
following:

12. ConvOverflowException.raise
13. convError
14. std.algorithm.skipOver
     - string -> enum
15. std.conv.to (including std.conv.text)
     - string -> floating
16. std.exception.enforce
17. 'static const int sign = 0;' near line 1109, should be immutable?
18. std.math.ldexpl
     - string -> floating
19. std.algorithm.skipAll
     - string -> array
20. std.string.icmp
     - string -> bool

std.conv.to itself cannot be fully pure, because of #4 (.toString) and #7
(.to!T), unless we require user's .toString must be 'pure' as well, which is
not necessarily possible (considering even making 'opEquals' const is
debatable). Therefore, the compiler or library must support some form of 'auto
pure' for 'to' to choose the strictest attribute
automatically/programmatically. This also applies to the two 'std.algorithm'
functions (#14 skipOver, #19 skipAll) which can run user code. But a problem of
'auto pure' is dealing with recursive functions, which happens a lot here (#5,
#15). And then there are some functions like #1 (appender), #10 (GC.malloc)
which I wonder should they be really 'pure', and avoiding them could reduce
efficiency a lot.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list