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

cranelift: Compress vcode range-lists #8506

Merged
merged 1 commit into from
May 2, 2024

Conversation

jameysharp
Copy link
Contributor

These lists of ranges always cover contiguous ranges of an index space, meaning the start of one range is the same as the end of the previous range, so we can cut storage in half by only storing one endpoint of each range.

This in turn means we don't have to keep track of the other endpoint while building these lists, reducing the state we need to keep while building vcode and simplifying the various build steps.

@jameysharp jameysharp requested a review from a team as a code owner April 29, 2024 20:20
@jameysharp jameysharp requested review from elliottt and removed request for a team April 29, 2024 20:20
These lists of ranges always cover contiguous ranges of an index space,
meaning the start of one range is the same as the end of the previous
range, so we can cut storage in half by only storing one endpoint of
each range.

This in turn means we don't have to keep track of the other endpoint
while building these lists, reducing the state we need to keep while
building vcode and simplifying the various build steps.
/// Reverse this list of ranges, so that the first range is at the
/// last index and the last range is at the first index.
///
/// ```ignore
Copy link
Member

Choose a reason for hiding this comment

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

Why ignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because doc-tests don't work in non-public types, since they're compiled in a separate crate. I couldn't figure out a better way to document what these methods do than with code, so doc-test style seemed good, but didn't quite work how I wanted. I did build this with the module made public and the doc-tests un-ignored, and verified that they pass.

Comment on lines +51 to +57
/// Get the range at the specified index.
pub fn get(&self, index: usize) -> Range<usize> {
let len = self.len();
assert!(index < len, "index {index} is too big for length {len}");
let index = self.map_index(index);
self.ranges[index] as usize..self.ranges[index + 1] as usize
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we add some typed indices for Ranges? Or reuse cranelift_entity::Entity?

I've always been slightly nervous about all of our raw indices in the backends.

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 guess we could add some sort of type-system tagging, but what we have now is usize almost everywhere this is used, so it would be noisy.

That said, I had wanted to somehow associate each instance of Ranges with the Vec or Ranges that it indexes. I couldn't figure out a good way to do that, but putting a newtype wrapper around the indexes could work, with some helpers.

I'd prefer to land this without that change, since I believe it's easier to understand and no less safe than the status quo, but I do think this is worth thinking about more.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. labels Apr 30, 2024
Copy link
Member

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

This is a really nice change!

@jameysharp jameysharp added this pull request to the merge queue May 2, 2024
Merged via the queue into bytecodealliance:main with commit 2c40953 May 2, 2024
21 checks passed
@jameysharp jameysharp deleted the compress-range-lists branch May 2, 2024 05:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:machinst Issues related to instruction selection and the new MachInst backend. cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants