Skip to content

Remove RegionExt; move methods to Region in rustc_type_ir - #160509

Open
Jamesbarford wants to merge 2 commits into
rust-lang:mainfrom
Jamesbarford:chore/shrink-region-ext-triats-pt2
Open

Remove RegionExt; move methods to Region in rustc_type_ir#160509
Jamesbarford wants to merge 2 commits into
rust-lang:mainfrom
Jamesbarford:chore/shrink-region-ext-triats-pt2

Conversation

@Jamesbarford

@Jamesbarford Jamesbarford commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Removes RegionExt from rustc_middle with all methods on Region.

Some changes I think are worth pointing out (of which are all in the first commit -> f949bb7) ;

  • Changed the signature of Region::new_late_param to accept a I::LateParamRegion where previously it was able to construct a LateParamRegion from some method parameters.

added to interner:

  • fn span_delayed_bug(self, span: Self::Span, msg: impl ToString) -> Self::ErrorGuaranteed; which could be useful elsewhere when porting things across to rustc_type_ir
  • fn generics_of_early_param_region_def_id(self, def_id: Self::DefId, ebr: Self::EarlyParamRegion) -> Self::DefId; which is quite nasty but calling generics_of returned another type that I would have possibly create a trait for which felt more messy.
  • fn get_re_var_lifetime(self, var_idx: usize) -> Option<Region<'tcx>> need to get a region in Region::new_var.

traits added to inherent

  • RegionName so we can get the names of LateParamRegion and EarlyParamRegion with a get_name() and also is_named().
  • DefIdGetter so we can get the DefId of kind in LateParamRegion

r? lcnr

@rustbot

rustbot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Aug 4, 2026
Comment thread compiler/rustc_middle/src/ty/context/impl_interner.rs Outdated
@lcnr

lcnr commented Aug 4, 2026

Copy link
Copy Markdown
Contributor
generics_of_early_param_region_def_id

hmm, without looking much at the code, I feel like we should move Generics into rustc_type_ir instead 🤔 how much effort is that/actually make it an inherent trait to make that transition easier in the future

Comment thread compiler/rustc_type_ir/src/sty/mod.rs Outdated
Comment on lines +30 to +33
// Use a pre-interned one when possible.
interner
.get_re_var_lifetime(v.as_usize())
.unwrap_or_else(|| interner.intern_region(RegionKind::ReVar(v)))

@lcnr lcnr Aug 4, 2026

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.

instead have interner, intern_re_var feel like the current thing has a bit too much impl detail of the way rustc does things

View changes since the review

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.

d2eb2a2 👍

Comment thread compiler/rustc_type_ir/src/interner.rs Outdated
self,
def_id: Self::DefId,
ebr: Self::EarlyParamRegion,
) -> Self::DefId;

@lcnr lcnr Aug 4, 2026

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.

ah yeah, definitely add this as a method on GenericsOf instead

View changes since the review

@Jamesbarford Jamesbarford Aug 4, 2026

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.

Sure thing, moving Generics into rustc_type_ir would result in a similar PR to this where some extra methods would either need to be added to a trait and/or the Interner (19 at a quick count). Moreover there is GenericParamDef with it's own methods (which I didn't count) and and finally GenericParamDefKind which is a trivial enum.

@Jamesbarford Jamesbarford Aug 5, 2026

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.

Moved the method to GenericsOf; d2eb2a2

@rust-bors

This comment has been minimized.

@Jamesbarford
Jamesbarford force-pushed the chore/shrink-region-ext-triats-pt2 branch from d2eb2a2 to 78adf31 Compare August 6, 2026 08:05
@rustbot

rustbot commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants