Skip to content

[WIP] Support param bounds on non-lifetime binders#115362

Closed
compiler-errors wants to merge 5 commits intorust-lang:mainfrom
compiler-errors:non-lifetime-binder-where-clauses
Closed

[WIP] Support param bounds on non-lifetime binders#115362
compiler-errors wants to merge 5 commits intorust-lang:mainfrom
compiler-errors:non-lifetime-binder-where-clauses

Conversation

@compiler-errors
Copy link
Copy Markdown
Contributor

@compiler-errors compiler-errors commented Aug 29, 2023

View all comments

This PR adds resolution and AST lowering for where clauses on binders. The meaning for for<T> now becomes for<T: Sized> like regular generics positions, and you are now able to write for<T: Trait> (and for<T: ?Sized>). Binder predicates are only considered in the new solver today. Since non-lifetime binders is an incomplete feature, I don't think we need to do any messaging to tell people that they don't work correctly in the old solver, but I'll see to that in a follow-up.

This PR then adds a new List<ty::Clause> to binders. Most places in the compiler shouldn't care about them existing, but eventually as support for non-lifetime binders gets fleshed out we should be more careful about asserting that they're handled. This will not happen in this PR.

Tracking:

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 29, 2023
@compiler-errors
Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@bors
Copy link
Copy Markdown
Collaborator

bors commented Aug 29, 2023

⌛ Trying commit 3471faa6dbd43943bb8dc2e3bdedf59fab546439 with merge ff357375eca19961c0e26a765585b8cf4b3a1b3c...

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 29, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Copy Markdown
Collaborator

bors commented Aug 29, 2023

💔 Test failed - checks-actions

@bors bors 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 Aug 29, 2023
@bors
Copy link
Copy Markdown
Collaborator

bors commented Sep 3, 2023

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

@rust-cloud-vms rust-cloud-vms bot force-pushed the non-lifetime-binder-where-clauses branch from 3471faa to c915474 Compare September 4, 2023 16:46
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Copy Markdown
Collaborator

bors commented Sep 14, 2023

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

@rust-cloud-vms rust-cloud-vms bot force-pushed the non-lifetime-binder-where-clauses branch from c915474 to 53c5310 Compare October 17, 2023 23:54
@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the non-lifetime-binder-where-clauses branch from 53c5310 to cbe1bbd Compare October 18, 2023 00:06
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Copy Markdown
Collaborator

bors commented Oct 18, 2023

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

@fmease
Copy link
Copy Markdown
Member

fmease commented Oct 19, 2023

Obviously, this is still WIP. Here's one observation I made while playing around with this patch:

trait Trait<T> {}
fn f(_: impl for<T: ?Sized> Trait<T>) {}

This successfully compiles (-Ztrait-solver=next ofc) while I don't think it should. impl for<T: ?Sized> Trait<T> isn't WF since the contained Trait<T> requires T: Sized to hold to be WF which isn't the case here. Cf: fn g<T: ?Sized>(_: impl Trait<T>) (ofc this is far from semantically equivalent) doesn't compile, rightly so.

@compiler-errors
Copy link
Copy Markdown
Contributor Author

compiler-errors commented Oct 19, 2023

@fmease: Yeah, that's pre-existing.

#![feature(non_lifetime_binders)]

trait Trait<T> {}
fn f<S: for<T> Trait<T>>(_: S) {}
//~^ Recall that `for<T>` on stable == `for<T: ?Sized>`

This is likely due to one of the many !obligation.has_escaping_bound_vars() in wf code.

@compiler-errors
Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Copy Markdown
Collaborator

bors commented Dec 18, 2023

⌛ Trying commit 82ae54c with merge 2e849e3...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2023
…where-clauses, r=<try>

[WIP] Support param bounds on non-lifetime binders

👀

r? `@ghost`
// tidy-alphabetical-start
static_assert_size!(ty::RegionKind<'_>, 24);
static_assert_size!(ty::TyKind<'_>, 24);
static_assert_size!(ty::TyKind<'_>, 32);
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 am personally not a big fan of supporting where-bounds inside of types and would like to only allow them in where-bounds. I also believe that this is where pretty much all of the perf regression is coming from.

I do expect that playing around with this feature is more annoying and ugly if we have to split binder for it, so 🤷 i guess i don't mind too much

@lcnr
Copy link
Copy Markdown
Contributor

lcnr commented Mar 26, 2025

Currently don't have the mental capacity to review changes related to this feature in-depth

r? oli-obk maybe 🤔

@rustbot rustbot assigned oli-obk and unassigned lcnr Mar 26, 2025
@nnethercote
Copy link
Copy Markdown
Contributor

w.r.t. perf: we have a lot of size assertions in the codebase, but the one on TyKind is one of the most important. There are many instances of that type and they are all interned, so if it gets bigger that's more memory usage and more hashing costs. It's up there with ast::Expr at the top of the list of "types I least want to get bigger" :(

@compiler-errors
Copy link
Copy Markdown
Contributor Author

Maybe I can intern the pair of clauses lists into one or something 🤔 Ideas would be helpful

@bors
Copy link
Copy Markdown
Collaborator

bors commented Mar 28, 2025

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

@oli-obk
Copy link
Copy Markdown
Contributor

oli-obk commented Mar 28, 2025

Since the type size regression comes solely from FnPtr, maybe just intern the contents of the FnPtr variant?

@compiler-errors
Copy link
Copy Markdown
Contributor Author

Well, we also have to intern unsafe binders 🤔

@compiler-errors compiler-errors force-pushed the non-lifetime-binder-where-clauses branch from 058f940 to f3652c5 Compare March 29, 2025 20:46
@compiler-errors
Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 29, 2025
@bors
Copy link
Copy Markdown
Collaborator

bors commented Mar 29, 2025

⌛ Trying commit f3652c5 with merge e985804...

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2025
…where-clauses, r=<try>

[WIP] Support param bounds on non-lifetime binders

This PR adds resolution and AST lowering for where clauses on binders. The meaning for `for<T>` now becomes `for<T: Sized>` like regular generics positions, and you are now able to write `for<T: Trait>` (and `for<T: ?Sized>`). Binder predicates are only considered in the new solver today. Since non-lifetime binders is an incomplete feature, I don't think we need to do any messaging to tell people that they don't work correctly in the old solver, but I'll see to that in a follow-up.

This PR then adds a new `List<ty::Clause>` to binders. Most places in the compiler shouldn't care about them existing, but eventually as support for non-lifetime binders gets fleshed out we should be more careful about asserting that they're handled. This will not happen in this PR.

Tracking:
* rust-lang#108185
@bors
Copy link
Copy Markdown
Collaborator

bors commented Mar 29, 2025

☀️ Try build successful - checks-actions
Build commit: e985804 (e985804039a6ff5eb9176c17876b1030ef7c149b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (e985804): comparison URL.

Overall result: ❌ regressions - please read the text below

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.6% [0.1%, 5.0%] 75
Regressions ❌
(secondary)
0.7% [0.1%, 2.4%] 62
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.6% [0.1%, 5.0%] 75

Max RSS (memory usage)

Results (primary 0.1%, secondary 2.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.3% [0.6%, 3.0%] 6
Regressions ❌
(secondary)
2.9% [0.8%, 5.3%] 15
Improvements ✅
(primary)
-3.5% [-3.7%, -3.2%] 2
Improvements ✅
(secondary)
-1.3% [-1.4%, -1.2%] 3
All ❌✅ (primary) 0.1% [-3.7%, 3.0%] 8

Cycles

Results (primary 1.4%, secondary 1.9%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.4% [0.8%, 4.0%] 38
Regressions ❌
(secondary)
1.9% [1.2%, 2.8%] 15
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.4% [0.8%, 4.0%] 38

Binary size

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

Bootstrap: 777.207s -> 792.224s (1.93%)
Artifact size: 365.95 MiB -> 366.51 MiB (0.15%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 30, 2025
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 27, 2025
@eericjacobson
Copy link
Copy Markdown

why was this closed?

@compiler-errors compiler-errors deleted the non-lifetime-binder-where-clauses branch March 24, 2026 00:48
@oli-obk
Copy link
Copy Markdown
Contributor

oli-obk commented Mar 24, 2026

EDIT (previously contained a personal rant):

The PR is something we should revive if we find a dev for it.

@eericjacobson
Copy link
Copy Markdown

how do big companies have an influence over single feature PRs in rust nightly?
also what does the time frame for finding a dev for this look like?

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

Labels

perf-regression Performance regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.