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

Misc. rustc_codegen_ssa cleanups 🧹 #136439

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yotamofek
Copy link
Contributor

@yotamofek yotamofek commented Feb 2, 2025

Just a bunch of stuff I found while reading the crate's code.
Each commit can stand on its own.
Maybe r? @Noratrieb because I saw you did some similar cleanups on these files a while ago? (feel free to re-assign, I'm just guessing)

@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 Feb 2, 2025
@yotamofek yotamofek force-pushed the pr/codegen-ssa-no-indexing branch from 6313520 to d39abe9 Compare February 5, 2025 10:07
@bors
Copy link
Contributor

bors commented Feb 11, 2025

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

@yotamofek yotamofek force-pushed the pr/codegen-ssa-no-indexing branch from d39abe9 to a5dff3c Compare February 11, 2025 09:43
@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2025

Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs

cc @jdonszelmann

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 11, 2025
@jdonszelmann
Copy link
Contributor

jdonszelmann commented Feb 11, 2025

This file could use some cleanups, that's for sure.

Just wanted to mention that the cleanup around the inline attribute might be short-lived as I'm preparing a pr to remove that code completely. Same for optimize. Not a reason to prevent merging this, but it's good to know :)

(See #131229)

@jdonszelmann
Copy link
Contributor

jdonszelmann commented Feb 11, 2025

looked through the changes themselves too. Couldn't find anything wrong, every rewrite seems to implement the exact same logic as it did before correctly. I'd just say this is a lot of commits for the small number of changes you made. I'd maybe see if you can either make it just one, or split it up for the changes per attribute with a slightly more descriptive name. Especially the 2nd commit right now doesn't really add much.

@yotamofek yotamofek force-pushed the pr/codegen-ssa-no-indexing branch from a5dff3c to 73d5fe1 Compare February 11, 2025 12:44
@yotamofek
Copy link
Contributor Author

Thanks for the review!
Yeah, it was too many small commits. Down to 4 (from 6).
I can just combine 9e5e6a9 and 73d5fe1 , whatever you think. The other two commits, IMHO, are ok as-is.

return Err(errors::LinkRlibError::MissingFormat);
let mut dep_formats = info.dependency_formats.iter();
let (ty1, list1) = dep_formats.next().ok_or(errors::LinkRlibError::MissingFormat)?;
if let Some((ty2, list2)) = dep_formats.find(|(_, list2)| list1 != *list2) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is equivalent, because if say the crate type 2 and 3 disagree it will no longer emit an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the == operator not transitive for this type?

Copy link
Member

Choose a reason for hiding this comment

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

It is. But say the dependency formats have 3 elements (where each element is a list), where the the second list and the last list are different. Previously, this was detected, because all combinations are checked, but now it is no longer detected because you only compare the first list against all other lists. The second and third lists are no longer compared.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do agree with @kadiwa4 on this. In your example if the second and last lists are different, then the first and last list will also be different, and it would still be caught.
But I might just be completely wrong on this, I dunno 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(assuming the second and first lists don't compare as equal)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that's what I thought.
This is the (slightly shortened) definition of the transitivity property from the std docs:

a == b and b == c implies a == c

Now say a = dep_formats[1].1, b = dep_formats[0].1 and c = dep_formats[2].1. In the .find() method, the code checks that b == a and b == c. Assuming that find finishes without finding a mismatch, we now know that according to the transitivity property, a == c is true (i.e. dep_formats[1].1 == dep_formats[2].1).
(I am assuming that b == a is the same as a == b of course.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants