Skip to content

GCI: Imply outlives-bounds on free (generic) const items#143029

Open
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:gci-imply
Open

GCI: Imply outlives-bounds on free (generic) const items#143029
fmease wants to merge 1 commit intorust-lang:mainfrom
fmease:gci-imply

Conversation

@fmease
Copy link
Member

@fmease fmease commented Jun 25, 2025

@fmease fmease added the F-generic_const_items `#![feature(generic_const_items)]` label Jun 25, 2025
@rustbot rustbot added A-rustc-dev-guide Area: rustc-dev-guide T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 25, 2025
@fmease fmease moved this to In Progress in Generic Const Items (GCI) Jun 25, 2025
@fmease
Copy link
Member Author

fmease commented Jun 25, 2025

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Jun 25, 2025
GCI: Imply outlives-bounds on free (generic) const items
@rust-bors
Copy link
Contributor

rust-bors bot commented Jun 25, 2025

⌛ Trying commit 5aa3d2a with merge eb427c5

To cancel the try build, run the command @bors2 try cancel.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 25, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jun 25, 2025

☀️ Try build successful (CI)
Build commit: eb427c5 (eb427c5414bee321329c635f289f46816100d758, parent: d14d202262d13df896b0c624b0cec6e4bfde631a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (eb427c5): comparison URL.

Overall result: ❌ regressions - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 3

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 689.033s -> 689.561s (0.08%)
Artifact size: 372.09 MiB -> 372.11 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 27, 2025
@fmease
Copy link
Member Author

fmease commented Jun 27, 2025

(All of these failures are cycle errors that now occur when we try to recover from the user using _ in / omitting the type of consts, this "niceness" really is the bane of my existence)

@fmease
Copy link
Member Author

fmease commented Jun 27, 2025

@bors2 try parent=last @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jun 27, 2025

⌛ Trying commit c2b8a0b with merge 25444d3

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 27, 2025
GCI: Imply outlives-bounds on free (generic) const items

Part of #113521.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 27, 2025
@fmease fmease added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Jun 27, 2025
@rust-bors
Copy link
Contributor

rust-bors bot commented Jun 27, 2025

☀️ Try build successful (CI)
Build commit: 25444d3 (25444d3ddb1285d7ea04f0b89fdf4318a474d5df, parent: d14d202262d13df896b0c624b0cec6e4bfde631a)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (25444d3): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (secondary 2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.6% [2.5%, 2.7%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 689.033s -> 690.033s (0.15%)
Artifact size: 372.09 MiB -> 372.08 MiB (-0.00%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Jun 28, 2025
@bors

This comment was marked as resolved.

@fmease fmease marked this pull request as ready for review March 1, 2026 12:15
@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2026

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol, @tshepang

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 1, 2026
Comment on lines +42 to 45
if tcx.generics_of(item_def_id).is_empty() {
// Fast path.
return &[];
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This fast path allowed me to turn a perf regression (#143029 (comment)) back into neutral state (#143029 (comment)).

@fmease fmease removed the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Mar 1, 2026
@rust-log-analyzer

This comment has been minimized.

@fmease
Copy link
Member Author

fmease commented Mar 1, 2026

Needs a trivial rebase but it's still ready for review. I'm afk now.

@rustbot
Copy link
Collaborator

rustbot commented Mar 1, 2026

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.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@fmease
Copy link
Member Author

fmease commented Mar 2, 2026

I forgot that I still had to break one more kind of query cycle. CI should be fixed now 🤞

Copy link
Member Author

@fmease fmease Mar 2, 2026

Choose a reason for hiding this comment

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

Right, I completely forgot about implementing that part of implied bounds back in June 2025. This PR should definitely be blocked on me implementing that but feel free to review the other parts already.

It should hopefully be straightforward to implement modulo perf, I just need to visit & handle ConstKind::Unevaluated in insert_outlives_predicate.

Edit: Actually it's not necessarily blocking since this is only observable under mGCA/GCE? I might just slap //@ known-bug: unknown on it 🤷

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 not even GCE as there you'll have anon consts with the same predicates as the item its inside of. mGCA should be the only way to get a const item directly used in a type signature which has clauses that are actual useful to derive implied bounds from

@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 5, 2026

I am... unsure of this 🤔 I need to think a bit about this conceptually.

@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 5, 2026

Is there a test that demonstrates the (lack of) implied bounds for associated consts?

@fmease
Copy link
Member Author

fmease commented Mar 5, 2026

Is there a test that demonstrates the (lack of) implied bounds for associated consts?

In tests/ui/generic-const-items/reference-outlives-referent.rs I've added some cases. However, they only exercise RegionOutlives (because that test file is a preexisting regression test for a regionck issue). I should probably add a dedicated test for this that (also) exercises TypeOutlives.

/// Infer outlives-predicates for the items in the local crate.
pub(super) fn infer_predicates(
tcx: TyCtxt<'_>,
) -> FxIndexMap<DefId, ty::EarlyBinder<'_, RequiredPredicates<'_>>> {
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 rename this stuff to be infer_outlives_predicates and RequiredOutlivesPredicates lol

//
// This is correct as we only ever imply outlives-predicates where the outlived
// region is early-bound ... for which the item must have generic parameters.
DefKind::Const { .. } if !tcx.generics_of(item_did).is_empty() => {
Copy link
Member

Choose a reason for hiding this comment

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

I could imagine for mgca wanting to imply bounds from the rhs too. e.g. const FOO<'a>: () = BAR::<'a> where BAR bounds 'a: 'static

//
// This is correct as we only ever imply outlives-predicates where the outlived
// region is early-bound ... for which the item must have generic parameters.
DefKind::Const { .. } if !tcx.generics_of(item_did).is_empty() => {
Copy link
Member

Choose a reason for hiding this comment

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

where does that perf regression you were talking about actually come from? is it having this query return more stuff? would feature gating this match arm improve things too?

Copy link
Member

Choose a reason for hiding this comment

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

also kind of generally wondering if itd be "safer" to gate this behind GCI to avoid any accidents but that seems.. unlikely to happen

@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 13, 2026

OK makes sense to me 🤔

@BoxyUwU
Copy link
Member

BoxyUwU commented Mar 13, 2026

can you record an item on the tracking issue for GCI that we should think about implied bounds before stabilization (i.e. what kinds we want)

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 13, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 15, 2026

☔ The latest upstream changes (presumably #153919) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustc-dev-guide Area: rustc-dev-guide F-generic_const_items `#![feature(generic_const_items)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants