Do not emit implict_op if from/to are same type (#862)
authorkingces95 <kingces95@users.noreply.github.com>
Mon, 10 Apr 2017 06:48:54 +0000 (02:48 -0400)
committerStephane Delcroix <stephane@delcroix.org>
Mon, 10 Apr 2017 06:48:54 +0000 (08:48 +0200)
Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs
Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
Xamarin.Forms.Build.Tasks/TypeDefinitionExtensions.cs
Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
Xamarin.Forms.Build.Tasks/XamlCTask.cs

index 1e441c9..5544b7e 100644 (file)
@@ -73,6 +73,7 @@ namespace Xamarin.Forms.Build.Tasks
                                                if (initCompRuntime == null) {
                                                        Logger.LogString(2, "   Creating empty {0}.__InitComponentRuntime ...", typeDef.Name);
                                                        initCompRuntime = new MethodDefinition("__InitComponentRuntime", initComp.Attributes, initComp.ReturnType);
+                                                       initCompRuntime.Body.InitLocals = true;
                                                        Logger.LogLine(2, "done.");
                                                        Logger.LogString(2, "   Copying body of InitializeComponent to __InitComponentRuntime ...", typeDef.Name);
                                                        initCompRuntime.Body = new MethodBody(initCompRuntime);
@@ -116,6 +117,7 @@ namespace Xamarin.Forms.Build.Tasks
                                                }
 
                                                var body = new MethodBody(altCtor);
+                                               body.InitLocals = true;
                                                var il = body.GetILProcessor();
                                                var br2 = Instruction.Create(OpCodes.Ldarg_0);
                                                var ret = Instruction.Create(OpCodes.Ret);
index 6f07b37..5cbf075 100644 (file)
@@ -480,6 +480,7 @@ namespace Xamarin.Forms.Build.Tasks
                                        new CustomAttribute (context.Module.ImportReference(compilerGeneratedCtor))
                                }
                        };
+                       getter.Body.InitLocals = true;
                        var il = getter.Body.GetILProcessor();
 
                        il.Emit(OpCodes.Ldarg_0);
@@ -550,6 +551,7 @@ namespace Xamarin.Forms.Build.Tasks
                                        new CustomAttribute (module.ImportReference(compilerGeneratedCtor))
                                }
                        };
+                       setter.Body.InitLocals = true;
 
                        var il = setter.Body.GetILProcessor();
                        var lastProperty = properties.LastOrDefault();
@@ -640,6 +642,7 @@ namespace Xamarin.Forms.Build.Tasks
                                                new CustomAttribute (context.Module.ImportReference(compilerGeneratedCtor))
                                        }
                                };
+                               partGetter.Body.InitLocals = true;
                                var il = partGetter.Body.GetILProcessor();
                                il.Emit(OpCodes.Ldarg_0);
                                for (int j = 0; j < i; j++) {
@@ -1142,6 +1145,7 @@ namespace Xamarin.Forms.Build.Tasks
                        var loadTemplate = new MethodDefinition("LoadDataTemplate",
                                MethodAttributes.Assembly | MethodAttributes.HideBySig,
                                module.TypeSystem.Object);
+                       loadTemplate.Body.InitLocals = true;
                        anonType.Methods.Add(loadTemplate);
 
                        var parentValues = new FieldDefinition("parentValues", FieldAttributes.Assembly, module.ImportReference(typeof (object[])));
index bd0b4b4..40bf374 100644 (file)
@@ -42,6 +42,7 @@ namespace Xamarin.Forms.Build.Tasks
                                CallingConvention = MethodCallingConvention.Default,
                                ImplAttributes = (MethodImplAttributes.IL | MethodImplAttributes.Managed)
                        };
+                       ctor.Body.InitLocals = true;
 
                        var IL = ctor.Body.GetILProcessor();
 
index f862de3..bc26b5e 100644 (file)
@@ -246,6 +246,9 @@ namespace Xamarin.Forms.Build.Tasks
 
                public static MethodReference GetImplicitOperatorTo(this TypeReference fromType, TypeReference toType, ModuleDefinition module)
                {
+                       if (TypeRefComparer.Default.Equals(fromType, toType))
+                               return null;
+
                        var implicitOperatorsOnFromType = fromType.GetMethods(md => md.IsPublic && md.IsStatic && md.IsSpecialName && md.Name == "op_Implicit", module);
                        var implicitOperatorsOnToType = toType.GetMethods(md => md.IsPublic && md.IsStatic && md.IsSpecialName && md.Name == "op_Implicit", module);
                        var implicitOperators = implicitOperatorsOnFromType.Concat(implicitOperatorsOnToType).ToList();
index 5503ccf..f72c655 100644 (file)
@@ -152,6 +152,7 @@ namespace Xamarin.Forms.Build.Tasks
                                                else {
                                                        Logger.LogString(2, "   Creating empty {0}.__InitComponentRuntime ...", typeDef.Name);
                                                        initCompRuntime = new MethodDefinition("__InitComponentRuntime", initComp.Attributes, initComp.ReturnType);
+                                                       initCompRuntime.Body.InitLocals = true;
                                                        Logger.LogLine(2, "done.");
                                                        Logger.LogString(2, "   Copying body of InitializeComponent to __InitComponentRuntime ...", typeDef.Name);
                                                        initCompRuntime.Body = new MethodBody(initCompRuntime);
@@ -160,6 +161,7 @@ namespace Xamarin.Forms.Build.Tasks
                                                                iCRIl.Append(instr);
                                                        initComp.Body.Instructions.Clear();
                                                        initComp.Body.GetILProcessor().Emit(OpCodes.Ret);
+                                                       initComp.Body.InitLocals = true;
                                                        typeDef.Methods.Add(initCompRuntime);
                                                        Logger.LogLine(2, "done.");
                                                }
@@ -245,6 +247,7 @@ namespace Xamarin.Forms.Build.Tasks
                        try {
                                var body = new MethodBody(initComp);
                                var module = body.Method.Module;
+                               body.InitLocals = true;
                                var il = body.GetILProcessor();
                                il.Emit(OpCodes.Nop);