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

Use Embark standard lints v0.3 #482

Merged
merged 1 commit into from
Mar 12, 2021
Merged

Use Embark standard lints v0.3 #482

merged 1 commit into from
Mar 12, 2021

Conversation

repi
Copy link
Contributor

@repi repi commented Mar 9, 2021

Fixes up our code to support the additional lints in the draft v0.3 of our standard set: EmbarkStudios/rust-ecosystem#60. This is not final yet, but getting close there. Probably be quite a while until the next version after this, now we have most of the main lints we've been testing with.

The main change was with the match_same_arms lint, many match cases worked nicely and got merged together which do find easier to read, but some would require larger ordering changes & merges which looked like it could reduce readability in the complex backend code so left it with `allow´ in those few cases.

Leaving this as draft until EmbarkStudios/rust-ecosystem#60 is merged and v0.3 finalized. If you have any issues with any of these changes/lints, please do comment here and/or in the PR if we should not enable one of the lints.

@repi repi requested review from XAMPPRocky and eddyb March 9, 2021 23:02
Copy link
Member

@XAMPPRocky XAMPPRocky left a comment

Choose a reason for hiding this comment

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

LGTM. There seems to be some trailing whitespace failing CI.

@repi
Copy link
Contributor Author

repi commented Mar 10, 2021

Fixed CI

@@ -60,7 +59,9 @@ impl<'tcx> CodegenCx<'tcx> {
SpirvType::Integer(32, true) => self
.builder
.def_constant(SpirvConst::U32(ty, val as i64 as i32 as u32)),
SpirvType::Integer(64, true) => self.builder.def_constant(SpirvConst::U64(ty, val)),
SpirvType::Integer(64, false) | SpirvType::Integer(64, true) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be collapsed further into SpirvType::Integer(64, _) - note that the 32-bit case can also be collapsed, if you replace val as i64 as i32 as u32 with val as u32 (they're equivalent, no order of truncations is different from any other, since you're chopping off bits - {sign,zero}-extension can only happen when you're widening the type).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds like a good idea

Comment on lines 274 to 273
SpirvConst::Bool(_, false) => 0,
SpirvConst::Bool(_, true) => 0,
SpirvConst::Bool(_, false) | SpirvConst::Bool(_, true) => 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a mistake, should be SpirvConst::Bool(_, v) => v as u8.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

suspected that as well, can you apply that change?

Self::Vector { element, count } => {
cx.lookup_type(element).sizeof(cx)? * count.next_power_of_two() as u64
}
Self::Array { element, count } => {
cx.lookup_type(element).sizeof(cx)? * cx.builder.lookup_const_u64(count).unwrap()
}
Self::RuntimeArray { .. } => return None,
Self::Pointer { .. } => cx.tcx.data_layout.pointer_size,
Self::Function { .. } => cx.tcx.data_layout.pointer_size,
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is wrong I'm pretty sure, a SPIR-V function is not a function pointer, and should return None here - assuming that still can compile examples and tests, ofc.

Copy link
Contributor Author

@repi repi Mar 10, 2021

Choose a reason for hiding this comment

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

nice that the lint caught it, it does read better and easier to spot bugs when same arms are collapsed!

can you do an issue or fix it in a separate PR? not sure if good idea to fix and change behavior here in the lint PR. or can you commit directly into this PR? I would be more confident a compiler engineer does these behavior changes than me enabling lints :)

Comment on lines 72 to 78
clippy::todo, // still lots to implement :)
clippy::todo // still lots to implement :)
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, we use todo!()? I remember trying to use unimplemented!() and getting an error from a lint.

Copy link
Contributor Author

@repi repi Mar 10, 2021

Choose a reason for hiding this comment

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

yup plenty of todo! in the crate, and only like 1 unimplemented!. I guess they both do a very similar

Comment on lines 159 to 160
SpirvType::Bool => TypeKind::Integer, // thanks llvm
SpirvType::Integer(_, _) => TypeKind::Integer,
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a lint bug, it should suggest collapsing these two cases, but somehow it finds the other ones down below instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It did suggest collapsing them, that's why I had to move it down to the integer arm, but formatted it a bit differently to keep the comment.

Would indeed be good if the lint took comments into consideration, as we talked about on discord. but this is the best I could get it to do without that.

any ideas on how to improve it here in the code?

@repi repi marked this pull request as ready for review March 10, 2021 17:52
@repi repi requested a review from khyperia as a code owner March 10, 2021 17:52
@repi
Copy link
Contributor Author

repi commented Mar 10, 2021

Let's get #487 in first with the behavioural fixes that @eddyb did, then we can get this in

@XAMPPRocky
Copy link
Member

XAMPPRocky commented Mar 12, 2021

This PR now needs a rebase to be merged.

@repi
Copy link
Contributor Author

repi commented Mar 12, 2021

@XAMPPRocky can you take it over?

Co-Authored-By: Johan Andersson <[email protected]>
@XAMPPRocky XAMPPRocky enabled auto-merge (squash) March 12, 2021 12:23
@XAMPPRocky XAMPPRocky merged commit a173208 into main Mar 12, 2021
@XAMPPRocky XAMPPRocky deleted the embark-lints-v0.3 branch March 12, 2021 12:35
@khyperia khyperia removed their request for review March 23, 2021 08:35
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.

3 participants