From a531a213c284979706a2cbe8f359950aef7a9517 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 12 Jan 2024 21:36:04 +0800 Subject: [PATCH] =?UTF-8?q?[opt]=20=E4=BC=98=E5=8C=96=20AOTReference?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=B3=9B=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E6=B3=9B=E5=9E=8B=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=83=BD=E6=98=AFclass=E7=BA=A6=E6=9D=9F=EF=BC=8C=E5=88=99?= =?UTF-8?q?=E4=B8=8D=E5=8A=A0=E5=85=A5=E5=88=B0=E9=9C=80=E8=A6=81=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E5=85=83=E6=95=B0=E6=8D=AE=E7=9A=84=E9=9B=86=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/AOT/Analyzer.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Editor/AOT/Analyzer.cs b/Editor/AOT/Analyzer.cs index 5d9c475..68253e3 100644 --- a/Editor/AOT/Analyzer.cs +++ b/Editor/AOT/Analyzer.cs @@ -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()