If you could make any changes to D, what would they look like?
Dennis
dkorpel at gmail.com
Thu Oct 28 10:53:25 UTC 2021
On Wednesday, 27 October 2021 at 19:53:52 UTC, H. S. Teoh wrote:
> Unfortunately, a quick test with dmd did not show the expected
> optimization. Which confirms what I said before that pure's
> optimization benefit is really rather marginal.
The function needs to be `nothrow` and compiled with `-O
-release`, because dmd needs to account for exceptions / errors,
and even then the optimization [shouldn't really be
done](https://issues.dlang.org/show_bug.cgi?id=22277). LDC
doesn't do anything with `pure` for optimizations, but since it
has cross module inlining, it doesn't need it.
> The bigger benefit is the mechanical verification that you
> didn't accidentally depend on global state when you didn't want
> to, which can help with improving code quality.
That, but it can also help proving a lack of aliasing. For
example:
```D
int[] duplicate(scope int[] x) pure;
```
The returned array can safely be converted to `immutable int[]`.
(N.b. this is not implemented yet)
```D
void foo(int[] x, int[] y) pure nothrow;
```
Parameters `x` and `y` can freely be inferred `scope`, which is
useful since dmd's `scope` inference from function bodies is not
good.
More information about the Digitalmars-d
mailing list