Repository navigation
Remove packed_struct dependency - #1282
Conversation
|
@sstangl, @bnjbvr: I pushed this so you could observe this failure: I've looked over the code I changed and I don't exactly understand why the following assertion should fail due to my changes: cranelift/cranelift-codegen/meta/src/isa/x86/encodings.rs Lines 46 to 52 in 6e2bffc [edit: I thought the |
90c78be to
a815c13
Compare
Never mind, I pushed a new version with a corrected constructor. Hopefully you all can see any other potential issues in the bit-fiddling logic ( |
sstangl
left a comment
There was a problem hiding this comment.
Looks good to me! Thanks for removing that.
Just some minor changes to the masking, and undefined behavior could be caused by some RangeInclusive inputs.
| /// Convenience method for reading bits from a specific range. | ||
| #[inline] | ||
| fn read(self, range: RangeInclusive<u16>) -> u8 { | ||
| let size = range.end() - range.start() + 1; // Calculate the number of bits in the range. |
There was a problem hiding this comment.
The RangeInclusive<u16> doesn't actually enforce that start <= end. It merely guarantees that if given a range with an empty inclusive range, as an iterator it will not yield any elements.
However, if given such a range, the documentation for RangeInclusive::start() and RangeInclusive::end() say that calling start() and end() yield unspecified values. The documentation says that before using those functions, the existence of a valid range must be checked explicitly via is_empty().
I do understand that the ranges are controlled here, but I'd still recommend checking the invariants as the docs suggest.
There was a problem hiding this comment.
Maybe it's a Rust version issue or something (I'm on 1.39.0) but when I add the assert I see the following error:
error[E0034]: multiple applicable items in scope
--> cranelift-codegen/shared/src/isa/x86/encoding_bits.rs:70:24
|
70 | assert!(!range.is_empty());
| ^^^^^^^^ multiple `is_empty` found
|
= note: candidate #1 is defined in an impl for the type `std::ops::RangeInclusive<_>`
= note: candidate #2 is defined in an impl of the trait `std::iter::ExactSizeIterator` for the type `std::ops::RangeInclusive<u16>`
= help: to disambiguate the method call, write `std::iter::ExactSizeIterator::is_empty(range)` instead
When I take the compiler's advice I still see the error and adding feature flags as in rust-lang/rust#48111 (comment) does not seem to work either. I may have to create a new issue for this...
There was a problem hiding this comment.
Both is_empty methods are still unstable. Maybe use range.len() instead of calculating the size yourself?
There was a problem hiding this comment.
Does it have len? I can't seem to find it...
There was a problem hiding this comment.
I haven't tried, but it should have it via the ExactSizeIterator impl.
There was a problem hiding this comment.
Thanks! I think that works.
|
Removing myself from the reviewers, since Sean has taken care of it, thanks! Just a side comment: can you remove the dependencies section in the meta-shared crate Cargo.toml, and add a comment in there that we should really strive to not having any dependencies in this crate? (Since it blocks both the meta and non-meta codegen crates to compile, and these are slow to build) |
58a65bc to
efd3365
Compare
efd3365 to
009e4bb
Compare
009e4bb to
8df5e50
Compare
|
Thanks for doing this, @abrown ! |
This re-factors
EncodingBitsto remove the dependency onpacked_struct; the result is more lines of code, which is unfortunate.