-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Make string concat assert more precise #80619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
These asserts are intended to ensure that, if we ever come across a scenario that should be optimized, we consider that. The current assert is broader than this though, and already isn't in line with the code it reflects. This updates the assert to be clearer. Fixes dotnet#80254.
| } | ||
|
|
||
| if (argument is BoundConversion { ConversionKind: ConversionKind.Boxing, Type.SpecialType: SpecialType.System_Object, Operand: { Type.SpecialType: SpecialType.System_Char } operand }) | ||
| if (argument is BoundConversion conversion && StringConcatOptimizationPatterns.IsBoxedChar(conversion, out BoundExpression? operand)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than duplicating these checks, making it non-obvious why the assert is what it is, I've opted to pull them into the single StringConcatOptimizationPatterns struct as a single place for all the different possible checks.
| { | ||
| var source = """ | ||
| var c = new C(); | ||
| c.P += "a" + c.P; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue was that c.P is a property, so visitedCompoundAssignmentLeftRead was just a BoundCall to the getter. This ran afoul of the existing assert, which made the bad assumption that the only BoundCalls left in the tree at this point would be optimizable.
|
@dotnet/roslyn-compiler for review |
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Show resolved
Hide resolved
|
Done with review pass (commit 1) #Closed |
|
@AlekseyTs addressed your feedback, thanks. To hopefully simplify your review, I did the reset in a separate commit from the extraction: 41462f0 was just |
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Outdated
Show resolved
Hide resolved
|
Done with review pass (commit 4) #Closed |
AlekseyTs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 5)
|
@dotnet/roslyn-compiler for a second review |
5279cea to
b9d768a
Compare
|
@dotnet/roslyn-compiler for a second revie |
|
It looks like the original version of this assertion was failing when building the complog in dotnet/runtime#120975 using a debug compiler, when compiling this line. Including a little more info here in case it helps verify that the change to this assert is sufficient. Dump of the failing
|
|
@RikkiGibson do you have reason to suspect that this is not sufficient? |
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_StringConcat.cs
Outdated
Show resolved
Hide resolved
* upstream/main: (332 commits) Cache lambdas in analyzer driver (dotnet#80759) Add information for NuGet package version 4.14 (dotnet#80870) Add missing search keywords to VB Advanced options page Fix IDE0031 false positive when preprocessor directives are used in if statements (dotnet#80878) Use core compiler on netfx hosts with toolset package (dotnet#80631) Make string concat assert more precise (dotnet#80619) Extensions: address some diagnostic quality issues (dotnet#80827) Add note on traversal order for bound nodes (dotnet#80872) Ensure that locals at the top level of a constructor have the same safe-context as parameters (dotnet#80807) Fix handling of SymbolDisplayCompilerInternalOptions.UseArityForGenericTypes option for non-native symbol implementations (dotnet#80826) Update src/Analyzers/CSharp/Tests/UseCollectionInitializer/UseCollectionInitializerTests.cs Add IsValidContainingStatement check to prevent collection initializers in using declarations Add back old DocumentSpan constructor (dotnet#80864) Add tests verifying pointer types in type parameters require unsafe context (dotnet#80776) Add regression test for Interlocked.Exchange with nullable types (dotnet#80796) Add regression test for ParseAttributeArgumentList with invalid input (fixes dotnet#8699) (dotnet#80705) Add regression test for compiler crash with syntax error in indexer declaration (dotnet#80772) Add runtime NullReferenceException validation to foreach null iteration tests (dotnet#80839) Update MicrosoftBuildTasksCoreVersionForMetrics to 17.11.48 (dotnet#80812) Mark CS4009 error as a "build only" error. (dotnet#80698) ...
These asserts are intended to ensure that, if we ever come across a scenario that should be optimized, we consider that. The current assert is broader than this though, and already isn't in line with the code it reflects. This updates the assert to be clearer. Fixes #80254.