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

Add unpolished, experimental support for AFIDT (async fn in dyn trait) #133122

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Nov 16, 2024

This allows us to begin messing around async fn in dyn Trait. Calling an async fn from a trait object always returns a dyn* Future<Output = ...>.

To make it work, Implementations are currently required to return something that can be coerced to a dyn* Future (see the example in tests/ui/async-await/dyn/works.rs). If it's not the right size, then it'll raise an error at the coercion site (see the example in tests/ui/async-await/dyn/wrong-size.rs). Currently the only practical way of doing this is wrapping the body in Box::pin(async move { .. }).

This PR does not implement a helper type like a "Boxing"1 adapter, and I'll probably follow-up with another PR to improve the error message for the PointerLike trait (something that explains in just normal prose what is happening here, rather than a trait error).

This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do.

This could also be generalized:

  • To work on functions that are -> impl Future (soon).
  • To work on functions that are -> impl Iterator and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon).

Tracking:

Footnotes

  1. https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter

@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
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

@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 Nov 16, 2024
@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@compiler-errors
Copy link
Member Author

r? types

Probably best for a types team review.

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Nov 16, 2024
@rustbot rustbot assigned jackh726 and unassigned nnethercote Nov 16, 2024
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 19, 2024

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

@rust-log-analyzer

This comment has been minimized.

if tcx.asyncness(fn_def_id).is_async() {
return Some(MethodViolationCode::AsyncFn);
if tcx.features().async_fn_in_dyn_trait() {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of rejecting if the feature is not enabled, we could always use code path for when the feature is enabled and just emit a feature gate error. Or are you trying to not impact stable code for now in diagnostics?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess we could. I'm gonna leave it as a follow-up, since this needs to be reworked once again to support -> impl Future style RPITITs.

compiler/rustc_ty_utils/src/abi.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

fmease added a commit to fmease/rust that referenced this pull request Dec 4, 2024
…li-obk

`fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder

r? oli-obk

Split out of rust-lang#133122
fmease added a commit to fmease/rust that referenced this pull request Dec 4, 2024
…li-obk

`fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder

r? oli-obk

Split out of rust-lang#133122
fmease added a commit to fmease/rust that referenced this pull request Dec 5, 2024
…li-obk

`fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder

r? oli-obk

Split out of rust-lang#133122
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2024
Rollup merge of rust-lang#133874 - compiler-errors:fn-sig-binder, r=oli-obk

`fn_sig_for_fn_abi` should return a `ty::FnSig`, no need for a binder

r? oli-obk

Split out of rust-lang#133122
@jackh726
Copy link
Member

jackh726 commented Dec 5, 2024

Sorry I never finished my review here >.<

Looking through my drafted comments, seems like Oli got them all.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Dec 9, 2024
fmease added a commit to fmease/rust that referenced this pull request Dec 9, 2024
Add unpolished, experimental support for AFIDT (async fn in dyn trait)

This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`.

To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`.

This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error).
[^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter

This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do.

This could also be generalized:
* To work on functions that are `-> impl Future` (soon).
* To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon).

Tracking:
* rust-lang#133119
fmease added a commit to fmease/rust that referenced this pull request Dec 9, 2024
Add unpolished, experimental support for AFIDT (async fn in dyn trait)

This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`.

To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`.

This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error).
[^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter

This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do.

This could also be generalized:
* To work on functions that are `-> impl Future` (soon).
* To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon).

Tracking:
* rust-lang#133119
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 10, 2024
Rollup of 10 pull requests

Successful merges:

 - rust-lang#131558 (Lint on combining `#[no_mangle]` and `#[export_name]`)
 - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait))
 - rust-lang#133184 (wasi/fs: Improve stopping condition for <ReadDir as Iterator>::next)
 - rust-lang#133456 (Add licenses + Run `cargo update`)
 - rust-lang#133472 (Run TLS destructors for wasm32-wasip1-threads)
 - rust-lang#133853 (use vendor sources by default on dist tarballs)
 - rust-lang#133946 (coverage: Prefer to visit nodes whose predecessors have been visited)
 - rust-lang#134010 (fix ICE on type error in promoted)
 - rust-lang#134029 (coverage: Use a query to find counters/expressions that must be zero)
 - rust-lang#134071 (Configure renovatebot)

r? `@ghost`
`@rustbot` modify labels: rollup
@fmease
Copy link
Member

fmease commented Dec 10, 2024

#134099 (comment)
@bors r-

@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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 10, 2024
@compiler-errors
Copy link
Member Author

Added the check for Self: Sized :)

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Dec 10, 2024

📌 Commit 57e8a1c has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 10, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Dec 11, 2024
Add unpolished, experimental support for AFIDT (async fn in dyn trait)

This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`.

To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`.

This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error).
[^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter

This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do.

This could also be generalized:
* To work on functions that are `-> impl Future` (soon).
* To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon).

Tracking:
* rust-lang#133119
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 12, 2024
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#122003 (link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets)
 - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait))
 - rust-lang#133859 (Move some alloc tests to the alloctests crate)
 - rust-lang#134095 ([CI] Use a lockfile for installing the `datadog` package)
 - rust-lang#134155 (Forbid `unsafe_op_in_unsafe_fn` for Hurd)
 - rust-lang#134173 (allow `symbol_intern_string_literal` lint in test modules)
 - rust-lang#134178 (Stabilize the Rust 2024 prelude)
 - rust-lang#134179 (Remove outdated consteval note from `<*mut T>::align_offset` docs.)

r? `@ghost`
`@rustbot` modify labels: rollup
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Dec 12, 2024
Add unpolished, experimental support for AFIDT (async fn in dyn trait)

This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`.

To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`.

This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error).
[^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter

This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do.

This could also be generalized:
* To work on functions that are `-> impl Future` (soon).
* To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon).

Tracking:
* rust-lang#133119
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 12, 2024
Rollup of 13 pull requests

Successful merges:

 - rust-lang#122003 (link libunwind dynamically and allow controlling it via `crt-static` on gnullvm targets)
 - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait))
 - rust-lang#133859 (Move some alloc tests to the alloctests crate)
 - rust-lang#134070 (Some asm! diagnostic adjustments and a papercut fix)
 - rust-lang#134095 ([CI] Use a lockfile for installing the `datadog` package)
 - rust-lang#134144 (Properly consider APITs for never type fallback ascription fix)
 - rust-lang#134152 (Simplify `rustc_mir_dataflow::abs_domain`.)
 - rust-lang#134154 (suppress field expr with generics error message if it's a method)
 - rust-lang#134155 (Forbid `unsafe_op_in_unsafe_fn` for Hurd)
 - rust-lang#134173 (allow `symbol_intern_string_literal` lint in test modules)
 - rust-lang#134178 (Stabilize the Rust 2024 prelude)
 - rust-lang#134179 (Remove outdated consteval note from `<*mut T>::align_offset` docs.)
 - rust-lang#134187 (Remove `PErr`.)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 12, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#133122 (Add unpolished, experimental support for AFIDT (async fn in dyn trait))
 - rust-lang#133249 (ABI checks: add support for loongarch)
 - rust-lang#134089 (Use newly added exceptions to non default branch warning)
 - rust-lang#134188 (Bump Fuchsia)
 - rust-lang#134204 (Fix our `llvm::Bool` typedef to be signed, to match `LLVMBool`)
 - rust-lang#134207 (Revert "bootstrap: print{ln}! -> eprint{ln}! (take 2) rust-lang#134040")
 - rust-lang#134214 (rustdoc: fix self cmp)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 2e8807d into rust-lang:master Dec 12, 2024
6 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 12, 2024
Rollup merge of rust-lang#133122 - compiler-errors:afidt, r=oli-obk

Add unpolished, experimental support for AFIDT (async fn in dyn trait)

This allows us to begin messing around `async fn` in `dyn Trait`. Calling an async fn from a trait object always returns a `dyn* Future<Output = ...>`.

To make it work, Implementations are currently required to return something that can be coerced to a `dyn* Future` (see the example in `tests/ui/async-await/dyn/works.rs`). If it's not the right size, then it'll raise an error at the coercion site (see the example in `tests/ui/async-await/dyn/wrong-size.rs`). Currently the only practical way of doing this is wrapping the body in `Box::pin(async move { .. })`.

This PR does not implement a helper type like a "`Boxing`"[^boxing] adapter, and I'll probably follow-up with another PR to improve the error message for the `PointerLike` trait (something that explains in just normal prose what is happening here, rather than a trait error).
[^boxing]: https://rust-lang.github.io/async-fundamentals-initiative/explainer/user_guide_future.html#the-boxing-adapter

This PR also does not implement new trait solver support for AFIDT; I'll need to think how best to integrate it into candidate assembly, and that's a bit of a matter of taste, but I don't think it will be difficult to do.

This could also be generalized:
* To work on functions that are `-> impl Future` (soon).
* To work on functions that are `-> impl Iterator` and other "dyn rpitit safe" traits. We still need to nail down exactly what is needed for this to be okay (not soon).

Tracking:
* rust-lang#133119
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants