Browse Source

Merge pull request #3587 from ds5678/issue3584

Improve inlining of boxed values
pull/3613/merge
Daniel Grunwald 2 months ago committed by GitHub
parent
commit
167192eb75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      ICSharpCode.Decompiler.Tests/ICSharpCode.Decompiler.Tests.csproj
  2. 6
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  3. 47
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue3584.cs
  4. 2
      ICSharpCode.Decompiler/IL/ILTypeExtensions.cs
  5. 9
      ICSharpCode.Decompiler/IL/Instructions.cs
  6. 2
      ICSharpCode.Decompiler/IL/Instructions.tt

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

@ -163,6 +163,7 @@ @@ -163,6 +163,7 @@
<Compile Include="TestCases\Pretty\Issue3571_B.cs" />
<Compile Include="TestCases\Pretty\Issue3571_A.cs" />
<Compile Include="TestCases\Pretty\Issue3576.cs" />
<Compile Include="TestCases\Pretty\Issue3584.cs" />
<Compile Include="TestCases\Pretty\PlaystationPreferPrimary.cs" />
<Compile Include="TestCases\Pretty\Playstation.cs" />
<None Include="TestCases\Ugly\NoLocalFunctions.Expected.cs" />

6
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -718,6 +718,12 @@ namespace ICSharpCode.Decompiler.Tests @@ -718,6 +718,12 @@ namespace ICSharpCode.Decompiler.Tests
await RunForLibrary(cscOptions: cscOptions);
}
[Test]
public async Task Issue3584([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{
await RunForLibrary(cscOptions: cscOptions);
}
[Test]
public async Task AssemblyCustomAttributes([ValueSource(nameof(defaultOptions))] CompilerOptions cscOptions)
{

47
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Issue3584.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
internal abstract class Issue4000<T> : IEnumerable<T>, IEnumerable
{
public int Length;
protected T[] results;
#if !ROSLYN4
public T this[int i] {
get {
if (i >= Length || i < 0)
{
return default(T);
}
if (results[i] != null && results[i].Equals(default(T)))
{
results[i] = CreateIthElement(i);
}
return results[i];
}
}
#endif
protected abstract T CreateIthElement(int i);
public IEnumerator<T> GetEnumerator()
{
for (int i = 0; i < Length; i++)
{
if (results[i] != null && results[i].Equals(default(T)))
{
results[i] = CreateIthElement(i);
}
yield return results[i];
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}

2
ICSharpCode.Decompiler/IL/ILTypeExtensions.cs

@ -238,6 +238,8 @@ namespace ICSharpCode.Decompiler.IL @@ -238,6 +238,8 @@ namespace ICSharpCode.Decompiler.IL
default:
return SpecialType.UnknownType;
}
case DefaultValue defaultValue:
return defaultValue.Type;
case ILFunction func when func.DelegateType != null:
return func.DelegateType;
default:

9
ICSharpCode.Decompiler/IL/Instructions.cs

@ -4355,15 +4355,6 @@ namespace ICSharpCode.Decompiler.IL @@ -4355,15 +4355,6 @@ namespace ICSharpCode.Decompiler.IL
set { type = value; InvalidateFlags(); }
}
public override StackType ResultType { get { return StackType.O; } }
protected override InstructionFlags ComputeFlags()
{
return base.ComputeFlags() | InstructionFlags.SideEffect | InstructionFlags.MayThrow;
}
public override InstructionFlags DirectFlags {
get {
return base.DirectFlags | InstructionFlags.SideEffect | InstructionFlags.MayThrow;
}
}
public override void WriteTo(ITextOutput output, ILAstWritingOptions options)
{
WriteILRange(output, options);

2
ICSharpCode.Decompiler/IL/Instructions.tt

@ -266,7 +266,7 @@ @@ -266,7 +266,7 @@
CustomInvariant("CheckTargetSlot();")),
new OpCode("box", "Boxes a value.",
Unary, HasTypeOperand, MemoryAccess, MayThrow, ResultType("O")),
Unary, HasTypeOperand, ResultType("O")),
new OpCode("unbox", "Compute address inside box.",
Unary, HasTypeOperand, MayThrow, ResultType("Ref")),
new OpCode("unbox.any", "Unbox a value.",

Loading…
Cancel
Save