Skip to content

Flip "region lattice" in RegionKind doc comment#152968

Open
khyperia wants to merge 1 commit intorust-lang:mainfrom
khyperia:regionkind-comment
Open

Flip "region lattice" in RegionKind doc comment#152968
khyperia wants to merge 1 commit intorust-lang:mainfrom
khyperia:regionkind-comment

Conversation

@khyperia
Copy link
Contributor

If we assume that references take their region covariantly, and use that to define the subtyping relationship of regions, 'empty is ⊤ (top) and 'static is ⊥ (bottom), and that 'a <: 'b is defined as 'a >= 'b. However, the RegionKind doc comment's "region lattice" had 'static at Top. While this is perhaps technically correct (a so-called "region lattice" is not a "type lattice"), it confused me a lot, and took me half an hour to be like "no, ok, I do understand things correctly, this region lattice is just flipped from the subtype lattice". Seems better to just have them be the same!

I also took the opportunity to rewrite some parts of the comment with notes that would have helped me when starting out.

Bikesheds welcome (as long as they don't go on forever)!

For context: the comment "'static is Top" was written in 2013, before there was a discussion in 2014 that clarified that references take their regions covariantly, and 'a <: 'b is defined as 'a >= 'b.

See also Zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/RegionKind.20rustc.20doc.20comment

@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. labels Feb 22, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, types
  • compiler, types expanded to 68 candidates
  • Random selection from 15 candidates

@jieyouxu
Copy link
Member

@rustbot reroll

@rustbot rustbot assigned wesleywiser and unassigned jieyouxu Feb 22, 2026
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 23, 2026

r? me

@rustbot rustbot assigned BoxyUwU and unassigned wesleywiser Feb 23, 2026
/// function declaration. They have relationships to one another
/// determined based on the declared relationships from the
/// function.
/// Early-bound/free regions ([`RegionKind::ReEarlyParam`]) are the
Copy link
Member

Choose a reason for hiding this comment

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

I think this comment is out of date in that "free regions" here refers to a previously existing RegionKind::Free which got renamed to ReLateParam. This should probably say something like "Early/LateParam regions are the..."

Copy link
Member

Choose a reason for hiding this comment

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

alternatively we did actually mean free regions in which case this includes 'static but talking explicitly about early bound regions is confusing...

Copy link
Member

Choose a reason for hiding this comment

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

maybe this should actually be "Free regions (ReEarlyParam ReLateParam ReStatic) are the named lifetimes in scope from.." i'm not sure 😅

Copy link
Member

Choose a reason for hiding this comment

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

"Early/LateParam regions are the named lifetimes in scope from the function declaration. They have relationships to one another and 'static based on .." is probably the most useful thing to document 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Early/LateParam regions are the named lifetimes in scope from the function declaration

late params can be anonymous, right? just gonna remove the word "named".

Also hm, ReLateParam can be constructed from HKT ReBound stuff (liberate_late_bound_regions), so they're not always "from the function declaration". Maybe flipping the sentence:

Lifetimes in scope from a function declaration are represented via ReEarlyParam/ReLateParam. They have relationships to one another and 'static based on the declared relationships from the function.

because all lifetimes from a function declaration are ReEarlyParam/ReLateParam, but not all ReLateParam are from a function declaration.

///
/// ## Bound Regions
///
/// These are regions that are stored behind a binder and must be instantiated
Copy link
Member

Choose a reason for hiding this comment

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

I think the pre-existing comment here is wrong/wildly misleading. Early bound parameters are not ReBound. This comment implies that a ReBound can correspond to either an early or a late bound parameter but actually it just always corresponds to a lifetime from a for<'a, ...> binder

I would probably drop everything about early/late here and only talk about them in relation to the Binder type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just pushed an edit, how's this?

@khyperia khyperia force-pushed the regionkind-comment branch from 8cca904 to d0ac5b1 Compare March 8, 2026 12:06
@khyperia khyperia force-pushed the regionkind-comment branch from d0ac5b1 to 40374b4 Compare March 8, 2026 12:20
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants