From ab430c6f2b92ec488fa8c5e92bcce1823df42670 Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Sat, 1 Jul 2017 00:34:02 +0700 Subject: [PATCH 1/9] FunctionCompiler: rename field --- .../Uno.Compiler.Core/Syntax/Builders/TypeBuilder.cs | 2 +- .../Syntax/Compilers/FunctionCompiler.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/Uno.Compiler.Core/Syntax/Builders/TypeBuilder.cs b/src/compiler/Uno.Compiler.Core/Syntax/Builders/TypeBuilder.cs index 1eb611f53..c9c30d996 100644 --- a/src/compiler/Uno.Compiler.Core/Syntax/Builders/TypeBuilder.cs +++ b/src/compiler/Uno.Compiler.Core/Syntax/Builders/TypeBuilder.cs @@ -44,7 +44,7 @@ public TypeBuilder( void EnqueueCompiler(FunctionCompiler fc) { - if (fc.DeclarationBody != null) + if (fc.Body != null) _enqueuedCompilers.Add(fc); else if (_compiler.Backend.CanLink(fc.Function)) fc.Function.Stats |= EntityStats.CanLink; diff --git a/src/compiler/Uno.Compiler.Core/Syntax/Compilers/FunctionCompiler.cs b/src/compiler/Uno.Compiler.Core/Syntax/Compilers/FunctionCompiler.cs index 9e80b5280..a63018181 100644 --- a/src/compiler/Uno.Compiler.Core/Syntax/Compilers/FunctionCompiler.cs +++ b/src/compiler/Uno.Compiler.Core/Syntax/Compilers/FunctionCompiler.cs @@ -32,7 +32,7 @@ public sealed partial class FunctionCompiler : LogObject // For nested lambdas public readonly Stack Lambdas = new Stack(); - public readonly AstScope DeclarationBody; + public readonly AstScope Body; public readonly MetaProperty MetaProperty; public readonly Namescope Namescope; @@ -47,12 +47,12 @@ public sealed partial class FunctionCompiler : LogObject public bool IsFunctionScope => Function != null && Namescope is DataType && Function.DeclaringType.MasterDefinition == (Namescope as DataType).MasterDefinition || (Function as Method)?.GenericType == Namescope; - public FunctionCompiler(Compiler compiler, Function func, DataType parameterizedParent, AstScope declarationBody) + public FunctionCompiler(Compiler compiler, Function func, DataType parameterizedParent, AstScope body) : this(compiler) { Function = func; Namescope = (func as Method)?.GenericType ?? parameterizedParent; - DeclarationBody = declarationBody; + Body = body; } public FunctionCompiler(Compiler compiler, DataType dt, Expression obj) @@ -148,7 +148,7 @@ public void Compile() } else { - var result = CompileScope(DeclarationBody); + var result = CompileScope(Body); if (Function.Body.Statements.Count > 0) result.Statements.InsertRange(0, Function.Body.Statements); From c7eece45f661c4e0fa2ca3ac855937957d72fab4 Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Mon, 17 Jul 2017 15:18:08 +0200 Subject: [PATCH 2/9] Uno.Testing: make Registry.Add() method public This method is being called from generated code inside higher-level packages, and must be public to be accessible. --- lib/Uno.Testing/Registry.uno | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Uno.Testing/Registry.uno b/lib/Uno.Testing/Registry.uno index c7175fd82..608d1322b 100644 --- a/lib/Uno.Testing/Registry.uno +++ b/lib/Uno.Testing/Registry.uno @@ -6,7 +6,7 @@ namespace Uno.Testing { private List _tests = new List(); - internal void Add(Action method, string name, bool ignore, string ignoreReason) + public void Add(Action method, string name, bool ignore, string ignoreReason) { _tests.Add(new NamedTestMethod(method, name, ignore, ignoreReason)); } From c0b2498a4d275812dcd629ae9e9633160b693b6b Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Mon, 7 Aug 2017 16:53:12 +0200 Subject: [PATCH 3/9] Uno.Compiler: replace while-loop with for-loop Now the code-style is slightly nicer... --- src/compiler/Uno.Compiler.Core/IL/Validation/ILVerifier.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compiler/Uno.Compiler.Core/IL/Validation/ILVerifier.cs b/src/compiler/Uno.Compiler.Core/IL/Validation/ILVerifier.cs index 84aa910a6..39a74f18e 100644 --- a/src/compiler/Uno.Compiler.Core/IL/Validation/ILVerifier.cs +++ b/src/compiler/Uno.Compiler.Core/IL/Validation/ILVerifier.cs @@ -118,9 +118,7 @@ bool IsPublicMetaProperty { if (MetaProperty != null && MetaProperty.IsPublic) { - var cn = Namescope; - - while (cn != null) + for (var cn = Namescope; cn != null; cn = cn.Parent) { switch (cn.NamescopeType) { @@ -138,8 +136,6 @@ bool IsPublicMetaProperty default: return false; } - - cn = cn.Parent; } } From c812c219397c73fd59ee354a985b39b3e8e2d96d Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Mon, 14 Aug 2017 12:46:44 +0200 Subject: [PATCH 4/9] Uno.UX.Markup: don't throw ICE when building Tag could already be assigned a non-string object. --- src/ux/Uno.UX.Markup.CompilerReflection/CompilerReflection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ux/Uno.UX.Markup.CompilerReflection/CompilerReflection.cs b/src/ux/Uno.UX.Markup.CompilerReflection/CompilerReflection.cs index afdf19500..0ddc79eae 100644 --- a/src/ux/Uno.UX.Markup.CompilerReflection/CompilerReflection.cs +++ b/src/ux/Uno.UX.Markup.CompilerReflection/CompilerReflection.cs @@ -13,7 +13,7 @@ static class DataTypeExtensions // Optimization as reading 'FullName' is slow public static string GetCachedFullName(this DataType dt) { - return (string)dt.Tag ?? (string)(dt.Tag = dt.FullName); + return dt.Tag as string ?? (string)(dt.Tag = dt.FullName); } } From dad520f8a203b68c236a65696d210b2be857bd4d Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Fri, 19 Apr 2019 03:17:14 +0700 Subject: [PATCH 5/9] CIL: fix issue with generic twin methods --- src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs b/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs index 0cf9b351c..a8c035a0f 100644 --- a/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs +++ b/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs @@ -45,8 +45,10 @@ private void OnTwinMethod(ref Method method) if (method.IsGenericDefinition) { - twin = new Method(method.Source, twinClass, method.DocComment, method.Modifiers, method.Name, method.GenericType, method.ReturnType, method.Parameters, method.Body); - method.GenericType.SetParent(twinClass); + var generic = new ClassType(method.Source, twinClass, method.DocComment, Modifiers.Private | Modifiers.Static | Modifiers.Generated, method.UnoName); + generic.MakeGenericDefinition(method.GenericParameters); + twin = new Method(method.Source, twinClass, method.DocComment, method.Modifiers, method.Name, generic, method.ReturnType, method.Parameters, method.Body); + generic.Methods.Add(twin); } else twin = new Method(method.Source, twinClass, method.DocComment, method.Modifiers, method.Name, method.ReturnType, method.Parameters, method.Body); From a984f93ef5f42c03d958395361140ca96d890d11 Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Sat, 20 Apr 2019 20:37:41 +0700 Subject: [PATCH 6/9] CIL: process twin methods in Type objects --- .../Uno.Compiler.Backends.CIL/CilTransform.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs b/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs index a8c035a0f..acc5872de 100644 --- a/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs +++ b/src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs @@ -25,6 +25,17 @@ public override void Begin(ref Expression e, ExpressionUsage u) } } + public override bool Begin(DataType dt) + { + foreach (var m in dt.Methods) + { + var refMethod = m; + OnTwinMethod(ref refMethod); + } + + return true; + } + private void OnTwinMethod(ref Method method) { Method twin; From a839142e166c692e8d0e5beed25ebd961ef5da3c Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Sat, 20 Apr 2019 23:23:05 +0700 Subject: [PATCH 7/9] CIL: avoid missing out on [DotNetOverride] methods in CilTransform --- src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs b/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs index 531e44302..54f6d7cf3 100644 --- a/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs +++ b/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs @@ -40,13 +40,15 @@ public override void Configure() public override bool CanLink(DataType dt) { - return dt.Package.CanLink || dt.HasAttribute(Essentials.DotNetTypeAttribute, true); + // Can't check DotNetTypeAttribute because we don't know if any members with DotNetOverrideAttriute exist. + return dt.Package.CanLink; } public override bool CanLink(Function f) { - return f.DeclaringType.Package.CanLink || f.DeclaringType.CanLink && - !f.HasAttribute(Essentials.DotNetOverrideAttribute); + return f.DeclaringType.CanLink || + f.DeclaringType.HasAttribute(Essentials.DotNetTypeAttribute, true) && + !f.HasAttribute(Essentials.DotNetOverrideAttribute); } public override void BeginBuild() From c81ea084c78995035c222999785e6c2394cfc460 Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Sun, 21 Apr 2019 05:17:36 +0700 Subject: [PATCH 8/9] Uno.Data.Xml: add abstract methods in System.Xml This fixes the following errors: E4036: System.Xml.Linq.XComment does not implement abstract member 'System.Xml.Linq.XNode.get_NodeType()' E4036: System.Xml.Linq.XProcessingInstruction does not implement abstract member 'System.Xml.Linq.XNode.get_NodeType()' E4036: System.Xml.Linq.XElement does not implement abstract member 'System.Xml.Linq.XNode.get_NodeType()' E4036: System.Xml.Linq.XCData does not implement abstract member 'System.Xml.Linq.XNode.get_NodeType()' --- lib/Uno.Data.Xml/Source/System.Xml.uno | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Uno.Data.Xml/Source/System.Xml.uno b/lib/Uno.Data.Xml/Source/System.Xml.uno index ee08df359..32b7233e6 100644 --- a/lib/Uno.Data.Xml/Source/System.Xml.uno +++ b/lib/Uno.Data.Xml/Source/System.Xml.uno @@ -46,12 +46,14 @@ namespace System.Xml.Linq [DotNetType] extern(CIL) class XComment : XNode { + public extern override XmlNodeType NodeType { get; } public extern string Value { get; set; } } [DotNetType] extern(CIL) class XProcessingInstruction : XNode { + public extern override XmlNodeType NodeType { get; } public extern string Target { get; set; } public extern string Data { get; set; } } @@ -71,6 +73,7 @@ namespace System.Xml.Linq [DotNetType] extern(CIL) sealed class XElement : XContainer { + public extern override XmlNodeType NodeType { get; } public extern XName Name { get; set; } public extern XNode FirstNode { get; } public extern IEnumerable Attributes(); @@ -85,6 +88,7 @@ namespace System.Xml.Linq [DotNetType] extern(CIL) sealed class XCData : XText { + public extern override XmlNodeType NodeType { get; } } [DotNetType] From 3ad4c5fe2fb7838e9954a57428b7121b9865e9a2 Mon Sep 17 00:00:00 2001 From: Morten Daniel Fornes Date: Tue, 14 May 2019 22:18:10 +0700 Subject: [PATCH 9/9] CIL: more profiling --- .../Uno.Compiler.Backends.CIL/CilBackend.cs | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs b/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs index 54f6d7cf3..b28d301ce 100644 --- a/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs +++ b/src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs @@ -90,22 +90,27 @@ public override void EndBuild() return; // Create an executable for given architecture (-DX86 or -DX64) - var loader = new AppLoader(Environment.GetString("AppLoader.Assembly")); - var executable = Environment.Combine(Environment.GetString("Product").TrimPath()); - - if (Environment.IsDefined("X64")) - loader.SetX64(); - else if (Environment.IsDefined("X86")) - loader.SetX86(); - - Log.Verbose("Creating executable: " + executable.ToRelativePath() + " (" + loader.Architecture + ")"); - loader.SetAssemblyInfo(Input.Package.Name + "-loader", new Version(), Environment.GetString); - loader.SetMainClass(Data.MainClass.CilTypeName(), - Path.Combine(_outputDir, Input.Package.Name + ".dll"), - Environment.GetString("AppLoader.Class"), - Environment.GetString("AppLoader.Method")); - loader.ClearPublicKey(); - loader.Save(executable); + using (Log.StartProfiler(typeof(AppLoader))) + { + var loader = new AppLoader(Environment.GetString("AppLoader.Assembly")); + var executable = Environment.Combine(Environment.GetString("Product").TrimPath()); + + if (Environment.IsDefined("X64")) + loader.SetX64(); + else if (Environment.IsDefined("X86")) + loader.SetX86(); + + Log.Verbose("Creating executable: " + executable.ToRelativePath() + " (" + loader.Architecture + ")"); + loader.SetAssemblyInfo(Input.Package.Name + "-loader", + new Version(), + Environment.GetString); + loader.SetMainClass(Data.MainClass.CilTypeName(), + Path.Combine(_outputDir, Input.Package.Name + ".dll"), + Environment.GetString("AppLoader.Class"), + Environment.GetString("AppLoader.Method")); + loader.ClearPublicKey(); + loader.Save(executable); + } } public override BackendResult Build() @@ -121,13 +126,16 @@ public override BackendResult Build() var g = new CilGenerator(Disk, Data, Essentials, this, _linker, package, _outputDir); g.Configure(Environment.Debug); - g.Generate(); + + using (Log.StartProfiler(g.GetType().FullName + ".Generate")) + g.Generate(); if (Log.HasErrors) return null; + using (Log.StartProfiler(g.GetType().FullName + ".Save")) + g.Save(); - g.Save(); return new CilResult( g.Assembly, _linker.TypeMap,