On 12/11/2012 5:15 PM, bearophile wrote:
Regarding safeInt I think today there is no way to write it efficiently in D,
because the overflow flags are not accessible from D, and if you use inlined
asm, you lose inlining in DMD. This is just one of the problems.

The way to deal with this is to examine the implementation of CheckedInt, and design a couple of compiler intrinsics to use in its implementation that will eliminate the asm code. (This is how the high level vector library Manu is implementing is done.)


The other problems are syntax incompatibilities of user-defined structs 
compared to
built-in ints.

This is not an issue.

Other problems are the probable lack of high-level optimizations
done on such user defined type.

Using intrinsics deals with this issue nicely, as the optimizer knows about 
them.

We are very far from a good solution to such problems.

No, we are not.

The problem, as I see it, is nobody actually cares about this. Why would I say something so provocative? Because I've seen D programmers go to herculean lengths to get around problems they are having in the language. These efforts make a strong case that they need better language support (UDAs are a primo example of this). I see nobody bothering to write a CheckedInt type and seeing how far they can push it, even though writing such a type is not a significant challenge; it's a bread-and-butter job.

Also, as I said before, there is a SafeInt class in C++. So far as I can tell, nobody uses it.

Want to prove me wrong? Implement such a user defined type, and demonstrate user interest in it.

(Also note the HalfFloat class I implemented for Manu, as a demonstration of how a user defined type can implement a floating point type that is unknown to the compiler.)

Reply via email to