Skip to content

Commit

Permalink
Merge pull request #314 from mortend/compiler-clean-ups
Browse files Browse the repository at this point in the history
Compiler clean-ups
  • Loading branch information
mortend authored Apr 16, 2020
2 parents dd3a4d8 + 4a6186e commit 8cfc2e3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/compiler/Uno.Compiler.API/Domain/Graphics/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public bool IsAccessibleFrom(Source src)
public SourcePackage Package => Source.Package;
NewObject[] IEntity.Attributes => Attributes;
string IEntity.DocComment => DocComment;
bool IEntity.HasRefCount => false;
bool IEntity.IsStripped => true;
public bool IsPublic => Modifiers.HasFlag(Modifiers.Public);
bool IEntity.IsProtected => Modifiers.HasFlag(Modifiers.Protected);
Expand Down
1 change: 1 addition & 0 deletions src/compiler/Uno.Compiler.API/Domain/IL/IEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface IEntity
NamescopeType NamescopeType { get; }
IEntity MasterDefinition { get; }

bool HasRefCount { get; }
bool IsStripped { get; }
bool IsPublic { get; }
bool IsProtected { get; }
Expand Down
1 change: 1 addition & 0 deletions src/compiler/Uno.Compiler.API/Domain/IL/Members/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public Member DeclaringMember
}
}

public bool HasRefCount => Stats.HasFlag(EntityStats.RefCount);
public bool IsStripped => DeclaringType.MasterDefinition.StrippedMembers.Contains(MasterDefinition) || DeclaringType.IsStripped;

Source IEntity.Source => Source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public override string ToString()
string IEntity.FullName => Name;
string IEntity.UnoName => UnoName;
string IEntity.Name => Name;
bool IEntity.HasRefCount => true;
bool IEntity.IsStripped => false;
bool IEntity.IsPublic => true;
bool IEntity.IsProtected => false;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/Uno.Compiler.API/Domain/IL/Namespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public bool IsAccessibleFrom(Source src)
MemberType IEntity.MemberType => MemberType.Other;
NewObject[] IEntity.Attributes => AttributeList.Empty;
string IEntity.DocComment => null;
bool IEntity.HasRefCount => true;
bool IEntity.IsStripped => false;
bool IEntity.IsPublic => false;
bool IEntity.IsProtected => false;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/Uno.Compiler.API/Domain/IL/Types/DataType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ public bool IsGenericType
public bool IsGenericMethodType => Stats.HasFlag(EntityStats.GenericMethodType);
public bool IsParameterizedDefinition => Stats.HasFlag(EntityStats.ParameterizedDefinition);
public bool CanLink => MasterDefinition.Stats.HasFlag(EntityStats.CanLink);
public bool HasRefCount => Stats.HasFlag(EntityStats.RefCount);

Source IEntity.Source => Source;
IEntity IEntity.MasterDefinition => MasterDefinition;
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/Uno.Compiler.Backends.CPlusPlus/CppPrecalc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void RegisterType(DataType dt)
!(Function.IsGenericMethod && CppBackend.Compare(dt, Function.GenericType)) &&
!CppBackend.Compare(dt, Type) &&
!dt.IsGenericParameter &&
dt.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
dt.MasterDefinition.HasRefCount)
_func.PrecalcedTypes.Add(dt);
}

Expand All @@ -306,7 +306,7 @@ void RegisterDependency(DataType dt)
if (!(Function.IsGenericMethod && CppBackend.Compare(dt, Function.GenericType)) &&
!CppBackend.Compare(dt, Type) && dt.HasInitializer &&
dt.BuiltinType != BuiltinType.String && dt.BuiltinType != BuiltinType.Char &&
dt.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
dt.MasterDefinition.HasRefCount)
_func.Dependencies.Add(dt);
}
}
Expand Down
45 changes: 24 additions & 21 deletions src/compiler/Uno.Compiler.Core/IL/Optimizing/ILStripper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Method GetBaseMethod(Method m)

void VisitType(DataType dt)
{
if (dt.Stats.HasFlag(EntityStats.RefCount))
if (dt.HasRefCount)
return;

dt.Stats |= EntityStats.RefCount;
Expand Down Expand Up @@ -191,7 +191,7 @@ void VisitType(DataType dt)

void VisitFunction(Function f)
{
if (f.Stats.HasFlag(EntityStats.RefCount))
if (f.HasRefCount)
return;

f.Stats |= EntityStats.RefCount;
Expand Down Expand Up @@ -281,7 +281,7 @@ void VisitFile(CopyFile f)

void VisitField(Field f)
{
if (f.Stats.HasFlag(EntityStats.RefCount))
if (f.HasRefCount)
return;

f.Stats |= EntityStats.RefCount;
Expand Down Expand Up @@ -435,15 +435,15 @@ void ConstrainOverriddenMethod(Method m)

void ConstrainOverridingMethod(Method m)
{
if (m.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
if (m.MasterDefinition.HasRefCount)
{
ConstrainOverriddenMethod(m.OverriddenMethod);
return;
}

for (var om = m.OverriddenMethod; om != null; om = om.OverriddenMethod)
{
if (om.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
if (om.MasterDefinition.HasRefCount)
{
VisitFunction(m);
ConstrainOverriddenMethod(m.OverriddenMethod);
Expand All @@ -454,7 +454,7 @@ void ConstrainOverridingMethod(Method m)

void ConstrainRefsRecursive(DataType dt)
{
if (!dt.Stats.HasFlag(EntityStats.RefCount))
if (!dt.HasRefCount)
{
// Visit generic parameterization used as base class
if (!dt.IsMasterDefinition && dt.Stats.HasFlag(EntityStats.RefCountAsBase) && !CanStrip(dt))
Expand All @@ -478,10 +478,10 @@ void ConstrainRefsRecursive(DataType dt)
if (!dt.IsMasterDefinition)
{
foreach (var m in dt.EnumerateFields())
if (m.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
if (m.MasterDefinition.HasRefCount)
VisitField(m);
foreach (var m in dt.EnumerateFunctions())
if (m.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
if (m.MasterDefinition.HasRefCount)
VisitFunction(m);
}

Expand Down Expand Up @@ -522,10 +522,10 @@ void ConstrainRefsRecursive(DataType dt)

foreach (var m in dt.Events)
{
if (m.Stats.HasFlag(EntityStats.RefCount) ||
m.AddMethod != null && m.AddMethod.Stats.HasFlag(EntityStats.RefCount) ||
m.RemoveMethod != null && m.RemoveMethod.Stats.HasFlag(EntityStats.RefCount) ||
m.ImplicitField != null && m.ImplicitField.Stats.HasFlag(EntityStats.RefCount))
if (m.HasRefCount ||
m.AddMethod != null && m.AddMethod.HasRefCount ||
m.RemoveMethod != null && m.RemoveMethod.HasRefCount ||
m.ImplicitField != null && m.ImplicitField.HasRefCount)
{
if (m.AddMethod != null)
VisitFunction(m.AddMethod);
Expand All @@ -552,10 +552,10 @@ void ConstrainRefsRecursive(DataType dt)

foreach (var m in dt.Properties)
{
if (m.Stats.HasFlag(EntityStats.RefCount) ||
m.GetMethod != null && m.GetMethod.Stats.HasFlag(EntityStats.RefCount) ||
m.SetMethod != null && m.SetMethod.Stats.HasFlag(EntityStats.RefCount) ||
m.ImplicitField != null && m.ImplicitField.Stats.HasFlag(EntityStats.RefCount))
if (m.HasRefCount ||
m.GetMethod != null && m.GetMethod.HasRefCount ||
m.SetMethod != null && m.SetMethod.HasRefCount ||
m.ImplicitField != null && m.ImplicitField.HasRefCount)
{
if (m.GetMethod != null)
VisitFunction(m.GetMethod);
Expand Down Expand Up @@ -593,7 +593,7 @@ void ConstrainRefsRecursive(DataType dt)

foreach (var e in dt.InterfaceMethods)
if (!e.Value.IsPrototype &&
e.Value.Prototype.Stats.HasFlag(EntityStats.RefCount))
e.Value.Prototype.HasRefCount)
VisitFunction(e.Value);

foreach (var it in dt.Interfaces)
Expand All @@ -602,7 +602,7 @@ void ConstrainRefsRecursive(DataType dt)
{
var decl = f as Method;

if (decl == null || !decl.MasterDefinition.Stats.HasFlag(EntityStats.RefCount))
if (decl == null || !decl.MasterDefinition.HasRefCount)
continue;

for (var bt = dt; bt != null; bt = bt.Base)
Expand All @@ -615,6 +615,9 @@ void ConstrainRefsRecursive(DataType dt)
}
}
}

if (!it.HasRefCount && !CanStrip(it))
VisitType(it);
}
}

Expand Down Expand Up @@ -642,7 +645,7 @@ void ConstrainRefsRecursive(Namespace ns)

void NormalizeRefsRecursive(DataType dt)
{
if (!dt.Stats.HasFlag(EntityStats.RefCount))
if (!dt.HasRefCount)
return;

if (dt.IsGenericDefinition)
Expand Down Expand Up @@ -694,13 +697,13 @@ bool CanStrip(Namespace ns)

bool CanStrip(DataType dt)
{
return Environment.Strip && !dt.MasterDefinition.Stats.HasFlag(EntityStats.RefCount) && !dt.Prototype.Stats.HasFlag(EntityStats.RefCount) ||
return Environment.Strip && !dt.MasterDefinition.HasRefCount && !dt.Prototype.HasRefCount ||
!Backend.CanExportDontExports && !Environment.CanExport(dt);
}

bool CanStrip(Member m)
{
return Environment.Strip && !m.MasterDefinition.Stats.HasFlag(EntityStats.RefCount) && !m.Prototype.Stats.HasFlag(EntityStats.RefCount) ||
return Environment.Strip && !m.MasterDefinition.HasRefCount && !m.Prototype.HasRefCount ||
!Backend.CanExportDontExports && !Environment.CanExport(m);
}

Expand Down

0 comments on commit 8cfc2e3

Please sign in to comment.