[opt] 优化 AOTReference计算,如果泛型的所有泛型参数都是class约束,则不加入到需要补充元数据的集合

main
walon 2024-01-12 21:36:04 +08:00
parent 2b42376505
commit a531a213c2
1 changed files with 20 additions and 2 deletions

View File

@ -191,11 +191,29 @@ namespace HybridCLR.Editor.AOT
}
}
private bool IsNotShareableAOTGenericType(TypeDef typeDef)
{
if (!IsAotType(typeDef))
{
return false;
}
return typeDef.GenericParameters.Any(c => !c.HasReferenceTypeConstraint);
}
private bool IsNotShareableAOTGenericMethod(MethodDef method)
{
if (!IsAotGenericMethod(method))
{
return false;
}
return method.GenericParameters.Concat(method.DeclaringType.GenericParameters).Any(c => !c.HasReferenceTypeConstraint);
}
private void FilterAOTGenericTypeAndMethods()
{
ConstraintContext cc = this.ConstraintContext;
AotGenericTypes.AddRange(_genericTypes.Where(type => IsAotType(type.Type)).Select(gc => cc.ApplyConstraints(gc)));
AotGenericMethods.AddRange(_genericMethods.Where(method => IsAotGenericMethod(method.Method)).Select(gm => cc.ApplyConstraints(gm)));
AotGenericTypes.AddRange(_genericTypes.Where(type => IsNotShareableAOTGenericType(type.Type)).Select(gc => cc.ApplyConstraints(gc)));
AotGenericMethods.AddRange(_genericMethods.Where(method => IsNotShareableAOTGenericMethod(method.Method)).Select(gm => cc.ApplyConstraints(gm)));
}
public void Run()