Skip to content

Rustfmt-ing librustc_mir. #29076

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

Closed

Conversation

goyox86
Copy link
Contributor

@goyox86 goyox86 commented Oct 15, 2015

Hi Rustaceans!

This is the result of running latest rustfmt on librustc_mir!

//cc @nrc

@rust-highfive
Copy link
Contributor

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

fields.into_iter()
.map(|f| (f.name, unpack!(block = this.as_operand(block, f.expr))))
.collect();
let fields_map: FnvHashMap<_, _> = fields.into_iter()
Copy link
Contributor

Choose a reason for hiding this comment

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

@nrc so I was looking more closely here...I would say this is a definite regression in readability. This is a tough heuristic (non-local), but certainly when I choose where to put a new line, I have a kind of "global optimization" over the entire function call chain going on, and I feel like it applies here. Is there any kind of open bug on this scenario? Do you even see what I'm pointing out :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@nrc in particular, I'm optimizing largely for keeping the inner expressions readable, I think, which is where this formatting fails

Copy link
Contributor

Choose a reason for hiding this comment

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

Not @nrc but this is certainly something I've been thinking about. One of the more simple heuristics we could start with is comparing the result of formatting on the same line and breaking after the assignment and choosing the one with the fewest line breaks (no break on tie).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's something I've seen. I agree it is sub-optimal. I think the simple idea of comparing with or without line breaks after the = in assignments is probably a good idea - the majority of times I see this is in a let statement, so it would probably get us 90% of the way there. I worry a bit about combinatorial explosion - we'd want to do the check in as few places as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

@marcusklaas

One of the more simple heuristics we could start with is comparing the result of formatting on the same line and breaking after the assignment and choosing the one with the fewest line breaks (no break on tie).

@nrc

the majority of times I see this is in a let statement, so it would probably get us 90% of the way there

yes to both

Copy link
Member

Choose a reason for hiding this comment

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

@marcusklaas do you know if we have an issue open for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so.

Copy link
Member

Choose a reason for hiding this comment

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

@nrc nrc assigned nikomatsakis and unassigned pnkfelix Oct 15, 2015
})
})
.map(|(arm_index, pattern, guard)| {
Candidate {
match_pairs: vec![self.match_pair(discriminant_lvalue.clone(), pattern)],
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation here is wrong; should be relative to Candidate {.

cx.tcx.region_maps.lookup_code_extent(remainder_extent);
let remainder_extent = cx.tcx
.region_maps
.lookup_code_extent(remainder_extent);
Copy link
Contributor

Choose a reason for hiding this comment

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

another case where the = heuristic ought to be used. I'd prefer to revert.

Copy link
Member

Choose a reason for hiding this comment

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

In this case I actually prefer the new version, although I bet a simple = heuristic would choose the former. I prefer it because scanning the elements in a chain of method calls is useful, but there is no aid in scanning code in having a line break after =.

@nrc
Copy link
Member

nrc commented Oct 18, 2015

@goyox86 There's a lot of discussion on this one and a lot of places where there are bugs in rustfmt. It might be worth waiting for rustfmt to get better and then trying this again, rather than fixing up what is here. On the other hand, you could try to cherry pick the non-controversial changes and do some of the fixups (like moving comments) to make a smaller PR which could land. Up to you.

@goyox86
Copy link
Contributor Author

goyox86 commented Oct 21, 2015

@nrc Gonna close this one and wiat for rustfmt to get smarter ;)

@goyox86 goyox86 closed this Oct 21, 2015
@goyox86 goyox86 deleted the goyox86/rustfmting-librustc_mir branch October 21, 2015 15:08
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.

8 participants