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

Recursive priorities (or push-priorities, or leafy priorities) #845

Merged
merged 3 commits into from
Oct 18, 2022

Conversation

yannham
Copy link
Member

@yannham yannham commented Sep 22, 2022

Closes #279. Implement push priority operators as described in RFC001. The general idea is that:

let foo = {
  bar = 1,
  baz = {
    x = "a",
    y = "b",
  }
} in
foo | _push_default

is equivalent to

{
  bar | default = 1,
  baz = {
    x | default = "a",
    y | default = "b",
  }
}

The push priority operators are dynamic and not just syntactic sugar. They operate on arbitrary expressions and are thus not limited to record literals. The syntax _push_default and _push_force is temporary (and ugly on purpose), to proceed with the technical implementation without being blocked by bikeshedding considerations, which can happen after, prior to the next release.

@github-actions github-actions bot temporarily deployed to pull request September 22, 2022 15:44 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 28, 2022 13:47 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 28, 2022 14:09 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 29, 2022 09:45 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 4, 2022 15:01 Inactive
@github-actions github-actions bot temporarily deployed to pull request October 4, 2022 16:59 Inactive
@yannham yannham force-pushed the feature/priorities-rec-ops branch 3 times, most recently from 7d6c1d1 to bce64ac Compare October 5, 2022 16:58
@yannham yannham marked this pull request as ready for review October 7, 2022 09:26
Add operators to push merge priorities down to the values inside a
record in lazy and recursive manner, as initially proposed in the RFC001
on overriding. This PR adds the syntax `| _push_default` and `|
_push_force` to metavalues as a temporary, ugly-on-purpose keyword such
that bikeshedding can happen later and doesn't block the technical
implementation.
Copy link
Contributor

@matthew-healy matthew-healy left a comment

Choose a reason for hiding this comment

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

I think this looks good, with the obvious caveat that I'm still very new to the codebase. I left some small comments, but neither needs to block the PR.

src/eval/operation.rs Outdated Show resolved Hide resolved
Comment on lines +164 to +167
/// Presence of an annotation `push force`
pub push_force: bool,
/// Presence of an annotation `push default`
pub push_default: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it ever make sense for a value to be annotated with both _push_force and _push_default? If not, I'm wondering if it could make more sense to model this in a way where it's not possible for both to be true at the same time, e.g.

pub push_prio: Option<PushPriority>

Copy link
Member Author

@yannham yannham Oct 18, 2022

Choose a reason for hiding this comment

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

It's indeed fishy semantically, but the thing is that nothing currently prevents the user from doing so:

x | _push_default | _push_force = ...

because annotations are just parsed one by one and combined. In some sense, you can see ExtdAnnot as an AST for meta-annotation, and the source syntax does allow both to be set, just as they were flags. Once it's actually transformed into a term by attach(), it does have to chose an actual push_prio to use.

Copy link
Contributor

@dpl0a dpl0a left a comment

Choose a reason for hiding this comment

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

Looks ok to me. I second Matthew's comments though.

@dpl0a dpl0a self-requested a review October 18, 2022 08:57
@yannham yannham merged commit 163a4a2 into master Oct 18, 2022
@yannham yannham deleted the feature/priorities-rec-ops branch October 18, 2022 11:00
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.

"Leafy" defaults
3 participants