Fix #4136: Re-allow condition-slot comp!=0 simplification for non-IfInstruction operands - #4141
Sadik00789 wants to merge 1 commit into
Conversation
…nstruction operands
|
I don't see a good reason why The original issue was: if |
|
Something that could work: allow direct condition slots (i.e. |
|
@dgrunwald Thank you for the detailed explanation of the I tested your suggestion of allowing direct condition slots ( The AST Structure in
|
|
That's still broken. AI unfortunately likes to build special cases instead code that is correct in the general case. |
|
@Sadik00789 please read https://github.com/icsharpcode/ILSpy/blob/master/CONTRIBUTING.md: Especially:
And please stop bombarding us with verbatim copies of text generated by your clanker. Put it into your own words. Thanks! |
|
Noted. Thanks for clarifying your architectural preferences—leaving the cleanup of #4091 to the core team. |
Summary of Changes
Fixes #4136.
Commit
c760a1d62(part of #4091) narrowed thecomp(x != 0)reduction inExpressionTransforms.VisitCompto only trigger whenInferTypeis boolean or matching constants0/1.In cases like
SixLabors.ImageSharp.Formats.Png.PngEncoderCore.WriteXmpChunk,inst.Leftis a call toGetValueOrDefault()returningInt32inside anIfInstructioncondition slot. Rejecting this preventedcomp(call GetValueOrDefault() != 0)from simplifying down to its operand. Consequently:NullableLiftingTransformfailed to recognize the candidate expression tree, dropping the high-level(num ?? 0) == 0coalescing form.(!num.HasValue || num.GetValueOrDefault() == 0) ? true : false.Fix
Re-allowed condition-slot simplification in
ExpressionTransforms.VisitCompwheninst.Left is not IfInstruction. This preserves the intendedc760a1d62invariant (preventing integer-valued conditionals likeflag ? 2 : 0from truncating to boolean values) while restoring expected reduction for non-IfInstructioninteger expressions in condition slots.The redundant
? true : falsedisappears naturally without modifyingVisitIfInstruction.Verification
SixLabors.ImageSharp4.1.1 (PngEncoderCore) andSwashbuckle.AspNetCore.SwaggerGen10.2.3 (XmlCommentsRequestBodyFilter). Output matches the pre-Split StackType.O into StackType.Obj+StackType.VT #4091 baseline.Issue4136.csand registered[Test] Issue4136inPrettyTestRunner.cscovering zero-fallbacks, non-zero fallbacks, enum fallbacks, and null-conditional propagation.LiftedNullCoalescingComparisontoTestCases/Correctness/Comparisons.cs.