Skip to content

Commit 167192e

Browse files
authored
Merge pull request #3587 from ds5678/issue3584
Improve inlining of boxed values
2 parents 7a5a2a0 + b9d6ba7 commit 167192e

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed

ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<Compile Include="TestCases\Pretty\Issue3571_B.cs" />
164164
<Compile Include="TestCases\Pretty\Issue3571_A.cs" />
165165
<Compile Include="TestCases\Pretty\Issue3576.cs" />
166+
<Compile Include="TestCases\Pretty\Issue3584.cs" />
166167
<Compile Include="TestCases\Pretty\PlaystationPreferPrimary.cs" />
167168
<Compile Include="TestCases\Pretty\Playstation.cs" />
168169
<None Include="TestCases\Ugly\NoLocalFunctions.Expected.cs" />

ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,12 @@ public async Task Issue3576([ValueSource(nameof(roslyn2OrNewerWithNet40Options))
718718
await RunForLibrary(cscOptions: cscOptions);
719719
}
720720

721+
[Test]
722+
public async Task Issue3584([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
723+
{
724+
await RunForLibrary(cscOptions: cscOptions);
725+
}
726+
721727
[Test]
722728
public async Task AssemblyCustomAttributes([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
723729
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
4+
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
5+
{
6+
internal abstract class Issue4000<T> : IEnumerable<T>, IEnumerable
7+
{
8+
public int Length;
9+
10+
protected T[] results;
11+
12+
#if !ROSLYN4
13+
public T this[int i] {
14+
get {
15+
if (i >= Length || i < 0)
16+
{
17+
return default(T);
18+
}
19+
if (results[i] != null && results[i].Equals(default(T)))
20+
{
21+
results[i] = CreateIthElement(i);
22+
}
23+
return results[i];
24+
}
25+
}
26+
#endif
27+
28+
protected abstract T CreateIthElement(int i);
29+
30+
public IEnumerator<T> GetEnumerator()
31+
{
32+
for (int i = 0; i < Length; i++)
33+
{
34+
if (results[i] != null && results[i].Equals(default(T)))
35+
{
36+
results[i] = CreateIthElement(i);
37+
}
38+
yield return results[i];
39+
}
40+
}
41+
42+
IEnumerator IEnumerable.GetEnumerator()
43+
{
44+
return GetEnumerator();
45+
}
46+
}
47+
}

ICSharpCode.Decompiler/IL/ILTypeExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ public static IType InferType(this ILInstruction inst, ICompilation? compilation
238238
default:
239239
return SpecialType.UnknownType;
240240
}
241+
case DefaultValue defaultValue:
242+
return defaultValue.Type;
241243
case ILFunction func when func.DelegateType != null:
242244
return func.DelegateType;
243245
default:

ICSharpCode.Decompiler/IL/Instructions.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4355,15 +4355,6 @@ public IType Type {
43554355
set { type = value; InvalidateFlags(); }
43564356
}
43574357
public override StackType ResultType { get { return StackType.O; } }
4358-
protected override InstructionFlags ComputeFlags()
4359-
{
4360-
return base.ComputeFlags() | InstructionFlags.SideEffect | InstructionFlags.MayThrow;
4361-
}
4362-
public override InstructionFlags DirectFlags {
4363-
get {
4364-
return base.DirectFlags | InstructionFlags.SideEffect | InstructionFlags.MayThrow;
4365-
}
4366-
}
43674358
public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
43684359
{
43694360
WriteILRange(output, options);

ICSharpCode.Decompiler/IL/Instructions.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
CustomInvariant("CheckTargetSlot();")),
267267

268268
new OpCode("box", "Boxes a value.",
269-
Unary, HasTypeOperand, MemoryAccess, MayThrow, ResultType("O")),
269+
Unary, HasTypeOperand, ResultType("O")),
270270
new OpCode("unbox", "Compute address inside box.",
271271
Unary, HasTypeOperand, MayThrow, ResultType("Ref")),
272272
new OpCode("unbox.any", "Unbox a value.",

0 commit comments

Comments
 (0)