From 27b48c51098ab01b809b9b9439c5836db4407f35 Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Fri, 24 May 2024 13:12:16 -0700 Subject: [PATCH 1/4] Final editor side changes for "allow ref struct" support Per Tomas, the enc analyzer can be trivially changed for this support. Also, smal change where I missed one location in method extractor analyzer that needed a change --- src/Features/CSharpTest/EditAndContinue/TopLevelEditingTests.cs | 2 ++ .../Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs | 1 + .../Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs | 1 + 3 files changed, 4 insertions(+) diff --git a/src/Features/CSharpTest/EditAndContinue/TopLevelEditingTests.cs b/src/Features/CSharpTest/EditAndContinue/TopLevelEditingTests.cs index f76afa5df2876..7cf962f9814f8 100644 --- a/src/Features/CSharpTest/EditAndContinue/TopLevelEditingTests.cs +++ b/src/Features/CSharpTest/EditAndContinue/TopLevelEditingTests.cs @@ -21669,6 +21669,7 @@ class B : System.Attribute {} [InlineData("unmanaged")] [InlineData("System.IDisposable")] [InlineData("System.Delegate")] + [InlineData("allows ref struct")] public void TypeConstraint_Insert(string newConstraint) { var src1 = "class C { }"; @@ -21691,6 +21692,7 @@ public void TypeConstraint_Insert(string newConstraint) [InlineData("unmanaged")] [InlineData("System.IDisposable")] [InlineData("System.Delegate")] + [InlineData("allows ref struct")] public void TypeConstraint_Delete(string oldConstraint) { var src1 = "class C where T : " + oldConstraint + " { }"; diff --git a/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs b/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs index efdc3998e98f4..e8d2fd1d3de3c 100644 --- a/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs +++ b/src/Features/Core/Portable/EditAndContinue/AbstractEditAndContinueAnalyzer.cs @@ -2355,6 +2355,7 @@ protected static bool TypeParameterConstraintsEquivalent(ITypeParameterSymbol ol => TypesEquivalent(oldParameter.ConstraintTypes, newParameter.ConstraintTypes, exact) && oldParameter.HasReferenceTypeConstraint == newParameter.HasReferenceTypeConstraint && oldParameter.HasValueTypeConstraint == newParameter.HasValueTypeConstraint && + oldParameter.AllowsRefLikeType == newParameter.AllowsRefLikeType && oldParameter.HasConstructorConstraint == newParameter.HasConstructorConstraint && oldParameter.HasNotNullConstraint == newParameter.HasNotNullConstraint && oldParameter.HasUnmanagedTypeConstraint == newParameter.HasUnmanagedTypeConstraint && diff --git a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs index 4c25aeab0f33a..1e284257313db 100644 --- a/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs +++ b/src/Features/Core/Portable/ExtractMethod/MethodExtractor.Analyzer.cs @@ -910,6 +910,7 @@ private static IEnumerable AppendTypeParametersInConstrain if (!parameter.HasConstructorConstraint && !parameter.HasReferenceTypeConstraint && !parameter.HasValueTypeConstraint && + !parameter.AllowsRefLikeType && parameter.ConstraintTypes.IsDefaultOrEmpty) { continue; From 73bb9cf0209bd56fd16ca7720b08266ef7be2248 Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Fri, 24 May 2024 14:03:04 -0700 Subject: [PATCH 2/4] Modify (Large/Source)Text.ParseLineStart to specify an initial capacity for line count Noticed this in a Find All References profile, the LargeText.ParseLineStarts was showing as 6.2% of allocations and SourceText.ParseLineStarts was 0.4%. With this change, these reduced to 4.7% and 0.2% respectively. --- src/Compilers/Core/Portable/Text/LargeText.cs | 3 ++- src/Compilers/Core/Portable/Text/SourceText.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Compilers/Core/Portable/Text/LargeText.cs b/src/Compilers/Core/Portable/Text/LargeText.cs index 9fc77a99eb920..a372a683c55f7 100644 --- a/src/Compilers/Core/Portable/Text/LargeText.cs +++ b/src/Compilers/Core/Portable/Text/LargeText.cs @@ -238,7 +238,8 @@ private SegmentedList ParseLineStarts() var position = 0; var index = 0; var lastCr = -1; - var list = new SegmentedList(); + // Initial line capacity estimated at 64 chars / line + var list = new SegmentedList(Length / 64); // The following loop goes through every character in the text. It is highly // performance critical, and thus inlines knowledge about common line breaks diff --git a/src/Compilers/Core/Portable/Text/SourceText.cs b/src/Compilers/Core/Portable/Text/SourceText.cs index 0dac9ac001d04..bfda0e2d38953 100644 --- a/src/Compilers/Core/Portable/Text/SourceText.cs +++ b/src/Compilers/Core/Portable/Text/SourceText.cs @@ -1049,7 +1049,8 @@ private SegmentedList ParseLineStarts() return [0]; } - var lineStarts = new SegmentedList() + // Initial line capacity estimated at 64 chars / line + var lineStarts = new SegmentedList(Length / 64) { 0 // there is always the first line }; From 5759682928058854a768965530d8d44b6fec9e8a Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Fri, 24 May 2024 14:51:10 -0700 Subject: [PATCH 3/4] Add comment indicating how magic number was determined. --- src/Compilers/Core/Portable/Text/LargeText.cs | 3 ++- src/Compilers/Core/Portable/Text/SourceText.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Compilers/Core/Portable/Text/LargeText.cs b/src/Compilers/Core/Portable/Text/LargeText.cs index a372a683c55f7..a46a2a1058bab 100644 --- a/src/Compilers/Core/Portable/Text/LargeText.cs +++ b/src/Compilers/Core/Portable/Text/LargeText.cs @@ -238,7 +238,8 @@ private SegmentedList ParseLineStarts() var position = 0; var index = 0; var lastCr = -1; - // Initial line capacity estimated at 64 chars / line + // Initial line capacity estimated at 64 chars / line. This values was obtained by + // looking at ratios in large files in the roslyn repo. var list = new SegmentedList(Length / 64); // The following loop goes through every character in the text. It is highly diff --git a/src/Compilers/Core/Portable/Text/SourceText.cs b/src/Compilers/Core/Portable/Text/SourceText.cs index bfda0e2d38953..10c3c7ee3fafa 100644 --- a/src/Compilers/Core/Portable/Text/SourceText.cs +++ b/src/Compilers/Core/Portable/Text/SourceText.cs @@ -1049,7 +1049,8 @@ private SegmentedList ParseLineStarts() return [0]; } - // Initial line capacity estimated at 64 chars / line + // Initial line capacity estimated at 64 chars / line. This values was obtained by + // looking at ratios in large files in the roslyn repo. var lineStarts = new SegmentedList(Length / 64) { 0 // there is always the first line From 0fe95fb628f999495ddb660100c3a60cde0e61e8 Mon Sep 17 00:00:00 2001 From: Todd Grunke Date: Wed, 29 May 2024 10:31:09 -0700 Subject: [PATCH 4/4] fix typo --- src/Compilers/Core/Portable/Text/LargeText.cs | 2 +- src/Compilers/Core/Portable/Text/SourceText.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/Core/Portable/Text/LargeText.cs b/src/Compilers/Core/Portable/Text/LargeText.cs index a46a2a1058bab..7572861c5f1e2 100644 --- a/src/Compilers/Core/Portable/Text/LargeText.cs +++ b/src/Compilers/Core/Portable/Text/LargeText.cs @@ -238,7 +238,7 @@ private SegmentedList ParseLineStarts() var position = 0; var index = 0; var lastCr = -1; - // Initial line capacity estimated at 64 chars / line. This values was obtained by + // Initial line capacity estimated at 64 chars / line. This value was obtained by // looking at ratios in large files in the roslyn repo. var list = new SegmentedList(Length / 64); diff --git a/src/Compilers/Core/Portable/Text/SourceText.cs b/src/Compilers/Core/Portable/Text/SourceText.cs index 10c3c7ee3fafa..d58eb8d2b86e7 100644 --- a/src/Compilers/Core/Portable/Text/SourceText.cs +++ b/src/Compilers/Core/Portable/Text/SourceText.cs @@ -1049,7 +1049,7 @@ private SegmentedList ParseLineStarts() return [0]; } - // Initial line capacity estimated at 64 chars / line. This values was obtained by + // Initial line capacity estimated at 64 chars / line. This value was obtained by // looking at ratios in large files in the roslyn repo. var lineStarts = new SegmentedList(Length / 64) {