Skip to content

feat: early late classification of lifetimes#22283

Open
dfireBird wants to merge 7 commits into
rust-lang:masterfrom
dfireBird:push-vqzllvyozoqs
Open

feat: early late classification of lifetimes#22283
dfireBird wants to merge 7 commits into
rust-lang:masterfrom
dfireBird:push-vqzllvyozoqs

Conversation

@dfireBird
Copy link
Copy Markdown
Contributor

@dfireBird dfireBird commented May 4, 2026

Some things to note:

  1. We still don't handle the HRTB Lifetimes (in both where and fn ptr) and will be done in a future PR and that PR should also remove the in_binders and fully replace it with bound_vars stack.
  2. I haven't added a new tests, not sure how to test this particularly, so any approach to test them are helpful (this should be done before merging)
  3. There are some IDE features which lose information that I consider to be essential, need to find a way to not have that loss of information (see FIXME in ide tests)
  4. I have implemented this to best of my understanding of both r-a and rustc, so if there are panics or data mismatch, I'm really sorry that happened, I'll try to fix it as soon as I get to know about it.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 4, 2026
@rustbot

This comment has been minimized.

@dfireBird dfireBird force-pushed the push-vqzllvyozoqs branch from f164e84 to 7febdbd Compare May 9, 2026 07:58
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@dfireBird dfireBird force-pushed the push-vqzllvyozoqs branch from 91d006d to 1686871 Compare May 15, 2026 17:30
@rustbot

This comment has been minimized.

@dfireBird dfireBird force-pushed the push-vqzllvyozoqs branch from 8f91999 to 7a9b149 Compare May 15, 2026 17:40
@rustbot

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

Comment thread crates/hir-def/src/hir/generics.rs Outdated
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub struct LifetimeParamData {
pub name: Name,
pub bound_type: LifetimeBoundType,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we should have different arenas for the early and late bound lifetimes, so locating a lifetime param's index can be O(1).

Copy link
Copy Markdown
Contributor Author

@dfireBird dfireBird May 18, 2026

Choose a reason for hiding this comment

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

Coming to this (I kept this to the last), we can't do that with what we have. Since we don't know if lifetime is late bound or early bound until after we finish our hir-def lowering. We can not mutate the arena itself that will make the Idx of that arena to be invalidated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

True, but we don't need the Idx during lowering. We can just make the arenas after we finish lowering.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If that's the case, I'll try doing something.

Copy link
Copy Markdown
Contributor Author

@dfireBird dfireBird May 19, 2026

Choose a reason for hiding this comment

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

It was fairly simple to get it to compile without errors, the only thing I find problematic is implementation of std::ops::Idx<LocalLifetimeParamId>, which lifetime arena to choose? We are currently (with my changes ofc) indexing with both early and late lifetimes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

They need to have a different ID, otherwise many things will be problematic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I feel like that's unnecessary complexity for an optimization that would only benefit two methods, the new lifetime_param_idx and len_late_bound_lifetimes. Both for which can be handled through pre-computing and storing those value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I didn't say we should do this, I was only wondering whether it's better. But do note that these methods may be fairly hot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I get it.

I was just voicing out my thoughts 😅 .

Comment thread crates/hir-def/src/expr_store/lower.rs Outdated
Comment thread crates/hir-def/src/expr_store/lower.rs Outdated
Comment thread crates/hir-def/src/expr_store/lower.rs
Comment thread crates/hir-ty/src/lower.rs Outdated
Comment thread crates/hir-ty/src/lower.rs Outdated
Comment thread crates/hir-ty/src/lower.rs
Comment thread crates/hir-ty/src/next_solver/generics.rs Outdated
Comment thread crates/hir-ty/src/generics.rs Outdated
@dfireBird dfireBird force-pushed the push-vqzllvyozoqs branch from b2f078f to 3c22245 Compare May 18, 2026 18:00
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 18, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@dfireBird dfireBird force-pushed the push-vqzllvyozoqs branch from 3c22245 to 963cf62 Compare May 18, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants