Skip to content

Comments

Improve and tighten pure functions specification#1528

Merged
andralex merged 9 commits intodlang:masterfrom
andralex:pureSpec
Dec 24, 2016
Merged

Improve and tighten pure functions specification#1528
andralex merged 9 commits intodlang:masterfrom
andralex:pureSpec

Conversation

@andralex
Copy link
Member

This is in keeping with the current implementation and tightens the spec to ensure no future shenanigans.

Copy link
Member

@jmdavis jmdavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've kind of tried to avoid making the terms "strong" and "weak" purity official, since it's really more of a range rather binary, and the difference really only applies to stuff like optimization, so I'm not sure that I'm all that enthused about using the term "strong" here like this, but it is a term that we keep having to use in discussions with regards to optimization - which is exactly how it's used here - and I don't really have a better suggestion. So, I guess that we should just go with it.

Aside from that possible nitpick though, everything looks good to me, and I think that we can live without fixing the nitpick.

spec/function.dd Outdated
$(P `pure` functions returning `void` will be always called even if it is
strongly `pure`. The implementation must assume the function does something
outside the confines of the type system and is therefore not allowed to
elide the call, even if it appears to have no possible effect.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be simpler to just say that pure functions returning void are not strongly pure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's sort of implied by "... (b) returns a result without mutable indirections", if we agree that void functions don't return any result.

@WalterBright
Copy link
Member

Should cover what happens when an exception is thrown by the pure function. I suggest regarding the exception thrown as its 'return value' as far as uniqueness and memoization rules go.

@andralex
Copy link
Member Author

@WalterBright will do with this PR.

@andralex
Copy link
Member Author

@WalterBright updated with no special requirements for exceptions so as to leave maximum freedom

@andralex
Copy link
Member Author

@WalterBright ping - guess we're now good

spec/function.dd Outdated
may still be elided, or results be memoized, by means of traditional
inlining and optimization techniques available for all functions.)

$(P A function that accepts only parameters without mutable indirections and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, should be: "A pure function" ?

@andralex
Copy link
Member Author

@JohanEngelen thx fixed

assumptions related to memoization and references do not carry to the thrown
exception.)

$(P Destructors will always be called even if they appear to be strongly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Destructors will always be called" is not want you want to say I think; instead, it should only say something about pure destructors.
Perhaps: "When a destructor is pure, it does not imply that it need not be called."

Maybe I am approaching this from too low-level viewpoint. When you write "destructors will always be called", do you mean it in the sense of debug-call-tracing-low-levelness, or in the high level sense of "the program will be executed as if destructors are always called" (thus allowing empty destructor calls to be eliminated)?

@andralex andralex merged commit 26af9b2 into dlang:master Dec 24, 2016
@nordlow
Copy link
Contributor

nordlow commented Dec 29, 2016

Can we now go forward with purifying free and GC add/remove Range?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants