From 24fa558ae19b238a88b11fab38268cc057a64485 Mon Sep 17 00:00:00 2001 From: Rikki Gibson Date: Tue, 7 May 2024 18:19:59 -0700 Subject: [PATCH] Use a simple temp instead of InlineArray1 (#73086) --- .../LocalRewriter_CollectionExpression.cs | 47 +- .../Lowering/SyntheticBoundNodeFactory.cs | 15 + .../Semantics/CollectionExpressionTests.cs | 1743 +++++++++-------- .../Emit2/Semantics/ParamsCollectionTests.cs | 87 +- .../Symbol/Symbols/MissingSpecialMember.cs | 2 + .../Core/Portable/WellKnownMember.cs | 2 + .../Core/Portable/WellKnownMembers.cs | 18 + .../WellKnownTypeValidationTests.vb | 8 +- 8 files changed, 1072 insertions(+), 850 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs index ef6e145345c23..6cbecefe3f188 100644 --- a/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs +++ b/src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_CollectionExpression.cs @@ -195,8 +195,7 @@ private BoundExpression VisitArrayOrSpanCollectionExpression(BoundCollectionExpr syntax, elementType, elements, - asReadOnlySpan: collectionTypeKind == CollectionExpressionTypeKind.ReadOnlySpan, - _additionalLocals); + asReadOnlySpan: collectionTypeKind == CollectionExpressionTypeKind.ReadOnlySpan); } Debug.Assert(IsAllocatingRefStructCollectionExpression(node, collectionTypeKind, elementType.Type, _compilation)); @@ -243,7 +242,7 @@ private BoundExpression VisitCollectionInitializerCollectionExpression(BoundColl // Create a temp for the collection. BoundAssignmentOperator assignmentToTemp; - BoundLocal temp = _factory.StoreToTemp(rewrittenReceiver, out assignmentToTemp, isKnownToReferToTempIfReferenceType: true); + BoundLocal temp = _factory.StoreToTemp(rewrittenReceiver, out assignmentToTemp); var sideEffects = ArrayBuilder.GetInstance(elements.Length + 1); sideEffects.Add(assignmentToTemp); @@ -429,16 +428,33 @@ private BoundExpression CreateAndPopulateSpanFromInlineArray( SyntaxNode syntax, TypeWithAnnotations elementType, ImmutableArray elements, - bool asReadOnlySpan, - ArrayBuilder locals) + bool asReadOnlySpan) { Debug.Assert(elements.Length > 0); Debug.Assert(elements.All(e => e is BoundExpression)); Debug.Assert(_factory.ModuleBuilderOpt is { }); Debug.Assert(_diagnostics.DiagnosticBag is { }); Debug.Assert(_compilation.Assembly.RuntimeSupportsInlineArrayTypes); + Debug.Assert(_additionalLocals is { }); int arrayLength = elements.Length; + if (arrayLength == 1 + && _factory.WellKnownMember(asReadOnlySpan + ? WellKnownMember.System_ReadOnlySpan_T__ctor_ref_readonly_T + : WellKnownMember.System_Span_T__ctor_ref_T, isOptional: true) is MethodSymbol spanRefConstructor) + { + // Special case: no need to create an InlineArray1 type. Just use a temp of the element type. + var spanType = _factory + .WellKnownType(asReadOnlySpan ? WellKnownType.System_ReadOnlySpan_T : WellKnownType.System_Span_T) + .Construct([elementType]); + var constructor = spanRefConstructor.AsMember(spanType); + var element = VisitExpression((BoundExpression)elements[0]); + var temp = _factory.StoreToTemp(element, out var assignment); + _additionalLocals.Add(temp.LocalSymbol); + var call = _factory.New(constructor, arguments: [temp], argumentRefKinds: [asReadOnlySpan ? RefKindExtensions.StrictIn : RefKind.Ref]); + return _factory.Sequence([assignment], call); + } + var inlineArrayType = _factory.ModuleBuilderOpt.EnsureInlineArrayTypeExists(syntax, _factory, arrayLength, _diagnostics.DiagnosticBag).Construct(ImmutableArray.Create(elementType)); Debug.Assert(inlineArrayType.HasInlineArrayAttribute(out int inlineArrayLength) && inlineArrayLength == arrayLength); @@ -449,10 +465,10 @@ private BoundExpression CreateAndPopulateSpanFromInlineArray( // Create an inline array and assign to a local. // var tmp = new <>y__InlineArrayN(); BoundAssignmentOperator assignmentToTemp; - BoundLocal inlineArrayLocal = _factory.StoreToTemp(new BoundDefaultExpression(syntax, inlineArrayType), out assignmentToTemp, isKnownToReferToTempIfReferenceType: true); + BoundLocal inlineArrayLocal = _factory.StoreToTemp(new BoundDefaultExpression(syntax, inlineArrayType), out assignmentToTemp); var sideEffects = ArrayBuilder.GetInstance(); sideEffects.Add(assignmentToTemp); - locals.Add(inlineArrayLocal.LocalSymbol); + _additionalLocals.Add(inlineArrayLocal.LocalSymbol); // Populate the inline array. // InlineArrayElementRef<<>y__InlineArrayN, ElementType>(ref tmp, 0) = element0; @@ -604,8 +620,7 @@ bool tryGetToArrayMethod(TypeSymbol spreadTypeOriginalDefinition, WellKnownType // int index = 0; BoundLocal indexTemp = _factory.StoreToTemp( _factory.Literal(0), - out assignmentToTemp, - isKnownToReferToTempIfReferenceType: true); + out assignmentToTemp); localsBuilder.Add(indexTemp); sideEffects.Add(assignmentToTemp); @@ -615,8 +630,7 @@ bool tryGetToArrayMethod(TypeSymbol spreadTypeOriginalDefinition, WellKnownType ImmutableArray.Create(GetKnownLengthExpression(elements, numberIncludingLastSpread, localsBuilder)), initializerOpt: null, arrayType), - out assignmentToTemp, - isKnownToReferToTempIfReferenceType: true); + out assignmentToTemp); localsBuilder.Add(arrayTemp); sideEffects.Add(assignmentToTemp); @@ -903,7 +917,7 @@ private BoundExpression CreateAndPopulateList(BoundCollectionExpression node, Ty // If we use optimizations, we know the length of the resulting list, and we store it in a temp so we can pass it to List.ctor(int32) and to CollectionsMarshal.SetCount // int knownLengthTemp = N + s1.Length + ...; - knownLengthTemp = _factory.StoreToTemp(knownLengthExpression, out assignmentToTemp, isKnownToReferToTempIfReferenceType: true); + knownLengthTemp = _factory.StoreToTemp(knownLengthExpression, out assignmentToTemp); localsBuilder.Add(knownLengthTemp); sideEffects.Add(assignmentToTemp); @@ -924,7 +938,7 @@ private BoundExpression CreateAndPopulateList(BoundCollectionExpression node, Ty } // Create a temp for the list. - BoundLocal listTemp = _factory.StoreToTemp(rewrittenReceiver, out assignmentToTemp, isKnownToReferToTempIfReferenceType: true); + BoundLocal listTemp = _factory.StoreToTemp(rewrittenReceiver, out assignmentToTemp); localsBuilder.Add(listTemp); sideEffects.Add(assignmentToTemp); @@ -940,7 +954,7 @@ private BoundExpression CreateAndPopulateList(BoundCollectionExpression node, Ty sideEffects.Add(_factory.Call(receiver: null, setCount, listTemp, knownLengthTemp)); // var span = CollectionsMarshal.AsSpan args) => new BoundObjectCreationExpression(Syntax, ctor, args) { WasCompilerGenerated = true }; + public BoundObjectCreationExpression New(MethodSymbol constructor, ImmutableArray arguments, ImmutableArray argumentRefKinds) + => new BoundObjectCreationExpression( + Syntax, + constructor, + arguments, + argumentNamesOpt: default, + argumentRefKinds, + expanded: false, + argsToParamsOpt: default, + defaultArguments: default, + constantValueOpt: null, + initializerExpressionOpt: null, + constructor.ContainingType) + { WasCompilerGenerated = true }; + public BoundObjectCreationExpression New(WellKnownMember wm, ImmutableArray args) { var ctor = WellKnownMethod(wm); diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs index 47f7b9a565775..8dc5c8c34570d 100644 --- a/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Semantics/CollectionExpressionTests.cs @@ -13967,7 +13967,7 @@ static void M2() comp, symbolValidator: module => { - AssertEx.Equal(new[] { "<>y__InlineArray1", "<>y__InlineArray3" }, getInlineArrayTypeNames(module)); + AssertEx.Equal(new[] { "<>y__InlineArray3" }, getInlineArrayTypeNames(module)); }, verify: Verification.Skipped); @@ -18053,6 +18053,8 @@ public class MyCollectionBuilder var comp = CreateCompilation(sourceA, targetFramework: TargetFramework.Net80); var refA = AsReference(comp, useCompilationReference); + // https://github.com/dotnet/roslyn/issues/73085 + // Test hits an assertion failure when collection-expr with a single element is used here string sourceB = """ #pragma warning disable 219 class Program @@ -18060,7 +18062,7 @@ class Program static void Main() { MyCollection x = []; - MyCollection y = ["2"]; + MyCollection y = ["2", "3"]; MyCollection z = new(); } } @@ -18069,14 +18071,17 @@ static void Main() comp.MakeTypeMissing(SpecialType.System_Int32); comp.VerifyEmitDiagnostics( // (7,34): error CS0518: Predefined type 'System.Int32' is not defined or imported - // MyCollection y = ["2"]; - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, @"[""2""]").WithArguments("System.Int32").WithLocation(7, 34), + // MyCollection y = ["2", "3"]; + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, @"[""2"", ""3""]").WithArguments("System.Int32").WithLocation(7, 34), // (7,34): error CS0518: Predefined type 'System.Int32' is not defined or imported - // MyCollection y = ["2"]; - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, @"[""2""]").WithArguments("System.Int32").WithLocation(7, 34), + // MyCollection y = ["2", "3"]; + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, @"[""2"", ""3""]").WithArguments("System.Int32").WithLocation(7, 34), // (7,34): error CS0518: Predefined type 'System.Int32' is not defined or imported - // MyCollection y = ["2"]; - Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, @"[""2""]").WithArguments("System.Int32").WithLocation(7, 34)); + // MyCollection y = ["2", "3"]; + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, @"[""2"", ""3""]").WithArguments("System.Int32").WithLocation(7, 34), + // (7,34): error CS0518: Predefined type 'System.Int32' is not defined or imported + // MyCollection y = ["2", "3"]; + Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, @"[""2"", ""3""]").WithArguments("System.Int32").WithLocation(7, 34)); } [Fact] @@ -20911,6 +20916,397 @@ static void Report(MyCollection c) Diagnostic(ErrorCode.ERR_CollectionExpressionEscape, "[x, y, z]").WithArguments("MyCollection").WithLocation(12, 60)); } + [Fact] + public void Span_SingleElement() + { + var source = """ + using System; + + class Program + { + static void Main() => M(1); + + static void M(int x) + { + Span y = [x]; + x++; + Console.Write(y[0]); + Console.Write(x); + } + } + """; + + var verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net80, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("12")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 36 (0x24) + .maxstack 2 + .locals init (System.Span V_0, //y + int V_1) + IL_0000: ldarg.0 + IL_0001: stloc.1 + IL_0002: ldloca.s V_1 + IL_0004: newobj "System.Span..ctor(ref int)" + IL_0009: stloc.0 + IL_000a: ldarg.0 + IL_000b: ldc.i4.1 + IL_000c: add + IL_000d: starg.s V_0 + IL_000f: ldloca.s V_0 + IL_0011: ldc.i4.0 + IL_0012: call "ref int System.Span.this[int].get" + IL_0017: ldind.i4 + IL_0018: call "void System.Console.Write(int)" + IL_001d: ldarg.0 + IL_001e: call "void System.Console.Write(int)" + IL_0023: ret + } + """); + + verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net70, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("12")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 43 (0x2b) + .maxstack 5 + .locals init (System.Span V_0) //y + IL_0000: ldloca.s V_0 + IL_0002: ldc.i4.1 + IL_0003: newarr "int" + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldarg.0 + IL_000b: stelem.i4 + IL_000c: call "System.Span..ctor(int[])" + IL_0011: ldarg.0 + IL_0012: ldc.i4.1 + IL_0013: add + IL_0014: starg.s V_0 + IL_0016: ldloca.s V_0 + IL_0018: ldc.i4.0 + IL_0019: call "ref int System.Span.this[int].get" + IL_001e: ldind.i4 + IL_001f: call "void System.Console.Write(int)" + IL_0024: ldarg.0 + IL_0025: call "void System.Console.Write(int)" + IL_002a: ret + } + """); + } + + [Fact] + public void Span_SingleElement_TempsAreNotReused() + { + var source = """ + using System; + + class Program + { + static void Main() => M(1); + + static void M(int x) + { + { + Span y = [x]; + Console.Write(y[0]); + y[0]++; + } + { + Span y = [x]; + Console.Write(y[0]); + } + } + } + """; + + var verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net80, options: TestOptions.ReleaseExe, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("11")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 62 (0x3e) + .maxstack 3 + .locals init (int V_0, + int V_1, + System.Span V_2, //y + System.Span V_3) //y + IL_0000: ldarg.0 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: newobj "System.Span..ctor(ref int)" + IL_0009: stloc.2 + IL_000a: ldloca.s V_2 + IL_000c: ldc.i4.0 + IL_000d: call "ref int System.Span.this[int].get" + IL_0012: ldind.i4 + IL_0013: call "void System.Console.Write(int)" + IL_0018: ldloca.s V_2 + IL_001a: ldc.i4.0 + IL_001b: call "ref int System.Span.this[int].get" + IL_0020: dup + IL_0021: ldind.i4 + IL_0022: ldc.i4.1 + IL_0023: add + IL_0024: stind.i4 + IL_0025: ldarg.0 + IL_0026: stloc.1 + IL_0027: ldloca.s V_1 + IL_0029: newobj "System.Span..ctor(ref int)" + IL_002e: stloc.3 + IL_002f: ldloca.s V_3 + IL_0031: ldc.i4.0 + IL_0032: call "ref int System.Span.this[int].get" + IL_0037: ldind.i4 + IL_0038: call "void System.Console.Write(int)" + IL_003d: ret + } + """); + + verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net70, options: TestOptions.ReleaseExe, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("11")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 76 (0x4c) + .maxstack 5 + .locals init (System.Span V_0, //y + System.Span V_1) //y + IL_0000: ldloca.s V_0 + IL_0002: ldc.i4.1 + IL_0003: newarr "int" + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldarg.0 + IL_000b: stelem.i4 + IL_000c: call "System.Span..ctor(int[])" + IL_0011: ldloca.s V_0 + IL_0013: ldc.i4.0 + IL_0014: call "ref int System.Span.this[int].get" + IL_0019: ldind.i4 + IL_001a: call "void System.Console.Write(int)" + IL_001f: ldloca.s V_0 + IL_0021: ldc.i4.0 + IL_0022: call "ref int System.Span.this[int].get" + IL_0027: dup + IL_0028: ldind.i4 + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stind.i4 + IL_002c: ldloca.s V_1 + IL_002e: ldc.i4.1 + IL_002f: newarr "int" + IL_0034: dup + IL_0035: ldc.i4.0 + IL_0036: ldarg.0 + IL_0037: stelem.i4 + IL_0038: call "System.Span..ctor(int[])" + IL_003d: ldloca.s V_1 + IL_003f: ldc.i4.0 + IL_0040: call "ref int System.Span.this[int].get" + IL_0045: ldind.i4 + IL_0046: call "void System.Console.Write(int)" + IL_004b: ret + } + """); + } + + [Fact] + public void Span_SingleElement_TempsAreNotReused_SameBlock() + { + var source = """ + using System; + + class Program + { + static void Main() => M(1); + + static void M(int x) + { + Span y = [x]; + Console.Write(y[0]); + y[0]++; + + Span z = [x]; + Console.Write(z[0]); + } + } + """; + + var verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net80, options: TestOptions.ReleaseExe, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("11")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 62 (0x3e) + .maxstack 3 + .locals init (System.Span V_0, //y + System.Span V_1, //z + int V_2, + int V_3) + IL_0000: ldarg.0 + IL_0001: stloc.2 + IL_0002: ldloca.s V_2 + IL_0004: newobj "System.Span..ctor(ref int)" + IL_0009: stloc.0 + IL_000a: ldloca.s V_0 + IL_000c: ldc.i4.0 + IL_000d: call "ref int System.Span.this[int].get" + IL_0012: ldind.i4 + IL_0013: call "void System.Console.Write(int)" + IL_0018: ldloca.s V_0 + IL_001a: ldc.i4.0 + IL_001b: call "ref int System.Span.this[int].get" + IL_0020: dup + IL_0021: ldind.i4 + IL_0022: ldc.i4.1 + IL_0023: add + IL_0024: stind.i4 + IL_0025: ldarg.0 + IL_0026: stloc.3 + IL_0027: ldloca.s V_3 + IL_0029: newobj "System.Span..ctor(ref int)" + IL_002e: stloc.1 + IL_002f: ldloca.s V_1 + IL_0031: ldc.i4.0 + IL_0032: call "ref int System.Span.this[int].get" + IL_0037: ldind.i4 + IL_0038: call "void System.Console.Write(int)" + IL_003d: ret + } + """); + + verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net70, options: TestOptions.ReleaseExe, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("11")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 76 (0x4c) + .maxstack 5 + .locals init (System.Span V_0, //y + System.Span V_1) //z + IL_0000: ldloca.s V_0 + IL_0002: ldc.i4.1 + IL_0003: newarr "int" + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldarg.0 + IL_000b: stelem.i4 + IL_000c: call "System.Span..ctor(int[])" + IL_0011: ldloca.s V_0 + IL_0013: ldc.i4.0 + IL_0014: call "ref int System.Span.this[int].get" + IL_0019: ldind.i4 + IL_001a: call "void System.Console.Write(int)" + IL_001f: ldloca.s V_0 + IL_0021: ldc.i4.0 + IL_0022: call "ref int System.Span.this[int].get" + IL_0027: dup + IL_0028: ldind.i4 + IL_0029: ldc.i4.1 + IL_002a: add + IL_002b: stind.i4 + IL_002c: ldloca.s V_1 + IL_002e: ldc.i4.1 + IL_002f: newarr "int" + IL_0034: dup + IL_0035: ldc.i4.0 + IL_0036: ldarg.0 + IL_0037: stelem.i4 + IL_0038: call "System.Span..ctor(int[])" + IL_003d: ldloca.s V_1 + IL_003f: ldc.i4.0 + IL_0040: call "ref int System.Span.this[int].get" + IL_0045: ldind.i4 + IL_0046: call "void System.Console.Write(int)" + IL_004b: ret + } + """); + } + + [Fact] + public void ReadOnlySpan_SingleElement() + { + var source = """ + using System; + + class Program + { + static void Main() => M(1); + + static void M(int x) + { + ReadOnlySpan y = [x]; + x++; + Console.Write(y[0]); + Console.Write(x); + } + } + """; + + var verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net80, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("12")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 36 (0x24) + .maxstack 2 + .locals init (System.ReadOnlySpan V_0, //y + int V_1) + IL_0000: ldarg.0 + IL_0001: stloc.1 + IL_0002: ldloca.s V_1 + IL_0004: newobj "System.ReadOnlySpan..ctor(in int)" + IL_0009: stloc.0 + IL_000a: ldarg.0 + IL_000b: ldc.i4.1 + IL_000c: add + IL_000d: starg.s V_0 + IL_000f: ldloca.s V_0 + IL_0011: ldc.i4.0 + IL_0012: call "ref readonly int System.ReadOnlySpan.this[int].get" + IL_0017: ldind.i4 + IL_0018: call "void System.Console.Write(int)" + IL_001d: ldarg.0 + IL_001e: call "void System.Console.Write(int)" + IL_0023: ret + } + """); + + verifier = CompileAndVerify(source, targetFramework: TargetFramework.Net70, verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("12")); + verifier.VerifyDiagnostics(); + + verifier.VerifyIL("Program.M", """ + { + // Code size 43 (0x2b) + .maxstack 5 + .locals init (System.ReadOnlySpan V_0) //y + IL_0000: ldloca.s V_0 + IL_0002: ldc.i4.1 + IL_0003: newarr "int" + IL_0008: dup + IL_0009: ldc.i4.0 + IL_000a: ldarg.0 + IL_000b: stelem.i4 + IL_000c: call "System.ReadOnlySpan..ctor(int[])" + IL_0011: ldarg.0 + IL_0012: ldc.i4.1 + IL_0013: add + IL_0014: starg.s V_0 + IL_0016: ldloca.s V_0 + IL_0018: ldc.i4.0 + IL_0019: call "ref readonly int System.ReadOnlySpan.this[int].get" + IL_001e: ldind.i4 + IL_001f: call "void System.Console.Write(int)" + IL_0024: ldarg.0 + IL_0025: call "void System.Console.Write(int)" + IL_002a: ret + } + """); + } + [CombinatorialData] [Theory] public void SpanArgument_01([CombinatorialValues(TargetFramework.Net70, TargetFramework.Net80)] TargetFramework targetFramework) @@ -20936,81 +21332,48 @@ static void Main() new[] { source, s_collectionExtensionsWithSpan }, targetFramework: targetFramework, verify: Verification.Skipped, - symbolValidator: module => - { - if (targetFramework == TargetFramework.Net80) - { - var synthesizedType = module.GlobalNamespace.GetTypeMember("<>y__InlineArray1"); - Assert.Equal("<>y__InlineArray1", synthesizedType.ToTestDisplayString()); - Assert.Equal("<>y__InlineArray1`1", synthesizedType.MetadataName); - } - }, expectedOutput: IncludeExpectedOutput("[1], [2], [3], [4], ")); if (targetFramework == TargetFramework.Net80) { verifier.VerifyIL("Program.Main", """ { - // Code size 161 (0xa1) + // Code size 87 (0x57) .maxstack 2 - .locals init (<>y__InlineArray1 V_0, - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3, + .locals init (object V_0, + int? V_1, + int? V_2, + object V_3, System.Span V_4, System.ReadOnlySpan V_5) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_0 - IL_0019: ldc.i4.1 - IL_001a: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_001f: call "void Program.F1(System.Span)" - IL_0024: ldloca.s V_1 - IL_0026: initobj "<>y__InlineArray1" - IL_002c: ldloca.s V_1 - IL_002e: ldc.i4.0 - IL_002f: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_0034: ldc.i4.2 - IL_0035: newobj "int?..ctor(int)" - IL_003a: stobj "int?" - IL_003f: ldloca.s V_1 - IL_0041: ldc.i4.1 - IL_0042: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_0047: call "void Program.F2(System.ReadOnlySpan)" - IL_004c: ldloca.s V_2 - IL_004e: initobj "<>y__InlineArray1" - IL_0054: ldloca.s V_2 - IL_0056: ldc.i4.0 - IL_0057: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_005c: ldc.i4.3 - IL_005d: newobj "int?..ctor(int)" - IL_0062: stobj "int?" - IL_0067: ldloca.s V_2 - IL_0069: ldc.i4.1 - IL_006a: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_006f: stloc.s V_4 - IL_0071: ldloca.s V_4 - IL_0073: call "void Program.F3(in System.Span)" - IL_0078: ldloca.s V_3 - IL_007a: initobj "<>y__InlineArray1" - IL_0080: ldloca.s V_3 - IL_0082: ldc.i4.0 - IL_0083: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0088: ldc.i4.4 - IL_0089: box "int" - IL_008e: stind.ref - IL_008f: ldloca.s V_3 - IL_0091: ldc.i4.1 - IL_0092: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0097: stloc.s V_5 - IL_0099: ldloca.s V_5 - IL_009b: call "void Program.F4(in System.ReadOnlySpan)" - IL_00a0: ret + IL_0000: ldc.i4.1 + IL_0001: box "int" + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: newobj "System.Span..ctor(ref object)" + IL_000e: call "void Program.F1(System.Span)" + IL_0013: ldloca.s V_1 + IL_0015: ldc.i4.2 + IL_0016: call "int?..ctor(int)" + IL_001b: ldloca.s V_1 + IL_001d: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_0022: call "void Program.F2(System.ReadOnlySpan)" + IL_0027: ldloca.s V_2 + IL_0029: ldc.i4.3 + IL_002a: call "int?..ctor(int)" + IL_002f: ldloca.s V_2 + IL_0031: newobj "System.Span..ctor(ref int?)" + IL_0036: stloc.s V_4 + IL_0038: ldloca.s V_4 + IL_003a: call "void Program.F3(in System.Span)" + IL_003f: ldc.i4.4 + IL_0040: box "int" + IL_0045: stloc.3 + IL_0046: ldloca.s V_3 + IL_0048: newobj "System.ReadOnlySpan..ctor(in object)" + IL_004d: stloc.s V_5 + IL_004f: ldloca.s V_5 + IL_0051: call "void Program.F4(in System.ReadOnlySpan)" + IL_0056: ret } """); } @@ -21098,65 +21461,41 @@ static void Main() expectedOutput: IncludeExpectedOutput("[1], [2], [3], [4], ")); verifier.VerifyIL("Program.Main", """ { - // Code size 149 (0x95) - .maxstack 2 - .locals init (<>y__InlineArray1 V_0, - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_0 - IL_0019: ldc.i4.1 - IL_001a: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_001f: call "S Program.ReturnsStruct(System.Span)" - IL_0024: pop - IL_0025: ldloca.s V_1 - IL_0027: initobj "<>y__InlineArray1" - IL_002d: ldloca.s V_1 - IL_002f: ldc.i4.0 - IL_0030: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0035: ldc.i4.2 - IL_0036: box "int" - IL_003b: stind.ref - IL_003c: ldloca.s V_1 - IL_003e: ldc.i4.1 - IL_003f: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0044: call "R Program.ReturnsRefStruct(System.Span)" - IL_0049: pop - IL_004a: ldloca.s V_2 - IL_004c: initobj "<>y__InlineArray1" - IL_0052: ldloca.s V_2 - IL_0054: ldc.i4.0 - IL_0055: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_005a: ldc.i4.3 - IL_005b: box "int" - IL_0060: stind.ref - IL_0061: ldloca.s V_2 - IL_0063: ldc.i4.1 - IL_0064: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0069: call "ref int Program.ReturnsRef(System.Span)" - IL_006e: pop - IL_006f: ldloca.s V_3 - IL_0071: initobj "<>y__InlineArray1" - IL_0077: ldloca.s V_3 - IL_0079: ldc.i4.0 - IL_007a: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_007f: ldc.i4.4 - IL_0080: box "int" - IL_0085: stind.ref - IL_0086: ldloca.s V_3 - IL_0088: ldc.i4.1 - IL_0089: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_008e: call "ref readonly int Program.ReturnsRefReadOnly(System.Span)" - IL_0093: pop - IL_0094: ret + // Code size 81 (0x51) + .maxstack 1 + .locals init (object V_0, + object V_1, + object V_2, + object V_3) + IL_0000: ldc.i4.1 + IL_0001: box "int" + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: newobj "System.Span..ctor(ref object)" + IL_000e: call "S Program.ReturnsStruct(System.Span)" + IL_0013: pop + IL_0014: ldc.i4.2 + IL_0015: box "int" + IL_001a: stloc.1 + IL_001b: ldloca.s V_1 + IL_001d: newobj "System.Span..ctor(ref object)" + IL_0022: call "R Program.ReturnsRefStruct(System.Span)" + IL_0027: pop + IL_0028: ldc.i4.3 + IL_0029: box "int" + IL_002e: stloc.2 + IL_002f: ldloca.s V_2 + IL_0031: newobj "System.Span..ctor(ref object)" + IL_0036: call "ref int Program.ReturnsRef(System.Span)" + IL_003b: pop + IL_003c: ldc.i4.4 + IL_003d: box "int" + IL_0042: stloc.3 + IL_0043: ldloca.s V_3 + IL_0045: newobj "System.Span..ctor(ref object)" + IL_004a: call "ref readonly int Program.ReturnsRefReadOnly(System.Span)" + IL_004f: pop + IL_0050: ret } """); } @@ -21189,51 +21528,33 @@ static void Main() expectedOutput: IncludeExpectedOutput("[2], [3], [4], ")); verifier.VerifyIL("Program.Main", """ { - // Code size 112 (0x70) - .maxstack 2 - .locals init (<>y__InlineArray1 V_0, - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.2 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_0 - IL_0019: ldc.i4.1 - IL_001a: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_001f: call "R Program.ReturnsRefStruct(scoped System.Span)" - IL_0024: pop - IL_0025: ldloca.s V_1 - IL_0027: initobj "<>y__InlineArray1" - IL_002d: ldloca.s V_1 - IL_002f: ldc.i4.0 - IL_0030: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0035: ldc.i4.3 - IL_0036: box "int" - IL_003b: stind.ref - IL_003c: ldloca.s V_1 - IL_003e: ldc.i4.1 - IL_003f: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0044: call "ref int Program.ReturnsRef(scoped System.Span)" - IL_0049: pop - IL_004a: ldloca.s V_2 - IL_004c: initobj "<>y__InlineArray1" - IL_0052: ldloca.s V_2 - IL_0054: ldc.i4.0 - IL_0055: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_005a: ldc.i4.4 - IL_005b: box "int" - IL_0060: stind.ref - IL_0061: ldloca.s V_2 - IL_0063: ldc.i4.1 - IL_0064: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0069: call "ref readonly int Program.ReturnsRefReadOnly(scoped System.Span)" - IL_006e: pop - IL_006f: ret + // Code size 61 (0x3d) + .maxstack 1 + .locals init (object V_0, + object V_1, + object V_2) + IL_0000: ldc.i4.2 + IL_0001: box "int" + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: newobj "System.Span..ctor(ref object)" + IL_000e: call "R Program.ReturnsRefStruct(scoped System.Span)" + IL_0013: pop + IL_0014: ldc.i4.3 + IL_0015: box "int" + IL_001a: stloc.1 + IL_001b: ldloca.s V_1 + IL_001d: newobj "System.Span..ctor(ref object)" + IL_0022: call "ref int Program.ReturnsRef(scoped System.Span)" + IL_0027: pop + IL_0028: ldc.i4.4 + IL_0029: box "int" + IL_002e: stloc.2 + IL_002f: ldloca.s V_2 + IL_0031: newobj "System.Span..ctor(ref object)" + IL_0036: call "ref readonly int Program.ReturnsRefReadOnly(scoped System.Span)" + IL_003b: pop + IL_003c: ret } """); } @@ -21318,105 +21639,69 @@ static void Main() expectedOutput: IncludeExpectedOutput("[1], [2], [3], [4], [5], [6], ")); verifier.VerifyIL("Program.Main", """ { - // Code size 280 (0x118) + // Code size 160 (0xa0) .maxstack 3 .locals init (S V_0, //s R1 V_1, //r1 R2 V_2, //r2 - <>y__InlineArray1 V_3, - <>y__InlineArray1 V_4, - <>y__InlineArray1 V_5, - <>y__InlineArray1 V_6, - <>y__InlineArray1 V_7, - <>y__InlineArray1 V_8) + int? V_3, + int? V_4, + int? V_5, + int? V_6, + int? V_7, + int? V_8) IL_0000: ldloca.s V_0 IL_0002: initobj "S" IL_0008: ldloca.s V_0 IL_000a: ldloca.s V_3 - IL_000c: initobj "<>y__InlineArray1" + IL_000c: ldc.i4.1 + IL_000d: call "int?..ctor(int)" IL_0012: ldloca.s V_3 - IL_0014: ldc.i4.0 - IL_0015: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_001a: ldc.i4.1 - IL_001b: newobj "int?..ctor(int)" - IL_0020: stobj "int?" - IL_0025: ldloca.s V_3 - IL_0027: ldc.i4.1 - IL_0028: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_002d: call "void S.M(System.ReadOnlySpan)" - IL_0032: ldloca.s V_0 - IL_0034: ldloca.s V_4 - IL_0036: initobj "<>y__InlineArray1" - IL_003c: ldloca.s V_4 - IL_003e: ldc.i4.0 - IL_003f: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_0044: ldc.i4.2 - IL_0045: newobj "int?..ctor(int)" - IL_004a: stobj "int?" - IL_004f: ldloca.s V_4 - IL_0051: ldc.i4.1 - IL_0052: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_0057: ldnull - IL_0058: call "void S.this[System.ReadOnlySpan].set" - IL_005d: ldloca.s V_1 - IL_005f: initobj "R1" - IL_0065: ldloca.s V_1 - IL_0067: ldloca.s V_5 - IL_0069: initobj "<>y__InlineArray1" - IL_006f: ldloca.s V_5 - IL_0071: ldc.i4.0 - IL_0072: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_0077: ldc.i4.3 - IL_0078: newobj "int?..ctor(int)" - IL_007d: stobj "int?" - IL_0082: ldloca.s V_5 - IL_0084: ldc.i4.1 - IL_0085: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_008a: call "void R1.M(System.ReadOnlySpan)" - IL_008f: ldloca.s V_1 - IL_0091: ldloca.s V_6 - IL_0093: initobj "<>y__InlineArray1" - IL_0099: ldloca.s V_6 - IL_009b: ldc.i4.0 - IL_009c: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_00a1: ldc.i4.4 - IL_00a2: newobj "int?..ctor(int)" - IL_00a7: stobj "int?" - IL_00ac: ldloca.s V_6 - IL_00ae: ldc.i4.1 - IL_00af: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_00b4: ldnull - IL_00b5: call "void R1.this[System.ReadOnlySpan].set" - IL_00ba: ldloca.s V_2 - IL_00bc: initobj "R2" - IL_00c2: ldloca.s V_2 - IL_00c4: ldloca.s V_7 - IL_00c6: initobj "<>y__InlineArray1" - IL_00cc: ldloca.s V_7 - IL_00ce: ldc.i4.0 - IL_00cf: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_00d4: ldc.i4.5 - IL_00d5: newobj "int?..ctor(int)" - IL_00da: stobj "int?" - IL_00df: ldloca.s V_7 - IL_00e1: ldc.i4.1 - IL_00e2: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_00e7: call "void R2.M(scoped System.ReadOnlySpan)" - IL_00ec: ldloca.s V_2 - IL_00ee: ldloca.s V_8 - IL_00f0: initobj "<>y__InlineArray1" - IL_00f6: ldloca.s V_8 - IL_00f8: ldc.i4.0 - IL_00f9: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_00fe: ldc.i4.6 - IL_00ff: newobj "int?..ctor(int)" - IL_0104: stobj "int?" - IL_0109: ldloca.s V_8 - IL_010b: ldc.i4.1 - IL_010c: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_0111: ldnull - IL_0112: call "void R2.this[scoped System.ReadOnlySpan].set" - IL_0117: ret + IL_0014: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_0019: call "void S.M(System.ReadOnlySpan)" + IL_001e: ldloca.s V_0 + IL_0020: ldloca.s V_4 + IL_0022: ldc.i4.2 + IL_0023: call "int?..ctor(int)" + IL_0028: ldloca.s V_4 + IL_002a: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_002f: ldnull + IL_0030: call "void S.this[System.ReadOnlySpan].set" + IL_0035: ldloca.s V_1 + IL_0037: initobj "R1" + IL_003d: ldloca.s V_1 + IL_003f: ldloca.s V_5 + IL_0041: ldc.i4.3 + IL_0042: call "int?..ctor(int)" + IL_0047: ldloca.s V_5 + IL_0049: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_004e: call "void R1.M(System.ReadOnlySpan)" + IL_0053: ldloca.s V_1 + IL_0055: ldloca.s V_6 + IL_0057: ldc.i4.4 + IL_0058: call "int?..ctor(int)" + IL_005d: ldloca.s V_6 + IL_005f: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_0064: ldnull + IL_0065: call "void R1.this[System.ReadOnlySpan].set" + IL_006a: ldloca.s V_2 + IL_006c: initobj "R2" + IL_0072: ldloca.s V_2 + IL_0074: ldloca.s V_7 + IL_0076: ldc.i4.5 + IL_0077: call "int?..ctor(int)" + IL_007c: ldloca.s V_7 + IL_007e: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_0083: call "void R2.M(scoped System.ReadOnlySpan)" + IL_0088: ldloca.s V_2 + IL_008a: ldloca.s V_8 + IL_008c: ldc.i4.6 + IL_008d: call "int?..ctor(int)" + IL_0092: ldloca.s V_8 + IL_0094: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_0099: ldnull + IL_009a: call "void R2.this[scoped System.ReadOnlySpan].set" + IL_009f: ret } """); } @@ -21456,73 +21741,49 @@ static void Main() expectedOutput: IncludeExpectedOutput("[3], [4], [5], [6], ")); verifier.VerifyIL("Program.Main", """ { - // Code size 187 (0xbb) + // Code size 107 (0x6b) .maxstack 3 .locals init (R1 V_0, //r1 R2 V_1, //r2 - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3, - <>y__InlineArray1 V_4, - <>y__InlineArray1 V_5) + int? V_2, + int? V_3, + int? V_4, + int? V_5) IL_0000: ldloca.s V_0 IL_0002: initobj "R1" IL_0008: ldloca.s V_0 IL_000a: ldloca.s V_2 - IL_000c: initobj "<>y__InlineArray1" + IL_000c: ldc.i4.3 + IL_000d: call "int?..ctor(int)" IL_0012: ldloca.s V_2 - IL_0014: ldc.i4.0 - IL_0015: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_001a: ldc.i4.3 - IL_001b: newobj "int?..ctor(int)" - IL_0020: stobj "int?" - IL_0025: ldloca.s V_2 - IL_0027: ldc.i4.1 - IL_0028: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_002d: call "void R1.M(System.ReadOnlySpan)" - IL_0032: ldloca.s V_0 - IL_0034: ldloca.s V_3 - IL_0036: initobj "<>y__InlineArray1" - IL_003c: ldloca.s V_3 - IL_003e: ldc.i4.0 - IL_003f: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_0044: ldc.i4.4 - IL_0045: newobj "int?..ctor(int)" - IL_004a: stobj "int?" - IL_004f: ldloca.s V_3 - IL_0051: ldc.i4.1 - IL_0052: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_0057: call "object R1.this[System.ReadOnlySpan].get" - IL_005c: pop - IL_005d: ldloca.s V_1 - IL_005f: initobj "R2" - IL_0065: ldloca.s V_1 - IL_0067: ldloca.s V_4 - IL_0069: initobj "<>y__InlineArray1" - IL_006f: ldloca.s V_4 - IL_0071: ldc.i4.0 - IL_0072: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_0077: ldc.i4.5 - IL_0078: newobj "int?..ctor(int)" - IL_007d: stobj "int?" - IL_0082: ldloca.s V_4 - IL_0084: ldc.i4.1 - IL_0085: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_008a: call "readonly void R2.M(System.ReadOnlySpan)" - IL_008f: ldloca.s V_1 - IL_0091: ldloca.s V_5 - IL_0093: initobj "<>y__InlineArray1" - IL_0099: ldloca.s V_5 - IL_009b: ldc.i4.0 - IL_009c: call "ref int? .InlineArrayElementRef<<>y__InlineArray1, int?>(ref <>y__InlineArray1, int)" - IL_00a1: ldc.i4.6 - IL_00a2: newobj "int?..ctor(int)" - IL_00a7: stobj "int?" - IL_00ac: ldloca.s V_5 - IL_00ae: ldc.i4.1 - IL_00af: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int?>(in <>y__InlineArray1, int)" - IL_00b4: call "readonly object R2.this[System.ReadOnlySpan].get" - IL_00b9: pop - IL_00ba: ret + IL_0014: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_0019: call "void R1.M(System.ReadOnlySpan)" + IL_001e: ldloca.s V_0 + IL_0020: ldloca.s V_3 + IL_0022: ldc.i4.4 + IL_0023: call "int?..ctor(int)" + IL_0028: ldloca.s V_3 + IL_002a: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_002f: call "object R1.this[System.ReadOnlySpan].get" + IL_0034: pop + IL_0035: ldloca.s V_1 + IL_0037: initobj "R2" + IL_003d: ldloca.s V_1 + IL_003f: ldloca.s V_4 + IL_0041: ldc.i4.5 + IL_0042: call "int?..ctor(int)" + IL_0047: ldloca.s V_4 + IL_0049: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_004e: call "readonly void R2.M(System.ReadOnlySpan)" + IL_0053: ldloca.s V_1 + IL_0055: ldloca.s V_5 + IL_0057: ldc.i4.6 + IL_0058: call "int?..ctor(int)" + IL_005d: ldloca.s V_5 + IL_005f: newobj "System.ReadOnlySpan..ctor(in int?)" + IL_0064: call "readonly object R2.this[System.ReadOnlySpan].get" + IL_0069: pop + IL_006a: ret } """); } @@ -21550,52 +21811,34 @@ static void Main() expectedOutput: IncludeExpectedOutput("[1], [3], [2], [4], ")); verifier.VerifyIL("Program.Main", """ { - // Code size 113 (0x71) - .maxstack 3 - .locals init (<>y__InlineArray1 V_0, - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref int .InlineArrayElementRef<<>y__InlineArray1, int>(ref <>y__InlineArray1, int)" - IL_0010: ldloca.s V_1 - IL_0012: initobj "<>y__InlineArray1" - IL_0018: ldloca.s V_1 - IL_001a: ldc.i4.0 - IL_001b: call "ref int .InlineArrayElementRef<<>y__InlineArray1, int>(ref <>y__InlineArray1, int)" - IL_0020: ldc.i4.1 - IL_0021: stind.i4 - IL_0022: ldloca.s V_1 - IL_0024: ldc.i4.1 - IL_0025: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, int>(ref <>y__InlineArray1, int)" - IL_002a: call "int Program.F1(System.Span)" - IL_002f: ldc.i4.2 - IL_0030: add - IL_0031: stind.i4 - IL_0032: ldloca.s V_0 - IL_0034: ldc.i4.1 - IL_0035: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, int>(ref <>y__InlineArray1, int)" - IL_003a: call "int Program.F1(System.Span)" - IL_003f: pop - IL_0040: ldloca.s V_2 - IL_0042: initobj "<>y__InlineArray1" - IL_0048: ldloca.s V_2 - IL_004a: ldc.i4.0 - IL_004b: call "ref int .InlineArrayElementRef<<>y__InlineArray1, int>(ref <>y__InlineArray1, int)" - IL_0050: ldtoken ".__StaticArrayInitTypeSize=4_Align=4 .26B25D457597A7B0463F9620F666DD10AA2C4373A505967C7C8D70922A2D6ECE4" - IL_0055: call "System.ReadOnlySpan System.Runtime.CompilerServices.RuntimeHelpers.CreateSpan(System.RuntimeFieldHandle)" - IL_005a: call "int Program.F2(System.ReadOnlySpan)" - IL_005f: ldc.i4.2 - IL_0060: add - IL_0061: stind.i4 - IL_0062: ldloca.s V_2 - IL_0064: ldc.i4.1 - IL_0065: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, int>(in <>y__InlineArray1, int)" - IL_006a: call "int Program.F2(System.ReadOnlySpan)" - IL_006f: pop - IL_0070: ret + // Code size 62 (0x3e) + .maxstack 2 + .locals init (int V_0, + int V_1, + int V_2) + IL_0000: ldc.i4.1 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: newobj "System.Span..ctor(ref int)" + IL_0009: call "int Program.F1(System.Span)" + IL_000e: ldc.i4.2 + IL_000f: add + IL_0010: stloc.1 + IL_0011: ldloca.s V_1 + IL_0013: newobj "System.Span..ctor(ref int)" + IL_0018: call "int Program.F1(System.Span)" + IL_001d: pop + IL_001e: ldtoken ".__StaticArrayInitTypeSize=4_Align=4 .26B25D457597A7B0463F9620F666DD10AA2C4373A505967C7C8D70922A2D6ECE4" + IL_0023: call "System.ReadOnlySpan System.Runtime.CompilerServices.RuntimeHelpers.CreateSpan(System.RuntimeFieldHandle)" + IL_0028: call "int Program.F2(System.ReadOnlySpan)" + IL_002d: ldc.i4.2 + IL_002e: add + IL_002f: stloc.2 + IL_0030: ldloca.s V_2 + IL_0032: newobj "System.ReadOnlySpan..ctor(in int)" + IL_0037: call "int Program.F2(System.ReadOnlySpan)" + IL_003c: pop + IL_003d: ret } """); } @@ -21633,67 +21876,43 @@ static ReadOnlySpan F2(scoped ReadOnlySpan x, ReadOnlySpan y) expectedOutput: IncludeExpectedOutput("[2], [1], [4], [3], ")); verifier.VerifyIL("Program.Main", """ { - // Code size 145 (0x91) + // Code size 77 (0x4d) .maxstack 2 - .locals init (<>y__InlineArray1 V_0, - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3, + .locals init (object V_0, + object V_1, + object V_2, + object V_3, System.Span V_4, System.ReadOnlySpan V_5) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 + IL_0000: ldc.i4.1 + IL_0001: box "int" + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: newobj "System.Span..ctor(ref object)" + IL_000e: stloc.s V_4 + IL_0010: ldc.i4.2 IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_0 - IL_0019: ldc.i4.1 - IL_001a: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_001f: stloc.s V_4 - IL_0021: ldloca.s V_1 - IL_0023: initobj "<>y__InlineArray1" - IL_0029: ldloca.s V_1 - IL_002b: ldc.i4.0 - IL_002c: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0031: ldc.i4.2 - IL_0032: box "int" - IL_0037: stind.ref - IL_0038: ldloca.s V_1 - IL_003a: ldc.i4.1 - IL_003b: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0040: ldloc.s V_4 - IL_0042: call "System.Span Program.F1(System.Span, scoped System.Span)" - IL_0047: pop - IL_0048: ldloca.s V_2 - IL_004a: initobj "<>y__InlineArray1" - IL_0050: ldloca.s V_2 - IL_0052: ldc.i4.0 - IL_0053: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0058: ldc.i4.3 - IL_0059: box "int" - IL_005e: stind.ref - IL_005f: ldloca.s V_2 - IL_0061: ldc.i4.1 - IL_0062: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0067: stloc.s V_5 - IL_0069: ldloca.s V_3 - IL_006b: initobj "<>y__InlineArray1" - IL_0071: ldloca.s V_3 - IL_0073: ldc.i4.0 - IL_0074: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0079: ldc.i4.4 - IL_007a: box "int" - IL_007f: stind.ref - IL_0080: ldloca.s V_3 - IL_0082: ldc.i4.1 - IL_0083: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0088: ldloc.s V_5 - IL_008a: call "System.ReadOnlySpan Program.F2(scoped System.ReadOnlySpan, System.ReadOnlySpan)" - IL_008f: pop - IL_0090: ret + IL_0016: stloc.1 + IL_0017: ldloca.s V_1 + IL_0019: newobj "System.Span..ctor(ref object)" + IL_001e: ldloc.s V_4 + IL_0020: call "System.Span Program.F1(System.Span, scoped System.Span)" + IL_0025: pop + IL_0026: ldc.i4.3 + IL_0027: box "int" + IL_002c: stloc.2 + IL_002d: ldloca.s V_2 + IL_002f: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0034: stloc.s V_5 + IL_0036: ldc.i4.4 + IL_0037: box "int" + IL_003c: stloc.3 + IL_003d: ldloca.s V_3 + IL_003f: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0044: ldloc.s V_5 + IL_0046: call "System.ReadOnlySpan Program.F2(scoped System.ReadOnlySpan, System.ReadOnlySpan)" + IL_004b: pop + IL_004c: ret } """); } @@ -21947,48 +22166,36 @@ static object[] F2() expectedOutput: IncludeExpectedOutput("[1], [2], ")); verifier.VerifyIL("Program.F1", """ { - // Code size 40 (0x28) - .maxstack 2 - .locals init (System.Span V_0, //s1 - <>y__InlineArray1 V_1) - IL_0000: ldloca.s V_1 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_1 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_1 - IL_0019: ldc.i4.1 - IL_001a: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_001f: stloc.0 - IL_0020: ldloca.s V_0 - IL_0022: call "object[] System.Span.ToArray()" - IL_0027: ret + // Code size 23 (0x17) + .maxstack 1 + .locals init (System.Span V_0, //s1 + object V_1) + IL_0000: ldc.i4.1 + IL_0001: box "int" + IL_0006: stloc.1 + IL_0007: ldloca.s V_1 + IL_0009: newobj "System.Span..ctor(ref object)" + IL_000e: stloc.0 + IL_000f: ldloca.s V_0 + IL_0011: call "object[] System.Span.ToArray()" + IL_0016: ret } """); verifier.VerifyIL("Program.F2", """ { - // Code size 40 (0x28) - .maxstack 2 - .locals init (System.ReadOnlySpan V_0, //s2 - <>y__InlineArray1 V_1) - IL_0000: ldloca.s V_1 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_1 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.2 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_1 - IL_0019: ldc.i4.1 - IL_001a: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_001f: stloc.0 - IL_0020: ldloca.s V_0 - IL_0022: call "object[] System.ReadOnlySpan.ToArray()" - IL_0027: ret + // Code size 23 (0x17) + .maxstack 1 + .locals init (System.ReadOnlySpan V_0, //s2 + object V_1) + IL_0000: ldc.i4.2 + IL_0001: box "int" + IL_0006: stloc.1 + IL_0007: ldloca.s V_1 + IL_0009: newobj "System.ReadOnlySpan..ctor(in object)" + IL_000e: stloc.0 + IL_000f: ldloca.s V_0 + IL_0011: call "object[] System.ReadOnlySpan.ToArray()" + IL_0016: ret } """); } @@ -22021,41 +22228,29 @@ static void Main() { verifier.VerifyIL("Program.Main", """ { - // Code size 79 (0x4f) - .maxstack 2 + // Code size 45 (0x2d) + .maxstack 1 .locals init (System.Span V_0, //x System.ReadOnlySpan V_1, //y - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3) - IL_0000: ldloca.s V_2 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_2 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_2 - IL_0019: ldc.i4.1 - IL_001a: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_001f: stloc.0 - IL_0020: ldloca.s V_3 - IL_0022: initobj "<>y__InlineArray1" - IL_0028: ldloca.s V_3 - IL_002a: ldc.i4.0 - IL_002b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0030: ldc.i4.2 - IL_0031: box "int" - IL_0036: stind.ref - IL_0037: ldloca.s V_3 - IL_0039: ldc.i4.1 - IL_003a: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_003f: stloc.1 - IL_0040: ldloca.s V_0 - IL_0042: call "void CollectionExtensions.Report(in System.Span)" - IL_0047: ldloca.s V_1 - IL_0049: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" - IL_004e: ret + object V_2, + object V_3) + IL_0000: ldc.i4.1 + IL_0001: box "int" + IL_0006: stloc.2 + IL_0007: ldloca.s V_2 + IL_0009: newobj "System.Span..ctor(ref object)" + IL_000e: stloc.0 + IL_000f: ldc.i4.2 + IL_0010: box "int" + IL_0015: stloc.3 + IL_0016: ldloca.s V_3 + IL_0018: newobj "System.ReadOnlySpan..ctor(in object)" + IL_001d: stloc.1 + IL_001e: ldloca.s V_0 + IL_0020: call "void CollectionExtensions.Report(in System.Span)" + IL_0025: ldloca.s V_1 + IL_0027: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" + IL_002c: ret } """); } @@ -22149,49 +22344,37 @@ static void Main() expectedOutput: IncludeExpectedOutput("[1], [2], ")); verifier.VerifyIL("Program.Main", """ { - // Code size 117 (0x75) - .maxstack 3 + // Code size 83 (0x53) + .maxstack 2 .locals init (R V_0, //x R V_1, //y - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3) + object V_2, + object V_3) IL_0000: ldloca.s V_0 IL_0002: initobj "R" IL_0008: ldloca.s V_1 IL_000a: initobj "R" IL_0010: ldloca.s V_0 - IL_0012: ldloca.s V_2 - IL_0014: initobj "<>y__InlineArray1" - IL_001a: ldloca.s V_2 - IL_001c: ldc.i4.0 - IL_001d: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0022: ldc.i4.1 - IL_0023: box "int" - IL_0028: stind.ref - IL_0029: ldloca.s V_2 - IL_002b: ldc.i4.1 - IL_002c: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0031: stfld "System.ReadOnlySpan R.F" - IL_0036: ldloca.s V_1 - IL_0038: ldloca.s V_3 - IL_003a: initobj "<>y__InlineArray1" - IL_0040: ldloca.s V_3 - IL_0042: ldc.i4.0 - IL_0043: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0048: ldc.i4.2 - IL_0049: box "int" - IL_004e: stind.ref - IL_004f: ldloca.s V_3 - IL_0051: ldc.i4.1 - IL_0052: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0057: stfld "System.ReadOnlySpan R.F" - IL_005c: ldloca.s V_0 - IL_005e: ldflda "System.ReadOnlySpan R.F" - IL_0063: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" - IL_0068: ldloca.s V_1 - IL_006a: ldflda "System.ReadOnlySpan R.F" - IL_006f: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" - IL_0074: ret + IL_0012: ldc.i4.1 + IL_0013: box "int" + IL_0018: stloc.2 + IL_0019: ldloca.s V_2 + IL_001b: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0020: stfld "System.ReadOnlySpan R.F" + IL_0025: ldloca.s V_1 + IL_0027: ldc.i4.2 + IL_0028: box "int" + IL_002d: stloc.3 + IL_002e: ldloca.s V_3 + IL_0030: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0035: stfld "System.ReadOnlySpan R.F" + IL_003a: ldloca.s V_0 + IL_003c: ldflda "System.ReadOnlySpan R.F" + IL_0041: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" + IL_0046: ldloca.s V_1 + IL_0048: ldflda "System.ReadOnlySpan R.F" + IL_004d: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" + IL_0052: ret } """); } @@ -22451,64 +22634,40 @@ static void F(bool b) { verifier.VerifyIL("Program.F", """ { - // Code size 134 (0x86) - .maxstack 2 - .locals init (<>y__InlineArray1 V_0, - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_0 - IL_0019: ldc.i4.1 - IL_001a: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_001f: pop - IL_0020: ldarg.0 - IL_0021: brfalse.s IL_0045 - IL_0023: ldloca.s V_1 - IL_0025: initobj "<>y__InlineArray1" - IL_002b: ldloca.s V_1 - IL_002d: ldc.i4.0 - IL_002e: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0033: ldc.i4.2 - IL_0034: box "int" - IL_0039: stind.ref - IL_003a: ldloca.s V_1 - IL_003c: ldc.i4.1 - IL_003d: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0042: pop - IL_0043: br.s IL_0065 - IL_0045: ldloca.s V_2 - IL_0047: initobj "<>y__InlineArray1" - IL_004d: ldloca.s V_2 - IL_004f: ldc.i4.0 - IL_0050: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0055: ldc.i4.3 - IL_0056: box "int" - IL_005b: stind.ref - IL_005c: ldloca.s V_2 - IL_005e: ldc.i4.1 - IL_005f: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0064: pop - IL_0065: ldloca.s V_3 - IL_0067: initobj "<>y__InlineArray1" - IL_006d: ldloca.s V_3 - IL_006f: ldc.i4.0 - IL_0070: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0075: ldc.i4.4 - IL_0076: box "int" - IL_007b: stind.ref - IL_007c: ldloca.s V_3 - IL_007e: ldc.i4.1 - IL_007f: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0084: pop - IL_0085: ret + // Code size 66 (0x42) + .maxstack 1 + .locals init (object V_0, + object V_1, + object V_2, + object V_3) + IL_0000: ldc.i4.1 + IL_0001: box "int" + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: newobj "System.ReadOnlySpan..ctor(in object)" + IL_000e: pop + IL_000f: ldarg.0 + IL_0010: brfalse.s IL_0023 + IL_0012: ldc.i4.2 + IL_0013: box "int" + IL_0018: stloc.1 + IL_0019: ldloca.s V_1 + IL_001b: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0020: pop + IL_0021: br.s IL_0032 + IL_0023: ldc.i4.3 + IL_0024: box "int" + IL_0029: stloc.2 + IL_002a: ldloca.s V_2 + IL_002c: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0031: pop + IL_0032: ldc.i4.4 + IL_0033: box "int" + IL_0038: stloc.3 + IL_0039: ldloca.s V_3 + IL_003b: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0040: pop + IL_0041: ret } """); } @@ -22766,25 +22925,19 @@ void A2() expectedOutput: IncludeExpectedOutput("[1], [2], [3], [4], [1], ")); verifier.VerifyIL("Program.<>c__DisplayClass1_0.g__A2|1()", """ { - // Code size 44 (0x2c) - .maxstack 2 + // Code size 23 (0x17) + .maxstack 1 .locals init (System.Span V_0, //s3 - <>y__InlineArray1 V_1) - IL_0000: ldloca.s V_1 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_1 - IL_000a: ldc.i4.0 - IL_000b: call "ref T .InlineArrayElementRef<<>y__InlineArray1, T>(ref <>y__InlineArray1, int)" - IL_0010: ldarg.0 - IL_0011: ldfld "T Program.<>c__DisplayClass1_0.z" - IL_0016: stobj "T" - IL_001b: ldloca.s V_1 - IL_001d: ldc.i4.1 - IL_001e: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, T>(ref <>y__InlineArray1, int)" - IL_0023: stloc.0 - IL_0024: ldloca.s V_0 - IL_0026: call "void CollectionExtensions.Report(in System.Span)" - IL_002b: ret + T V_1) + IL_0000: ldarg.0 + IL_0001: ldfld "T Program.<>c__DisplayClass1_0.z" + IL_0006: stloc.1 + IL_0007: ldloca.s V_1 + IL_0009: newobj "System.Span..ctor(ref T)" + IL_000e: stloc.0 + IL_000f: ldloca.s V_0 + IL_0011: call "void CollectionExtensions.Report(in System.Span)" + IL_0016: ret } """); } @@ -22826,10 +22979,10 @@ static void Main() expectedOutput: IncludeExpectedOutput("[b], [a], ")); verifier.VerifyIL("C.<>c.<.ctor>b__1_0(T, T)", """ { - // Code size 76 (0x4c) + // Code size 55 (0x37) .maxstack 2 .locals init (System.ReadOnlySpan V_0, //r1 - <>y__InlineArray1 V_1) + T V_1) IL_0000: ldsfld "System.Action C.<>c.<>9__1_1" IL_0005: dup IL_0006: brtrue.s IL_001f @@ -22841,20 +22994,14 @@ .locals init (System.ReadOnlySpan V_0, //r1 IL_001a: stsfld "System.Action C.<>c.<>9__1_1" IL_001f: ldarg.2 IL_0020: callvirt "void System.Action.Invoke(T)" - IL_0025: ldloca.s V_1 - IL_0027: initobj "<>y__InlineArray1" - IL_002d: ldloca.s V_1 - IL_002f: ldc.i4.0 - IL_0030: call "ref T .InlineArrayElementRef<<>y__InlineArray1, T>(ref <>y__InlineArray1, int)" - IL_0035: ldarg.1 - IL_0036: stobj "T" - IL_003b: ldloca.s V_1 - IL_003d: ldc.i4.1 - IL_003e: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, T>(in <>y__InlineArray1, int)" - IL_0043: stloc.0 - IL_0044: ldloca.s V_0 - IL_0046: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" - IL_004b: ret + IL_0025: ldarg.1 + IL_0026: stloc.1 + IL_0027: ldloca.s V_1 + IL_0029: newobj "System.ReadOnlySpan..ctor(in T)" + IL_002e: stloc.0 + IL_002f: ldloca.s V_0 + IL_0031: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" + IL_0036: ret } """); } @@ -22883,60 +23030,48 @@ static void Main() var verifier = CompileAndVerify( new[] { source, s_collectionExtensionsWithSpan }, targetFramework: TargetFramework.Net80, - verify: Verification.Fails, + verify: Verification.Skipped, expectedOutput: IncludeExpectedOutput("[1], [2], Disposed, ")); verifier.VerifyIL("Program.Main", """ { - // Code size 97 (0x61) - .maxstack 2 + // Code size 64 (0x40) + .maxstack 1 .locals init (System.ReadOnlySpan V_0, //x Disposable V_1, //d System.ReadOnlySpan V_2, //y - <>y__InlineArray1 V_3, - <>y__InlineArray1 V_4) - IL_0000: ldloca.s V_3 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_3 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 - IL_0011: box "int" - IL_0016: stind.ref - IL_0017: ldloca.s V_3 - IL_0019: ldc.i4.1 - IL_001a: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_001f: stloc.0 - IL_0020: newobj "Disposable..ctor()" - IL_0025: stloc.1 + object V_3, + object V_4) + IL_0000: ldc.i4.1 + IL_0001: box "int" + IL_0006: stloc.3 + IL_0007: ldloca.s V_3 + IL_0009: newobj "System.ReadOnlySpan..ctor(in object)" + IL_000e: stloc.0 + IL_000f: newobj "Disposable..ctor()" + IL_0014: stloc.1 .try { - IL_0026: ldloca.s V_4 - IL_0028: initobj "<>y__InlineArray1" - IL_002e: ldloca.s V_4 - IL_0030: ldc.i4.0 - IL_0031: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0036: ldc.i4.2 - IL_0037: box "int" - IL_003c: stind.ref - IL_003d: ldloca.s V_4 - IL_003f: ldc.i4.1 - IL_0040: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_0045: stloc.2 - IL_0046: ldloca.s V_0 - IL_0048: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" - IL_004d: ldloca.s V_2 - IL_004f: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" - IL_0054: leave.s IL_0060 + IL_0015: ldc.i4.2 + IL_0016: box "int" + IL_001b: stloc.s V_4 + IL_001d: ldloca.s V_4 + IL_001f: newobj "System.ReadOnlySpan..ctor(in object)" + IL_0024: stloc.2 + IL_0025: ldloca.s V_0 + IL_0027: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" + IL_002c: ldloca.s V_2 + IL_002e: call "void CollectionExtensions.Report(in System.ReadOnlySpan)" + IL_0033: leave.s IL_003f } finally { - IL_0056: ldloc.1 - IL_0057: brfalse.s IL_005f - IL_0059: ldloc.1 - IL_005a: callvirt "void System.IDisposable.Dispose()" - IL_005f: endfinally + IL_0035: ldloc.1 + IL_0036: brfalse.s IL_003e + IL_0038: ldloc.1 + IL_0039: callvirt "void System.IDisposable.Dispose()" + IL_003e: endfinally } - IL_0060: ret + IL_003f: ret } """); } @@ -23326,59 +23461,35 @@ static void Report(ReadOnlySpan s) """)); verifier.VerifyIL("Program.Main", """ { - // Code size 135 (0x87) - .maxstack 2 - .locals init (<>y__InlineArray1 V_0, - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2, - <>y__InlineArray1 V_3) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref object .InlineArrayElementRef<<>y__InlineArray1, object>(ref <>y__InlineArray1, int)" - IL_0010: ldstr "1" - IL_0015: stind.ref - IL_0016: ldloca.s V_0 - IL_0018: ldc.i4.1 - IL_0019: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, object>(in <>y__InlineArray1, int)" - IL_001e: call "void Program.Report(System.ReadOnlySpan)" - IL_0023: ldloca.s V_1 - IL_0025: initobj "<>y__InlineArray1" - IL_002b: ldloca.s V_1 - IL_002d: ldc.i4.0 - IL_002e: call "ref string .InlineArrayElementRef<<>y__InlineArray1, string>(ref <>y__InlineArray1, int)" - IL_0033: ldstr "2" - IL_0038: stind.ref - IL_0039: ldloca.s V_1 - IL_003b: ldc.i4.1 - IL_003c: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, string>(in <>y__InlineArray1, int)" - IL_0041: call "void Program.Report(System.ReadOnlySpan)" - IL_0046: ldloca.s V_2 - IL_0048: initobj "<>y__InlineArray1" - IL_004e: ldloca.s V_2 - IL_0050: ldc.i4.0 - IL_0051: call "ref nint .InlineArrayElementRef<<>y__InlineArray1, nint>(ref <>y__InlineArray1, int)" - IL_0056: ldc.i4.3 - IL_0057: conv.i - IL_0058: stind.i - IL_0059: ldloca.s V_2 - IL_005b: ldc.i4.1 - IL_005c: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, nint>(in <>y__InlineArray1, int)" - IL_0061: call "void Program.Report(System.ReadOnlySpan)" - IL_0066: ldloca.s V_3 - IL_0068: initobj "<>y__InlineArray1" - IL_006e: ldloca.s V_3 - IL_0070: ldc.i4.0 - IL_0071: call "ref nuint .InlineArrayElementRef<<>y__InlineArray1, nuint>(ref <>y__InlineArray1, int)" - IL_0076: ldc.i4.4 - IL_0077: conv.i - IL_0078: stind.i - IL_0079: ldloca.s V_3 - IL_007b: ldc.i4.1 - IL_007c: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, nuint>(in <>y__InlineArray1, int)" - IL_0081: call "void Program.Report(System.ReadOnlySpan)" - IL_0086: ret + // Code size 67 (0x43) + .maxstack 1 + .locals init (object V_0, + string V_1, + nint V_2, + nuint V_3) + IL_0000: ldstr "1" + IL_0005: stloc.0 + IL_0006: ldloca.s V_0 + IL_0008: newobj "System.ReadOnlySpan..ctor(in object)" + IL_000d: call "void Program.Report(System.ReadOnlySpan)" + IL_0012: ldstr "2" + IL_0017: stloc.1 + IL_0018: ldloca.s V_1 + IL_001a: newobj "System.ReadOnlySpan..ctor(in string)" + IL_001f: call "void Program.Report(System.ReadOnlySpan)" + IL_0024: ldc.i4.3 + IL_0025: conv.i + IL_0026: stloc.2 + IL_0027: ldloca.s V_2 + IL_0029: newobj "System.ReadOnlySpan..ctor(in nint)" + IL_002e: call "void Program.Report(System.ReadOnlySpan)" + IL_0033: ldc.i4.4 + IL_0034: conv.i + IL_0035: stloc.3 + IL_0036: ldloca.s V_3 + IL_0038: newobj "System.ReadOnlySpan..ctor(in nuint)" + IL_003d: call "void Program.Report(System.ReadOnlySpan)" + IL_0042: ret } """); } @@ -28675,29 +28786,23 @@ .maxstack 4 verifier.VerifyDiagnostics(); verifier.VerifyIL("Program.M", """ { - // Code size 44 (0x2c) + // Code size 27 (0x1b) .maxstack 4 - .locals init (<>y__InlineArray1 V_0) - IL_0000: ldloca.s V_0 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_0 - IL_000a: ldc.i4.0 - IL_000b: call "ref int .InlineArrayElementRef<<>y__InlineArray1, int>(ref <>y__InlineArray1, int)" - IL_0010: ldc.i4.1 - IL_0011: stind.i4 - IL_0012: ldloca.s V_0 - IL_0014: ldc.i4.1 - IL_0015: call "System.Span .InlineArrayAsSpan<<>y__InlineArray1, int>(ref <>y__InlineArray1, int)" - IL_001a: pop - IL_001b: ldc.i4.1 - IL_001c: newarr "int" - IL_0021: dup - IL_0022: ldc.i4.0 - IL_0023: ldc.i4.1 - IL_0024: stelem.i4 - IL_0025: call "System.Span System.Span.op_Implicit(int[])" - IL_002a: pop - IL_002b: ret + .locals init (int V_0) + IL_0000: ldc.i4.1 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: newobj "System.Span..ctor(ref int)" + IL_0009: pop + IL_000a: ldc.i4.1 + IL_000b: newarr "int" + IL_0010: dup + IL_0011: ldc.i4.0 + IL_0012: ldc.i4.1 + IL_0013: stelem.i4 + IL_0014: call "System.Span System.Span.op_Implicit(int[])" + IL_0019: pop + IL_001a: ret } """); } @@ -31576,92 +31681,80 @@ class D : C { } verifier.VerifyDiagnostics(); verifier.VerifyIL("C.Main", """ { - // Code size 185 (0xb9) + // Code size 151 (0x97) .maxstack 3 .locals init (System.ReadOnlySpan V_0, //li1 - <>y__InlineArray1 V_1, - <>y__InlineArray1 V_2, + D V_1, + D V_2, System.ReadOnlySpan V_3, System.ReadOnlySpan V_4, int V_5, C[] V_6, System.ReadOnlySpan.Enumerator V_7, D V_8) - IL_0000: ldloca.s V_1 - IL_0002: initobj "<>y__InlineArray1" - IL_0008: ldloca.s V_1 - IL_000a: ldc.i4.0 - IL_000b: call "ref D .InlineArrayElementRef<<>y__InlineArray1, D>(ref <>y__InlineArray1, int)" - IL_0010: newobj "D..ctor()" - IL_0015: stind.ref - IL_0016: ldloca.s V_1 - IL_0018: ldc.i4.1 - IL_0019: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, D>(in <>y__InlineArray1, int)" - IL_001e: stloc.0 - IL_001f: ldloca.s V_2 - IL_0021: initobj "<>y__InlineArray1" - IL_0027: ldloca.s V_2 - IL_0029: ldc.i4.0 - IL_002a: call "ref D .InlineArrayElementRef<<>y__InlineArray1, D>(ref <>y__InlineArray1, int)" - IL_002f: newobj "D..ctor()" - IL_0034: stind.ref - IL_0035: ldloca.s V_2 - IL_0037: ldc.i4.1 - IL_0038: call "System.ReadOnlySpan .InlineArrayAsReadOnlySpan<<>y__InlineArray1, D>(in <>y__InlineArray1, int)" - IL_003d: ldloc.0 - IL_003e: stloc.3 - IL_003f: stloc.s V_4 - IL_0041: ldc.i4.0 - IL_0042: stloc.s V_5 - IL_0044: ldloca.s V_3 - IL_0046: call "int System.ReadOnlySpan.Length.get" - IL_004b: ldloca.s V_4 - IL_004d: call "int System.ReadOnlySpan.Length.get" - IL_0052: add - IL_0053: newarr "C" - IL_0058: stloc.s V_6 - IL_005a: ldloca.s V_3 - IL_005c: call "System.ReadOnlySpan.Enumerator System.ReadOnlySpan.GetEnumerator()" - IL_0061: stloc.s V_7 - IL_0063: br.s IL_007c - IL_0065: ldloca.s V_7 - IL_0067: call "ref readonly D System.ReadOnlySpan.Enumerator.Current.get" - IL_006c: ldind.ref - IL_006d: stloc.s V_8 - IL_006f: ldloc.s V_6 - IL_0071: ldloc.s V_5 - IL_0073: ldloc.s V_8 - IL_0075: stelem.ref - IL_0076: ldloc.s V_5 - IL_0078: ldc.i4.1 - IL_0079: add - IL_007a: stloc.s V_5 - IL_007c: ldloca.s V_7 - IL_007e: call "bool System.ReadOnlySpan.Enumerator.MoveNext()" - IL_0083: brtrue.s IL_0065 - IL_0085: ldloca.s V_4 - IL_0087: call "System.ReadOnlySpan.Enumerator System.ReadOnlySpan.GetEnumerator()" - IL_008c: stloc.s V_7 - IL_008e: br.s IL_00a7 - IL_0090: ldloca.s V_7 - IL_0092: call "ref readonly D System.ReadOnlySpan.Enumerator.Current.get" - IL_0097: ldind.ref - IL_0098: stloc.s V_8 - IL_009a: ldloc.s V_6 - IL_009c: ldloc.s V_5 - IL_009e: ldloc.s V_8 - IL_00a0: stelem.ref - IL_00a1: ldloc.s V_5 - IL_00a3: ldc.i4.1 - IL_00a4: add - IL_00a5: stloc.s V_5 - IL_00a7: ldloca.s V_7 - IL_00a9: call "bool System.ReadOnlySpan.Enumerator.MoveNext()" - IL_00ae: brtrue.s IL_0090 - IL_00b0: ldloc.s V_6 - IL_00b2: ldc.i4.0 - IL_00b3: call "void CollectionExtensions.Report(object, bool)" - IL_00b8: ret + IL_0000: newobj "D..ctor()" + IL_0005: stloc.1 + IL_0006: ldloca.s V_1 + IL_0008: newobj "System.ReadOnlySpan..ctor(in D)" + IL_000d: stloc.0 + IL_000e: newobj "D..ctor()" + IL_0013: stloc.2 + IL_0014: ldloca.s V_2 + IL_0016: newobj "System.ReadOnlySpan..ctor(in D)" + IL_001b: ldloc.0 + IL_001c: stloc.3 + IL_001d: stloc.s V_4 + IL_001f: ldc.i4.0 + IL_0020: stloc.s V_5 + IL_0022: ldloca.s V_3 + IL_0024: call "int System.ReadOnlySpan.Length.get" + IL_0029: ldloca.s V_4 + IL_002b: call "int System.ReadOnlySpan.Length.get" + IL_0030: add + IL_0031: newarr "C" + IL_0036: stloc.s V_6 + IL_0038: ldloca.s V_3 + IL_003a: call "System.ReadOnlySpan.Enumerator System.ReadOnlySpan.GetEnumerator()" + IL_003f: stloc.s V_7 + IL_0041: br.s IL_005a + IL_0043: ldloca.s V_7 + IL_0045: call "ref readonly D System.ReadOnlySpan.Enumerator.Current.get" + IL_004a: ldind.ref + IL_004b: stloc.s V_8 + IL_004d: ldloc.s V_6 + IL_004f: ldloc.s V_5 + IL_0051: ldloc.s V_8 + IL_0053: stelem.ref + IL_0054: ldloc.s V_5 + IL_0056: ldc.i4.1 + IL_0057: add + IL_0058: stloc.s V_5 + IL_005a: ldloca.s V_7 + IL_005c: call "bool System.ReadOnlySpan.Enumerator.MoveNext()" + IL_0061: brtrue.s IL_0043 + IL_0063: ldloca.s V_4 + IL_0065: call "System.ReadOnlySpan.Enumerator System.ReadOnlySpan.GetEnumerator()" + IL_006a: stloc.s V_7 + IL_006c: br.s IL_0085 + IL_006e: ldloca.s V_7 + IL_0070: call "ref readonly D System.ReadOnlySpan.Enumerator.Current.get" + IL_0075: ldind.ref + IL_0076: stloc.s V_8 + IL_0078: ldloc.s V_6 + IL_007a: ldloc.s V_5 + IL_007c: ldloc.s V_8 + IL_007e: stelem.ref + IL_007f: ldloc.s V_5 + IL_0081: ldc.i4.1 + IL_0082: add + IL_0083: stloc.s V_5 + IL_0085: ldloca.s V_7 + IL_0087: call "bool System.ReadOnlySpan.Enumerator.MoveNext()" + IL_008c: brtrue.s IL_006e + IL_008e: ldloc.s V_6 + IL_0090: ldc.i4.0 + IL_0091: call "void CollectionExtensions.Report(object, bool)" + IL_0096: ret } """); } diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs index 28ac9cf203aca..81467ecb958c5 100644 --- a/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Semantics/ParamsCollectionTests.cs @@ -359,6 +359,85 @@ void assertAttributeData(string name) } } + [Fact] + public void Span_SingleElement_TempsAreNotReused() + { + var source = """ + using System; + + class Program + { + static void Main() + { + M(1); + M(2); + } + + static void M(params Span span) + { + Console.Write(span[0]); + Console.Write(span.Length); + } + } + """; + + var verifier = CompileAndVerify( + source, + targetFramework: TargetFramework.Net80, + verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.Passes : Verification.Skipped, + expectedOutput: ExpectedOutput("1121")); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program.Main", """ + { + // Code size 29 (0x1d) + .maxstack 1 + .locals init (int V_0, + int V_1) + IL_0000: ldc.i4.1 + IL_0001: stloc.0 + IL_0002: ldloca.s V_0 + IL_0004: newobj "System.Span..ctor(ref int)" + IL_0009: call "void Program.M(params System.Span)" + IL_000e: ldc.i4.2 + IL_000f: stloc.1 + IL_0010: ldloca.s V_1 + IL_0012: newobj "System.Span..ctor(ref int)" + IL_0017: call "void Program.M(params System.Span)" + IL_001c: ret + } + """); + + verifier = CompileAndVerify( + source, + targetFramework: TargetFramework.Net70, + verify: ExecutionConditionUtil.IsMonoOrCoreClr ? Verification.Passes : Verification.Skipped, + expectedOutput: ExpectedOutput("1121")); + verifier.VerifyDiagnostics(); + verifier.VerifyIL("Program.Main", """ + { + // Code size 41 (0x29) + .maxstack 4 + IL_0000: ldc.i4.1 + IL_0001: newarr "int" + IL_0006: dup + IL_0007: ldc.i4.0 + IL_0008: ldc.i4.1 + IL_0009: stelem.i4 + IL_000a: newobj "System.Span..ctor(int[])" + IL_000f: call "void Program.M(params System.Span)" + IL_0014: ldc.i4.1 + IL_0015: newarr "int" + IL_001a: dup + IL_001b: ldc.i4.0 + IL_001c: ldc.i4.2 + IL_001d: stelem.i4 + IL_001e: newobj "System.Span..ctor(int[])" + IL_0023: call "void Program.M(params System.Span)" + IL_0028: ret + } + """); + } + [Fact] public void String() { @@ -4663,9 +4742,7 @@ static void Test(params System.Span a) CompileAndVerify( comp, - verify: ExecutionConditionUtil.IsMonoOrCoreClr ? - Verification.FailsILVerify with { ILVerifyMessage = "[InlineArrayAsSpan]: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. { Offset = 0xc }" } - : Verification.Skipped, + verify: Verification.Skipped, expectedOutput: ExpectedOutput(@" int int")).VerifyDiagnostics(); @@ -4703,9 +4780,7 @@ class C3 : C2 {} CompileAndVerify( comp, - verify: ExecutionConditionUtil.IsMonoOrCoreClr ? - Verification.FailsILVerify with { ILVerifyMessage = "[InlineArrayAsSpan]: Return type is ByRef, TypedReference, ArgHandle, or ArgIterator. { Offset = 0xc }" } - : Verification.Skipped, + verify: Verification.Skipped, expectedOutput: ExpectedOutput(@" C2 C2")).VerifyDiagnostics(); diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs index 132f3bcfa02b7..4ebef05edb5b3 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/MissingSpecialMember.cs @@ -1071,6 +1071,8 @@ public void AllWellKnownTypeMembers() case WellKnownMember.System_Span_T__CopyTo_Span_T: case WellKnownMember.System_ReadOnlySpan_T__CopyTo_Span_T: case WellKnownMember.System_Collections_Immutable_ImmutableArray_T__AsSpan: + case WellKnownMember.System_Span_T__ctor_ref_T: + case WellKnownMember.System_ReadOnlySpan_T__ctor_ref_readonly_T: // Not always available. continue; } diff --git a/src/Compilers/Core/Portable/WellKnownMember.cs b/src/Compilers/Core/Portable/WellKnownMember.cs index dbcb737b52e09..1cdddef0d9097 100644 --- a/src/Compilers/Core/Portable/WellKnownMember.cs +++ b/src/Compilers/Core/Portable/WellKnownMember.cs @@ -479,6 +479,7 @@ internal enum WellKnownMember System_Span_T__ctor_Pointer, System_Span_T__ctor_Array, + System_Span_T__ctor_ref_T, System_Span_T__get_Item, System_Span_T__get_Length, System_Span_T__Slice_Int_Int, @@ -486,6 +487,7 @@ internal enum WellKnownMember System_ReadOnlySpan_T__ctor_Pointer, System_ReadOnlySpan_T__ctor_Array, System_ReadOnlySpan_T__ctor_Array_Start_Length, + System_ReadOnlySpan_T__ctor_ref_readonly_T, System_ReadOnlySpan_T__get_Item, System_ReadOnlySpan_T__get_Length, System_ReadOnlySpan_T__Slice_Int_Int, diff --git a/src/Compilers/Core/Portable/WellKnownMembers.cs b/src/Compilers/Core/Portable/WellKnownMembers.cs index 351d772afc467..0fd77f299f9c2 100644 --- a/src/Compilers/Core/Portable/WellKnownMembers.cs +++ b/src/Compilers/Core/Portable/WellKnownMembers.cs @@ -3333,6 +3333,14 @@ static WellKnownMembers() 1, // Method Signature (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Void, // Return Type (byte)SignatureTypeCode.SZArray, (byte)SignatureTypeCode.GenericTypeParameter, 0, + + // System_Span_T__ctor_ref_T + (byte)(MemberFlags.Constructor), // Flags + (byte)WellKnownType.ExtSentinel, (byte)(WellKnownType.System_Span_T - WellKnownType.ExtSentinel), // DeclaringTypeId + 0, // Arity + 1, // Method Signature + (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Void, // Return Type + (byte)SignatureTypeCode.ByReference, (byte)SignatureTypeCode.GenericTypeParameter, 0, // System_Span_T__get_Item (byte)(MemberFlags.PropertyGet), // Flags @@ -3388,6 +3396,14 @@ static WellKnownMembers() (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Int32, (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Int32, + // System_ReadOnlySpan_T__ctor_ref_readonly_T + (byte)(MemberFlags.Constructor), // Flags + (byte)WellKnownType.ExtSentinel, (byte)(WellKnownType.System_ReadOnlySpan_T - WellKnownType.ExtSentinel), // DeclaringTypeId + 0, // Arity + 1, // Method Signature + (byte)SignatureTypeCode.TypeHandle, (byte)SpecialType.System_Void, // Return Type + (byte)SignatureTypeCode.ByReference, (byte)SignatureTypeCode.GenericTypeParameter, 0, + // System_ReadOnlySpan_T__get_Item (byte)(MemberFlags.PropertyGet), // Flags (byte)WellKnownType.ExtSentinel, (byte)(WellKnownType.System_ReadOnlySpan_T - WellKnownType.ExtSentinel), // DeclaringTypeId @@ -4722,12 +4738,14 @@ static WellKnownMembers() ".ctor", // System_Runtime_CompilerServices_ObsoleteAttribute__ctor ".ctor", // System_Span_T__ctor_Pointer ".ctor", // System_Span_T__ctor_Array + ".ctor", // System_Span_T__ctor_ref_T "get_Item", // System_Span_T__get_Item "get_Length", // System_Span_T__get_Length "Slice", // System_Span_T__Slice_Int_Int ".ctor", // System_ReadOnlySpan_T__ctor_Pointer ".ctor", // System_ReadOnlySpan_T__ctor_Array ".ctor", // System_ReadOnlySpan_T__ctor_Array_Start_Length + ".ctor", // System_ReadOnlySpan_T__ctor_ref_readonly_T "get_Item", // System_ReadOnlySpan_T__get_Item "get_Length", // System_ReadOnlySpan_T__get_Length "Slice", // System_ReadOnlySpan_T__Slice_Int_Int diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb index 59b991849251c..46f6caf769314 100644 --- a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/WellKnownTypeValidationTests.vb @@ -821,7 +821,9 @@ End Namespace WellKnownMember.System_ReadOnlySpan_T__ToArray, WellKnownMember.System_Span_T__CopyTo_Span_T, WellKnownMember.System_ReadOnlySpan_T__CopyTo_Span_T, - WellKnownMember.System_Collections_Immutable_ImmutableArray_T__AsSpan + WellKnownMember.System_Collections_Immutable_ImmutableArray_T__AsSpan, + WellKnownMember.System_Span_T__ctor_ref_T, + WellKnownMember.System_ReadOnlySpan_T__ctor_ref_readonly_T ' Not always available. Continue For End Select @@ -1026,7 +1028,9 @@ End Namespace WellKnownMember.System_ReadOnlySpan_T__ToArray, WellKnownMember.System_Span_T__CopyTo_Span_T, WellKnownMember.System_ReadOnlySpan_T__CopyTo_Span_T, - WellKnownMember.System_Collections_Immutable_ImmutableArray_T__AsSpan + WellKnownMember.System_Collections_Immutable_ImmutableArray_T__AsSpan, + WellKnownMember.System_Span_T__ctor_ref_T, + WellKnownMember.System_ReadOnlySpan_T__ctor_ref_readonly_T ' Not always available. Continue For End Select