[New DIP] Attributes for Higher-Order Functions#199
Merged
mdparker merged 62 commits intodlang:masterfrom Apr 7, 2021
Merged
Conversation
Geod24
reviewed
Dec 30, 2020
Member
Geod24
left a comment
There was a problem hiding this comment.
I have multiple issues with this DIP. I'll admit I stopped around 2/3rd in.
First, the form of the DIP makes it very hard to understand:
- The abstract is a bit short and vague, and the DIP jumps immediately into terms and definition;
- The terms and definition are not used consistently within the document;
- The language of the DIP is uneven, sometimes colloquial, sometimes formal, confusing the reader even more;
- There is almost no code example: What becomes legal ? What becomes illegal ?
- The DIP re-invent existing terminology instead of using pre-established one;
My understanding is that the DIP suggest to simply ignore attributes on callables in higher-order function, that is, allow the following:
void function (void function (int) fp) @nogc @safe pure nothrow
{
fp(42);
}Is that so ?
Member
|
@Bolpat I emailed you about this DIP some days ago. If you don't find it, could you please email me at aldacron@gmail.com so we can discuss it? Thanks! |
Contributor
Author
|
@mdparker, I answered your email just now. In short, let's move on with this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Functions that have function pointers or delegates as parameters cannot be integrated well in
pure,nothrow,@safe, and@nogccode. This DIP proposes to adjust the constraints that the mentioned attributes impose. It will only affect aforementioned functions with function pointers or delegates asconstorimmutableparameters.The goal is to recognize more code as valid that factually behaves in accordance to the attributes.
An example is this:
Notice how
sinkis not annotated@safe, but it is declaredconst. The key observations of this DIP are that because it isconst, any call likesink('c')can only execute the delegate passed to it (sinkcannot e.g. be reassigned), and thus, thetoString()function has full knowledge about whether the argument&appendthat binds tosinkis@safe.This DIP proposes
toStringoverload allowed to call its parametersinkeven if not annotated@safe— andtoString(&append)is only@safewhen both the called functiontoStringand the argument&appendare@safe.Calling
toStringwith a@systemsink is also valid, but the call will be considered@systemsince the condition that the argument be@safeis violated.These rules allow making
lazya lowering to a delegate type. Binding of arguments can still be done by implicitly embedding them in a delegate; a general implicit conversion from expressions to delegates is not necessary, but would work equally well.Furthermore, when making e.g.
@safethe default, the changes proposed by this DIP allow for an especially smooth transition path for higher-order functions that is not available otherwise.Delegates and function pointers with different attributes are compatible yet different types. For method overriding to behave as expected, overriding with contravariant parameters must be available to some degree.