Skip to content

Add more "ref in async" tests#73444

Merged
jjonescz merged 3 commits intodotnet:features/RefInAsyncfrom
jjonescz:RefInAsync-05-Tests
May 15, 2024
Merged

Add more "ref in async" tests#73444
jjonescz merged 3 commits intodotnet:features/RefInAsyncfrom
jjonescz:RefInAsync-05-Tests

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

@ghost ghost 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers 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