8000 CIL fixes and tweaks by mortend · Pull Request #281 · fuse-open/uno · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

CIL fixes and tweaks #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Uno.Data.Xml/Source/System.Xml.uno
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Expand All @@ -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<XAttribute> Attributes();
Expand All @@ -85,6 +88,7 @@ namespace System.Xml.Linq
[DotNetType]
extern(CIL) sealed class XCData : XText
{
public extern override XmlNodeType NodeType { get; }
}

[DotNetType]
Expand Down
2 changes: 1 addition & 1 deletion lib/Uno.Testing/Registry.uno
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Uno.Testing
{
private List<NamedTestMethod> _tests = new List<NamedTestMethod>();

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));
}
Expand Down
52 changes: 31 additions & 21 deletions src/compiler/Uno.Compiler.Backends.CIL/CilBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -88,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()
Expand All @@ -119,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,
Expand Down
17 changes: 15 additions & 2 deletions src/compiler/Uno.Compiler.Backends.CIL/CilTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -45,8 +56,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);
Expand Down
6 changes: 1 addition & 5 deletions src/compiler/Uno.Compiler.Core/IL/Validation/ILVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -138,8 +136,6 @@ bool IsPublicMetaProperty
default:
return false;
}

cn = cn.Parent;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed partial class FunctionCompiler : LogObject
// For nested lambdas
public readonly Stack<Lambda> Lambdas = new Stack<Lambda>();

public readonly AstScope DeclarationBody;
public readonly AstScope Body;
public readonly MetaProperty MetaProperty;
public readonly Namescope Namescope;

Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
0