From c0f1f800c6449773de944569b2e59ad86a7525a9 Mon Sep 17 00:00:00 2001 From: Andrey Shchekin Date: Sun, 25 Jun 2017 15:48:46 +1200 Subject: [PATCH] [closes gh-9] Unrolled array and collection initializers. --- source/#external/ILSpy | 2 +- .../Decompilation/AstBasedDecompiler.cs | 4 +- source/Tests/DecompilationTests.cs | 2 + .../Tests/TestCode/Lambda.CallInArray.cs2cs | 55 ++++++++++++++----- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/source/#external/ILSpy b/source/#external/ILSpy index 1c66a85..1e338e0 160000 --- a/source/#external/ILSpy +++ b/source/#external/ILSpy @@ -1 +1 @@ -Subproject commit 1c66a85cfa9f4ca9793d96a8d1187a0bc21bc8be +Subproject commit 1e338e0fdc676a005522ae6a10adb627a6b94b11 diff --git a/source/Server/Decompilation/AstBasedDecompiler.cs b/source/Server/Decompilation/AstBasedDecompiler.cs index dbb9cf7..38af27a 100644 --- a/source/Server/Decompilation/AstBasedDecompiler.cs +++ b/source/Server/Decompilation/AstBasedDecompiler.cs @@ -29,7 +29,9 @@ namespace SharpLab.Server.Decompilation { YieldReturn = false, AsyncAwait = false, AutomaticProperties = false, - ExpressionTrees = false + ExpressionTrees = false, + ArrayInitializers = false, + ObjectOrCollectionInitializers = false } }; diff --git a/source/Tests/DecompilationTests.cs b/source/Tests/DecompilationTests.cs index 52f7701..5d65f5c 100644 --- a/source/Tests/DecompilationTests.cs +++ b/source/Tests/DecompilationTests.cs @@ -29,6 +29,8 @@ namespace SharpLab.Tests { [InlineData("Simple.cs2il")] [InlineData("Simple.vb2vb")] [InlineData("Module.vb2vb")] + // https://github.com/ashmind/SharpLab/issues/9 + [InlineData("Lambda.CallInArray.cs2cs")] public async Task SlowUpdate_ReturnsExpectedDecompiledCode(string resourceName) { var data = TestData.FromResource(resourceName); var driver = await NewTestDriverAsync(data); diff --git a/source/Tests/TestCode/Lambda.CallInArray.cs2cs b/source/Tests/TestCode/Lambda.CallInArray.cs2cs index 6ab8e84..bcdeaf6 100644 --- a/source/Tests/TestCode/Lambda.CallInArray.cs2cs +++ b/source/Tests/TestCode/Lambda.CallInArray.cs2cs @@ -7,14 +7,18 @@ public class C { } } -?=> +#=> using System; +using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.Security; using System.Security.Permissions; + [assembly: AssemblyVersion("0.0.0.0")] +[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] @@ -22,25 +26,46 @@ using System.Security.Permissions; public class C { [CompilerGenerated] - private static Func CS$<>9__CachedAnonymousMethodDelegate1; + [Serializable] + private sealed class <>c + { + public static readonly C.<>c <>9; + + public static Func <>9__0_0; + + static <>c() + { + // Note: this type is marked as 'beforefieldinit'. + C.<>c.<>9 = new C.<>c(); + } + + internal int b__0_0(int s) + { + return s; + } + } + public void M() { - Func arg_1B_0; - if (arg_1B_0 = C.CS$<>9__CachedAnonymousMethodDelegate1 == null) + Func arg_1F_0; + if (arg_1F_0 = C.<>c.<>9__0_0 == null) { - C.CS$<>9__CachedAnonymousMethodDelegate1 = new Func(C.b__0); + arg_1F_0 = C.<>c.<>9__0_0 = new Func(C.<>c.<>9.b__0_0); } - int[] array = new int[] { - 1, - 2, - 3, - 0 - }; - Console.WriteLine(array[3]); + Func func = arg_1F_0; + int[] expr_26 = new int[4]; + RuntimeHelpers.InitializeArray(expr_26, fieldof(.7C7D749A182D008FD83D960F228CB2B1A0177992).FieldHandle); + expr_26[3] = func(1); + Console.WriteLine(expr_26[3]); } - [CompilerGenerated] - private static int b__0(int s) +} +[CompilerGenerated] +internal sealed class +{ + [StructLayout(LayoutKind.Explicit, Pack = 1, Size = 16)] + private struct __StaticArrayInitTypeSize=16 { - return s; } + + internal static readonly .__StaticArrayInitTypeSize=16 7C7D749A182D008FD83D960F228CB2B1A0177992 = bytearray(1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0); } \ No newline at end of file