runtime: CollectionsMarshal.AsSpan assertion failure in System.Text.Json tests

Build Information

Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=524311 Build error leg or test failing: System.Text.Json.Tests.WorkItemExecution Pull request: https://github.com/dotnet/runtime/pull/96870

Error Message

Fill the error message using step by step known issues guidance.

{
  "ErrorMessage": "Implementation depends on List<T> always using a T[] and not U[] where U : T.",
  "ErrorPattern": "",
  "BuildRetry": false,
  "ExcludeConsoleLog": false
}

Known issue validation

Build: 🔎 https://dev.azure.com/dnceng-public/public/_build/results?buildId=524311 Error message validated: Implementation depends on List<T> always using a T[] and not U[] where U : T. Result validation: ✅ Known issue matched with the provided build. Validation performed at: 1/12/2024 1:31:48 AM UTC

Report

Build Definition Test Pull Request
524882 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#95583
525560 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96609
526100 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96880
525785 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96913
525988 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96928
525991 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#89472
525957 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96927
525923 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96926
525892 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96201
525842 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96924
525765 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96921
525686 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96916
525621 dotnet/runtime System.Text.Json.Tests.WorkItemExecution
525570 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96880
525477 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96805
525444 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96867
525362 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96880
525344 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96741
525094 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96894
525249 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96896
525236 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96445
525231 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96890
525196 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96214
525140 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96676
525086 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96893
525001 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96741
524968 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96892
524959 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96558
524862 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96889
524798 dotnet/runtime System.Text.Json.Tests.WorkItemExecution
524790 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#95583
524621 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96860
524464 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96805
524458 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96867
524255 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96829
524448 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96858
524210 dotnet/runtime System.Text.Json.Tests.WorkItemExecution
524311 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96870
524291 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96867
524193 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96858
524168 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96805
524110 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96795
524101 dotnet/runtime System.Text.Json.Tests.WorkItemExecution dotnet/runtime#96699

Summary

24-Hour Hit Count 7-Day Hit Count 1-Month Count
0 43 43

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (14 by maintainers)

Commits related to this issue

Most upvoted comments

This is codegen bug in PGO optimized code. The repro is not deterministic since it is triggered by a particular profile.

I have looked at the dump from runfo get-helix-payload -j ec78045b-ffd3-4800-9c13-a3f3db5a5b72 -w System.Text.Json.Tests -o $HOME/helix_payload/System.Text.Json.Tests.

The codegen bug is in the PGO optimized VerifyWeatherForecastWithPOCOs method. The JIT inlines the OrderBy Linq call graph into the method, including the CollectionsMarshal.AsSpan method called by the Linq.

Here is the disassembly of the inlined CollectionsMarshal.AsSpan with the codegen bug:

...
    // Debug.Assert(items is not null, "Implementation depends on List<T> always having an array.");
    0x7fa2699feef8: testq  %r8, %r8
    0x7fa2699feefb: jne    0x7fa2699fef17
    0x7fa2699feefd: movabsq $0x7fa254205690, %rdi     ; string "Implementation depends on List<T> always having an array."
    0x7fa2699fef07: movabsq $0x7fa254200008, %rsi     ; string ""
    0x7fa2699fef11: callq  *-0x10151d47(%rip)

    // if ((uint)size > (uint)items.Length)
    0x7fa2699fef17: movq   -0x418(%rbp), %r8 items
    0x7fa2699fef1e: movl   -0x1c0(%rbp), %ecx length
    0x7fa2699fef24: cmpl   %ecx, 0x8(%r8) items.Length
    0x7fa2699fef28: jb     0x7fa2699ffe5c

    // Debug.Assert(typeof(T[]) == list._items.GetType(), "Implementation depends on List<T> always using a T[] and not U[] where U : T.");
    // BUG: The JIT incorrectly evaluated typeof(T[]) == list._items.GetType() as constant false and just left the null check
    0x7fa2699fef2e: movq   -0x400(%rbp), %rax
    0x7fa2699fef35: movq   0x8(%rax), %rdi
    0x7fa2699fef39: cmpb   %dil, (%rdi) // null check
    0x7fa2699fef3c: movabsq $0x7fa254228198, %rdi     ; string "Implementation depends on List<T> always using a T[] and not U[] where U : T."
    0x7fa2699fef46: movabsq $0x7fa254200008, %rsi     ; string ""
    0x7fa2699fef50: callq  *-0x10151d86(%rip) System.Diagnostics.Debug.Fail
...

Could it be https://github.com/dotnet/runtime/pull/96466 ?

Yes, that change included a fix in HasSameTypeDefAs that broke implementation of compareTypesForEquality. Thank you for tracking it down!