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

[Feature] Merge priorities #829

Merged
merged 11 commits into from
Sep 19, 2022
Merged

[Feature] Merge priorities #829

merged 11 commits into from
Sep 19, 2022

Conversation

yannham
Copy link
Member

@yannham yannham commented Sep 13, 2022

This PR depends on #198. Implement merge priorities as of RFC001. The special operator default rec and force rec are not implemented in this PR but left as future work.

@yannham yannham marked this pull request as ready for review September 13, 2022 14:44
@yannham yannham mentioned this pull request Sep 13, 2022
@github-actions github-actions bot temporarily deployed to pull request September 13, 2022 14:45 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 13, 2022 14:48 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 14, 2022 08:54 Inactive
src/term.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request September 14, 2022 13:26 Inactive
Base automatically changed from refator/tests-lib-ncl to master September 15, 2022 10:52
failed with a `non mergeable fields` error, because merging being symmetric, it
doesn't know how to combine `1` and `2` in a generic and meaningful way.
evaluates to `{foo = 2}`. A default value is just a special case of a priority,
being the lowest possible one.
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if the implementationementation doesn't manage as such, may we say it is like having -inf value? Actually, how nickel manage infinites?

Copy link
Member Author

Choose a reason for hiding this comment

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

Infinite can't be represented as a float literal (they can be obtained by operations on float, I guess, but not written down), so +inf and -inf aren't currently possible as numeral priorities. I don't know, is it really that clearer to say that it is -inf, rather than spelling out loud "this is the lowest possible priority"? To me the latter requires less maths notion (arguably, +inf and -inf are not exactly rocket science, but still). I don't have a strong opinion, honestly.

Comment on lines +312 to +314
Dually, values with the `force` annotation are given the highest priority. Such
a value can never be overriden, and will either take precedence over another
value or be tentatively merged if the other value is forcing as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

same idea as default but with +inf here.

.with_labels(labels)]
.with_labels(labels)
.with_notes(vec![String::from(
"Both values have the same merge priority but they can't be combined",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Both values have the same merge priority but they can't be combined",
"Both values have the same merge priority so they can't be combined",

Copy link
Member Author

@yannham yannham Sep 16, 2022

Choose a reason for hiding this comment

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

I would keep the but. Two values with the same priority may very well be combined, like records. Here the problem is that they have the same priority AND we don't know how to merge them.

priority: MergePriority::Normal,
priority: MergePriority::Neutral,
Copy link
Contributor

@francois-caddet francois-caddet Sep 15, 2022

Choose a reason for hiding this comment

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

An alternative could be to use Option<float>.
then Bottom become Some(-float::inf()), Top become Some(float::inf()), and Neutral become None
Sorry not sure how to write infinite in Rust but that's the idea.
May easy the priority comparaisons but may be less clear in the code... Also is harder to pretty print, even it can be managed anyway.

value: Some(t),
..
} if selected_attrs.value => {
renderer.write_metadata(out, "priority", &format!("{}", n))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

an improvement could be to check 0 equality and don't print anything if it's the case

Copy link
Member Author

@yannham yannham Sep 16, 2022

Choose a reason for hiding this comment

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

Not really, because 0.0 may have been written down. We could check for Neutral though. On the other hand, it can be useful to know the actual priority, even if it hasn't been annotated?

Copy link
Contributor

@francois-caddet francois-caddet left a comment

Choose a reason for hiding this comment

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

A nice improvement for nickel with a clear implementation :)
Only a few changes proposed.
Just to be sure, are we really not needing Merge token anymore? maybe for RFC001 (custom merge functions)?

@github-actions github-actions bot temporarily deployed to pull request September 16, 2022 14:46 Inactive
doc/manual/merging.md Outdated Show resolved Hide resolved
@yannham
Copy link
Member Author

yannham commented Sep 16, 2022

Just to be sure, are we really not needing Merge token anymore? maybe for RFC001 (custom merge functions)?

Ah yes, good catch. Will drop this commit.

@github-actions github-actions bot temporarily deployed to pull request September 16, 2022 14:54 Inactive
@github-actions github-actions bot temporarily deployed to pull request September 16, 2022 15:01 Inactive
@yannham yannham merged commit ecab9db into master Sep 19, 2022
@yannham yannham deleted the feature/priorities branch September 19, 2022 09:39
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.

2 participants