Skip to content

Fix representation when printing abstract consts #119212

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

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

w-utter
Copy link
Contributor

@w-utter w-utter commented Dec 22, 2023

Previously, when printing a const generic expr, it would only display it as {{const expr}}. This allows for a more legible representation when printing these out.

I also zipped the types with their constants for abstract consts that contain function calls when using type annotations, eg: foo(S: usize, true: bool) -> usize insteaad of foo(S, true): fn(usize, bool) -> usize for conciseness.

@rustbot
Copy link
Collaborator

rustbot commented Dec 22, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jackh726 (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 22, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

I like this a lot

@compiler-errors
Copy link
Member

Please squash this into one commit, then I can approve it.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 22, 2023
@w-utter w-utter force-pushed the pretty-print-const-expr branch from c5e7a60 to ac8c8d2 Compare December 23, 2023 01:13
@w-utter
Copy link
Contributor Author

w-utter commented Dec 23, 2023

Thanks! Just squashed them into one commit.

I also want to look into formatting the statements with parentheses based on the expr tree when I get the chance, as something like -(N + 1) * 2 prints as -N + 1 * 2, but couldn't seem to find a quick solution without wrapping every statement in parenthesis which I don't think looks nice

@compiler-errors
Copy link
Member

Ah, I had totally overlooked that. Thanks for pointing it out. I... actually don't think we should be printing out wrong expressions, and we should fix this in this PR.

You should be able to get a precedence from a hir::BinOp (which is a ast::BinOp) by turning it first into an AssocOp via (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/util/parser/enum.AssocOp.html#method.from_ast_binop) then calling precedence/fixity. You can then compare the precedence and fixity of the LHS and RHS to know when to insert parentheses.

@rustbot author

@compiler-errors
Copy link
Member

If you don't want to do this, let's just always parenthesize inner expressions, and I can implement a better heuristic for this.

@w-utter w-utter force-pushed the pretty-print-const-expr branch from ac8c8d2 to 143e260 Compare December 23, 2023 07:53
@w-utter
Copy link
Contributor Author

w-utter commented Dec 23, 2023

No worries, this new commit should take precedence into account when adding parenthesis.

I didn't bother with fixity as the unop kind does not have an equivalent to_hir_binop() and all fixities are already seperated by its respective expr kind so I just had a different implementation for each.

Having a fn for precedence in rustc_middle::ty::consts::kind::Expr would be nice to have and would clean up some of the stuff I wrote, but it seemed out of scope for this pr

@jackh726
Copy link
Member

r? compiler-errors

@rustbot rustbot assigned compiler-errors and unassigned jackh726 Dec 23, 2023
@Dylan-DPC
Copy link
Member

@w-utter any updates on this? thanks

@bors
Copy link
Collaborator

bors commented Mar 9, 2024

☔ The latest upstream changes (presumably #122150) made this pull request unmergeable. Please resolve the merge conflicts.

@w-utter
Copy link
Contributor Author

w-utter commented Mar 16, 2024

I completely forgot about this after holiday break 😅 It's finished as far as I remember, I was just waiting on approval

Hopefully I can guess what the unconstrained generic const is first try and it can get merged as I don't have the environment to test it set up anymore

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label Mar 16, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2024

There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

You can start a rebase with the following commands:

$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git push --force-with-lease

The following commits are merge commits:

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Dylan-DPC
Copy link
Member

@w-utter this still has a merge commit in the list of commits. You have to unmerge it or reset that commit using an interactive rebase.

@w-utter w-utter force-pushed the pretty-print-const-expr branch 2 times, most recently from f888724 to 63fb0de Compare March 16, 2024 13:33
@rustbot rustbot removed the has-merge-commits PR has merge commits, merge with caution. label Mar 16, 2024
@w-utter w-utter force-pushed the pretty-print-const-expr branch from 63fb0de to e247579 Compare March 16, 2024 13:55
@rust-log-analyzer

This comment has been minimized.

@w-utter w-utter force-pushed the pretty-print-const-expr branch from e247579 to 78e1869 Compare March 16, 2024 14:14
@rust-log-analyzer

This comment has been minimized.

@w-utter w-utter force-pushed the pretty-print-const-expr branch from 78e1869 to 7c4b07d Compare March 16, 2024 14:38
@w-utter
Copy link
Contributor Author

w-utter commented Mar 16, 2024

That took a lot longer than I'd like to admit but we should be all good to go now 😁

@Dylan-DPC Dylan-DPC added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 16, 2024
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 18, 2024

📌 Commit 7c4b07d has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 18, 2024
@bors
Copy link
Collaborator

bors commented Mar 19, 2024

⌛ Testing commit 7c4b07d with merge 8579a18...

@bors
Copy link
Collaborator

bors commented Mar 19, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 8579a18 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 19, 2024
@bors bors merged commit 8579a18 into rust-lang:master Mar 19, 2024
@rustbot rustbot added this to the 1.79.0 milestone Mar 19, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8579a18): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 669.426s -> 669.396s (-0.00%)
Artifact size: 312.79 MiB -> 312.81 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants