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 support for for await loops #118847

Merged
merged 3 commits into from
Dec 22, 2023
Merged

Add support for for await loops #118847

merged 3 commits into from
Dec 22, 2023

Conversation

eholk
Copy link
Contributor

@eholk eholk commented Dec 12, 2023

This adds support for for await loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:

for await i in iter {
    ...
}

this is desugared to something like:

let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}

This PR also adds a basic IntoAsyncIterator trait. This is partly for symmetry with the way Iterator and IntoIterator work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. IntoAsyncIterator gives us a good place to do this.

I've gated this feature behind async_for_loop and opened #118898 as the feature tracking issue.

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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 12, 2023
@compiler-errors
Copy link
Member

Yeah, I think this could use a lang-ok.

@compiler-errors compiler-errors added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). I-lang-nominated Nominated for discussion during a lang team meeting. labels Dec 12, 2023
compiler/rustc_ast/src/ast.rs Outdated Show resolved Hide resolved
library/core/src/async_iter/mod.rs Outdated Show resolved Hide resolved
@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 Dec 12, 2023
@compiler-errors compiler-errors added the I-async-nominated Nominated for discussion during an async working group meeting. label Dec 12, 2023
@eholk
Copy link
Contributor Author

eholk commented Dec 12, 2023

Oh, I also need to add a test to make sure we don't parse for await without the feature.

@compiler-errors
Copy link
Member

I also think this should be a separate feature gate, async_for or for_async.

@rust-log-analyzer

This comment has been minimized.

@the8472
Copy link
Member

the8472 commented Dec 12, 2023

The proposed desugaring doesn't seem great. It'll have to poll a future and then match an option on each loop iteration, which means 2 conditions per iteration which is just terrible for optimizations. It's already hard to make regular for loop desugaring efficient and in some cases internal iteration still outperforms it. This would be much worse.
Consider the worst case where one is iterating over bytes and the bytes would become ready in large batches.

I think a pattern closer to nonblocking IO would be better where one keeps reading until EAGAIN and only then polls (awaits). That way things could be split into an inner next() + outer await loop.

Alternatively an async equivalent to try_for_each where all control flow is funneled through an enum might work too, though that'd require more work by the compiler.

@the8472
Copy link
Member

the8472 commented Dec 12, 2023

Perhaps the signature of async_iter_next could be changed to return a I: IntoIterator<IntoIter=IN>, IN: ExactSizeIterator. Option fulfills those bounds. So single-item-per-await async iters could continue to return options while batchable async iters could return longer iterables.

@rust-log-analyzer

This comment has been minimized.

@eholk
Copy link
Contributor Author

eholk commented Dec 13, 2023

Okay, I've reworked this PR significantly to get rid of async_iter_next and generate code that calls poll_next directly.

@rust-log-analyzer

This comment has been minimized.

@lightsing
Copy link

Hi,

While I appreciate the efforts to introduce for await loops in Rust, I have some reservations about the proposed syntax and semantics.

In the current design, await is consistently used as a postfix operator (.await). Introducing for await breaks this consistency, potentially leading to confusion. The semantic clarity of await as a postfix operator has been a strong point in Rust's async design, and deviating from this pattern might weaken the language's overall coherence.

Personally, I would advocate for a syntax more in line with the existing async constructs. For example, async for e in async_iter seems more intuitive.

I believe this change warrants a more extensive discussion within the community. The introduction of a new syntax, especially one that deviates from established patterns, is a significant decision. It's crucial to consider the implications on the language's learning curve, consistency, and future extensibility.

While I support the initiative to enhance async iteration in Rust, I would urge reconsideration of the syntax to align better with existing conventions. A broader discussion might yield a more agreeable and consistent solution.

@asquared31415
Copy link
Contributor

Note that in edition 2015 for await in iter is valid code, creating a binding with the identifier await, since it was not a reserved keyword at that time. There should be syntax tests for that edition as well.

@slanterns
Copy link
Contributor

slanterns commented Dec 13, 2023

It does not introduce a new async block but rather implicitly doing await-like thing in the desugaring, so I think await is probably more reasonable than async. Anyway it may not be necessary to bikeshedding on the concrete syntax at this point :)

@traviscross
Copy link
Contributor

While I appreciate the efforts to introduce for await loops in Rust, I have some reservations about the proposed syntax and semantics.... this change warrants a more extensive discussion within the community.

Keep in mind that this is just a nightly experiment at this point. No sticky decisions have been made on these details and they are still the subject of much reflection and discussion among the people working on this.

The purpose of the nightly experiment is to collect the kind of experience that can only come from implementing and trying the feature in nightly so that we can better write an RFC.

While feedback and participation is of course welcome here, the RFC process will be the main venue for the extensive discussion with the community that you mention.

@bors
Copy link
Contributor

bors commented Dec 20, 2023

⌛ Testing commit 397f4a1 with merge 0262302...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 20, 2023
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened rust-lang#118898 as the feature tracking issue.

r? `@compiler-errors`
@rust-log-analyzer
Copy link
Collaborator

The job i686-msvc failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
failures:

---- [debuginfo-cdb] tests\debuginfo\tuple-in-tuple.rs stdout ----

error: check directive(s) from `C:\a\rust\rust\tests\debuginfo\tuple-in-tuple.rs` not found in debugger output. errors:
    (tuple-in-tuple.rs:68) `no_padding1,d [...]: ((0, 1), 2, 3) [Type: tuple$<tuple$<u32,u32>,u32,u32>]`
    (tuple-in-tuple.rs:69) `[...][0]              : (0, 1) [Type: tuple$<u32,u32>]`
    (tuple-in-tuple.rs:71) `[...][2]              : 3 [Type: [...]]`
    (tuple-in-tuple.rs:73) `no_padding1.__0,d [...]: (0, 1) [Type: tuple$<u32,u32>]`
    (tuple-in-tuple.rs:74) `[...][0]              : 0 [Type: [...]]`
    (tuple-in-tuple.rs:75) `[...][1]              : 1 [Type: [...]]`
    (tuple-in-tuple.rs:77) `no_padding2,d [...]: (4, (5, 6), 7) [Type: tuple$<u32,tuple$<u32,u32>,u32>]`
    (tuple-in-tuple.rs:78) `[...][0]              : 4 [Type: [...]]`
    (tuple-in-tuple.rs:79) `[...][1]              : (5, 6) [Type: tuple$<u32,u32>]`
    (tuple-in-tuple.rs:80) `[...][2]              : 7 [Type: [...]]`
    (tuple-in-tuple.rs:82) `no_padding2.__1,d [...]: (5, 6) [Type: tuple$<u32,u32>]`
    (tuple-in-tuple.rs:83) `[...][0]              : 5 [Type: [...]]`
    (tuple-in-tuple.rs:84) `[...][1]              : 6 [Type: [...]]`
    (tuple-in-tuple.rs:86) `no_padding3,d [...]: (8, 9, (10, 11)) [Type: tuple$<u32,u32,tuple$<u32,u32> >]`
    (tuple-in-tuple.rs:87) `[...][0]              : 8 [Type: [...]]`
    (tuple-in-tuple.rs:88) `[...][1]              : 9 [Type: [...]]`
    (tuple-in-tuple.rs:89) `[...][2]              : (10, 11) [Type: tuple$<u32,u32>]`
    (tuple-in-tuple.rs:91) `no_padding3.__2,d [...]: (10, 11) [Type: tuple$<u32,u32>]`
    (tuple-in-tuple.rs:92) `[...][0]              : 10 [Type: [...]]`
    (tuple-in-tuple.rs:93) `[...][1]              : 11 [Type: [...]]`
    (tuple-in-tuple.rs:96) `internal_padding1,d [...]: (12, (13, 14)) [Type: tuple$<i16,tuple$<i32,i32> >]`
    (tuple-in-tuple.rs:97) `[...][0]              : 12 [Type: [...]]`
    (tuple-in-tuple.rs:98) `[...][1]              : (13, 14) [Type: tuple$<i32,i32>]`
    (tuple-in-tuple.rs:100) `internal_padding1.__1,d [...]: (13, 14) [Type: tuple$<i32,i32>]`
    (tuple-in-tuple.rs:101) `[...][0]              : 13 [Type: [...]]`
    (tuple-in-tuple.rs:102) `[...][1]              : 14 [Type: [...]]`
    (tuple-in-tuple.rs:104) `internal_padding2,d [...]: (15, (16, 17)) [Type: tuple$<i16,tuple$<i16,i32> >]`
    (tuple-in-tuple.rs:105) `[...][0]              : 15 [Type: [...]]`
    (tuple-in-tuple.rs:106) `[...][1]              : (16, 17) [Type: tuple$<i16,i32>]`
    (tuple-in-tuple.rs:108) `internal_padding2.__1,d [...]: (16, 17) [Type: tuple$<i16,i32>]`
    (tuple-in-tuple.rs:109) `[...][0]              : 16 [Type: [...]]`
    (tuple-in-tuple.rs:110) `[...][1]              : 17 [Type: [...]]`
    (tuple-in-tuple.rs:113) `padding_at_end1,d [...]: (18, (19, 20)) [Type: tuple$<i32,tuple$<i32,i16> >]`
    (tuple-in-tuple.rs:114) `[...][0]              : 18 [Type: [...]]`
    (tuple-in-tuple.rs:115) `[...][1]              : (19, 20) [Type: tuple$<i32,i16>]`
    (tuple-in-tuple.rs:117) `padding_at_end1.__1,d [...][Type: tuple$<i32,i16>]`
    (tuple-in-tuple.rs:118) `[...][0]              : 19 [Type: [...]]`
    (tuple-in-tuple.rs:119) `[...][1]              : 20 [Type: [...]]`
    (tuple-in-tuple.rs:121) `padding_at_end2,d [...]: ((21, 22), 23) [Type: tuple$<tuple$<i32,i16>,i32>]`
    (tuple-in-tuple.rs:122) `[...][0]              : (21, 22) [Type: tuple$<i32,i16>]`
    (tuple-in-tuple.rs:123) `[...][1]              : 23 [Type: [...]]`
    (tuple-in-tuple.rs:125) `padding_at_end2.__0,d [...]: (21, 22) [Type: tuple$<i32,i16>]`
    (tuple-in-tuple.rs:126) `[...][0]              : 21 [Type: [...]]`
    (tuple-in-tuple.rs:127) `[...][1]              : 22 [Type: [...]]`
the following subset of check directive(s) was found successfully:
    (tuple-in-tuple.rs:70) `    [1]              : 2 [Type: short]`
status: exit code: 0
command: PATH="C:\a\rust\rust\build\i686-pc-windows-msvc\stage2\lib\rustlib\i686-pc-windows-msvc\lib;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x86;C:\a\rust\rust\build\i686-pc-windows-msvc\stage0-bootstrap-tools\i686-pc-windows-msvc\release\deps;C:\a\rust\rust\build\i686-pc-windows-msvc\stage0\bin;C:\Program Files\PowerShell\7;C:\a\rust\rust\ninja;C:\a\rust\rust\msys2\mingw32\bin;C:\hostedtoolcache\windows\Python\3.12.1\x64\Scripts;C:\hostedtoolcache\windows\Python\3.12.1\x64;C:\msys64\usr\bin;C:\a\rust\rust\sccache;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\cf-cli;C:\Program Files (x86)\NSIS;C:\tools\zstd;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\2.13.1\x64;C:\cabal\bin;C:\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 5.7\bin;C:\Program Files\R\R-4.3.2\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.20.12\x64\bin;C:\hostedtoolcache\windows\Python\3.7.9\x64\Scripts;C:\hostedtoolcache\windows\Python\3.7.9\x64;C:\hostedtoolcache\windows\Ruby\2.5.9\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.392-8\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\bin;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin;C:\Program Files (x86)\Microsoft BizTalk Server;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps" "C:\\Program Files (x86)\\Windows Kits\\10\\Debuggers\\x86\\cdb.exe" "-lines" "-cf" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\test\\debuginfo\\tuple-in-tuple.cdb\\tuple-in-tuple.debugger.script" "C:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\test\\debuginfo\\tuple-in-tuple.cdb\\a.exe"

Microsoft (R) Windows Debugger Version 10.0.22000.832 X86
Copyright (c) Microsoft Corporation. All rights reserved.


CommandLine: C:\a\rust\rust\build\i686-pc-windows-msvc\test\debuginfo\tuple-in-tuple.cdb\a.exe

************* Path validation summary **************
Response                         Time (ms)     Location
Deferred                                       srv*
Symbol search path is: srv*
Executable search path is: 
ModLoad: 00e70000 00e75000   a.exe   
ModLoad: 777c0000 7795d000   ntdll.dll
ModLoad: 750d0000 751b0000   C:\Windows\SysWOW64\KERNEL32.DLL
ModLoad: 75230000 75431000   C:\Windows\SysWOW64\KERNELBASE.dll
ModLoad: 71fc0000 7205c000   C:\Windows\SysWOW64\apphelp.dll
ModLoad: 77580000 776a3000   C:\Windows\SysWOW64\ucrtbase.dll
ModLoad: 72160000 72175000   C:\Windows\SysWOW64\VCRUNTIME140.dll
ModLoad: 65be0000 6652f000   C:\a\rust\rust\build\i686-pc-windows-msvc\stage2\lib\rustlib\i686-pc-windows-msvc\lib\std-4aa069bca77a392d.dll
ModLoad: 75ef0000 75f70000   C:\Windows\SysWOW64\ADVAPI32.dll
ModLoad: 74e00000 74ec0000   C:\Windows\SysWOW64\msvcrt.dll
ModLoad: 751b0000 75229000   C:\Windows\SysWOW64\sechost.dll
ModLoad: 776f0000 777ad000   C:\Windows\SysWOW64\RPCRT4.dll
ModLoad: 74de0000 74e00000   C:\Windows\SysWOW64\SspiCli.dll
ModLoad: 74dd0000 74dda000   C:\Windows\SysWOW64\CRYPTBASE.dll
ModLoad: 76180000 761e5000   C:\Windows\SysWOW64\bcryptPrimitives.dll
ModLoad: 760e0000 760f9000   C:\Windows\SysWOW64\bcrypt.dll
ModLoad: 74f40000 74f9f000   C:\Windows\SysWOW64\WS2_32.dll
ModLoad: 72180000 721a5000   C:\Windows\SysWOW64\USERENV.dll
ModLoad: 76f60000 76f7c000   C:\Windows\SysWOW64\profapi.dll
(b58.1a6c): Break instruction exception - code 80000003 (first chance)
eax=00000000 ebx=00000010 ecx=9e410000 edx=00000000 esi=001b6ce8 edi=00bc2000
eip=7786ea36 esp=00cff7a0 ebp=00cff7cc iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
ntdll!LdrpDoDebuggerBreak+0x2b:
7786ea36 cc              int     3
0:000> version
Windows 10 Version 17763 MP (8 procs) Free x86 compatible
Product: Server, suite: TerminalServer DataCenter SingleUserTS
Edition build lab: 17763.1.x86fre.rs5_release.180914-1434
Build layer:            -> 
Build layer:            -> 
Build layer:            -> 
Machine Name:
Debug session time: Wed Dec 20 05:13:56.825 2023 (UTC + 0:00)
System Uptime: 0 days 3:55:50.125
Process Uptime: 0 days 0:00:00.061
  Kernel time: 0 days 0:00:00.015
  User time: 0 days 0:00:00.000
Live user mode: <Local>
Microsoft (R) Windows Debugger Version 10.0.22000.832 X86
Copyright (c) Microsoft Corporation. All rights reserved.


command line: '"C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\cdb.exe" -lines -cf C:\a\rust\rust\build\i686-pc-windows-msvc\test\debuginfo\tuple-in-tuple.cdb\tuple-in-tuple.debugger.script C:\a\rust\rust\build\i686-pc-windows-msvc\test\debuginfo\tuple-in-tuple.cdb\a.exe'  Debugger Process 0x598 
dbgeng:  image 10.0.22000.832, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\dbgeng.dll]
dbghelp: image 10.0.22000.832, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\dbghelp.dll]
        DIA version: 29395
Extension DLL search Path:
Build completed unsuccessfully in 0:44:31
    C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\WINXP;C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext;C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext\arcade;C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\pri;C:\Program Files (x86)\Windows Kits\10\Debuggers\x86;C:\Users\runneradmin\AppData\Local\Dbg\EngineExtensions32;C:\Program Files (x86)\Windows Kits\10\Debuggers\x86;C:\a\rust\rust\build\i686-pc-windows-msvc\stage2\lib\rustlib\i686-pc-windows-msvc\lib;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x86;C:\a\rust\rust\build\i686-pc-windows-msvc\stage0-bootstrap-tools\i686-pc-windows-msvc\release\deps;C:\a\rust\rust\build\i686-pc-windows-msvc\stage0\bin;C:\Program Files\PowerShell\7;C:\a\rust\rust\ninja;C:\a\rust\rust\msys2\mingw32\bin;C:\hostedtoolcache\windows\Python\3.12.1\x64\Scripts;C:\hostedtoolcache\windows\Python\3.12.1\x64;C:\msys64\usr\bin;C:\a\rust\rust\sccache;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\cf-cli;C:\Program Files (x86)\NSIS;C:\tools\zstd;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\2.13.1\x64;C:\cabal\bin;C:\ghcup\bin;C:\mingw64\bin;C:\Program Files\dotnet;C:\Program Files\MySQL\MySQL Server 5.7\bin;C:\Program Files\R\R-4.3.2\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\SeleniumWebDrivers\ChromeDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\npm\prefix;C:\hostedtoolcache\windows\go\1.20.12\x64\bin;C:\hostedtoolcache\windows\Python\3.7.9\x64\Scripts;C:\hostedtoolcache\windows\Python\3.7.9\x64;C:\hostedtoolcache\windows\Ruby\2.5.9\x64\bin;C:\Program Files\OpenSSL\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.392-8\x64\bin;C:\Program Files\ImageMagick-7.1.1-Q16-HDRI;C:\Program Files\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\bin;C:\ProgramData\Chocolatey\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\160\DTS\Binn;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.7\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin;C:\Program Files (x86)\Microsoft BizTalk Server;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps
Extension DLL chain:
    dbghelp: image 10.0.22000.832, API 10.0.6, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\dbghelp.dll]
    ext: image 10.0.22000.832, API 1.0.0, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext\ext.dll]
    wow64exts: image 10.0.22000.832, API 1.0.0, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\WINXP\wow64exts.dll]
    exts: image 10.0.22000.832, API 1.0.0, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\WINXP\exts.dll]
    uext: image 10.0.22000.832, API 1.0.0, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\winext\uext.dll]
    ntsdexts: image 10.0.22000.832, API 1.0.0, 
        [path: C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\WINXP\ntsdexts.dll]
WOW64 extensions loaded
0:000> .nvlist
Loaded NatVis Files:
    <None Loaded>
0:000> bp `tuple-in-tuple.rs:144`
*** WARNING: Unable to verify checksum for a.exe
0:000>  g
Breakpoint 0 hit
eax=00000016 ebx=00bc2000 ecx=00000015 edx=00000000 esi=00e720f8 edi=00cffc80
eip=00e712b1 esp=00cffb10 ebp=00cffc60 iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000202
a!tuple_in_tuple::main+0x151:
00e712b1 e80a000000      call    a!tuple_in_tuple::zzz (00e712c0)
0:000> dx no_padding1,d
no_padding1,d    : ((5, 1826994), 0, 0) [Type: tuple$<tuple$<u32,u32>,u32,u32>]
    [<Raw View>]     [Type: tuple$<tuple$<u32,u32>,u32,u32>]
    [0]              : (5, 1826994) [Type: tuple$<u32,u32>]
    [1]              : 0 [Type: unsigned int]
    [2]              : 0 [Type: unsigned int]
0:000> dx no_padding1.__0,d
no_padding1.__0,d : (5, 1826994) [Type: tuple$<u32,u32>]
    [<Raw View>]     [Type: tuple$<u32,u32>]
    [0]              : 5 [Type: unsigned int]
    [1]              : 1826994 [Type: unsigned int]
0:000> dx no_padding2,d
no_padding2,d    : (0, (13630516, 2002523325), 1965010) [Type: tuple$<u32,tuple$<u32,u32>,u32>]
    [<Raw View>]     [Type: tuple$<u32,tuple$<u32,u32>,u32>]
    [0]              : 0 [Type: unsigned int]
    [1]              : (13630516, 2002523325) [Type: tuple$<u32,u32>]
    [2]              : 1965010 [Type: unsigned int]
0:000> dx no_padding2.__1,d
no_padding2.__1,d : (13630516, 2002523325) [Type: tuple$<u32,u32>]
    [<Raw View>]     [Type: tuple$<u32,u32>]
    [0]              : 13630516 [Type: unsigned int]
    [1]              : 2002523325 [Type: unsigned int]
0:000> dx no_padding3,d
no_padding3,d    : (2003382360, 1893416, (0, 13630536)) [Type: tuple$<u32,u32,tuple$<u32,u32> >]
    [<Raw View>]     [Type: tuple$<u32,u32,tuple$<u32,u32> >]
    [0]              : 2003382360 [Type: unsigned int]
    [1]              : 1893416 [Type: unsigned int]
    [2]              : (0, 13630536) [Type: tuple$<u32,u32>]
0:000> dx no_padding3.__2,d
no_padding3.__2,d : (0, 13630536) [Type: tuple$<u32,u32>]
    [<Raw View>]     [Type: tuple$<u32,u32>]
    [0]              : 0 [Type: unsigned int]
    [1]              : 13630536 [Type: unsigned int]
0:000> dx internal_padding1,d
internal_padding1,d : (0, (-2147483648, 13630420)) [Type: tuple$<i16,tuple$<i32,i32> >]
    [<Raw View>]     [Type: tuple$<i16,tuple$<i32,i32> >]
    [0]              : 0 [Type: short]
    [1]              : (-2147483648, 13630420) [Type: tuple$<i32,i32>]
0:000> dx internal_padding1.__1,d
internal_padding1.__1,d : (-2147483648, 13630420) [Type: tuple$<i32,i32>]
    [<Raw View>]     [Type: tuple$<i32,i32>]
    [0]              : -2147483648 [Type: int]
    [1]              : 13630420 [Type: int]
0:000> dx internal_padding2,d
internal_padding2,d : (9, (8440, 13630592)) [Type: tuple$<i16,tuple$<i16,i32> >]
    [<Raw View>]     [Type: tuple$<i16,tuple$<i16,i32> >]
    [0]              : 9 [Type: short]
    [1]              : (8440, 13630592) [Type: tuple$<i16,i32>]
0:000> dx internal_padding2.__1,d
internal_padding2.__1,d : (8440, 13630592) [Type: tuple$<i16,i32>]
    [<Raw View>]     [Type: tuple$<i16,i32>]
    [0]              : 8440 [Type: short]
    [1]              : 13630592 [Type: int]
0:000> dx padding_at_end1,d
padding_at_end1,d : (15143006, (13630592, 8440)) [Type: tuple$<i32,tuple$<i32,i16> >]
    [<Raw View>]     [Type: tuple$<i32,tuple$<i32,i16> >]
    [0]              : 15143006 [Type: int]
    [1]              : (13630592, 8440) [Type: tuple$<i32,i16>]
0:000> dx padding_at_end1.__1,d
padding_at_end1.__1,d : (13630592, 8440) [Type: tuple$<i32,i16>]
    [<Raw View>]     [Type: tuple$<i32,i16>]
    [0]              : 13630592 [Type: int]
    [1]              : 8440 [Type: short]
0:000> dx padding_at_end2,d
padding_at_end2,d : ((0, 2), 15143264) [Type: tuple$<tuple$<i32,i16>,i32>]
    [<Raw View>]     [Type: tuple$<tuple$<i32,i16>,i32>]
    [0]              : (0, 2) [Type: tuple$<i32,i16>]
    [1]              : 15143264 [Type: int]
0:000> dx padding_at_end2.__0,d
padding_at_end2.__0,d : (0, 2) [Type: tuple$<i32,i16>]
    [<Raw View>]     [Type: tuple$<i32,i16>]
    [0]              : 0 [Type: int]
    [1]              : 2 [Type: short]
0:000> qq
quit:
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\atlmfc.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\ObjectiveC.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\concurrency.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\cpp_rest.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\stl.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\Windows.Data.Json.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\Windows.Devices.Geolocation.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\Windows.Devices.Sensors.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\Windows.Media.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\windows.natvis'
NatVis script unloaded from 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x86\Visualizers\winrt.natvis'
stderr: none




failures:
    [debuginfo-cdb] tests\debuginfo\tuple-in-tuple.rs

test result: FAILED. 129 passed; 1 failed; 18 ignored; 0 measured; 0 filtered out; finished in 19.35s

Some tests failed in compiletest suite=debuginfo mode=debuginfo host=i686-pc-windows-msvc target=i686-pc-windows-msvc
make: *** [Makefile:73: ci-msvc-ps1] Error 1
  network time: Wed, 20 Dec 2023 05:13:59 GMT
##[error]Process completed with exit code 2.
Post job cleanup.
[command]"C:\Program Files\Git\bin\git.exe" version

@bors
Copy link
Contributor

bors commented Dec 20, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 20, 2023
@compiler-errors
Copy link
Member

No idea what's up with the test failure..

@bors retry

@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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 21, 2023
@bors
Copy link
Contributor

bors commented Dec 22, 2023

⌛ Testing commit 397f4a1 with merge a877d6d...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 22, 2023
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened rust-lang#118898 as the feature tracking issue.

r? `@compiler-errors`
@bors
Copy link
Contributor

bors commented Dec 22, 2023

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 22, 2023
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@matthiaskrgr
Copy link
Member

@bors retry

@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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 22, 2023
@bors
Copy link
Contributor

bors commented Dec 22, 2023

⌛ Testing commit 397f4a1 with merge 208dd20...

@bors
Copy link
Contributor

bors commented Dec 22, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 208dd20 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 22, 2023
@bors bors merged commit 208dd20 into rust-lang:master Dec 22, 2023
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Dec 22, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (208dd20): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -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.5% [0.5%, 0.5%] 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.5% [3.5%, 3.5%] 1
Improvements ✅
(primary)
-2.0% [-2.0%, -2.0%] 1
Improvements ✅
(secondary)
-3.5% [-4.8%, -1.7%] 3
All ❌✅ (primary) -2.0% [-2.0%, -2.0%] 1

Cycles

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

Binary size

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

Bootstrap: 674.428s -> 674.366s (-0.01%)
Artifact size: 312.81 MiB -> 312.84 MiB (0.01%)

@apiraino
Copy link
Contributor

since merge happened, I'll assume the I-async nomination can be now removed

@rustbot label -I-async-nominated

@rustbot rustbot removed the I-async-nominated Nominated for discussion during an async working group meeting. label Dec 28, 2023
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 28, 2023
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened rust-lang#118898 as the feature tracking issue.

r? `@compiler-errors`
@fmease fmease added the F-async_for_loop `#![feature(async_for_loop)]` label Feb 28, 2024
calebcartwright pushed a commit to calebcartwright/rust that referenced this pull request Jun 22, 2024
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened rust-lang#118898 as the feature tracking issue.

r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. F-async_for_loop `#![feature(async_for_loop)]` merged-by-bors This PR was explicitly merged by bors. 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-libs Relevant to the library team, which will review and decide on the PR/issue. WG-async Working group: Async & await
Projects
None yet
Development

Successfully merging this pull request may close these issues.