Bug 7314 – strong purity should be inferred at call site

Status
REOPENED
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-01-18T12:05:05Z
Last change time
2024-12-13T17:57:42Z
Assigned to
No Owner
Creator
timon.gehr
Moved to GitHub: dmd#18398 →

Comments

Comment #0 by timon.gehr — 2012-01-18T12:05:05Z
Currently, a function is considered to be strongly pure if all its formal parameters implicitly convert to immutable. But a function invocation can be considered strongly pure if all actual arguments are implicitly convertible to immutable. The following code should compile: const(int)[] foo(const(int)[] x)pure{return x;} void main(){ immutable(int)[] x; immutable(int)[] y = foo(x); }
Comment #1 by bearophile_hugs — 2012-01-18T14:49:09Z
I think there are ways to further improve this idea. And I think such ideas will lead to quite useful code. I have recently written two posts about related ideas. I think this is an improvement. But I think language complexity too should be kept into account. When a programmer writes code like this: auto foo(...) pure { ... } void main() { immutable x = foo(...); } She should be able to usually guess correctly if such code is correct, or if it doesn't compile. The more complex D purity becomes, the less easy is to remember all the rules and exceptions to the rule, and this increases the risk of turning programming more into guesswork than design. This sometimes happens even if every single rule looks like an improvement.
Comment #2 by maxhaton — 2021-01-24T06:46:16Z
spec problem + this behaviour would make it inconsistent with regular assignments
Comment #3 by timon.gehr — 2021-01-24T12:31:55Z
???
Comment #4 by robert.schadek — 2024-12-13T17:57:42Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18398 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB