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

Inline DebruijnIndex methods #80057

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_type_ir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,28 @@ impl DebruijnIndex {
///
/// you would need to shift the index for `'a` into a new binder.
#[must_use]
#[inline]
pub fn shifted_in(self, amount: u32) -> DebruijnIndex {
DebruijnIndex::from_u32(self.as_u32() + amount)
}

/// Update this index in place by shifting it "in" through
/// `amount` number of binders.
#[inline]
pub fn shift_in(&mut self, amount: u32) {
*self = self.shifted_in(amount);
}

/// Returns the resulting index when this value is moved out from
/// `amount` number of new binders.
#[must_use]
#[inline]
pub fn shifted_out(self, amount: u32) -> DebruijnIndex {
DebruijnIndex::from_u32(self.as_u32() - amount)
}

/// Update in place by shifting out from `amount` binders.
#[inline]
pub fn shift_out(&mut self, amount: u32) {
*self = self.shifted_out(amount);
}
Expand All @@ -192,6 +196,7 @@ impl DebruijnIndex {
/// If we invoke `shift_out_to_binder` and the region is in fact
/// bound by one of the binders we are shifting out of, that is an
/// error (and should fail an assertion failure).
#[inline]
pub fn shifted_out_to_binder(self, to_binder: DebruijnIndex) -> Self {
self.shifted_out(to_binder.as_u32() - INNERMOST.as_u32())
}
Expand Down