Skip to content
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

Document and unify the order in which GAP evaluates function arguments and options #4632

Merged
merged 2 commits into from
Aug 28, 2021

Conversation

fingolfin
Copy link
Member

Previously, this was what the immediate interpreter did, but not
what the executor did; the latter always evaluated options first.

Fixes #4631

@fingolfin fingolfin added kind: bug Issues describing general bugs, and PRs fixing them topic: kernel kind: quirk Issues that are not bugs, but a discrepancy between user expectation and system behavior labels Aug 19, 2021
@fingolfin fingolfin force-pushed the mh/func-opts-eval-order branch 2 times, most recently from 23206aa to 0d3d39c Compare August 20, 2021 14:11
Copy link
Member

@wilfwilson wilfwilson left a comment

Choose a reason for hiding this comment

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

The kernel changes seem to be doing what you want, from what I can tell.

I'm a bit worried that the (thankfully now consistent) order of things happening is not documented. As far as I can tell, the closest documentation that address this behaviour is 4.11-2 Function Call With Options https://www.gap-system.org/Manuals/doc/ref/chap4.html#X867D54987EF86D1D which includes:

The following example shows a call to Size (30.4-6) passing the options hard (with the value true) and tcselection (with the string "external" as value).

gap> Size( fpgrp : hard, tcselection := "external" );

Options supplied with function calls in this way are passed down using the global options stack described in chapter 8, so that the call above is exactly equivalent to

gap> PushOptions( rec( hard := true, tcselection := "external") );
gap> Size( fpgrp );
gap> PopOptions( );

This example doesn't address the topic at issue here, but a sentence could be added, and this example modified (perhaps by constructing fpgrp in the one-liner too), to show the order in which arguments are evaluated versus options set.

@fingolfin
Copy link
Member Author

That chapter of the reference manual also says this about evaluation order:

However, GAP does not make any guarantee about the order in which the arguments are evaluated. They might be evaluated left to right, right to left, or in any other order, but each argument is evaluated once

Based on this, one may argue that the "bug" this issue "fixes" isn't a bug at all -- it's a legitimate variation in otherwise undefined behavior.

However, I am not a fan of this, or of that sentence. GAP performs things in a fixed order (and typically that order is left-to-right, depth first), and it can be beneficial to users to be able to rely on that. Yes, we might in theory want to implement some kind of optimizations where it might be useful to be able to reorder these evaluations.... but does it seem likely we'll ever do this? I personally don't think so (but perhaps @ChrisJefferson disagrees?)

@ChrisJefferson
Copy link
Contributor

I don't think any optimisations would be worth the subtle bugs which would be introduced -- I think that both for GAP, and other programming languages, but GAP is the one where we can fix the order ourselves :)

@fingolfin
Copy link
Member Author

Good! I'll augment the documentation

@fingolfin fingolfin force-pushed the mh/func-opts-eval-order branch from 0d3d39c to 9ce4628 Compare August 25, 2021 13:51
@fingolfin
Copy link
Member Author

I've added a commit updating the documentation, please check it.

Editing this code made me realize that our documentation for variable length argument lists could be better, so I'll work on that next.

@fingolfin
Copy link
Member Author

Note that this conflicts with PR #4547 -- it'd be much easier for me if that PR was merged first, then I could easily update the PR here to match

@fingolfin fingolfin closed this Aug 27, 2021
@fingolfin fingolfin reopened this Aug 27, 2021
Copy link
Member

@wilfwilson wilfwilson left a comment

Choose a reason for hiding this comment

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

Thank you for the documentation changes, and I'm happy to also approve the code codes.

I'll review #4547 now and see about approving/merging that before this one 🙂

@wilfwilson
Copy link
Member

#4547 is merged so it's time to rebase this when you have a chance.

Previously, this was what the immediate interpreter did, but *not*
what the executor did; the latter always evaluated options first.
@fingolfin fingolfin force-pushed the mh/func-opts-eval-order branch from 9ce4628 to 5ec67bc Compare August 28, 2021 20:28
@fingolfin fingolfin added release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements labels Aug 28, 2021
@fingolfin fingolfin changed the title kernel: evaluate function call arguments before options Document and unify the order in which GAP evaluates function arguments and options Aug 28, 2021
@fingolfin fingolfin merged commit 1a0f502 into gap-system:master Aug 28, 2021
@fingolfin fingolfin deleted the mh/func-opts-eval-order branch August 28, 2021 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Issues describing general bugs, and PRs fixing them kind: enhancement Label for issues suggesting enhancements; and for pull requests implementing enhancements kind: quirk Issues that are not bugs, but a discrepancy between user expectation and system behavior release notes: use title For PRs: the title of this PR is suitable for direct use in the release notes topic: kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected behaviour of options
3 participants