D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7314 - strong purity should be inferred at call site
Summary: strong purity should be inferred at call site
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-18 12:05 UTC by timon.gehr
Modified: 2024-12-13 17:57 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2012-01-18 12:05:05 UTC
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 bearophile_hugs 2012-01-18 14:49:09 UTC
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 mhh 2021-01-24 06:46:16 UTC
spec problem + this behaviour would make it inconsistent with regular assignments
Comment 3 timon.gehr 2021-01-24 12:31:55 UTC
???
Comment 4 dlangBugzillaToGithub 2024-12-13 17:57:42 UTC
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