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 more "ref in async" tests #73444

Merged
merged 3 commits into from
May 15, 2024

Conversation

jjonescz
Copy link
Member

Test plan: #72662

All remaining tests from the test plan should be covered:

  • ref / ref struct local in iterator method: RefUnsafeInIteratorAndAsyncTests.LangVersion_*
  • unsafe block in async method in C#12-13: UnsafeTests.UnsafeBlock_InAsyncMethod
  • effect on unsafe context within iterator's body (the breaking change): UnsafeTests.UnsafeContext_LocalFunctionInIterator_BreakingChange_*
  • use ref / ref struct local
    • within / across await: RefUnsafeInIteratorAndAsyncTests.Await_*
    • within / across yield return; in
      • regular iterators: RefUnsafeInIteratorAndAsyncTests.YieldReturn_*
      • async iterators: RefUnsafeInIteratorAndAsyncTests.YieldReturn_*_Async
    • across yield break; in
      • regular iterators: RefUnsafeInIteratorAndAsyncTests.YieldBreak_*
      • async iterators: RefUnsafeInIteratorAndAsyncTests.YieldBreak_*_Async
    • within / across async foreach block: CodeGenAwaitForeachTests.TestWithPattern_Ref*
    • yield in nested block: YieldReturn_*_Across_NestedBlock
    • within async lambda / local function: RefLocalsAndReturnsTests.RefLocal_Async_LocalFunction and similar
    • within iterator local function: RefLocalsAndReturnsTests.RefLocal_Iterator_LocalFunction and similar
    • within property / indexer get iterator: RefUnsafeInIteratorAndAsyncTests.*_Indexer
    • error in async / iterator even in unsafe context - I'm not sure what this means
    • await in elements of stackalloc: StackAllocInitializerTests.TestAwait_Span_02
    • async Task<int[]> M() => ... ReadOnlySpan x = await M();: SpanStackSafetyTests.AwaitAssignSpan
    • Buffer2 b = [await a, await b];: InlineArrayTests.Initialization_RefStruct_Await
    • using (refStruct = ...) { await ...; }: CodeGenAwaitUsingTests.RefStruct_*
    • foreach (var _ in refStruct) { await ...; }: CodeGenAwaitForeachTests.TestWithPattern_RefStructEnumerable_Async
    • interpolation handlers - the ref struct is not used when there are awaits - InterpolationTests.AwaitInHoles_UsesFormat
  • unsafe context > error for await: BindingAsyncTests.BadAwaitInUnsafeContext

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels May 13, 2024
@jjonescz jjonescz marked this pull request as ready for review May 13, 2024 15:01
@jjonescz jjonescz requested a review from a team as a code owner May 13, 2024 15:01
@jjonescz
Copy link
Member Author

@AlekseyTs @cston for reviews, thanks


var expectedDiagnostics = new[]
{
// (6,22): error CS4007: Instance of type 'R' cannot be preserved across 'await' or 'yield' boundary.
Copy link
Contributor

@AlekseyTs AlekseyTs May 14, 2024

Choose a reason for hiding this comment

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

// (6,22): error CS4007: Instance of type 'R' cannot be preserved across 'await' or 'yield' boundary.

It feels like it would be better to report this error across all language versions #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, I will link the issue in a comment. Thanks.

static Task<int> GetInt() => Task.FromResult(42);

[System.Runtime.CompilerServices.InlineArray(4)]
ref struct Buffer
Copy link
Contributor

@AlekseyTs AlekseyTs May 14, 2024

Choose a reason for hiding this comment

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

ref struct Buffer

I would be good to have a test when this is not a ref struct. The scenario will use references underneath. #Resolved

Span<int> y = new(ref x);
yield return y[0];
y = new(ref x);
yield return y[0];
Copy link
Contributor

@AlekseyTs AlekseyTs May 14, 2024

Choose a reason for hiding this comment

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

yield return y[0];

This looks interesting. Do we understand why this works? The span is handled specially. What component does that and where?
I missed the re-assignment #Closed

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 1)

@jjonescz jjonescz enabled auto-merge (squash) May 15, 2024 09:05
@jjonescz jjonescz merged commit b582909 into dotnet:features/RefInAsync May 15, 2024
24 checks passed
@jjonescz jjonescz deleted the RefInAsync-05-Tests branch May 15, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Feature - Ref/Unsafe in Iterators/Async untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants