diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index a445ef7c8..3bd0da240 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -195,32 +195,32 @@ - + https://github.com/dotnet/arcade - fd9941799bb6983a7d00ed72682378b46a45f396 + 6a638cd0c13962ab2a1943cb1c878be5a41dd82e - + https://github.com/dotnet/arcade - fd9941799bb6983a7d00ed72682378b46a45f396 + 6a638cd0c13962ab2a1943cb1c878be5a41dd82e - + https://github.com/dotnet/arcade - fd9941799bb6983a7d00ed72682378b46a45f396 + 6a638cd0c13962ab2a1943cb1c878be5a41dd82e https://github.com/dotnet/source-build-reference-packages ddc5b4880b0bf18783fc6808c4d407214f7bdae1 - + https://github.com/dotnet/sourcelink - ec063efc0c81f061ec3a91e343f135135cd27418 + 508c31bb736f3e6d69b8f47fa9ee38eedd9ce785 - + https://github.com/dotnet/xliff-tasks - e1f318960e0e5dbea923349c8aea12f58626fdfa + 8dfdebfefc8acef481f28edadbf7f75a8d6efde4 diff --git a/eng/Versions.props b/eng/Versions.props index 7b456e76a..ea7c462ef 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -26,7 +26,7 @@ - 7.0.0-beta.22410.3 + 7.0.0-beta.22411.2 diff --git a/global.json b/global.json index 53771389b..aa6fea34d 100644 --- a/global.json +++ b/global.json @@ -11,7 +11,7 @@ "cmake": "3.16.4" }, "msbuild-sdks": { - "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22410.3", - "Microsoft.DotNet.CMake.Sdk": "7.0.0-beta.22410.3" + "Microsoft.DotNet.Arcade.Sdk": "7.0.0-beta.22411.2", + "Microsoft.DotNet.CMake.Sdk": "7.0.0-beta.22411.2" } } diff --git a/src/SourceBuild/tarball/patches/aspnetcore/0003-NoWarn-IL2070.patch b/src/SourceBuild/tarball/patches/aspnetcore/0003-NoWarn-IL2070.patch new file mode 100644 index 000000000..aa344aefa --- /dev/null +++ b/src/SourceBuild/tarball/patches/aspnetcore/0003-NoWarn-IL2070.patch @@ -0,0 +1,22 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MichaelSimons +Date: Fri, 12 Aug 2022 23:02:54 +0000 +Subject: [PATCH] NoWarn IL2070 + +Backport: https://github.com/dotnet/aspnetcore/issues/43253 +--- + Directory.Build.props | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Directory.Build.props b/Directory.Build.props +index 166dbd6487..d5b1c9a1a8 100644 +--- a/Directory.Build.props ++++ b/Directory.Build.props +@@ -113,6 +113,7 @@ + + $(NoWarn.Replace('1591', '')) + $(NoWarn);0105 ++ $(NoWarn);IL2070 + + + $(WarningsNotAsErrors);CS1591 diff --git a/src/SourceBuild/tarball/patches/linker/0001-Fix-exception-when-generating-warning-for-method-definition.patch b/src/SourceBuild/tarball/patches/linker/0001-Fix-exception-when-generating-warning-for-method-definition.patch new file mode 100644 index 000000000..a838817f4 --- /dev/null +++ b/src/SourceBuild/tarball/patches/linker/0001-Fix-exception-when-generating-warning-for-method-definition.patch @@ -0,0 +1,26 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: vitek-karas <10670590+vitek-karas@users.noreply.github.com> +Date: Fri, 12 Aug 2022 13:12:09 -0700 +Subject: [PATCH] Fix exception when generating warning for method definition + +If we produce a warning for the method itself (no IL offset) and the method has debug symbols, it can happen that there's no sequence point for the first instruction. In that case the current code will crash because we expect to always find sequence point for offset 0. + +Fix this by looking for the first sequence point instead. +This patch is originally PR https://github.com/dotnet/linker/pull/2972. +--- + src/linker/Linker/MessageOrigin.cs | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/linker/Linker/MessageOrigin.cs b/src/linker/Linker/MessageOrigin.cs +index 24d18c065d..402e529e7f 100644 +--- a/src/linker/Linker/MessageOrigin.cs ++++ b/src/linker/Linker/MessageOrigin.cs +@@ -83,7 +83,7 @@ public MessageOrigin (MessageOrigin other, int ilOffset) + string? fileName = FileName; + if (Provider is MethodDefinition method && + method.DebugInformation.HasSequencePoints) { +- var offset = ILOffset ?? 0; ++ var offset = ILOffset ?? method.DebugInformation.SequencePoints[0].Offset; + SequencePoint? correspondingSequencePoint = method.DebugInformation.SequencePoints + .Where (s => s.Offset <= offset)?.Last (); + diff --git a/src/SourceBuild/tarball/patches/linker/0002-Update-ILLink.RoslynAnalyzer-Microsoft.CodeAnalysis..patch b/src/SourceBuild/tarball/patches/linker/0002-Update-ILLink.RoslynAnalyzer-Microsoft.CodeAnalysis..patch new file mode 100644 index 000000000..b35252048 --- /dev/null +++ b/src/SourceBuild/tarball/patches/linker/0002-Update-ILLink.RoslynAnalyzer-Microsoft.CodeAnalysis..patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: MichaelSimons +Date: Fri, 12 Aug 2022 20:58:39 +0000 +Subject: [PATCH] Update ILLink.RoslynAnalyzer Microsoft.CodeAnalysis.CSharp + reference for source-build + +backport: https://github.com/dotnet/source-build/issues/2973 +--- + src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj b/src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj +index cafde32b..a5f450a3 100644 +--- a/src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj ++++ b/src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj +@@ -17,7 +17,8 @@ + + + +- ++ ++ + + all + contentfiles diff --git a/src/SourceBuild/tarball/patches/roslyn/0002-Revert-Consider-types-with-ref-fields-as-managed-632.patch b/src/SourceBuild/tarball/patches/roslyn/0002-Revert-Consider-types-with-ref-fields-as-managed-632.patch new file mode 100644 index 000000000..80544f3ed --- /dev/null +++ b/src/SourceBuild/tarball/patches/roslyn/0002-Revert-Consider-types-with-ref-fields-as-managed-632.patch @@ -0,0 +1,343 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Chris Rummel +Date: Fri, 12 Aug 2022 14:02:46 -0500 +Subject: [PATCH] Revert "Consider types with ref fields as managed (#63209)" + +This reverts commit e3985ed961e17ba4b53107d14d0bb43826988353. + +Related to https://github.com/dotnet/runtime/pull/73466, +https://github.com/dotnet/source-build/issues/2985, +https://github.com/dotnet/runtime/issues/73850. +--- + .../Portable/Symbols/BaseTypeAnalysis.cs | 169 +++++++++--------- + .../Test/Semantic/Semantics/RefFieldTests.cs | 111 ------------ + 2 files changed, 82 insertions(+), 198 deletions(-) + +diff --git a/src/Compilers/CSharp/Portable/Symbols/BaseTypeAnalysis.cs b/src/Compilers/CSharp/Portable/Symbols/BaseTypeAnalysis.cs +index 7d0ab5cfe12..5918d1d848e 100644 +--- a/src/Compilers/CSharp/Portable/Symbols/BaseTypeAnalysis.cs ++++ b/src/Compilers/CSharp/Portable/Symbols/BaseTypeAnalysis.cs +@@ -112,7 +112,7 @@ private static void StructDependsClosure(NamedTypeSymbol type, HashSet p + /// all special types have spec'd values (basically, (non-string) primitives) are not managed; + /// + /// Only structs are complicated, because the definition is recursive. A struct type is managed +- /// if one of its instance fields is managed or a ref field. Unfortunately, this can result in infinite recursion. ++ /// if one of its instance fields is managed. Unfortunately, this can result in infinite recursion. + /// If the closure is finite, and we don't find anything definitely managed, then we return true. + /// If the closure is infinite, we disregard all but a representative of any expanding cycle. + /// +@@ -128,12 +128,13 @@ internal static ManagedKind GetManagedKind(NamedTypeSymbol type, ref CompoundUse + { + // Otherwise, we have to build and inspect the closure of depended-upon types. + var hs = PooledHashSet.GetInstance(); +- var result = dependsOnDefinitelyManagedType(type, hs, ref useSiteInfo); ++ var result = DependsOnDefinitelyManagedType(type, hs, ref useSiteInfo); + definitelyManaged = result.definitelyManaged; + hasGenerics = hasGenerics || result.hasGenerics; + hs.Free(); + } + ++ + if (definitelyManaged) + { + return ManagedKind.Managed; +@@ -146,91 +147,6 @@ internal static ManagedKind GetManagedKind(NamedTypeSymbol type, ref CompoundUse + { + return ManagedKind.Unmanaged; + } +- +- static (bool definitelyManaged, bool hasGenerics) dependsOnDefinitelyManagedType(NamedTypeSymbol type, HashSet partialClosure, ref CompoundUseSiteInfo useSiteInfo) +- { +- Debug.Assert((object)type != null); +- +- var hasGenerics = false; +- if (partialClosure.Add(type)) +- { +- foreach (var member in type.GetInstanceFieldsAndEvents()) +- { +- // Only instance fields (including field-like events) affect the outcome. +- FieldSymbol field; +- switch (member.Kind) +- { +- case SymbolKind.Field: +- field = (FieldSymbol)member; +- Debug.Assert((object)(field.AssociatedSymbol as EventSymbol) == null, +- "Didn't expect to find a field-like event backing field in the member list."); +- break; +- case SymbolKind.Event: +- field = ((EventSymbol)member).AssociatedField; +- break; +- default: +- throw ExceptionUtilities.UnexpectedValue(member.Kind); +- } +- +- if ((object)field == null) +- { +- continue; +- } +- +- if (field.RefKind != RefKind.None) +- { +- // A ref struct which has a ref field is never considered unmanaged +- return (true, hasGenerics); +- } +- +- TypeSymbol fieldType = field.NonPointerType(); +- if (fieldType is null) +- { +- // pointers are unmanaged +- continue; +- } +- +- fieldType.AddUseSiteInfo(ref useSiteInfo); +- NamedTypeSymbol fieldNamedType = fieldType as NamedTypeSymbol; +- if ((object)fieldNamedType == null) +- { +- if (fieldType.IsManagedType(ref useSiteInfo)) +- { +- return (true, hasGenerics); +- } +- } +- else +- { +- var result = IsManagedTypeHelper(fieldNamedType); +- hasGenerics = hasGenerics || result.hasGenerics; +- // NOTE: don't use ManagedKind.get on a NamedTypeSymbol - that could lead +- // to infinite recursion. +- switch (result.isManaged) +- { +- case ThreeState.True: +- return (true, hasGenerics); +- +- case ThreeState.False: +- continue; +- +- case ThreeState.Unknown: +- if (!fieldNamedType.OriginalDefinition.KnownCircularStruct) +- { +- var (definitelyManaged, childHasGenerics) = dependsOnDefinitelyManagedType(fieldNamedType, partialClosure, ref useSiteInfo); +- hasGenerics = hasGenerics || childHasGenerics; +- if (definitelyManaged) +- { +- return (true, hasGenerics); +- } +- } +- continue; +- } +- } +- } +- } +- +- return (false, hasGenerics); +- } + } + + // NOTE: If we do not check HasPointerType, we will unconditionally +@@ -239,6 +155,85 @@ internal static ManagedKind GetManagedKind(NamedTypeSymbol type, ref CompoundUse + internal static TypeSymbol NonPointerType(this FieldSymbol field) => + field.HasPointerType ? null : field.Type; + ++ private static (bool definitelyManaged, bool hasGenerics) DependsOnDefinitelyManagedType(NamedTypeSymbol type, HashSet partialClosure, ref CompoundUseSiteInfo useSiteInfo) ++ { ++ Debug.Assert((object)type != null); ++ ++ var hasGenerics = false; ++ if (partialClosure.Add(type)) ++ { ++ foreach (var member in type.GetInstanceFieldsAndEvents()) ++ { ++ // Only instance fields (including field-like events) affect the outcome. ++ FieldSymbol field; ++ switch (member.Kind) ++ { ++ case SymbolKind.Field: ++ field = (FieldSymbol)member; ++ Debug.Assert((object)(field.AssociatedSymbol as EventSymbol) == null, ++ "Didn't expect to find a field-like event backing field in the member list."); ++ break; ++ case SymbolKind.Event: ++ field = ((EventSymbol)member).AssociatedField; ++ break; ++ default: ++ throw ExceptionUtilities.UnexpectedValue(member.Kind); ++ } ++ ++ if ((object)field == null) ++ { ++ continue; ++ } ++ ++ TypeSymbol fieldType = field.NonPointerType(); ++ if (fieldType is null) ++ { ++ // pointers are unmanaged ++ continue; ++ } ++ ++ fieldType.AddUseSiteInfo(ref useSiteInfo); ++ NamedTypeSymbol fieldNamedType = fieldType as NamedTypeSymbol; ++ if ((object)fieldNamedType == null) ++ { ++ if (fieldType.IsManagedType(ref useSiteInfo)) ++ { ++ return (true, hasGenerics); ++ } ++ } ++ else ++ { ++ var result = IsManagedTypeHelper(fieldNamedType); ++ hasGenerics = hasGenerics || result.hasGenerics; ++ // NOTE: don't use ManagedKind.get on a NamedTypeSymbol - that could lead ++ // to infinite recursion. ++ switch (result.isManaged) ++ { ++ case ThreeState.True: ++ return (true, hasGenerics); ++ ++ case ThreeState.False: ++ continue; ++ ++ case ThreeState.Unknown: ++ if (!fieldNamedType.OriginalDefinition.KnownCircularStruct) ++ { ++ var (definitelyManaged, childHasGenerics) = DependsOnDefinitelyManagedType(fieldNamedType, partialClosure, ref useSiteInfo); ++ hasGenerics = hasGenerics || childHasGenerics; ++ if (definitelyManaged) ++ { ++ return (true, hasGenerics); ++ } ++ } ++ continue; ++ } ++ } ++ } ++ } ++ ++ return (false, hasGenerics); ++ } ++ + /// + /// Returns True or False if we can determine whether the type is managed + /// without looking at its fields and Unknown otherwise. +diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +index 7afcdbf268d..f9c2b43d597 100644 +--- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs ++++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +@@ -7211,117 +7211,6 @@ class Program + Diagnostic(ErrorCode.ERR_EscapeVariable, "s1").WithArguments("s1").WithLocation(7, 20)); + } + +- [Fact, WorkItem(63104, "https://github.com/dotnet/roslyn/issues/63104")] +- public void RefFieldsConsideredManaged() +- { +- var source = @" +-unsafe +-{ +- StructWithRefField* p = stackalloc StructWithRefField[10]; // 1, 2 +- C.M(); // 3 +-} +- +-public ref struct StructWithRefField +-{ +- public ref byte RefField; +-} +- +-class C +-{ +- public static void M() where T : unmanaged { } +-}"; +- var comp = CreateCompilation(source, options: TestOptions.UnsafeDebugExe, runtimeFeature: RuntimeFlag.ByRefFields); +- comp.VerifyDiagnostics( +- // (4,5): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructWithRefField') +- // StructWithRefField* p = stackalloc StructWithRefField[10]; // 1, 2 +- Diagnostic(ErrorCode.ERR_ManagedAddr, "StructWithRefField*").WithArguments("StructWithRefField").WithLocation(4, 5), +- // (4,40): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructWithRefField') +- // StructWithRefField* p = stackalloc StructWithRefField[10]; // 1, 2 +- Diagnostic(ErrorCode.ERR_ManagedAddr, "StructWithRefField").WithArguments("StructWithRefField").WithLocation(4, 40), +- // (5,7): error CS0306: The type 'StructWithRefField' may not be used as a type argument +- // C.M(); // 3 +- Diagnostic(ErrorCode.ERR_BadTypeArgument, "M").WithArguments("StructWithRefField").WithLocation(5, 7) +- ); +- +- Assert.True(comp.GetTypeByMetadataName("StructWithRefField").IsManagedTypeNoUseSiteDiagnostics); +- } +- +- [Fact, WorkItem(63104, "https://github.com/dotnet/roslyn/issues/63104")] +- public void RefFieldsConsideredManaged_Generic() +- { +- var source = @" +-unsafe +-{ +- StructWithIndirectRefField* p = stackalloc StructWithIndirectRefField[10]; // 1, 2 +- C.M(); // 3 +-} +- +-ref struct StructWithIndirectRefField +-{ +- public StructWithRefField Field; +-} +-ref struct StructWithRefField +-{ +- public ref T RefField; +-} +- +-class C +-{ +- public static void M() where T : unmanaged { } +-}"; +- var comp = CreateCompilation(source, options: TestOptions.UnsafeDebugExe, runtimeFeature: RuntimeFlag.ByRefFields); +- comp.VerifyDiagnostics( +- // (4,5): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructWithIndirectRefField') +- // StructWithIndirectRefField* p = stackalloc StructWithIndirectRefField[10]; // 1, 2 +- Diagnostic(ErrorCode.ERR_ManagedAddr, "StructWithIndirectRefField*").WithArguments("StructWithIndirectRefField").WithLocation(4, 5), +- // (4,48): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructWithIndirectRefField') +- // StructWithIndirectRefField* p = stackalloc StructWithIndirectRefField[10]; // 1, 2 +- Diagnostic(ErrorCode.ERR_ManagedAddr, "StructWithIndirectRefField").WithArguments("StructWithIndirectRefField").WithLocation(4, 48), +- // (5,9): error CS0305: Using the generic type 'StructWithRefField' requires 1 type arguments +- // C.M(); // 3 +- Diagnostic(ErrorCode.ERR_BadArity, "StructWithRefField").WithArguments("StructWithRefField", "type", "1").WithLocation(5, 9), +- // (10,36): warning CS0649: Field 'StructWithIndirectRefField.Field' is never assigned to, and will always have its default value +- // public StructWithRefField Field; +- Diagnostic(ErrorCode.WRN_UnassignedInternalField, "Field").WithArguments("StructWithIndirectRefField.Field", "").WithLocation(10, 36), +- // (14,18): warning CS0649: Field 'StructWithRefField.RefField' is never assigned to, and will always have its default value +- // public ref T RefField; +- Diagnostic(ErrorCode.WRN_UnassignedInternalField, "RefField").WithArguments("StructWithRefField.RefField", "").WithLocation(14, 18) +- ); +- +- Assert.True(comp.GetTypeByMetadataName("StructWithIndirectRefField").IsManagedTypeNoUseSiteDiagnostics); +- } +- +- [Fact, WorkItem(63104, "https://github.com/dotnet/roslyn/issues/63104")] +- public void RefFieldsConsideredManaged_Indirect() +- { +- var source = @" +-unsafe +-{ +- StructWithIndirectRefField* p = stackalloc StructWithIndirectRefField[10]; // 1, 2 +-} +- +-public ref struct StructWithIndirectRefField +-{ +- public StructWithRefField Field; +-} +- +-public ref struct StructWithRefField +-{ +- public ref byte RefField; +-}"; +- var comp = CreateCompilation(source, options: TestOptions.UnsafeDebugExe, runtimeFeature: RuntimeFlag.ByRefFields); +- comp.VerifyDiagnostics( +- // (4,5): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructWithIndirectRefField') +- // StructWithIndirectRefField* p = stackalloc StructWithIndirectRefField[10]; // 1, 2 +- Diagnostic(ErrorCode.ERR_ManagedAddr, "StructWithIndirectRefField*").WithArguments("StructWithIndirectRefField").WithLocation(4, 5), +- // (4,48): error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('StructWithIndirectRefField') +- // StructWithIndirectRefField* p = stackalloc StructWithIndirectRefField[10]; // 1, 2 +- Diagnostic(ErrorCode.ERR_ManagedAddr, "StructWithIndirectRefField").WithArguments("StructWithIndirectRefField").WithLocation(4, 48) +- ); +- +- Assert.True(comp.GetTypeByMetadataName("StructWithIndirectRefField").IsManagedTypeNoUseSiteDiagnostics); +- } +- + // Breaking change in C#11: Cannot return an 'out' parameter by reference. + [Fact] + public void BreakingChange_ReturnOutByRef() diff --git a/src/SourceBuild/tarball/patches/runtime/0004-Update-Compiler-Changes.patch b/src/SourceBuild/tarball/patches/runtime/0004-Update-Compiler-Changes.patch new file mode 100644 index 000000000..93daf765c --- /dev/null +++ b/src/SourceBuild/tarball/patches/runtime/0004-Update-Compiler-Changes.patch @@ -0,0 +1,2504 @@ +From 41c373f179df5697aafe5d0b0ca16dae28f0cdf1 Mon Sep 17 00:00:00 2001 +From: Charles Stoner <10732005+cston@users.noreply.github.com> +Date: Fri, 5 Aug 2022 07:08:31 -0700 +Subject: Update for recent compiler changes for ref fields + +Backport: https://github.com/dotnet/runtime/pull/73466 + +--- + .../Globalization/FormatProvider.Number.cs | 20 ++-- + .../System/Net/Sockets/SocketPal.Windows.cs | 2 +- + .../src/System/Globalization/DateTimeParse.cs | 106 +++++++++--------- + .../src/System/Number.Formatting.cs | 2 +- + .../src/System/Number.Parsing.cs | 2 +- + .../System/Reflection/AssemblyNameParser.cs | 2 +- + .../Reader/Utf8JsonReader.MultiSegment.cs | 20 ++-- + .../System/Text/Json/Reader/Utf8JsonReader.cs | 14 +-- + .../Converters/CastingConverter.cs | 2 +- + .../Converters/Collection/ArrayConverter.cs | 4 +- + .../Collection/ConcurrentQueueOfTConverter.cs | 2 +- + .../Collection/ConcurrentStackOfTConverter.cs | 2 +- + .../DictionaryOfTKeyTValueConverter.cs | 2 +- + .../IAsyncEnumerableOfTConverter.cs | 6 +- + .../Collection/ICollectionOfTConverter.cs | 4 +- + .../Collection/IDictionaryConverter.cs | 4 +- + .../IDictionaryOfTKeyTValueConverter.cs | 4 +- + .../Collection/IEnumerableConverter.cs | 4 +- + .../Collection/IEnumerableOfTConverter.cs | 4 +- + .../Converters/Collection/IListConverter.cs | 4 +- + .../Collection/IListOfTConverter.cs | 4 +- + ...ReadOnlyDictionaryOfTKeyTValueConverter.cs | 4 +- + .../Converters/Collection/ISetOfTConverter.cs | 4 +- + ...mmutableDictionaryOfTKeyTValueConverter.cs | 4 +- + .../ImmutableEnumerableOfTConverter.cs | 4 +- + .../Collection/JsonCollectionConverter.cs | 6 +- + .../Collection/JsonDictionaryConverter.cs | 8 +- + .../Converters/Collection/ListOfTConverter.cs | 4 +- + .../Collection/QueueOfTConverter.cs | 4 +- + .../Collection/StackOfTConverter.cs | 4 +- + .../Collection/StackOrQueueConverter.cs | 4 +- + .../Converters/FSharp/FSharpListConverter.cs | 4 +- + .../Converters/FSharp/FSharpMapConverter.cs | 4 +- + .../FSharp/FSharpOptionConverter.cs | 2 +- + .../Converters/FSharp/FSharpSetConverter.cs | 4 +- + .../FSharp/FSharpValueOptionConverter.cs | 2 +- + .../JsonMetadataServicesConverter.cs | 2 +- + .../Converters/Node/JsonObjectConverter.cs | 2 +- + .../Converters/Object/ObjectConverter.cs | 2 +- + .../Object/ObjectDefaultConverter.cs | 6 +- + ...ParameterizedConstructorConverter.Large.cs | 4 +- + ...ParameterizedConstructorConverter.Small.cs | 6 +- + ...ctWithParameterizedConstructorConverter.cs | 18 +-- + .../Converters/Value/NullableConverter.cs | 2 +- + .../Serialization/JsonConverter.ReadAhead.cs | 4 +- + .../Text/Json/Serialization/JsonConverter.cs | 8 +- + .../Serialization/JsonConverterFactory.cs | 6 +- + .../JsonConverterOfT.ReadCore.cs | 4 +- + .../Json/Serialization/JsonConverterOfT.cs | 8 +- + .../JsonSerializer.Read.HandleMetadata.cs | 10 +- + .../JsonSerializer.Read.HandlePropertyName.cs | 4 +- + .../JsonSerializer.Read.Helpers.cs | 2 +- + .../Metadata/JsonPropertyInfo.cs | 8 +- + .../Metadata/JsonPropertyInfoOfT.cs | 4 +- + .../Text/Json/ThrowHelper.Serialization.cs | 30 ++--- + 55 files changed, 203 insertions(+), 203 deletions(-) + +diff --git a/src/libraries/Common/src/System/Globalization/FormatProvider.Number.cs b/src/libraries/Common/src/System/Globalization/FormatProvider.Number.cs +index 8636878c89502..3e12859eba454 100644 +--- a/src/libraries/Common/src/System/Globalization/FormatProvider.Number.cs ++++ b/src/libraries/Common/src/System/Globalization/FormatProvider.Number.cs +@@ -356,7 +356,7 @@ private static unsafe bool AllowHyphenDuringParsing(NumberFormatInfo info) + return ret; + } + +- private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles options, ref NumberBuffer number, StringBuilder? sb, NumberFormatInfo numfmt, bool parseDecimal) ++ private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles options, scoped ref NumberBuffer number, StringBuilder? sb, NumberFormatInfo numfmt, bool parseDecimal) + { + Debug.Assert(str != null); + Debug.Assert(strEnd != null); +@@ -589,7 +589,7 @@ private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles + // For compatibility, we need to allow trailing zeros at the end of a number string + s.Slice(index).IndexOfAnyExcept('\0') < 0; + +- internal static unsafe bool TryStringToNumber(ReadOnlySpan str, NumberStyles options, ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal) ++ internal static unsafe bool TryStringToNumber(ReadOnlySpan str, NumberStyles options, scoped ref NumberBuffer number, StringBuilder sb, NumberFormatInfo numfmt, bool parseDecimal) + { + Debug.Assert(numfmt != null); + +@@ -732,7 +732,7 @@ internal static char ParseFormatSpecifier(ReadOnlySpan format, out int dig + '\0'; + } + +- internal static unsafe void NumberToString(ref ValueStringBuilder sb, ref NumberBuffer number, char format, int nMaxDigits, NumberFormatInfo info, bool isDecimal) ++ internal static unsafe void NumberToString(ref ValueStringBuilder sb, scoped ref NumberBuffer number, char format, int nMaxDigits, NumberFormatInfo info, bool isDecimal) + { + int nMinDigits = -1; + +@@ -892,7 +892,7 @@ internal static unsafe void NumberToString(ref ValueStringBuilder sb, ref Number + } + } + +- private static void FormatCurrency(ref ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info) ++ private static void FormatCurrency(ref ValueStringBuilder sb, scoped ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info) + { + string fmt = number.sign ? + s_negCurrencyFormats[info.CurrencyNegativePattern] : +@@ -918,7 +918,7 @@ private static void FormatCurrency(ref ValueStringBuilder sb, ref NumberBuffer n + } + } + +- private static unsafe void FormatFixed(ref ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, int[]? groupDigits, string sDecimal, string? sGroup) ++ private static unsafe void FormatFixed(ref ValueStringBuilder sb, scoped ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, int[]? groupDigits, string sDecimal, string? sGroup) + { + Debug.Assert(sGroup != null || groupDigits == null); + +@@ -1039,7 +1039,7 @@ private static unsafe void FormatFixed(ref ValueStringBuilder sb, ref NumberBuff + } + } + +- private static void FormatNumber(ref ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info) ++ private static void FormatNumber(ref ValueStringBuilder sb, scoped ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info) + { + string fmt = number.sign ? + s_negNumberFormats[info.NumberNegativePattern] : +@@ -1062,7 +1062,7 @@ private static void FormatNumber(ref ValueStringBuilder sb, ref NumberBuffer num + } + } + +- private static unsafe void FormatScientific(ref ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, char expChar) ++ private static unsafe void FormatScientific(ref ValueStringBuilder sb, scoped ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, char expChar) + { + char* dig = number.digits; + +@@ -1109,7 +1109,7 @@ private static unsafe void FormatExponent(ref ValueStringBuilder sb, NumberForma + } + } + +- private static unsafe void FormatGeneral(ref ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, char expChar, bool bSuppressScientific) ++ private static unsafe void FormatGeneral(ref ValueStringBuilder sb, scoped ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info, char expChar, bool bSuppressScientific) + { + int digPos = number.scale; + bool scientific = false; +@@ -1160,7 +1160,7 @@ private static unsafe void FormatGeneral(ref ValueStringBuilder sb, ref NumberBu + } + } + +- private static void FormatPercent(ref ValueStringBuilder sb, ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info) ++ private static void FormatPercent(ref ValueStringBuilder sb, scoped ref NumberBuffer number, int nMinDigits, int nMaxDigits, NumberFormatInfo info) + { + string fmt = number.sign ? + s_negPercentFormats[info.PercentNegativePattern] : +@@ -1280,7 +1280,7 @@ private static unsafe int FindSection(ReadOnlySpan format, int section) + } + } + +- internal static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, ref NumberBuffer number, ReadOnlySpan format, NumberFormatInfo info) ++ internal static unsafe void NumberToStringFormat(ref ValueStringBuilder sb, scoped ref NumberBuffer number, ReadOnlySpan format, NumberFormatInfo info) + { + int digitCount; + int decimalPos; +diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs +index b18ca11541275..872e9ee128424 100644 +--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs ++++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs +@@ -883,7 +883,7 @@ public static unsafe SocketError Poll(SafeSocketHandle handle, int microseconds, + public static unsafe SocketError Select(IList? checkRead, IList? checkWrite, IList? checkError, int microseconds) + { + const int StackThreshold = 64; // arbitrary limit to avoid too much space on stack +- static bool ShouldStackAlloc(IList? list, ref IntPtr[]? lease, out Span span) ++ static bool ShouldStackAlloc(IList? list, scoped ref IntPtr[]? lease, out Span span) + { + int count; + if (list == null || (count = list.Count) == 0) +diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs +index 6455793addd00..28ba7c96a9c5d 100644 +--- a/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs ++++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeParse.cs +@@ -79,7 +79,7 @@ internal static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan form + return false; + } + +- internal static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result) ++ internal static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan format, DateTimeFormatInfo dtfi, DateTimeStyles style, scoped ref DateTimeResult result) + { + if (s.Length == 0) + { +@@ -166,7 +166,7 @@ internal static bool TryParseExact(ReadOnlySpan s, ReadOnlySpan form + } + + internal static bool TryParseExactMultiple(ReadOnlySpan s, string?[]? formats, +- DateTimeFormatInfo dtfi, DateTimeStyles style, ref DateTimeResult result) ++ DateTimeFormatInfo dtfi, DateTimeStyles style, scoped ref DateTimeResult result) + { + if (formats == null) + { +@@ -491,7 +491,7 @@ private static bool ParseFraction(ref __DTString str, out double result) + ** FormatException if invalid timezone format is found. + ============================================================================*/ + +- private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result) ++ private static bool ParseTimeZone(ref __DTString str, scoped ref TimeSpan result) + { + // The hour/minute offset for timezone. + int hourOffset; +@@ -565,7 +565,7 @@ private static bool ParseTimeZone(ref __DTString str, ref TimeSpan result) + } + + // This is the helper function to handle timezone in string in the format like +/-0800 +- private static bool HandleTimeZone(ref __DTString str, ref DateTimeResult result) ++ private static bool HandleTimeZone(ref __DTString str, scoped ref DateTimeResult result) + { + if (str.Index < str.Length - 1) + { +@@ -601,7 +601,7 @@ private static bool HandleTimeZone(ref __DTString str, ref DateTimeResult result + // This is the lexer. Check the character at the current index, and put the found token in dtok and + // some raw date/time information in raw. + // +- private static bool Lex(DS dps, ref __DTString str, ref DateTimeToken dtok, ref DateTimeRawInfo raw, ref DateTimeResult result, ref DateTimeFormatInfo dtfi, DateTimeStyles styles) ++ private static bool Lex(DS dps, ref __DTString str, scoped ref DateTimeToken dtok, scoped ref DateTimeRawInfo raw, scoped ref DateTimeResult result, scoped ref DateTimeFormatInfo dtfi, DateTimeStyles styles) + { + int indexBeforeSeparator; + char charBeforeSeparator; +@@ -1539,14 +1539,14 @@ private static bool SetDateYDM(ref DateTimeResult result, int year, int day, int + return SetDateYMD(ref result, year, month, day); + } + +- private static void GetDefaultYear(ref DateTimeResult result, ref DateTimeStyles styles) ++ private static void GetDefaultYear(ref DateTimeResult result, scoped ref DateTimeStyles styles) + { + result.Year = result.calendar.GetYear(GetDateTimeNow(ref result, ref styles)); + result.flags |= ParseFlags.YearDefault; + } + + // Processing teriminal case: DS.DX_NN +- private static bool GetDayOfNN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDayOfNN(ref DateTimeResult result, scoped ref DateTimeStyles styles, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1588,7 +1588,7 @@ private static bool GetDayOfNN(ref DateTimeResult result, ref DateTimeStyles sty + } + + // Processing teriminal case: DS.DX_NNN +- private static bool GetDayOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDayOfNNN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1644,7 +1644,7 @@ private static bool GetDayOfNNN(ref DateTimeResult result, ref DateTimeRawInfo r + return false; + } + +- private static bool GetDayOfMN(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDayOfMN(ref DateTimeResult result, scoped ref DateTimeStyles styles, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1703,7 +1703,7 @@ private static bool GetDayOfMN(ref DateTimeResult result, ref DateTimeStyles sty + // + //////////////////////////////////////////////////////////////////////// + +- private static bool GetHebrewDayOfNM(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetHebrewDayOfNM(ref DateTimeResult result, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if (!GetMonthDayOrder(dtfi.MonthDayPattern, out int monthDayOrder)) + { +@@ -1723,7 +1723,7 @@ private static bool GetHebrewDayOfNM(ref DateTimeResult result, ref DateTimeRawI + return false; + } + +- private static bool GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDayOfNM(ref DateTimeResult result, scoped ref DateTimeStyles styles, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1776,7 +1776,7 @@ private static bool GetDayOfNM(ref DateTimeResult result, ref DateTimeStyles sty + return true; + } + +- private static bool GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDayOfMNN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1845,7 +1845,7 @@ private static bool GetDayOfMNN(ref DateTimeResult result, ref DateTimeRawInfo r + return false; + } + +- private static bool GetDayOfYNN(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDayOfYNN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1879,7 +1879,7 @@ private static bool GetDayOfYNN(ref DateTimeResult result, ref DateTimeRawInfo r + return false; + } + +- private static bool GetDayOfNNY(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDayOfNNY(ref DateTimeResult result, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1917,7 +1917,7 @@ private static bool GetDayOfNNY(ref DateTimeResult result, ref DateTimeRawInfo r + return false; + } + +- private static bool GetDayOfYMN(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetDayOfYMN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1935,7 +1935,7 @@ private static bool GetDayOfYMN(ref DateTimeResult result, ref DateTimeRawInfo r + return false; + } + +- private static bool GetDayOfYN(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetDayOfYN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1953,7 +1953,7 @@ private static bool GetDayOfYN(ref DateTimeResult result, ref DateTimeRawInfo ra + return false; + } + +- private static bool GetDayOfYM(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetDayOfYM(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + if ((result.flags & ParseFlags.HaveDate) != 0) + { +@@ -1971,7 +1971,7 @@ private static bool GetDayOfYM(ref DateTimeResult result, ref DateTimeRawInfo ra + return false; + } + +- private static void AdjustTimeMark(DateTimeFormatInfo dtfi, ref DateTimeRawInfo raw) ++ private static void AdjustTimeMark(DateTimeFormatInfo dtfi, scoped ref DateTimeRawInfo raw) + { + // Specail case for culture which uses AM as empty string. + // E.g. af-ZA (0x0436) +@@ -2025,7 +2025,7 @@ private static bool AdjustHour(ref int hour, TM timeMark) + return true; + } + +- private static bool GetTimeOfN(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetTimeOfN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + if ((result.flags & ParseFlags.HaveTime) != 0) + { +@@ -2046,7 +2046,7 @@ private static bool GetTimeOfN(ref DateTimeResult result, ref DateTimeRawInfo ra + return true; + } + +- private static bool GetTimeOfNN(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetTimeOfNN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + Debug.Assert(raw.numCount >= 2, "raw.numCount >= 2"); + if ((result.flags & ParseFlags.HaveTime) != 0) +@@ -2062,7 +2062,7 @@ private static bool GetTimeOfNN(ref DateTimeResult result, ref DateTimeRawInfo r + return true; + } + +- private static bool GetTimeOfNNN(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetTimeOfNNN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + if ((result.flags & ParseFlags.HaveTime) != 0) + { +@@ -2081,7 +2081,7 @@ private static bool GetTimeOfNNN(ref DateTimeResult result, ref DateTimeRawInfo + // + // Processing terminal state: A Date suffix followed by one number. + // +- private static bool GetDateOfDSN(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetDateOfDSN(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + if (raw.numCount != 1 || result.Day != -1) + { +@@ -2092,7 +2092,7 @@ private static bool GetDateOfDSN(ref DateTimeResult result, ref DateTimeRawInfo + return true; + } + +- private static bool GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo raw) ++ private static bool GetDateOfNDS(ref DateTimeResult result, scoped ref DateTimeRawInfo raw) + { + if (result.Month == -1) + { +@@ -2116,7 +2116,7 @@ private static bool GetDateOfNDS(ref DateTimeResult result, ref DateTimeRawInfo + return true; + } + +- private static bool GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ private static bool GetDateOfNNDS(ref DateTimeResult result, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + // For partial CJK Dates, the only valid formats are with a specified year, followed by two numbers, which + // will be the Month and Day, and with a specified Month, when the numbers are either the year and day or +@@ -2165,7 +2165,7 @@ private static bool GetDateOfNNDS(ref DateTimeResult result, ref DateTimeRawInfo + // + // A date suffix is found, use this method to put the number into the result. + // +- private static bool ProcessDateTimeSuffix(ref DateTimeResult result, ref DateTimeRawInfo raw, ref DateTimeToken dtok) ++ private static bool ProcessDateTimeSuffix(ref DateTimeResult result, scoped ref DateTimeRawInfo raw, scoped ref DateTimeToken dtok) + { + switch (dtok.suffix) + { +@@ -2229,7 +2229,7 @@ private static bool ProcessDateTimeSuffix(ref DateTimeResult result, ref DateTim + // + //////////////////////////////////////////////////////////////////////// + +- internal static bool ProcessHebrewTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ internal static bool ProcessHebrewTerminalState(DS dps, scoped ref DateTimeResult result, scoped ref DateTimeStyles styles, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + // The following are accepted terminal state for Hebrew date. + switch (dps) +@@ -2339,7 +2339,7 @@ internal static bool ProcessHebrewTerminalState(DS dps, ref DateTimeResult resul + // A terminal state has been reached, call the appropriate function to fill in the parsing result. + // Return true if the state is a terminal state. + // +- internal static bool ProcessTerminalState(DS dps, ref DateTimeResult result, ref DateTimeStyles styles, ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) ++ internal static bool ProcessTerminalState(DS dps, scoped ref DateTimeResult result, scoped ref DateTimeStyles styles, scoped ref DateTimeRawInfo raw, DateTimeFormatInfo dtfi) + { + bool passed = true; + switch (dps) +@@ -2484,7 +2484,7 @@ internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, Dat + // + // This is the real method to do the parsing work. + // +- internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, DateTimeStyles styles, ref DateTimeResult result) ++ internal static bool TryParse(ReadOnlySpan s, DateTimeFormatInfo dtfi, DateTimeStyles styles, scoped ref DateTimeResult result) + { + if (s.Length == 0) + { +@@ -2951,7 +2951,7 @@ private static bool AdjustTimeZoneToLocal(ref DateTimeResult result, bool bTimeO + // Parse the ISO8601 format string found during Parse(); + // + // +- private static bool ParseISO8601(ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, ref DateTimeResult result) ++ private static bool ParseISO8601(scoped ref DateTimeRawInfo raw, ref __DTString str, DateTimeStyles styles, scoped ref DateTimeResult result) + { + str.Index--; + int second = 0; +@@ -3158,7 +3158,7 @@ internal static bool ParseDigits(ref __DTString str, int minDigitLen, int maxDig + **Exceptions: FormatException if error in parsing number. + ==============================================================================*/ + +- private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref double result) ++ private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, scoped ref double result) + { + if (!str.GetNextDigit()) + { +@@ -3191,7 +3191,7 @@ private static bool ParseFractionExact(ref __DTString str, int maxDigitLen, ref + ** symbol is not found. + ==============================================================================*/ + +- private static bool ParseSign(ref __DTString str, ref bool result) ++ private static bool ParseSign(ref __DTString str, scoped ref bool result) + { + if (!str.GetNext()) + { +@@ -3222,7 +3222,7 @@ private static bool ParseSign(ref __DTString str, ref bool result) + **Exceptions: FormatException if errors in parsing. + ==============================================================================*/ + +- private static bool ParseTimeZoneOffset(ref __DTString str, int len, ref TimeSpan result) ++ private static bool ParseTimeZoneOffset(ref __DTString str, int len, scoped ref TimeSpan result) + { + bool isPositive = true; + int hourOffset; +@@ -3293,7 +3293,7 @@ private static bool ParseTimeZoneOffset(ref __DTString str, int len, ref TimeSpa + **Exceptions: FormatException if an abbreviated month name can not be found. + ==============================================================================*/ + +- private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) ++ private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormatInfo dtfi, scoped ref int result) + { + int maxMatchStrLen = 0; + result = -1; +@@ -3364,7 +3364,7 @@ private static bool MatchAbbreviatedMonthName(ref __DTString str, DateTimeFormat + **Exceptions: FormatException if a month name can not be found. + ==============================================================================*/ + +- private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) ++ private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, scoped ref int result) + { + int maxMatchStrLen = 0; + result = -1; +@@ -3436,7 +3436,7 @@ private static bool MatchMonthName(ref __DTString str, DateTimeFormatInfo dtfi, + **Exceptions: FormatException if a abbreviated day of week name can not be found. + ==============================================================================*/ + +- private static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) ++ private static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatInfo dtfi, scoped ref int result) + { + int maxMatchStrLen = 0; + result = -1; +@@ -3474,7 +3474,7 @@ private static bool MatchAbbreviatedDayName(ref __DTString str, DateTimeFormatIn + **Exceptions: FormatException if a day of week name can not be found. + ==============================================================================*/ + +- private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) ++ private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, scoped ref int result) + { + // Turkish (tr-TR) got day names with the same prefix. + int maxMatchStrLen = 0; +@@ -3513,7 +3513,7 @@ private static bool MatchDayName(ref __DTString str, DateTimeFormatInfo dtfi, re + **Exceptions: FormatException if an era name can not be found. + ==============================================================================*/ + +- private static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, ref int result) ++ private static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, scoped ref int result) + { + if (str.GetNext()) + { +@@ -3551,7 +3551,7 @@ private static bool MatchEraName(ref __DTString str, DateTimeFormatInfo dtfi, re + **Exceptions: FormatException if a time mark can not be found. + ==============================================================================*/ + +- private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result) ++ private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, scoped ref TM result) + { + result = TM.NotSet; + // In some cultures have empty strings in AM/PM mark. E.g. af-ZA (0x0436), the AM mark is "", and PM mark is "nm". +@@ -3606,7 +3606,7 @@ private static bool MatchTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, r + **Exceptions: FormatException if a abbreviated time mark can not be found. + ==============================================================================*/ + +- private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, ref TM result) ++ private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatInfo dtfi, scoped ref TM result) + { + // NOTENOTE : the assumption here is that abbreviated time mark is the first + // character of the AM/PM designator. If this invariant changes, we have to +@@ -3640,7 +3640,7 @@ private static bool MatchAbbreviatedTimeMark(ref __DTString str, DateTimeFormatI + **Exceptions: + ==============================================================================*/ + +- private static bool CheckNewValue(ref int currentValue, int newValue, char patternChar, ref DateTimeResult result) ++ private static bool CheckNewValue(scoped ref int currentValue, int newValue, char patternChar, scoped ref DateTimeResult result) + { + if (currentValue == -1) + { +@@ -3658,7 +3658,7 @@ private static bool CheckNewValue(ref int currentValue, int newValue, char patte + return true; + } + +- private static DateTime GetDateTimeNow(ref DateTimeResult result, ref DateTimeStyles styles) ++ private static DateTime GetDateTimeNow(scoped ref DateTimeResult result, scoped ref DateTimeStyles styles) + { + if ((result.flags & ParseFlags.CaptureOffset) != 0) + { +@@ -3678,7 +3678,7 @@ private static DateTime GetDateTimeNow(ref DateTimeResult result, ref DateTimeSt + return DateTime.Now; + } + +- private static bool CheckDefaultDateTime(ref DateTimeResult result, ref Calendar cal, DateTimeStyles styles) ++ private static bool CheckDefaultDateTime(scoped ref DateTimeResult result, scoped ref Calendar cal, DateTimeStyles styles) + { + if ((result.flags & ParseFlags.CaptureOffset) != 0) + { +@@ -3779,7 +3779,7 @@ private static bool CheckDefaultDateTime(ref DateTimeResult result, ref Calendar + // This method also set the dtfi according/parseInfo to some special pre-defined + // formats. + // +- private static string ExpandPredefinedFormat(ReadOnlySpan format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result) ++ private static string ExpandPredefinedFormat(ReadOnlySpan format, scoped ref DateTimeFormatInfo dtfi, scoped ref ParsingInfo parseInfo, scoped ref DateTimeResult result) + { + // + // Check the format to see if we need to override the dtfi to be InvariantInfo, +@@ -3842,7 +3842,7 @@ private static bool ParseJapaneseEraStart(ref __DTString str, DateTimeFormatInfo + return true; + } + +- private static void ConfigureFormatR(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result) ++ private static void ConfigureFormatR(scoped ref DateTimeFormatInfo dtfi, scoped ref ParsingInfo parseInfo, scoped ref DateTimeResult result) + { + parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); + dtfi = DateTimeFormatInfo.InvariantInfo; +@@ -3852,7 +3852,7 @@ private static void ConfigureFormatR(ref DateTimeFormatInfo dtfi, ref ParsingInf + } + } + +- private static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo) ++ private static void ConfigureFormatOS(scoped ref DateTimeFormatInfo dtfi, scoped ref ParsingInfo parseInfo) + { + parseInfo.calendar = GregorianCalendar.GetDefaultInstance(); + dtfi = DateTimeFormatInfo.InvariantInfo; +@@ -3863,9 +3863,9 @@ private static void ConfigureFormatOS(ref DateTimeFormatInfo dtfi, ref ParsingIn + private static bool ParseByFormat( + ref __DTString str, + ref __DTString format, +- ref ParsingInfo parseInfo, ++ scoped ref ParsingInfo parseInfo, + DateTimeFormatInfo dtfi, +- ref DateTimeResult result) ++ scoped ref DateTimeResult result) + { + int tokenLen; + int tempYear = 0, tempMonth = 0, tempDay = 0, tempDayOfWeek = 0, tempHour = 0, tempMinute = 0, tempSecond = 0; +@@ -4451,7 +4451,7 @@ internal static bool TryParseQuoteString(ReadOnlySpan format, int pos, ref + ReadOnlySpan formatParam, + DateTimeStyles styles, + DateTimeFormatInfo dtfi, +- ref DateTimeResult result) ++ scoped ref DateTimeResult result) + { + ParsingInfo parseInfo = default; + parseInfo.Init(); +@@ -4657,7 +4657,7 @@ internal static bool TryParseQuoteString(ReadOnlySpan format, int pos, ref + return DetermineTimeZoneAdjustments(ref result, styles, bTimeOnly); + } + +- private static bool ParseFormatR(ReadOnlySpan source, ref ParsingInfo parseInfo, ref DateTimeResult result) ++ private static bool ParseFormatR(ReadOnlySpan source, scoped ref ParsingInfo parseInfo, scoped ref DateTimeResult result) + { + // Example: + // Tue, 03 Jan 2017 08:08:05 GMT +@@ -4852,7 +4852,7 @@ private static bool ParseFormatR(ReadOnlySpan source, ref ParsingInfo pars + return true; + } + +- private static bool ParseFormatO(ReadOnlySpan source, ref DateTimeResult result) ++ private static bool ParseFormatO(ReadOnlySpan source, scoped ref DateTimeResult result) + { + // Examples: + // 2017-06-12T05:30:45.7680000 (interpreted as local time wrt to current time zone) +@@ -5066,7 +5066,7 @@ private static bool ParseFormatO(ReadOnlySpan source, ref DateTimeResult r + return DetermineTimeZoneAdjustments(ref result, DateTimeStyles.None, bTimeOnly: false); + } + +- private static Exception GetDateTimeParseException(ref DateTimeResult result) ++ private static Exception GetDateTimeParseException(scoped ref DateTimeResult result) + { + switch (result.failure) + { +@@ -5438,7 +5438,7 @@ internal TokenType GetSeparatorToken(DateTimeFormatInfo dtfi, out int indexBefor + Index + target.Length <= Length && + m_info.Compare(Value.Slice(Index, target.Length), target, CompareOptions.IgnoreCase) == 0; + +- internal bool MatchSpecifiedWords(string target, bool checkWordBoundary, ref int matchLength) ++ internal bool MatchSpecifiedWords(string target, bool checkWordBoundary, scoped ref int matchLength) + { + int valueRemaining = Value.Length - Index; + matchLength = target.Length; +@@ -5584,7 +5584,7 @@ internal bool Match(char ch) + // maxMatchStrLen [in/out] the initialized maximum length. This parameter can be used to + // find the longest match in two string arrays. + // +- internal int MatchLongestWords(string[] words, ref int maxMatchStrLen) ++ internal int MatchLongestWords(string[] words, scoped ref int maxMatchStrLen) + { + int result = -1; + for (int i = 0; i < words.Length; i++) +diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs +index d84220ef8889b..1b28f08a0049f 100644 +--- a/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs ++++ b/src/libraries/System.Private.CoreLib/src/System/Number.Formatting.cs +@@ -349,7 +349,7 @@ public static unsafe bool TryFormatDecimal(decimal value, ReadOnlySpan for + return sb.TryCopyTo(destination, out charsWritten); + } + +- internal static unsafe void DecimalToNumber(ref decimal d, ref NumberBuffer number) ++ internal static unsafe void DecimalToNumber(scoped ref decimal d, ref NumberBuffer number) + { + byte* buffer = number.GetDigitsPointer(); + number.DigitsCount = DecimalPrecision; +diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs b/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs +index 65c1c8745eb65..a9bb8ec61bd68 100644 +--- a/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs ++++ b/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs +@@ -342,7 +342,7 @@ internal static UInt128 ParseUInt128(ReadOnlySpan value, NumberStyles styl + return result; + } + +- private static unsafe bool TryParseNumber(ref char* str, char* strEnd, NumberStyles styles, ref NumberBuffer number, NumberFormatInfo info) ++ private static unsafe bool TryParseNumber(scoped ref char* str, char* strEnd, NumberStyles styles, ref NumberBuffer number, NumberFormatInfo info) + { + Debug.Assert(str != null); + Debug.Assert(strEnd != null); +diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs +index ab6dce32c2b95..8ab6b644581f7 100644 +--- a/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs ++++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/AssemblyNameParser.cs +@@ -73,7 +73,7 @@ public static AssemblyNameParts Parse(ReadOnlySpan name) + return new AssemblyNameParser(name).Parse(); + } + +- private void RecordNewSeenOrThrow(ref AttributeKind seenAttributes, AttributeKind newAttribute) ++ private void RecordNewSeenOrThrow(scoped ref AttributeKind seenAttributes, AttributeKind newAttribute) + { + if ((seenAttributes & newAttribute) != 0) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs +index 9bdc3a1cad151..8635031292e32 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs +@@ -1102,7 +1102,7 @@ private bool ConsumeStringAndValidateMultiSegment(ReadOnlySpan data, int i + return true; + } + +- private void RollBackState(in PartialStateForRollback state, bool isError = false) ++ private void RollBackState(scoped in PartialStateForRollback state, bool isError = false) + { + _totalConsumed = state._prevTotalConsumed; + +@@ -1251,7 +1251,7 @@ private bool TryGetNumberMultiSegment(ReadOnlySpan data, out int consumed) + return true; + } + +- private ConsumeNumberResult ConsumeNegativeSignMultiSegment(ref ReadOnlySpan data, ref int i, in PartialStateForRollback rollBackState) ++ private ConsumeNumberResult ConsumeNegativeSignMultiSegment(ref ReadOnlySpan data, scoped ref int i, scoped in PartialStateForRollback rollBackState) + { + Debug.Assert(i == 0); + byte nextByte = data[i]; +@@ -1293,7 +1293,7 @@ private ConsumeNumberResult ConsumeNegativeSignMultiSegment(ref ReadOnlySpan data, ref int i, in PartialStateForRollback rollBackState) ++ private ConsumeNumberResult ConsumeZeroMultiSegment(ref ReadOnlySpan data, scoped ref int i, scoped in PartialStateForRollback rollBackState) + { + Debug.Assert(data[i] == (byte)'0'); + Debug.Assert(i == 0 || i == 1); +@@ -1349,7 +1349,7 @@ private ConsumeNumberResult ConsumeZeroMultiSegment(ref ReadOnlySpan data, + return ConsumeNumberResult.OperationIncomplete; + } + +- private ConsumeNumberResult ConsumeIntegerDigitsMultiSegment(ref ReadOnlySpan data, ref int i) ++ private ConsumeNumberResult ConsumeIntegerDigitsMultiSegment(ref ReadOnlySpan data, scoped ref int i) + { + byte nextByte = default; + int counter = 0; +@@ -1427,7 +1427,7 @@ private ConsumeNumberResult ConsumeIntegerDigitsMultiSegment(ref ReadOnlySpan data, ref int i, in PartialStateForRollback rollBackState) ++ private ConsumeNumberResult ConsumeDecimalDigitsMultiSegment(ref ReadOnlySpan data, scoped ref int i, scoped in PartialStateForRollback rollBackState) + { + if (i >= data.Length) + { +@@ -1461,7 +1461,7 @@ private ConsumeNumberResult ConsumeDecimalDigitsMultiSegment(ref ReadOnlySpan data, ref int i, in PartialStateForRollback rollBackState) ++ private ConsumeNumberResult ConsumeSignMultiSegment(ref ReadOnlySpan data, scoped ref int i, scoped in PartialStateForRollback rollBackState) + { + if (i >= data.Length) + { +@@ -1926,7 +1926,7 @@ private ConsumeTokenResult ConsumeNextTokenFromLastNonCommentTokenMultiSegment() + return ConsumeTokenResult.NotEnoughDataRollBackState; + } + +- private bool SkipAllCommentsMultiSegment(ref byte marker) ++ private bool SkipAllCommentsMultiSegment(scoped ref byte marker) + { + while (marker == JsonConstants.Slash) + { +@@ -1961,7 +1961,7 @@ private bool SkipAllCommentsMultiSegment(ref byte marker) + return false; + } + +- private bool SkipAllCommentsMultiSegment(ref byte marker, ExceptionResource resource) ++ private bool SkipAllCommentsMultiSegment(scoped ref byte marker, ExceptionResource resource) + { + while (marker == JsonConstants.Slash) + { +@@ -2394,7 +2394,7 @@ private bool SkipSingleLineCommentMultiSegment(ReadOnlySpan localBuffer, o + return true; + } + +- private int FindLineSeparatorMultiSegment(ReadOnlySpan localBuffer, ref int dangerousLineSeparatorBytesConsumed) ++ private int FindLineSeparatorMultiSegment(ReadOnlySpan localBuffer, scoped ref int dangerousLineSeparatorBytesConsumed) + { + Debug.Assert(dangerousLineSeparatorBytesConsumed >= 0 && dangerousLineSeparatorBytesConsumed <= 2); + +@@ -2444,7 +2444,7 @@ private int FindLineSeparatorMultiSegment(ReadOnlySpan localBuffer, ref in + } + + // assumes first byte (JsonConstants.UnexpectedEndOfLineSeparator) is already read +- private void ThrowOnDangerousLineSeparatorMultiSegment(ReadOnlySpan localBuffer, ref int dangerousLineSeparatorBytesConsumed) ++ private void ThrowOnDangerousLineSeparatorMultiSegment(ReadOnlySpan localBuffer, scoped ref int dangerousLineSeparatorBytesConsumed) + { + Debug.Assert(dangerousLineSeparatorBytesConsumed == 1 || dangerousLineSeparatorBytesConsumed == 2); + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs +index 699ccb6fb5a71..eb8518376681c 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs +@@ -1524,7 +1524,7 @@ private bool TryGetNumber(ReadOnlySpan data, out int consumed) + return true; + } + +- private ConsumeNumberResult ConsumeNegativeSign(ref ReadOnlySpan data, ref int i) ++ private ConsumeNumberResult ConsumeNegativeSign(ref ReadOnlySpan data, scoped ref int i) + { + byte nextByte = data[i]; + +@@ -1551,7 +1551,7 @@ private ConsumeNumberResult ConsumeNegativeSign(ref ReadOnlySpan data, ref + return ConsumeNumberResult.OperationIncomplete; + } + +- private ConsumeNumberResult ConsumeZero(ref ReadOnlySpan data, ref int i) ++ private ConsumeNumberResult ConsumeZero(ref ReadOnlySpan data, scoped ref int i) + { + Debug.Assert(data[i] == (byte)'0'); + i++; +@@ -1590,7 +1590,7 @@ private ConsumeNumberResult ConsumeZero(ref ReadOnlySpan data, ref int i) + return ConsumeNumberResult.OperationIncomplete; + } + +- private ConsumeNumberResult ConsumeIntegerDigits(ref ReadOnlySpan data, ref int i) ++ private ConsumeNumberResult ConsumeIntegerDigits(ref ReadOnlySpan data, scoped ref int i) + { + byte nextByte = default; + for (; i < data.Length; i++) +@@ -1623,7 +1623,7 @@ private ConsumeNumberResult ConsumeIntegerDigits(ref ReadOnlySpan data, re + return ConsumeNumberResult.OperationIncomplete; + } + +- private ConsumeNumberResult ConsumeDecimalDigits(ref ReadOnlySpan data, ref int i) ++ private ConsumeNumberResult ConsumeDecimalDigits(ref ReadOnlySpan data, scoped ref int i) + { + if (i >= data.Length) + { +@@ -1645,7 +1645,7 @@ private ConsumeNumberResult ConsumeDecimalDigits(ref ReadOnlySpan data, re + return ConsumeIntegerDigits(ref data, ref i); + } + +- private ConsumeNumberResult ConsumeSign(ref ReadOnlySpan data, ref int i) ++ private ConsumeNumberResult ConsumeSign(ref ReadOnlySpan data, scoped ref int i) + { + if (i >= data.Length) + { +@@ -2059,7 +2059,7 @@ private ConsumeTokenResult ConsumeNextTokenFromLastNonCommentToken() + return ConsumeTokenResult.NotEnoughDataRollBackState; + } + +- private bool SkipAllComments(ref byte marker) ++ private bool SkipAllComments(scoped ref byte marker) + { + while (marker == JsonConstants.Slash) + { +@@ -2094,7 +2094,7 @@ private bool SkipAllComments(ref byte marker) + return false; + } + +- private bool SkipAllComments(ref byte marker, ExceptionResource resource) ++ private bool SkipAllComments(scoped ref byte marker, ExceptionResource resource) + { + while (marker == JsonConstants.Slash) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/CastingConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/CastingConverter.cs +index 090480c83fb90..d33924a4dcdce 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/CastingConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/CastingConverter.cs +@@ -43,7 +43,7 @@ internal CastingConverter(JsonConverter sourceConverter) : base(initial + public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) + => _sourceConverter.Write(writer, CastOnWrite(value), options); + +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out T? value) + { + bool result = _sourceConverter.OnTryRead(ref reader, typeToConvert, options, ref state, out TSource? sourceValue); + value = CastOnRead(sourceValue); +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs +index 3aa53102d60e1..6ed3d1905fd30 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs +@@ -13,13 +13,13 @@ internal sealed class ArrayConverter : IEnumerableDefault + { + internal override bool CanHaveMetadata => false; + +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + state.Current.ReturnValue = new List(); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs +index 55c70f35f257d..1053a27bcdfdf 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs +@@ -9,7 +9,7 @@ internal sealed class ConcurrentQueueOfTConverter + : IEnumerableDefaultConverter + where TCollection : ConcurrentQueue + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Enqueue(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs +index 87506619bbfe7..5f7f9a5be84b4 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs +@@ -9,7 +9,7 @@ internal sealed class ConcurrentStackOfTConverter + : IEnumerableDefaultConverter + where TCollection : ConcurrentStack + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Push(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs +index cd83ea2925921..5d78f1e62ff1d 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs +@@ -15,7 +15,7 @@ internal sealed class DictionaryOfTKeyTValueConverter + where TCollection : Dictionary + where TKey : notnull + { +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!)[key] = value; + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs +index 8dd3924f66189..fb1887e30c813 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs +@@ -12,7 +12,7 @@ internal sealed class IAsyncEnumerableOfTConverter + : JsonCollectionConverter + where TAsyncEnumerable : IAsyncEnumerable + { +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out TAsyncEnumerable value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out TAsyncEnumerable value) + { + if (!typeToConvert.IsAssignableFrom(typeof(IAsyncEnumerable))) + { +@@ -22,13 +22,13 @@ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, + return base.OnTryRead(ref reader, typeToConvert, options, ref state, out value!); + } + +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((BufferedAsyncEnumerable)state.Current.ReturnValue!)._buffer.Add(value); + } + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + state.Current.ReturnValue = new BufferedAsyncEnumerable(); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs +index b975961d21c57..a423ae1b98f8c 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs +@@ -14,7 +14,7 @@ internal sealed class ICollectionOfTConverter + : IEnumerableDefaultConverter + where TCollection : ICollection + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +@@ -24,7 +24,7 @@ protected override void Add(in TElement value, ref ReadStack state) + }; + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + base.CreateCollection(ref reader, ref state, options); + TCollection returnValue = (TCollection)state.Current.ReturnValue!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs +index 3d86186659976..07c2165c68ca8 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs +@@ -16,7 +16,7 @@ internal sealed class IDictionaryConverter + : JsonDictionaryConverter + where TDictionary : IDictionary + { +- protected override void Add(string key, in object? value, JsonSerializerOptions options, ref ReadStack state) ++ protected override void Add(string key, in object? value, JsonSerializerOptions options, scoped ref ReadStack state) + { + TDictionary collection = (TDictionary)state.Current.ReturnValue!; + collection[key] = value; +@@ -26,7 +26,7 @@ protected override void Add(string key, in object? value, JsonSerializerOptions + } + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + base.CreateCollection(ref reader, ref state); + TDictionary returnValue = (TDictionary)state.Current.ReturnValue!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs +index 4102404974c1c..85ec30b2a9fb3 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs +@@ -16,7 +16,7 @@ internal sealed class IDictionaryOfTKeyTValueConverter + where TKey : notnull + { +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) + { + TDictionary collection = (TDictionary)state.Current.ReturnValue!; + collection[key] = value; +@@ -26,7 +26,7 @@ protected override void Add(TKey key, in TValue value, JsonSerializerOptions opt + }; + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + base.CreateCollection(ref reader, ref state); + TDictionary returnValue = (TDictionary)state.Current.ReturnValue!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs +index 9c98de517695b..f69d6780f5996 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs +@@ -17,13 +17,13 @@ internal sealed class IEnumerableConverter + { + private readonly bool _isDeserializable = typeof(TCollection).IsAssignableFrom(typeof(List)); + +- protected override void Add(in object? value, ref ReadStack state) ++ protected override void Add(in object? value, scoped ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + if (!_isDeserializable) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs +index ed1ba61a2132b..c11602fc75112 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs +@@ -15,13 +15,13 @@ internal sealed class IEnumerableOfTConverter + { + private readonly bool _isDeserializable = typeof(TCollection).IsAssignableFrom(typeof(List)); + +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + if (!_isDeserializable) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs +index 7c54b27ad93b5..d405282a054f1 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs +@@ -13,7 +13,7 @@ internal sealed class IListConverter + : JsonCollectionConverter + where TCollection : IList + { +- protected override void Add(in object? value, ref ReadStack state) ++ protected override void Add(in object? value, scoped ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +@@ -23,7 +23,7 @@ protected override void Add(in object? value, ref ReadStack state) + } + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + base.CreateCollection(ref reader, ref state, options); + TCollection returnValue = (TCollection)state.Current.ReturnValue!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs +index 4de171768d793..47a7f8c116283 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs +@@ -14,7 +14,7 @@ internal sealed class IListOfTConverter + : IEnumerableDefaultConverter + where TCollection : IList + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +@@ -24,7 +24,7 @@ protected override void Add(in TElement value, ref ReadStack state) + }; + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + base.CreateCollection(ref reader, ref state, options); + TCollection returnValue = (TCollection)state.Current.ReturnValue!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs +index 9841403ec7acc..29cafebf4013a 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs +@@ -13,13 +13,13 @@ internal sealed class IReadOnlyDictionaryOfTKeyTValueConverter)); + +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) + { + ((Dictionary)state.Current.ReturnValue!)[key] = value; + } + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + if (!_isDeserializable) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs +index 2c1fd6b756f3e..71da570158b2f 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs +@@ -11,7 +11,7 @@ internal sealed class ISetOfTConverter + : IEnumerableDefaultConverter + where TCollection : ISet + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +@@ -21,7 +21,7 @@ protected override void Add(in TElement value, ref ReadStack state) + }; + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + base.CreateCollection(ref reader, ref state, options); + TCollection returnValue = (TCollection)state.Current.ReturnValue!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs +index de10ec730bf0f..464d5b87caf7c 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs +@@ -12,7 +12,7 @@ internal class ImmutableDictionaryOfTKeyTValueConverter + where TKey : notnull + { +- protected sealed override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) ++ protected sealed override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) + { + ((Dictionary)state.Current.ReturnValue!)[key] = value; + } +@@ -20,7 +20,7 @@ protected sealed override void Add(TKey key, in TValue value, JsonSerializerOpti + internal sealed override bool CanHaveMetadata => false; + + internal override bool SupportsCreateObjectDelegate => false; +- protected sealed override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state) ++ protected sealed override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + state.Current.ReturnValue = new Dictionary(); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs +index 46d7f2cc11b8b..4bcd70e1341b0 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs +@@ -11,7 +11,7 @@ internal class ImmutableEnumerableOfTConverter + : IEnumerableDefaultConverter + where TCollection : IEnumerable + { +- protected sealed override void Add(in TElement value, ref ReadStack state) ++ protected sealed override void Add(in TElement value, scoped ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } +@@ -19,7 +19,7 @@ protected sealed override void Add(in TElement value, ref ReadStack state) + internal sealed override bool CanHaveMetadata => false; + + internal override bool SupportsCreateObjectDelegate => false; +- protected sealed override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected sealed override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + state.Current.ReturnValue = new List(); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs +index 0116002987455..2e3198ce33f2b 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs +@@ -18,12 +18,12 @@ internal abstract class JsonCollectionConverter : JsonRes + internal sealed override ConverterStrategy ConverterStrategy => ConverterStrategy.Enumerable; + internal override Type ElementType => typeof(TElement); + +- protected abstract void Add(in TElement value, ref ReadStack state); ++ protected abstract void Add(in TElement value, scoped ref ReadStack state); + + /// + /// When overridden, create the collection. It may be a temporary collection or the final collection. + /// +- protected virtual void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected virtual void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; + +@@ -63,7 +63,7 @@ protected static JsonConverter GetElementConverter(ref WriteStack stat + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options, +- ref ReadStack state, ++ scoped ref ReadStack state, + [MaybeNullWhen(false)] out TCollection value) + { + JsonTypeInfo elementTypeInfo = state.Current.JsonTypeInfo.ElementTypeInfo!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs +index b255d679b3446..0b148fefb7203 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs +@@ -27,7 +27,7 @@ internal abstract class JsonDictionaryConverter : Jso + /// + /// When overridden, adds the value to the collection. + /// +- protected abstract void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state); ++ protected abstract void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state); + + /// + /// When overridden, converts the temporary collection held in state.Current.ReturnValue to the final collection. +@@ -38,7 +38,7 @@ internal abstract class JsonDictionaryConverter : Jso + /// + /// When overridden, create the collection. It may be a temporary collection or the final collection. + /// +- protected virtual void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state) ++ protected virtual void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; + +@@ -78,7 +78,7 @@ protected static JsonConverter GetConverter(JsonTypeInfo typeInfo) + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options, +- ref ReadStack state, ++ scoped ref ReadStack state, + [MaybeNullWhen(false)] out TDictionary value) + { + JsonTypeInfo keyTypeInfo = state.Current.JsonTypeInfo.KeyTypeInfo!; +@@ -301,7 +301,7 @@ protected static JsonConverter GetConverter(JsonTypeInfo typeInfo) + value = (TDictionary)state.Current.ReturnValue!; + return true; + +- static TKey ReadDictionaryKey(JsonConverter keyConverter, ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ static TKey ReadDictionaryKey(JsonConverter keyConverter, ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + TKey key; + string unescapedPropertyNameAsString = reader.GetString()!; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs +index 35e398fe5869f..76aebb4d29cb8 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs +@@ -10,12 +10,12 @@ internal sealed class ListOfTConverter + : IEnumerableDefaultConverter + where TCollection: List + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Add(value); + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + if (state.Current.JsonTypeInfo.CreateObject == null) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs +index 6e28f4ef2458b..d0f95108cebd6 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs +@@ -9,12 +9,12 @@ internal sealed class QueueOfTConverter + : IEnumerableDefaultConverter + where TCollection : Queue + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Enqueue(value); + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + if (state.Current.JsonTypeInfo.CreateObject == null) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs +index 565754d6a24b8..429071bc2858d 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs +@@ -10,12 +10,12 @@ internal sealed class StackOfTConverter + : IEnumerableDefaultConverter + where TCollection : Stack + { +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Push(value); + } + +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + if (state.Current.JsonTypeInfo.CreateObject == null) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs +index 59f3f3c336ec9..410975df09bef 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs +@@ -11,14 +11,14 @@ internal class StackOrQueueConverter + : JsonCollectionConverter + where TCollection : IEnumerable + { +- protected sealed override void Add(in object? value, ref ReadStack state) ++ protected sealed override void Add(in object? value, scoped ref ReadStack state) + { + var addMethodDelegate = ((Action?)state.Current.JsonTypeInfo.AddMethodDelegate); + Debug.Assert(addMethodDelegate != null); + addMethodDelegate((TCollection)state.Current.ReturnValue!, value); + } + +- protected sealed override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected sealed override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; + Func? constructorDelegate = typeInfo.CreateObject; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs +index fa228e000f360..ae424affe9082 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs +@@ -20,13 +20,13 @@ public FSharpListConverter() + _listConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpListConstructor(); + } + +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + state.Current.ReturnValue = new List(); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs +index c7cebda077438..86ba3e913f432 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs +@@ -21,7 +21,7 @@ public FSharpMapConverter() + _mapConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpMapConstructor(); + } + +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) + { + ((List>)state.Current.ReturnValue!).Add (new Tuple(key, value)); + } +@@ -29,7 +29,7 @@ protected override void Add(TKey key, in TValue value, JsonSerializerOptions opt + internal override bool CanHaveMetadata => false; + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + state.Current.ReturnValue = new List>(); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs +index c0ba55e63d2a4..8130f829471c7 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpOptionConverter.cs +@@ -37,7 +37,7 @@ public FSharpOptionConverter(JsonConverter elementConverter) + RequiresReadAhead = elementConverter.RequiresReadAhead; + } + +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out TOption? value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out TOption? value) + { + // `null` values deserialize as `None` + if (!state.IsContinuation && reader.TokenType == JsonTokenType.Null) +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs +index 73230b273c99d..5993b7830ba93 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs +@@ -20,13 +20,13 @@ public FSharpSetConverter() + _setConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpSetConstructor(); + } + +- protected override void Add(in TElement value, ref ReadStack state) ++ protected override void Add(in TElement value, scoped ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } + + internal override bool SupportsCreateObjectDelegate => false; +- protected override void CreateCollection(ref Utf8JsonReader reader, ref ReadStack state, JsonSerializerOptions options) ++ protected override void CreateCollection(ref Utf8JsonReader reader, scoped ref ReadStack state, JsonSerializerOptions options) + { + state.Current.ReturnValue = new List(); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs +index 1c147c4b64069..7d960e17b0458 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpValueOptionConverter.cs +@@ -37,7 +37,7 @@ public FSharpValueOptionConverter(JsonConverter elementConverter) + RequiresReadAhead = elementConverter.RequiresReadAhead; + } + +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out TValueOption value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out TValueOption value) + { + // `null` values deserialize as `ValueNone` + if (!state.IsContinuation && reader.TokenType == JsonTokenType.Null) +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/JsonMetadataServicesConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/JsonMetadataServicesConverter.cs +index 45f8a66ce57c5..e029760aa9152 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/JsonMetadataServicesConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/JsonMetadataServicesConverter.cs +@@ -60,7 +60,7 @@ public JsonMetadataServicesConverter(JsonConverter converter) + _converterStrategy = converter.ConverterStrategy; + } + +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out T? value) + => Converter.OnTryRead(ref reader, typeToConvert, options, ref state, out value); + + internal override bool OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, ref WriteStack state) +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonObjectConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonObjectConverter.cs +index b3279a01936dd..b8e2d7eea528b 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonObjectConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonObjectConverter.cs +@@ -19,7 +19,7 @@ internal override void ConfigureJsonTypeInfo(JsonTypeInfo jsonTypeInfo, JsonSeri + string propertyName, + ref Utf8JsonReader reader, + JsonSerializerOptions options, +- ref ReadStack state) ++ scoped ref ReadStack state) + { + bool success = JsonNodeConverter.Instance.TryRead(ref reader, typeof(JsonNode), options, ref state, out JsonNode? value); + Debug.Assert(success); // Node converters are not resumable. +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverter.cs +index 6c0a095061fac..62835f45b9406 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectConverter.cs +@@ -35,7 +35,7 @@ public override void Write(Utf8JsonWriter writer, object? value, JsonSerializerO + writer.WriteEndObject(); + } + +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out object? value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out object? value) + { + object? referenceValue; + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectDefaultConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectDefaultConverter.cs +index f12f1991b5625..4a2090f659a99 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectDefaultConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectDefaultConverter.cs +@@ -17,7 +17,7 @@ internal class ObjectDefaultConverter : JsonObjectConverter where T : notn + internal override bool CanHaveMetadata => true; + internal override bool SupportsCreateObjectDelegate => true; + +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, [MaybeNullWhen(false)] out T value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, [MaybeNullWhen(false)] out T value) + { + JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo; + +@@ -413,7 +413,7 @@ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected static void ReadPropertyValue( + object obj, +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader, + JsonPropertyInfo jsonPropertyInfo, + bool useExtensionProperty) +@@ -442,7 +442,7 @@ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, + state.Current.EndProperty(); + } + +- protected static bool ReadAheadPropertyValue(ref ReadStack state, ref Utf8JsonReader reader, JsonPropertyInfo jsonPropertyInfo) ++ protected static bool ReadAheadPropertyValue(scoped ref ReadStack state, ref Utf8JsonReader reader, JsonPropertyInfo jsonPropertyInfo) + { + // Returning false below will cause the read-ahead functionality to finish the read. + state.Current.PropertyState = StackFramePropertyState.ReadValue; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs +index eabe8e6a62fec..1059bd1ef3971 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs +@@ -14,7 +14,7 @@ namespace System.Text.Json.Serialization.Converters + /// + internal class LargeObjectWithParameterizedConstructorConverter : ObjectWithParameterizedConstructorConverter where T : notnull + { +- protected sealed override bool ReadAndCacheConstructorArgument(ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo) ++ protected sealed override bool ReadAndCacheConstructorArgument(scoped ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo) + { + Debug.Assert(jsonParameterInfo.ShouldDeserialize); + Debug.Assert(jsonParameterInfo.Options != null); +@@ -51,7 +51,7 @@ protected sealed override object CreateObject(ref ReadStackFrame frame) + return obj; + } + +- protected sealed override void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options) ++ protected sealed override void InitializeConstructorArgumentCaches(scoped ref ReadStack state, JsonSerializerOptions options) + { + JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs +index 1482a32144ec4..1c7314b1b5960 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs +@@ -22,7 +22,7 @@ protected override object CreateObject(ref ReadStackFrame frame) + } + + protected override bool ReadAndCacheConstructorArgument( +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader, + JsonParameterInfo jsonParameterInfo) + { +@@ -54,7 +54,7 @@ protected override object CreateObject(ref ReadStackFrame frame) + } + + private static bool TryRead( +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader, + JsonParameterInfo jsonParameterInfo, + out TArg arg) +@@ -79,7 +79,7 @@ protected override object CreateObject(ref ReadStackFrame frame) + return success; + } + +- protected override void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options) ++ protected override void InitializeConstructorArgumentCaches(scoped ref ReadStack state, JsonSerializerOptions options) + { + JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs +index aeba2b9fc95d2..cb501ff8aa307 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs +@@ -21,7 +21,7 @@ internal abstract partial class ObjectWithParameterizedConstructorConverter : + { + internal sealed override bool ConstructorIsParameterized => true; + +- internal sealed override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, [MaybeNullWhen(false)] out T value) ++ internal sealed override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, [MaybeNullWhen(false)] out T value) + { + JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo; + +@@ -246,9 +246,9 @@ internal sealed override bool OnTryRead(ref Utf8JsonReader reader, Type typeToCo + return true; + } + +- protected abstract void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options); ++ protected abstract void InitializeConstructorArgumentCaches(scoped ref ReadStack state, JsonSerializerOptions options); + +- protected abstract bool ReadAndCacheConstructorArgument(ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo); ++ protected abstract bool ReadAndCacheConstructorArgument(scoped ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo); + + protected abstract object CreateObject(ref ReadStackFrame frame); + +@@ -256,7 +256,7 @@ internal sealed override bool OnTryRead(ref Utf8JsonReader reader, Type typeToCo + /// Performs a full first pass of the JSON input and deserializes the ctor args. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] +- private void ReadConstructorArguments(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options) ++ private void ReadConstructorArguments(scoped ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options) + { + BeginRead(ref state, ref reader, options); + +@@ -342,7 +342,7 @@ private void ReadConstructorArguments(ref ReadStack state, ref Utf8JsonReader re + } + } + +- private bool ReadConstructorArgumentsWithContinuation(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options) ++ private bool ReadConstructorArgumentsWithContinuation(scoped ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options) + { + // Process all properties. + while (true) +@@ -425,7 +425,7 @@ private bool ReadConstructorArgumentsWithContinuation(ref ReadStack state, ref U + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private bool HandleConstructorArgumentWithContinuation( +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader, + JsonParameterInfo jsonParameterInfo) + { +@@ -462,7 +462,7 @@ private bool ReadConstructorArgumentsWithContinuation(ref ReadStack state, ref U + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool HandlePropertyWithContinuation( +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader, + JsonPropertyInfo jsonPropertyInfo) + { +@@ -537,7 +537,7 @@ private bool ReadConstructorArgumentsWithContinuation(ref ReadStack state, ref U + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] +- private void BeginRead(ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options) ++ private void BeginRead(scoped ref ReadStack state, ref Utf8JsonReader reader, JsonSerializerOptions options) + { + JsonTypeInfo jsonTypeInfo = state.Current.JsonTypeInfo; + +@@ -562,7 +562,7 @@ private void BeginRead(ref ReadStack state, ref Utf8JsonReader reader, JsonSeria + /// Lookup the constructor parameter given its name in the reader. + /// + protected virtual bool TryLookupConstructorParameter( +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader, + JsonSerializerOptions options, + out JsonParameterInfo? jsonParameterInfo) +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverter.cs +index 292d70e42b646..1e31cba7043ea 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/NullableConverter.cs +@@ -25,7 +25,7 @@ public NullableConverter(JsonConverter elementConverter) + RequiresReadAhead = elementConverter.RequiresReadAhead; + } + +- internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) ++ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out T? value) + { + if (!state.IsContinuation && reader.TokenType == JsonTokenType.Null) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.ReadAhead.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.ReadAhead.cs +index 50987aa96cb65..b15deac8c486a 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.ReadAhead.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.ReadAhead.cs +@@ -17,7 +17,7 @@ public abstract partial class JsonConverter + // AggressiveInlining used since this method is on a hot path and short. The optionally called + // method DoSingleValueReadWithReadAhead is not inlined. + [MethodImpl(MethodImplOptions.AggressiveInlining)] +- internal static bool SingleValueReadWithReadAhead(bool requiresReadAhead, ref Utf8JsonReader reader, ref ReadStack state) ++ internal static bool SingleValueReadWithReadAhead(bool requiresReadAhead, ref Utf8JsonReader reader, scoped ref ReadStack state) + { + bool readAhead = requiresReadAhead && state.ReadAhead; + if (!readAhead) +@@ -28,7 +28,7 @@ internal static bool SingleValueReadWithReadAhead(bool requiresReadAhead, ref Ut + return DoSingleValueReadWithReadAhead(ref reader, ref state); + } + +- internal static bool DoSingleValueReadWithReadAhead(ref Utf8JsonReader reader, ref ReadStack state) ++ internal static bool DoSingleValueReadWithReadAhead(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + // When we're reading ahead we always have to save the state as we don't know if the next token + // is an opening object or an array brace. +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs +index 652637873a2d5..f2a4693dc73de 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs +@@ -62,7 +62,7 @@ public abstract partial class JsonConverter + string propertyName, + ref Utf8JsonReader reader, + JsonSerializerOptions options, +- ref ReadStack state) ++ scoped ref ReadStack state) + { + Debug.Fail("Should not be reachable."); + +@@ -95,7 +95,7 @@ public abstract partial class JsonConverter + /// + /// Loosely-typed ReadCore() that forwards to strongly-typed ReadCore(). + /// +- internal abstract object? ReadCoreAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state); ++ internal abstract object? ReadCoreAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, scoped ref ReadStack state); + + + internal static bool ShouldFlush(Utf8JsonWriter writer, ref WriteStack state) +@@ -107,8 +107,8 @@ internal static bool ShouldFlush(Utf8JsonWriter writer, ref WriteStack state) + // This is used internally to quickly determine the type being converted for JsonConverter. + internal abstract Type TypeToConvert { get; } + +- internal abstract bool OnTryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state, out object? value); +- internal abstract bool TryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state, out object? value); ++ internal abstract bool OnTryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, scoped ref ReadStack state, out object? value); ++ internal abstract bool TryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, scoped ref ReadStack state, out object? value); + + internal abstract bool TryWriteAsObject(Utf8JsonWriter writer, object? value, JsonSerializerOptions options, ref WriteStack state); + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterFactory.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterFactory.cs +index fbc407b4a347f..ecd84de71c066 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterFactory.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterFactory.cs +@@ -64,7 +64,7 @@ internal JsonConverter GetConverterInternal(Type typeToConvert, JsonSerializerOp + internal sealed override object ReadCoreAsObject( + ref Utf8JsonReader reader, + JsonSerializerOptions options, +- ref ReadStack state) ++ scoped ref ReadStack state) + { + Debug.Fail("We should never get here."); + +@@ -74,7 +74,7 @@ internal JsonConverter GetConverterInternal(Type typeToConvert, JsonSerializerOp + internal sealed override bool OnTryReadAsObject( + ref Utf8JsonReader reader, + JsonSerializerOptions options, +- ref ReadStack state, ++ scoped ref ReadStack state, + out object? value) + { + Debug.Fail("We should never get here."); +@@ -85,7 +85,7 @@ internal JsonConverter GetConverterInternal(Type typeToConvert, JsonSerializerOp + internal sealed override bool TryReadAsObject( + ref Utf8JsonReader reader, + JsonSerializerOptions options, +- ref ReadStack state, ++ scoped ref ReadStack state, + out object? value) + { + Debug.Fail("We should never get here."); +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs +index 129416323bc4c..df4963e3b6ef2 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs +@@ -10,7 +10,7 @@ public partial class JsonConverter + internal sealed override object? ReadCoreAsObject( + ref Utf8JsonReader reader, + JsonSerializerOptions options, +- ref ReadStack state) ++ scoped ref ReadStack state) + { + return ReadCore(ref reader, options, ref state); + } +@@ -18,7 +18,7 @@ public partial class JsonConverter + internal T? ReadCore( + ref Utf8JsonReader reader, + JsonSerializerOptions options, +- ref ReadStack state) ++ scoped ref ReadStack state) + { + try + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs +index 522f134a95296..551002c4b774f 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs +@@ -147,7 +147,7 @@ internal virtual bool OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerO + } + + // Provide a default implementation for value converters. +- internal virtual bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) ++ internal virtual bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out T? value) + { + value = Read(ref reader, typeToConvert, options); + return true; +@@ -166,7 +166,7 @@ internal virtual bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, J + /// Note that the value of determines if the converter handles null JSON tokens. + public abstract T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options); + +- internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, ref ReadStack state, out T? value) ++ internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options, scoped ref ReadStack state, out T? value) + { + // For perf and converter simplicity, handle null here instead of forwarding to the converter. + if (reader.TokenType == JsonTokenType.Null && !HandleNullOnRead && !state.IsContinuation) +@@ -288,14 +288,14 @@ internal bool TryRead(ref Utf8JsonReader reader, Type typeToConvert, JsonSeriali + return success; + } + +- internal sealed override bool OnTryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state, out object? value) ++ internal sealed override bool OnTryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, scoped ref ReadStack state, out object? value) + { + bool success = OnTryRead(ref reader, TypeToConvert, options, ref state, out T? typedValue); + value = typedValue; + return success; + } + +- internal sealed override bool TryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, ref ReadStack state, out object? value) ++ internal sealed override bool TryReadAsObject(ref Utf8JsonReader reader, JsonSerializerOptions options, scoped ref ReadStack state, out object? value) + { + bool success = TryRead(ref reader, TypeToConvert, options, ref state, out T? typedValue); + value = typedValue; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleMetadata.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleMetadata.cs +index 029c2b43fc38c..73cf9844ce392 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleMetadata.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandleMetadata.cs +@@ -21,7 +21,7 @@ public static partial class JsonSerializer + internal static readonly byte[] s_typePropertyName = Encoding.UTF8.GetBytes(TypePropertyName); + internal static readonly byte[] s_valuesPropertyName = Encoding.UTF8.GetBytes(ValuesPropertyName); + +- internal static bool TryReadMetadata(JsonConverter converter, JsonTypeInfo jsonTypeInfo, ref Utf8JsonReader reader, ref ReadStack state) ++ internal static bool TryReadMetadata(JsonConverter converter, JsonTypeInfo jsonTypeInfo, ref Utf8JsonReader reader, scoped ref ReadStack state) + { + Debug.Assert(state.Current.ObjectState == StackFrameObjectState.StartToken); + Debug.Assert(state.Current.CanContainMetadata); +@@ -285,7 +285,7 @@ internal static MetadataPropertyName GetMetadataPropertyName(ReadOnlySpan + + internal static bool TryHandleReferenceFromJsonElement( + ref Utf8JsonReader reader, +- ref ReadStack state, ++ scoped ref ReadStack state, + JsonElement element, + [NotNullWhen(true)] out object? referenceValue) + { +@@ -349,7 +349,7 @@ internal static MetadataPropertyName GetMetadataPropertyName(ReadOnlySpan + + internal static bool TryHandleReferenceFromJsonNode( + ref Utf8JsonReader reader, +- ref ReadStack state, ++ scoped ref ReadStack state, + JsonNode jsonNode, + [NotNullWhen(true)] out object? referenceValue) + { +@@ -425,7 +425,7 @@ static string ReadAsStringMetadataValue(JsonNode? jsonNode) + return refMetadataFound; + } + +- internal static void ValidateMetadataForObjectConverter(JsonConverter converter, ref Utf8JsonReader reader, ref ReadStack state) ++ internal static void ValidateMetadataForObjectConverter(JsonConverter converter, ref Utf8JsonReader reader, scoped ref ReadStack state) + { + if (state.Current.MetadataPropertyNames.HasFlag(MetadataPropertyName.Values)) + { +@@ -434,7 +434,7 @@ internal static void ValidateMetadataForObjectConverter(JsonConverter converter, + } + } + +- internal static void ValidateMetadataForArrayConverter(JsonConverter converter, ref Utf8JsonReader reader, ref ReadStack state) ++ internal static void ValidateMetadataForArrayConverter(JsonConverter converter, ref Utf8JsonReader reader, scoped ref ReadStack state) + { + switch (reader.TokenType) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs +index f374fc70daf79..b44461f661167 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs +@@ -19,7 +19,7 @@ public static partial class JsonSerializer + internal static JsonPropertyInfo LookupProperty( + object? obj, + ReadOnlySpan unescapedPropertyName, +- ref ReadStack state, ++ scoped ref ReadStack state, + JsonSerializerOptions options, + out bool useExtensionProperty, + bool createExtensionProperty = true) +@@ -71,7 +71,7 @@ public static partial class JsonSerializer + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static ReadOnlySpan GetPropertyName( +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader, + JsonSerializerOptions options) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs +index f3cb5b762fa59..318e25da2bc7a 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Helpers.cs +@@ -9,7 +9,7 @@ namespace System.Text.Json + { + public static partial class JsonSerializer + { +- private static TValue? ReadCore(ref Utf8JsonReader reader, JsonTypeInfo jsonTypeInfo, ref ReadStack state) ++ private static TValue? ReadCore(ref Utf8JsonReader reader, JsonTypeInfo jsonTypeInfo, scoped ref ReadStack state) + { + if (jsonTypeInfo is JsonTypeInfo typedInfo) + { +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs +index 137a3b238bace..dee80c211cbc9 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs +@@ -700,7 +700,7 @@ public int Order + + internal bool ReadJsonAndAddExtensionProperty( + object obj, +- ref ReadStack state, ++ scoped ref ReadStack state, + ref Utf8JsonReader reader) + { + object propValue = GetValueAsObject(obj)!; +@@ -748,11 +748,11 @@ JsonConverter GetDictionaryValueConverter() + } + } + +- internal abstract bool ReadJsonAndSetMember(object obj, ref ReadStack state, ref Utf8JsonReader reader); ++ internal abstract bool ReadJsonAndSetMember(object obj, scoped ref ReadStack state, ref Utf8JsonReader reader); + +- internal abstract bool ReadJsonAsObject(ref ReadStack state, ref Utf8JsonReader reader, out object? value); ++ internal abstract bool ReadJsonAsObject(scoped ref ReadStack state, ref Utf8JsonReader reader, out object? value); + +- internal bool ReadJsonExtensionDataValue(ref ReadStack state, ref Utf8JsonReader reader, out object? value) ++ internal bool ReadJsonExtensionDataValue(scoped ref ReadStack state, ref Utf8JsonReader reader, out object? value) + { + Debug.Assert(this == state.Current.JsonTypeInfo.ExtensionDataProperty); + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs +index f75d1da274f30..8c86d9462246c 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs +@@ -334,7 +334,7 @@ internal override bool GetMemberAndWriteJsonExtensionData(object obj, ref WriteS + return success; + } + +- internal override bool ReadJsonAndSetMember(object obj, ref ReadStack state, ref Utf8JsonReader reader) ++ internal override bool ReadJsonAndSetMember(object obj, scoped ref ReadStack state, ref Utf8JsonReader reader) + { + bool success; + +@@ -387,7 +387,7 @@ internal override bool ReadJsonAndSetMember(object obj, ref ReadStack state, ref + return success; + } + +- internal override bool ReadJsonAsObject(ref ReadStack state, ref Utf8JsonReader reader, out object? value) ++ internal override bool ReadJsonAsObject(scoped ref ReadStack state, ref Utf8JsonReader reader, out object? value) + { + bool success; + bool isNullToken = reader.TokenType == JsonTokenType.Null; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs b/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs +index c0d750799106e..b8ce2bacfd3f8 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs +@@ -334,7 +334,7 @@ public static void ThrowInvalidOperationException_ConverterCanConvertMultipleTyp + public static void ThrowNotSupportedException_ObjectWithParameterizedCtorRefMetadataNotSupported( + ReadOnlySpan propertyName, + ref Utf8JsonReader reader, +- ref ReadStack state) ++ scoped ref ReadStack state) + { + JsonTypeInfo jsonTypeInfo = state.GetTopJsonTypeInfoWithParameterizedConstructor(); + state.Current.JsonPropertyName = propertyName.ToArray(); +@@ -357,7 +357,7 @@ public static void ThrowInvalidOperationException_CreateObjectConverterNotCompat + } + + [DoesNotReturn] +- public static void ReThrowWithPath(ref ReadStack state, JsonReaderException ex) ++ public static void ReThrowWithPath(scoped ref ReadStack state, JsonReaderException ex) + { + Debug.Assert(ex.Path == null); + +@@ -383,14 +383,14 @@ public static void ReThrowWithPath(ref ReadStack state, JsonReaderException ex) + } + + [DoesNotReturn] +- public static void ReThrowWithPath(ref ReadStack state, in Utf8JsonReader reader, Exception ex) ++ public static void ReThrowWithPath(scoped ref ReadStack state, in Utf8JsonReader reader, Exception ex) + { + JsonException jsonException = new JsonException(null, ex); + AddJsonExceptionInformation(ref state, reader, jsonException); + throw jsonException; + } + +- public static void AddJsonExceptionInformation(ref ReadStack state, in Utf8JsonReader reader, JsonException ex) ++ public static void AddJsonExceptionInformation(scoped ref ReadStack state, in Utf8JsonReader reader, JsonException ex) + { + Debug.Assert(ex.Path is null); // do not overwrite existing path information + +@@ -482,7 +482,7 @@ public static void ThrowInvalidOperationException_NodeJsonObjectCustomConverterN + } + + [DoesNotReturn] +- public static void ThrowNotSupportedException(ref ReadStack state, in Utf8JsonReader reader, NotSupportedException ex) ++ public static void ThrowNotSupportedException(scoped ref ReadStack state, in Utf8JsonReader reader, NotSupportedException ex) + { + string message = ex.Message; + +@@ -536,7 +536,7 @@ public static void ThrowNotSupportedException(ref WriteStack state, NotSupported + } + + [DoesNotReturn] +- public static void ThrowNotSupportedException_DeserializeNoConstructor(Type type, ref Utf8JsonReader reader, ref ReadStack state) ++ public static void ThrowNotSupportedException_DeserializeNoConstructor(Type type, ref Utf8JsonReader reader, scoped ref ReadStack state) + { + string message; + +@@ -553,7 +553,7 @@ public static void ThrowNotSupportedException_DeserializeNoConstructor(Type type + } + + [DoesNotReturn] +- public static void ThrowNotSupportedException_CannotPopulateCollection(Type type, ref Utf8JsonReader reader, ref ReadStack state) ++ public static void ThrowNotSupportedException_CannotPopulateCollection(Type type, ref Utf8JsonReader reader, scoped ref ReadStack state) + { + ThrowNotSupportedException(ref state, reader, new NotSupportedException(SR.Format(SR.CannotPopulateCollection, type))); + } +@@ -583,14 +583,14 @@ public static void ThrowJsonException_MetadataValueWasNotString(JsonValueKind va + } + + [DoesNotReturn] +- public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(ReadOnlySpan propertyName, ref ReadStack state) ++ public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(ReadOnlySpan propertyName, scoped ref ReadStack state) + { + state.Current.JsonPropertyName = propertyName.ToArray(); + ThrowJsonException_MetadataReferenceObjectCannotContainOtherProperties(); + } + + [DoesNotReturn] +- public static void ThrowJsonException_MetadataUnexpectedProperty(ReadOnlySpan propertyName, ref ReadStack state) ++ public static void ThrowJsonException_MetadataUnexpectedProperty(ReadOnlySpan propertyName, scoped ref ReadStack state) + { + state.Current.JsonPropertyName = propertyName.ToArray(); + ThrowJsonException(SR.Format(SR.MetadataUnexpectedProperty)); +@@ -603,21 +603,21 @@ public static void ThrowJsonException_MetadataReferenceObjectCannotContainOtherP + } + + [DoesNotReturn] +- public static void ThrowJsonException_MetadataIdIsNotFirstProperty(ReadOnlySpan propertyName, ref ReadStack state) ++ public static void ThrowJsonException_MetadataIdIsNotFirstProperty(ReadOnlySpan propertyName, scoped ref ReadStack state) + { + state.Current.JsonPropertyName = propertyName.ToArray(); + ThrowJsonException(SR.MetadataIdIsNotFirstProperty); + } + + [DoesNotReturn] +- public static void ThrowJsonException_MetadataStandaloneValuesProperty(ref ReadStack state, ReadOnlySpan propertyName) ++ public static void ThrowJsonException_MetadataStandaloneValuesProperty(scoped ref ReadStack state, ReadOnlySpan propertyName) + { + state.Current.JsonPropertyName = propertyName.ToArray(); + ThrowJsonException(SR.MetadataStandaloneValuesProperty); + } + + [DoesNotReturn] +- public static void ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(ReadOnlySpan propertyName, ref ReadStack state, in Utf8JsonReader reader) ++ public static void ThrowJsonException_MetadataInvalidPropertyWithLeadingDollarSign(ReadOnlySpan propertyName, scoped ref ReadStack state, in Utf8JsonReader reader) + { + // Set PropertyInfo or KeyName to write down the conflicting property name in JsonException.Path + if (state.Current.IsProcessingDictionary()) +@@ -651,7 +651,7 @@ public static void ThrowJsonException_MetadataInvalidReferenceToValueType(Type p + } + + [DoesNotReturn] +- public static void ThrowJsonException_MetadataInvalidPropertyInArrayMetadata(ref ReadStack state, Type propertyType, in Utf8JsonReader reader) ++ public static void ThrowJsonException_MetadataInvalidPropertyInArrayMetadata(scoped ref ReadStack state, Type propertyType, in Utf8JsonReader reader) + { + state.Current.JsonPropertyName = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan.ToArray(); + string propertyNameAsString = reader.GetString()!; +@@ -662,7 +662,7 @@ public static void ThrowJsonException_MetadataInvalidPropertyInArrayMetadata(ref + } + + [DoesNotReturn] +- public static void ThrowJsonException_MetadataPreservedArrayValuesNotFound(ref ReadStack state, Type propertyType) ++ public static void ThrowJsonException_MetadataPreservedArrayValuesNotFound(scoped ref ReadStack state, Type propertyType) + { + // Missing $values, JSON path should point to the property's object. + state.Current.JsonPropertyName = null; +@@ -695,7 +695,7 @@ public static void ThrowInvalidOperationException_JsonPropertyInfoIsBoundToDiffe + internal static void ThrowUnexpectedMetadataException( + ReadOnlySpan propertyName, + ref Utf8JsonReader reader, +- ref ReadStack state) ++ scoped ref ReadStack state) + { + + MetadataPropertyName name = JsonSerializer.GetMetadataPropertyName(propertyName, state.Current.BaseJsonTypeInfo.PolymorphicTypeResolver); + +From 8240b5c0847faed1a0296d1f2220ae46ec395203 Mon Sep 17 00:00:00 2001 +From: Charles Stoner <10732005+cston@users.noreply.github.com> +Date: Fri, 5 Aug 2022 09:34:02 -0700 +Subject: [PATCH 2/5] More + +--- + .../Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs +index 7eaadb22a99d2..fe0a696109f31 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Utf8JsonReader.cs +@@ -262,7 +262,7 @@ public static partial class JsonSerializer + } + } + +- private static Utf8JsonReader GetReaderScopedToNextValue(ref Utf8JsonReader reader, ref ReadStack state) ++ private static Utf8JsonReader GetReaderScopedToNextValue(ref Utf8JsonReader reader, scoped ref ReadStack state) + { + // Advances the provided reader, validating that it is pointing to a complete JSON value. + // If successful, returns a new Utf8JsonReader that is scoped to the next value, reusing existing buffers. + +From b397d760cb9718e4805f01ad678d645af63fbe93 Mon Sep 17 00:00:00 2001 +From: Charles Stoner <10732005+cston@users.noreply.github.com> +Date: Thu, 11 Aug 2022 11:02:05 -0700 +Subject: [PATCH 3/5] Remove unnecessary 'scoped' + +--- + .../Converters/Collection/DictionaryOfTKeyTValueConverter.cs | 2 +- + .../Serialization/Converters/Collection/IDictionaryConverter.cs | 2 +- + .../Converters/Collection/IDictionaryOfTKeyTValueConverter.cs | 2 +- + .../Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs | 2 +- + .../Collection/ImmutableDictionaryOfTKeyTValueConverter.cs | 2 +- + .../Converters/Collection/JsonDictionaryConverter.cs | 2 +- + .../Json/Serialization/Converters/FSharp/FSharpMapConverter.cs | 2 +- + 7 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs +index 5d78f1e62ff1d..cd83ea2925921 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/DictionaryOfTKeyTValueConverter.cs +@@ -15,7 +15,7 @@ internal sealed class DictionaryOfTKeyTValueConverter + where TCollection : Dictionary + where TKey : notnull + { +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!)[key] = value; + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs +index 07c2165c68ca8..8a7017f535202 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryConverter.cs +@@ -16,7 +16,7 @@ internal sealed class IDictionaryConverter + : JsonDictionaryConverter + where TDictionary : IDictionary + { +- protected override void Add(string key, in object? value, JsonSerializerOptions options, scoped ref ReadStack state) ++ protected override void Add(string key, in object? value, JsonSerializerOptions options, ref ReadStack state) + { + TDictionary collection = (TDictionary)state.Current.ReturnValue!; + collection[key] = value; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs +index 85ec30b2a9fb3..9dd55564ed67f 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IDictionaryOfTKeyTValueConverter.cs +@@ -16,7 +16,7 @@ internal sealed class IDictionaryOfTKeyTValueConverter + where TKey : notnull + { +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) + { + TDictionary collection = (TDictionary)state.Current.ReturnValue!; + collection[key] = value; +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs +index 29cafebf4013a..e42ecfe496b49 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IReadOnlyDictionaryOfTKeyTValueConverter.cs +@@ -13,7 +13,7 @@ internal sealed class IReadOnlyDictionaryOfTKeyTValueConverter)); + +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) + { + ((Dictionary)state.Current.ReturnValue!)[key] = value; + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs +index 464d5b87caf7c..db6b62a8de82b 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableDictionaryOfTKeyTValueConverter.cs +@@ -12,7 +12,7 @@ internal class ImmutableDictionaryOfTKeyTValueConverter + where TKey : notnull + { +- protected sealed override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) ++ protected sealed override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) + { + ((Dictionary)state.Current.ReturnValue!)[key] = value; + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs +index 0b148fefb7203..2f32668898434 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonDictionaryConverter.cs +@@ -27,7 +27,7 @@ internal abstract class JsonDictionaryConverter : Jso + /// + /// When overridden, adds the value to the collection. + /// +- protected abstract void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state); ++ protected abstract void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state); + + /// + /// When overridden, converts the temporary collection held in state.Current.ReturnValue to the final collection. +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs +index 86ba3e913f432..112da6da2c8d6 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpMapConverter.cs +@@ -21,7 +21,7 @@ public FSharpMapConverter() + _mapConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpMapConstructor(); + } + +- protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, scoped ref ReadStack state) ++ protected override void Add(TKey key, in TValue value, JsonSerializerOptions options, ref ReadStack state) + { + ((List>)state.Current.ReturnValue!).Add (new Tuple(key, value)); + } + +From c021b9559393184b4fa1e13e511d306ba4d0f88b Mon Sep 17 00:00:00 2001 +From: Charles Stoner <10732005+cston@users.noreply.github.com> +Date: Thu, 11 Aug 2022 11:07:31 -0700 +Subject: [PATCH 4/5] Remove unnecessary 'scoped' + +--- + .../Json/Serialization/Converters/Collection/ArrayConverter.cs | 2 +- + .../Converters/Collection/ConcurrentQueueOfTConverter.cs | 2 +- + .../Converters/Collection/ConcurrentStackOfTConverter.cs | 2 +- + .../Converters/Collection/IAsyncEnumerableOfTConverter.cs | 2 +- + .../Converters/Collection/ICollectionOfTConverter.cs | 2 +- + .../Serialization/Converters/Collection/IEnumerableConverter.cs | 2 +- + .../Converters/Collection/IEnumerableOfTConverter.cs | 2 +- + .../Json/Serialization/Converters/Collection/IListConverter.cs | 2 +- + .../Serialization/Converters/Collection/IListOfTConverter.cs | 2 +- + .../Serialization/Converters/Collection/ISetOfTConverter.cs | 2 +- + .../Converters/Collection/ImmutableEnumerableOfTConverter.cs | 2 +- + .../Converters/Collection/JsonCollectionConverter.cs | 2 +- + .../Serialization/Converters/Collection/ListOfTConverter.cs | 2 +- + .../Serialization/Converters/Collection/QueueOfTConverter.cs | 2 +- + .../Serialization/Converters/Collection/StackOfTConverter.cs | 2 +- + .../Converters/Collection/StackOrQueueConverter.cs | 2 +- + .../Json/Serialization/Converters/FSharp/FSharpListConverter.cs | 2 +- + .../Json/Serialization/Converters/FSharp/FSharpSetConverter.cs | 2 +- + 18 files changed, 18 insertions(+), 18 deletions(-) + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs +index 6ed3d1905fd30..3c189d499275b 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ArrayConverter.cs +@@ -13,7 +13,7 @@ internal sealed class ArrayConverter : IEnumerableDefault + { + internal override bool CanHaveMetadata => false; + +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs +index 1053a27bcdfdf..55c70f35f257d 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentQueueOfTConverter.cs +@@ -9,7 +9,7 @@ internal sealed class ConcurrentQueueOfTConverter + : IEnumerableDefaultConverter + where TCollection : ConcurrentQueue + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Enqueue(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs +index 5f7f9a5be84b4..87506619bbfe7 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ConcurrentStackOfTConverter.cs +@@ -9,7 +9,7 @@ internal sealed class ConcurrentStackOfTConverter + : IEnumerableDefaultConverter + where TCollection : ConcurrentStack + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Push(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs +index fb1887e30c813..d518eb1596e1d 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IAsyncEnumerableOfTConverter.cs +@@ -22,7 +22,7 @@ internal override bool OnTryRead(ref Utf8JsonReader reader, Type typeToConvert, + return base.OnTryRead(ref reader, typeToConvert, options, ref state, out value!); + } + +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((BufferedAsyncEnumerable)state.Current.ReturnValue!)._buffer.Add(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs +index a423ae1b98f8c..47bcf0b9d554a 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ICollectionOfTConverter.cs +@@ -14,7 +14,7 @@ internal sealed class ICollectionOfTConverter + : IEnumerableDefaultConverter + where TCollection : ICollection + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs +index f69d6780f5996..33c6379542491 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableConverter.cs +@@ -17,7 +17,7 @@ internal sealed class IEnumerableConverter + { + private readonly bool _isDeserializable = typeof(TCollection).IsAssignableFrom(typeof(List)); + +- protected override void Add(in object? value, scoped ref ReadStack state) ++ protected override void Add(in object? value, ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs +index c11602fc75112..905e7211ae214 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IEnumerableOfTConverter.cs +@@ -15,7 +15,7 @@ internal sealed class IEnumerableOfTConverter + { + private readonly bool _isDeserializable = typeof(TCollection).IsAssignableFrom(typeof(List)); + +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs +index d405282a054f1..208d1c1fcc7e7 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListConverter.cs +@@ -13,7 +13,7 @@ internal sealed class IListConverter + : JsonCollectionConverter + where TCollection : IList + { +- protected override void Add(in object? value, scoped ref ReadStack state) ++ protected override void Add(in object? value, ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs +index 47a7f8c116283..36ee248dab4e1 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/IListOfTConverter.cs +@@ -14,7 +14,7 @@ internal sealed class IListOfTConverter + : IEnumerableDefaultConverter + where TCollection : IList + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs +index 71da570158b2f..390ed6097dda7 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ISetOfTConverter.cs +@@ -11,7 +11,7 @@ internal sealed class ISetOfTConverter + : IEnumerableDefaultConverter + where TCollection : ISet + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + TCollection collection = (TCollection)state.Current.ReturnValue!; + collection.Add(value); +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs +index 4bcd70e1341b0..541f5cbf57a70 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ImmutableEnumerableOfTConverter.cs +@@ -11,7 +11,7 @@ internal class ImmutableEnumerableOfTConverter + : IEnumerableDefaultConverter + where TCollection : IEnumerable + { +- protected sealed override void Add(in TElement value, scoped ref ReadStack state) ++ protected sealed override void Add(in TElement value, ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs +index 2e3198ce33f2b..ae28e2dc65810 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/JsonCollectionConverter.cs +@@ -18,7 +18,7 @@ internal abstract class JsonCollectionConverter : JsonRes + internal sealed override ConverterStrategy ConverterStrategy => ConverterStrategy.Enumerable; + internal override Type ElementType => typeof(TElement); + +- protected abstract void Add(in TElement value, scoped ref ReadStack state); ++ protected abstract void Add(in TElement value, ref ReadStack state); + + /// + /// When overridden, create the collection. It may be a temporary collection or the final collection. +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs +index 76aebb4d29cb8..0ab52bfc4939b 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/ListOfTConverter.cs +@@ -10,7 +10,7 @@ internal sealed class ListOfTConverter + : IEnumerableDefaultConverter + where TCollection: List + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Add(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs +index d0f95108cebd6..5c02525afa980 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/QueueOfTConverter.cs +@@ -9,7 +9,7 @@ internal sealed class QueueOfTConverter + : IEnumerableDefaultConverter + where TCollection : Queue + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Enqueue(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs +index 429071bc2858d..87e7369cee5b4 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOfTConverter.cs +@@ -10,7 +10,7 @@ internal sealed class StackOfTConverter + : IEnumerableDefaultConverter + where TCollection : Stack + { +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((TCollection)state.Current.ReturnValue!).Push(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs +index 410975df09bef..f291a263f3b9e 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Collection/StackOrQueueConverter.cs +@@ -11,7 +11,7 @@ internal class StackOrQueueConverter + : JsonCollectionConverter + where TCollection : IEnumerable + { +- protected sealed override void Add(in object? value, scoped ref ReadStack state) ++ protected sealed override void Add(in object? value, ref ReadStack state) + { + var addMethodDelegate = ((Action?)state.Current.JsonTypeInfo.AddMethodDelegate); + Debug.Assert(addMethodDelegate != null); +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs +index ae424affe9082..0cd7ccb1a3020 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpListConverter.cs +@@ -20,7 +20,7 @@ public FSharpListConverter() + _listConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpListConstructor(); + } + +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs +index 5993b7830ba93..167534d8de3f7 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/FSharp/FSharpSetConverter.cs +@@ -20,7 +20,7 @@ public FSharpSetConverter() + _setConstructor = FSharpCoreReflectionProxy.Instance.CreateFSharpSetConstructor(); + } + +- protected override void Add(in TElement value, scoped ref ReadStack state) ++ protected override void Add(in TElement value, ref ReadStack state) + { + ((List)state.Current.ReturnValue!).Add(value); + } + +From 65818d01f0690f612b0661d512c3acfa8610aa2f Mon Sep 17 00:00:00 2001 +From: Charles Stoner <10732005+cston@users.noreply.github.com> +Date: Thu, 11 Aug 2022 11:23:40 -0700 +Subject: [PATCH 5/5] Remove unnecessary 'scoped' + +--- + .../Object/ObjectWithParameterizedConstructorConverter.Large.cs | 2 +- + .../Object/ObjectWithParameterizedConstructorConverter.Small.cs | 2 +- + .../Object/ObjectWithParameterizedConstructorConverter.cs | 2 +- + .../Serialization/JsonSerializer.Read.HandlePropertyName.cs | 2 +- + 4 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs +index 1059bd1ef3971..938d2a9605699 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Large.cs +@@ -51,7 +51,7 @@ protected sealed override object CreateObject(ref ReadStackFrame frame) + return obj; + } + +- protected sealed override void InitializeConstructorArgumentCaches(scoped ref ReadStack state, JsonSerializerOptions options) ++ protected sealed override void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options) + { + JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs +index 1c7314b1b5960..3c7fd1a7c27f6 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.Small.cs +@@ -79,7 +79,7 @@ protected override object CreateObject(ref ReadStackFrame frame) + return success; + } + +- protected override void InitializeConstructorArgumentCaches(scoped ref ReadStack state, JsonSerializerOptions options) ++ protected override void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options) + { + JsonTypeInfo typeInfo = state.Current.JsonTypeInfo; + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs +index cb501ff8aa307..74137c578c7e8 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Object/ObjectWithParameterizedConstructorConverter.cs +@@ -246,7 +246,7 @@ internal sealed override bool OnTryRead(ref Utf8JsonReader reader, Type typeToCo + return true; + } + +- protected abstract void InitializeConstructorArgumentCaches(scoped ref ReadStack state, JsonSerializerOptions options); ++ protected abstract void InitializeConstructorArgumentCaches(ref ReadStack state, JsonSerializerOptions options); + + protected abstract bool ReadAndCacheConstructorArgument(scoped ref ReadStack state, ref Utf8JsonReader reader, JsonParameterInfo jsonParameterInfo); + +diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs +index b44461f661167..e88a52dd52ba7 100644 +--- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs ++++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.HandlePropertyName.cs +@@ -19,7 +19,7 @@ public static partial class JsonSerializer + internal static JsonPropertyInfo LookupProperty( + object? obj, + ReadOnlySpan unescapedPropertyName, +- scoped ref ReadStack state, ++ ref ReadStack state, + JsonSerializerOptions options, + out bool useExtensionProperty, + bool createExtensionProperty = true) diff --git a/src/SourceBuild/tarball/patches/runtime/0005-More-update-for-recent-compiler-changes-for-ref-fields.patch b/src/SourceBuild/tarball/patches/runtime/0005-More-update-for-recent-compiler-changes-for-ref-fields.patch new file mode 100644 index 000000000..ca5e4ac53 --- /dev/null +++ b/src/SourceBuild/tarball/patches/runtime/0005-More-update-for-recent-compiler-changes-for-ref-fields.patch @@ -0,0 +1,47 @@ +From 67062893af45f36d9b4ed1d0a46dca64aa427f7c Mon Sep 17 00:00:00 2001 +From: Charles Stoner <10732005+cston@users.noreply.github.com> +Date: Fri, 12 Aug 2022 20:34:14 -0700 +Subject: [PATCH 1/2] Add scoped + +Original PR is https://github.com/dotnet/runtime/pull/73883. + +--- + .../Runtime.Base/src/System/Runtime/ExceptionHandling.cs | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs +index 9e576853a44cb..81242191d1aab 100644 +--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs ++++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs +@@ -588,7 +588,7 @@ public static void RhRethrow(ref ExInfo activeExInfo, ref ExInfo exInfo) + FallbackFailFast(RhFailFastReason.InternalError, null); + } + +- private static void DispatchEx(ref StackFrameIterator frameIter, ref ExInfo exInfo, uint startIdx) ++ private static void DispatchEx(scoped ref StackFrameIterator frameIter, ref ExInfo exInfo, uint startIdx) + { + Debug.Assert(exInfo._passNumber == 1, "expected asm throw routine to set the pass"); + object exceptionObj = exInfo.ThrownException; + +From 86f07e350629aacf17db6b3f539eca214579a479 Mon Sep 17 00:00:00 2001 +From: Charles Stoner <10732005+cston@users.noreply.github.com> +Date: Fri, 12 Aug 2022 20:49:01 -0700 +Subject: [PATCH 2/2] More scoped + +--- + .../tests/System.Text.Json.Tests/JsonDocumentTests.cs | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDocumentTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDocumentTests.cs +index 45590069c094f..cc3d827ca729f 100644 +--- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDocumentTests.cs ++++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDocumentTests.cs +@@ -3611,7 +3611,7 @@ public static void NameEquals_Empty_Throws() + out Utf8JsonReader reader, + ReadOnlyMemory data, + int segmentCount, +- in JsonReaderState state, ++ scoped in JsonReaderState state, + bool isFinalBlock = false) + { + if (segmentCount == 0)