New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify variability of functions. #2924
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to pursue this view, I think the variability rules must be updated accordingly.
I also think that at least the function-compatibility definition must be refined to consider variability of any binding assignments.
I'm also wondering if one has to do it this way, considering how non-transparent it makes the variability of a function call. It would be good if a complicated design was backed up by real-world examples in need of it.
I also don't think it fixes:
unless you expect evaluation to happen before you try to compute the variability of an expression? |
Exactly, it's not legal, similarly as the following isn't:
That is a very esoteric case, when you have a constant/parameter bound to a replaceable function - and then redeclare that function to a function with additional defaults of higher variability. |
The problem is not the legality, it is the computability. As in, you can't compute the variability of |
But then we can just look at:
and conclude that the underlying issue is that the function-defaults use a recursive call; and add a restriction saying that the function defaults may not recursively call the function. |
That would work although I think having to do a prior analysis of the existing recursive dependency between functions and how these depend on the default-binding of a given argument to be able to finally check something as straight forward as the variability of an expression is disappointing. How would the following case be handled:
|
That seems normal as analysis of a function depend on the function being correct in some way.
I hope you mean another input and not a protected variable, since that cannot be modified. |
If we really care about whether a replaceable function will be constant with arguments we could introduce some variant of "replaceable constant function", inspired by "constexpr" functions in C++ (but with different meaning); meaning that it is constant if the inputs are constant. |
I forgot about that.
|
The solution we talked about at the time was to have a variability prefix for function definitions that behaved in that way. |
It's certainly possible, but it will:
Additionally the idea of "constant function" and "parameter function" will break down for "evaluable parameter function". I see the following variants:
I added text for the second variant to make it more concrete. We can always revert that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking review as request changes, but what I really mean by this is that I think we need more active participation from all tool vendors on this matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With suggested changes it looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting change because I think we can actually write the rules for variability analysis so that they properly describe how it needs to be done today.
To do this, I suggest that we add a section called Function Variability before Constant Expressions, where we explain how a variability is associated with every function class or component. Then we take this into consideration when defining the various expression variabilities.
Is it getting closer now? |
Yes, with minor details out of the way, we should now be able to focus on the principal question of how the variability of a function call should be defined. |
I have also thought about that in relation to this PR. I wonder if 3.8 Variability of Expressions just wasn't updated when It might be enough to just add a paragraph to 3.8 explaining why the variability of impure function calls doesn't matter, and then change all the rules for function call variability in the subsections to say "pure function". However, I guess this is actually something we could discuss in a separate PR, allowing the present PR to assume we're just talking about pure functions? |
Co-authored-by: Elena Shmoylova <eshmoylova@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're approaching something that could be good for now, but I think we can take the function variability a small step further to tie it even harder to function call variability:
- Let's just define function variability as a variability associated with the function itself, and define this in the Function Variability section.
- When defining variability of function call expressions, also take the function variability into consideration.
I don't see this, as I don't see functions having variability; and thus points disappear. |
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Without anyone else showing interest in my way of attaching variability to the function itself, I have to give up this idea for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to just remain some discussion about how to motivate why purity isn't considered for variability.
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
Co-authored-by: Henrik Tidefelt <henrikt@wolfram.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Guessing that an updated review is wanted at this time.)
I think this PR is good enough now considering that the idea of attaching variability to the functions didn't attract a lot of positive attention.
Closes #2538