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

Fix default methods with return-position impl Trait in trait #107013

Closed

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jan 17, 2023

Fixes #107002

Removes this weird hack in projection... and replaces it with some other hacks in HIR and MIR typeck.

r? types


Specifically, we should only be able to observe the opaque for a default method in the body of that method itself. For example:

trait Foo {
  async fn foo() {
    // The return type of `foo()` should be treated like an opaque ty here, so we can do inference.
  }

  fn bar() {
    let _ = Self::foo();
    // The return type of `foo()` must remain a projection here, so that when we monomorphize `bar` for some `Self` type, we dispatch to the right `foo` function.
  }
}

@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 17, 2023
@compiler-errors
Copy link
Member 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 Jan 17, 2023
@bors
Copy link
Contributor

bors commented Jan 17, 2023

⌛ Trying commit 5e7bb83 with merge e76d8749244270bde4f1e2b60717e8aa5873cfd4...

@@ -148,6 +150,22 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {

#[instrument(skip(self), level = "debug")]
fn equate_normalized_input_or_output(&mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: Span) {
let (a, b) = (a, b).fold_with(&mut BottomUpFolder {
Copy link
Member Author

Choose a reason for hiding this comment

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

Within a method, treat its own RPITITs as ty::Opaque.

This probably could be a custom folder so it's more efficient... perf will tell.

@@ -627,6 +628,42 @@ where
self.relate_opaques(a, b)
}

// Handle default-body RPITITs
Copy link
Member Author

@compiler-errors compiler-errors Jan 17, 2023

Choose a reason for hiding this comment

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

Within a method, relating one of that method's RPITITs against a concrete type should act just like opaque type inference.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looked at this for ~10 minutes and I don't understand it '^^ would probably be best to chat about this in sync next week

@@ -52,7 +52,7 @@ impl<'tcx> InferCtxt<'tcx> {
span: Span,
param_env: ty::ParamEnv<'tcx>,
) -> InferOk<'tcx, T> {
if !value.has_opaque_types() {
if !value.has_projections() {
Copy link
Member Author

Choose a reason for hiding this comment

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

We need to handle either RPITITs (projections) and opaques... hopefully this doesn't hurt perf too much :/

@bors
Copy link
Contributor

bors commented Jan 18, 2023

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

1 similar comment
@bors
Copy link
Contributor

bors commented Jan 18, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e76d8749244270bde4f1e2b60717e8aa5873cfd4): comparison URL.

Overall result: ❌ regressions - no action needed

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.

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

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

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

Max RSS (memory usage)

Results

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)
- - 0
Regressions ❌
(secondary)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

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

@@ -0,0 +1 @@
B
Copy link
Contributor

@lcnr lcnr Feb 8, 2023

Choose a reason for hiding this comment

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

instead of printing stuff return a bool and assert that it is correct?

@@ -627,6 +628,42 @@ where
self.relate_opaques(a, b)
}

// Handle default-body RPITITs
Copy link
Contributor

Choose a reason for hiding this comment

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

Looked at this for ~10 minutes and I don't understand it '^^ would probably be best to chat about this in sync next week

@lcnr
Copy link
Contributor

lcnr commented Feb 15, 2023

talked about this in sync.

the current approach is not quite right. We probably want to extend the param env with a Projection(RetTyProjection, RetTyOpaque) predicate instead.

@rustbot author

@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 Feb 15, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 21, 2023
…lt-constraint, r=oli-obk

Add a test for default trait method with RPITITs

This didn't work in rust-lang#107013, but now that rust-lang#108203 has landed, let's make sure we don't regress it.

r? types
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. 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.

Unexpected behaviour when calling associated async function of a trait with default implementations
5 participants