Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate opaque types to the typeck root #135445

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jan 13, 2025

still far from properly working

r? @compiler-errors

@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 Jan 13, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 14, 2025

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

@lcnr lcnr force-pushed the propagate-opaques branch 4 times, most recently from f8b46e1 to 3d6168a Compare January 15, 2025 11:08
@lcnr
Copy link
Contributor Author

lcnr commented Jan 15, 2025

alright, there are still a few hacks and bad diagnostics, but it's otherwise working as intended. Going to do a crater run to check whether it's breaking anything.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 15, 2025
@bors
Copy link
Contributor

bors commented Jan 15, 2025

⌛ Trying commit 3d6168a with merge cabf407...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2025
propagate opaque types to the typeck root

still far from properly working

r? `@compiler-errors`
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@aliemjay
Copy link
Member

aliemjay commented Jan 16, 2025

I am not current with the state of the new solver, but no matter how I think about it, I find it difficult to justify the added complexity (edit: of this PR, not the solver :). Member constraints are not simple post-inference checks—they directly impact region inference, and simply propagating them to the parent function renders them ineffective.

Is the goal here to allow defining opaque types with external lifetime arguments inside closures? If so, this approach does not work once the hidden type contains lifetimes

struct Relate<T>(T, T);
fn test<'a>() -> impl Sized + 'a {
    || Relate("", test::<'a>()); // Opaque<'a> := &'empty str
    "" // Opaque<'a> := &'a str
}

@lcnr
Copy link
Contributor Author

lcnr commented Jan 17, 2025

struct Relate<T>(T, T);
fn test<'a>() -> impl Sized + 'a {
    || Relate("", test::<'a>()); // Opaque<'a> := &'empty str
    "" // Opaque<'a> := &'a str
}

This also works with this approach as we lift 'local to be a fresh external region as well. SO we propagate exists<'whatever>: Opaque<'a> = &'whatever str to the parent fn which then proves this.

The only pattern I am aware of which is not supported by this approach is the following (regardless of whether we're in a closure)

struct Foo;
impl Foo {  
    fn recur<'a>(&'a self, b: bool) -> impl Sized + 'a {
        if b {
            let temp = Foo;
            // temp.recur(borrow, false);
            let borrow = &temp;
            Foo::recur(borrow, false); // defines in new solver, opaque use in old
        }
    }
}

And that's more a general issue of this recursive call being a defining one. Fixing this one requires a different perspective on opaques to allow non-defining uses in the defining scope

@aliemjay
Copy link
Member

So hidden type regions are lifted as well. Interesting indeed. 👍

This puts a heavy strain on the "region constraint propagation" code, which has a poor track record and, in some cases, is only approximate, as you encountered in #104477.

@bors
Copy link
Contributor

bors commented Jan 17, 2025

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

@lcnr lcnr force-pushed the propagate-opaques branch from 995a306 to 417be2c Compare January 17, 2025 15:21
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 17, 2025
[DO NOT MERGE] bootstrap with `-Znext-solver=globally`

A revival of rust-lang#124812.

Current status:

~~`./x.py b --stage 2` passes 🎉~~

`try` builds succeed 🎉 🎉 🎉

[first perf run](rust-lang#133502 (comment)) 👻

### in-flight changes

- ce66d92 is a rebased version of rust-lang#125334, unsure whether I actually want to land this PR for now
- rust-lang#135445
- https://github.com/lcnr/rust/tree/opaque-type-method-call support method calls on not-yet defined opaque types in their defining scope ☠️

r? `@ghost`
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling rustc_borrowck v0.0.0 (/checkout/compiler/rustc_borrowck)
error: unused import: `Obligation`
  --> compiler/rustc_borrowck/src/type_check/mod.rs:22:27
   |
22 | use rustc_infer::traits::{Obligation, ObligationCause, PredicateObligations};
   |
   = note: `-D unused-imports` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unused_imports)]`


   Compiling rustc_codegen_llvm v0.0.0 (/checkout/compiler/rustc_codegen_llvm)
error: unused variable: `fr_fn_body`
  --> compiler/rustc_borrowck/src/type_check/opaque_types.rs:47:9
   |
47 |     let fr_fn_body = ty::Region::new_var(
   |         ^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_fr_fn_body`
   = note: `-D unused-variables` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unused_variables)]`

error: could not compile `rustc_borrowck` (lib) due to 2 previous errors

@compiler-errors
Copy link
Member

@rustbot author since this is still draft/being worked on i think?

@rustbot rustbot 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 Jan 23, 2025
@bors
Copy link
Contributor

bors commented Jan 26, 2025

☔ The latest upstream changes (presumably #136085) 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
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-perf Status: Waiting on a perf run to be completed. 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.

7 participants