Start to move away from complex and imaginary types#6014
Start to move away from complex and imaginary types#6014dlang-bot merged 4 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
std/format.d
Outdated
| "float", "double", "real", | ||
| "char", "wchar", "dchar", | ||
| "ifloat", "idouble", "ireal", | ||
| "cfloat", "cdouble", "creal", |
There was a problem hiding this comment.
How can we call typeid without a deprecation warning?
There was a problem hiding this comment.
I think the right steps are to first deprecate in library (user-code). Once enough time has passed, remove support for complex and imaginary in the library.
Then we kill it in the compiler starting with deprecation by default.
| assert(isIdentical(abs(-0.0L), 0.0L)); | ||
| assert(isNaN(abs(real.nan))); | ||
| assert(abs(-real.infinity) == real.infinity); | ||
| assert(abs(-3.2Li) == 3.2L); |
There was a problem hiding this comment.
The complex deprecation currently triggers error in deprecated code. See https://issues.dlang.org/show_bug.cgi?id=18212
We can't do that. Phobos needs to build without deprecation messages. This was enabled about 9 months ago, because (1) deprecation messages were shown to users and (2) people always introduced deprecations without considering the fallout and viability. By |
Slight amendment: it's okay to have deprecation messages in phobos' unittest builds. |
Yep, but only if they are marked as |
174a4b7 to
fd9fca2
Compare
07a36c3 to
f0ecf05
Compare
wilzbach
left a comment
There was a problem hiding this comment.
Not so sure how to deal with functions returning creal. Would be adding deprecated creal opCast(T: creal) to std.complex good enough or do we have to completely deprecate these two functions?
std/math.d
Outdated
| { | ||
| return cos(y) + sin(y)*1i; | ||
| } | ||
| auto expi(real y) @trusted pure nothrow @nogc |
There was a problem hiding this comment.
Not sure how to deal with this in another way.
std/math.d
Outdated
| * cos(z) = cos(z.re)*cosh(z.im) - sin(z.re)*sinh(z.im)i | ||
| */ | ||
| creal cos(creal z) @safe pure nothrow @nogc | ||
| auto cos(C)(C z) @safe pure nothrow @nogc |
There was a problem hiding this comment.
Not sure how to deal with this in another way.
std/format.d
Outdated
| // is required since for arrays of ints we only have the mangled char | ||
| // to work from. If arrays always subclassed TypeInfo_Array this | ||
| // routine could go away. | ||
| private TypeInfo primitiveTypeInfo(Mangle m) |
There was a problem hiding this comment.
So primitiveTypeInfo is a relict from the old doFormat days. It's not used anywhere anymore.
See e.g. #4978
I do not think this is an issue. see #6014 (comment) |
Perhaps we should add an |
Yes!!! But plus |
This will allow to solve all problems I have with std.math and std.complex. And I will be happy to remove |
Please elaborate, I'm not sure what this would do. |
@fastmath auto foo(double a); { return bar(a); }
@inherit auto bar(double a) {
// this trivial case can be done by LLVM optimizer,
// but helpful for other tricky math hacks
static if (AllowsReciprocal!(__traits(llvmAttributes)))
return PI * 1 / a; // one algo
else
return PI / a; // another algo
}
template AllowsReciprocal(Attrs...) { ... } |
|
That won't work because the body of |
|
@thewilsonator can it be just a template without args? E. g. the attributes are special hiden template |
How would
Wouldn't it then be just a copy of
|
|
Formating not so sure, any reason this can't be done one |
|
@9il I don't think so. |
Neither are std.math or any other functions that use complex annotated with compiler specific attributes -> not a valid argument. |
If it's not part of the language, then I can't see it going in. Likewise fastmath, which means that code generated is no longer IEEE compliant. |
There are no D libs for math and algorithms, but Phobos? Entire mir-algorithm is annotated. I do not whant to argue why it is fine for IEEE, you can do experiments with LDC to ensure that IEEE is preserved if a lambda is not annotated. |
It is part of the best D compiler for math and finance. |
|
@9il when would that ever not be allowed ? |
|
@stefan-koch-sociomantic div operation can be optimised in fastmath to mul and reciprocal. This optimization is not allowed by default because of IEEE |
You're free to do that if you value speed over correctness. Talking about annotating functions with non-standard attributes is not up for debate though. |
The best compiler for math and finance is gdc (I say that with a grin, but the point stands - there is no best). (incidentally one of the Berlin meet up talks did a live demo talk benchmarking math performance between dmd, ldc, gdc - the winner was gdc by a landslide, the loser was ldc but the author was surprised and didn't know why). |
|
gdc's frontend does a better job then ldc's does. |
|
@ibuclaw this is your opinion. Mir-algorithm does not break IEEE, probably you do not understand how this attributes affects lambdas. I do not debate. I just showed how the prs kill perfomance. I will be happy with my own library |
|
@9il I'll start by removing fastmath from your examples and seeing what the real difference is. |
@ibuclaw Quite the opposite. @inherit void bar(...) { ... } // <-not @fastmath
@fastmath void foo(...)
{
bar(...); // inlined into foo. foo's inline copy of bar now @fastmath
}If there becomes a The question is if there is benefit in standardising it across compilers for propagating optimisation directives. |
You could start with a DIP. |
|
Well would GDC benefit from this? DMD doesn't have much in the way of perf tweaking attributes. |
|
Try playing around with gdc yourself, and see if there might be: https://explore.dgnu.org/ The module you're looking for is From what you describe though, I'm not sure. I would expect all inlined functions to be applied the same optimization flags as the function they are inlined into without the need to be explicit about it. |
|
Well in LDC the IEEE compliance (or lack thereof) is encoded into the function such that inlining will result in some instructions being |
|
In any case. Any solution or discussion needs to revolve around compiler-agnostic tests for performance and attributes. Anything else is out of scope. We could introduce |
I couldn't say off the top of my head. If anything it probably depends entirely on what order optimization passes are done in. I.e: whether or not inlining is done before or after reordering. I'm pretty certain that optimisation attributes are applied only at a function level and not a block level. So I don't think ldc's problem really applies for gdc. But as I said please test this! (I'm on my phone and can't for the moment) |
This is first PR which works in the direction of finally going through with the
complex and imaginary type deprecation.
See also: dlang/dmd#7640