From c462aeb2ef9954797b9e7988aa7a971f8b466542 Mon Sep 17 00:00:00 2001 From: walon Date: Wed, 7 Jun 2023 11:47:17 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8D=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=A1=A5=E6=8E=A5=E5=87=BD=E6=95=B0=E6=97=B6=E6=9C=AA=E8=80=83?= =?UTF-8?q?=E8=99=91=E5=88=B0=E8=A1=A5=E5=85=85=E5=85=83=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B3=9B=E5=9E=8B=E5=AE=9E=E4=BE=8B=E5=8C=96=E4=BC=9A=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E8=AE=BF=E9=97=AE=E5=88=B0=E4=B8=80=E4=BA=9B=E9=9D=9E?= =?UTF-8?q?=E5=85=AC=E5=BC=80=E7=9A=84=E5=87=BD=E6=95=B0=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=EF=BC=8C=E5=AF=BC=E8=87=B4=E5=B0=91=E7=94=9F=E6=88=90?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E5=BF=85=E8=A6=81=E7=9A=84=E6=A1=A5=E6=8E=A5?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Editor/ABI/TypeCreatorBase.cs | 2 +- Editor/AOT/Analyzer.cs | 2 +- Editor/Commands/MethodBridgeGeneratorCommand.cs | 1 + Editor/Meta/MethodReferenceAnalyzer.cs | 9 +++++---- Editor/MethodBridge/Analyzer.cs | 10 +++++++++- Editor/MethodBridge/Generator.cs | 15 ++++++++++++++- 6 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Editor/ABI/TypeCreatorBase.cs b/Editor/ABI/TypeCreatorBase.cs index b96bdc2..d8d0f32 100644 --- a/Editor/ABI/TypeCreatorBase.cs +++ b/Editor/ABI/TypeCreatorBase.cs @@ -136,7 +136,7 @@ namespace HybridCLR.Editor.ABI (int typeSize, int typeAligment) = ComputeSizeAndAligment(type); if (TryCreateCustomValueTypeInfo(type, typeSize, typeAligment, out var typeInfo)) { - Debug.Log($"[{GetType().Name}] CustomeValueType:{type} => {typeInfo.CreateSigName()}"); + //Debug.Log($"[{GetType().Name}] CustomeValueType:{type} => {typeInfo.CreateSigName()}"); return typeInfo; } else diff --git a/Editor/AOT/Analyzer.cs b/Editor/AOT/Analyzer.cs index ea446e2..a30410e 100644 --- a/Editor/AOT/Analyzer.cs +++ b/Editor/AOT/Analyzer.cs @@ -79,7 +79,7 @@ namespace HybridCLR.Editor.AOT return IsAotType(method.DeclaringType) && method.HasGenericParameters; } - private void OnNewMethod(GenericMethod method) + private void OnNewMethod(MethodDef methodDef, List klassGenericInst, List methodGenericInst, GenericMethod method) { if(method == null) { diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 923892b..2c7d3e5 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -37,6 +37,7 @@ namespace HybridCLR.Editor.Commands OutputFile = outputFile, GenericMethods = analyzer.GenericMethods, NotGenericMethods = analyzer.NotGenericMethods, + SpeicalPreserveMethods = analyzer.SpeicalPreserveMethods, }); g.PrepareMethods(); diff --git a/Editor/Meta/MethodReferenceAnalyzer.cs b/Editor/Meta/MethodReferenceAnalyzer.cs index 7fd8ccd..4f9ceb0 100644 --- a/Editor/Meta/MethodReferenceAnalyzer.cs +++ b/Editor/Meta/MethodReferenceAnalyzer.cs @@ -1,4 +1,5 @@ using dnlib.DotNet; +using HybridCLR.Editor.ABI; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -10,11 +11,11 @@ namespace HybridCLR.Editor.Meta { public class MethodReferenceAnalyzer { - private readonly Action _onNewMethod; + private readonly Action, List, GenericMethod> _onNewMethod; private readonly ConcurrentDictionary> _methodEffectInsts = new ConcurrentDictionary>(); - public MethodReferenceAnalyzer(Action onNewMethod) + public MethodReferenceAnalyzer(Action, List, GenericMethod> onNewMethod) { _onNewMethod = onNewMethod; } @@ -37,7 +38,7 @@ namespace HybridCLR.Editor.Meta foreach (var met in effectInsts) { var resolveMet = GenericMethod.ResolveMethod(met, ctx)?.ToGenericShare(); - _onNewMethod(resolveMet); + _onNewMethod(method, klassGenericInst, methodGenericInst, resolveMet); } return; } @@ -69,7 +70,7 @@ namespace HybridCLR.Editor.Meta continue; } effectInsts.Add(met); - _onNewMethod(resolveMet); + _onNewMethod(method, klassGenericInst, methodGenericInst, resolveMet); break; } case ITokenOperand token: diff --git a/Editor/MethodBridge/Analyzer.cs b/Editor/MethodBridge/Analyzer.cs index 33d24e5..d686389 100644 --- a/Editor/MethodBridge/Analyzer.cs +++ b/Editor/MethodBridge/Analyzer.cs @@ -30,6 +30,8 @@ namespace HybridCLR.Editor.MethodBridge private readonly HashSet _genericTypes = new HashSet(); private readonly HashSet _genericMethods = new HashSet(); + private readonly HashSet _speicalPreserveMethods = new HashSet(); + private List _processingMethods = new List(); private List _newMethods = new List(); @@ -37,6 +39,8 @@ namespace HybridCLR.Editor.MethodBridge public IReadOnlyList NotGenericMethods => _notGenericMethods; + public HashSet SpeicalPreserveMethods => _speicalPreserveMethods; + public IReadOnlyCollection GenericTypes => _genericTypes; public IReadOnlyCollection GenericMethods => _genericMethods; @@ -67,7 +71,7 @@ namespace HybridCLR.Editor.MethodBridge } } - private void OnNewMethod(GenericMethod method) + private void OnNewMethod(MethodDef methodDef, List klassGenericInst, List methodGenericInst, GenericMethod method) { lock(_lock) { @@ -75,6 +79,10 @@ namespace HybridCLR.Editor.MethodBridge { _newMethods.Add(method); } + if (methodDef.HasGenericParameters) + { + _speicalPreserveMethods.Add(method); + } if (method.KlassInst != null) { TryAddAndWalkGenericType(new GenericClass(method.Method.DeclaringType, method.KlassInst)); diff --git a/Editor/MethodBridge/Generator.cs b/Editor/MethodBridge/Generator.cs index c6b9281..7eee4b7 100644 --- a/Editor/MethodBridge/Generator.cs +++ b/Editor/MethodBridge/Generator.cs @@ -4,6 +4,7 @@ using HybridCLR.Editor.Meta; using HybridCLR.Editor.Template; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.IO; using System.Linq; using System.Reflection; @@ -28,6 +29,8 @@ namespace HybridCLR.Editor.MethodBridge public IReadOnlyList NotGenericMethods { get; set; } public IReadOnlyCollection GenericMethods { get; set; } + + public HashSet SpeicalPreserveMethods { get; set; } } private PlatformABI _platformABI; @@ -36,6 +39,8 @@ namespace HybridCLR.Editor.MethodBridge private readonly IReadOnlyCollection _genericMethods; + private readonly HashSet _preservedMethods; + private readonly string _templateCode; private readonly string _outputFile; @@ -61,6 +66,7 @@ namespace HybridCLR.Editor.MethodBridge _platformABI = options.PlatformABI; _notGenericMethods = options.NotGenericMethods; _genericMethods = options.GenericMethods; + _preservedMethods = options.SpeicalPreserveMethods; _templateCode = options.TemplateCode; _outputFile = options.OutputFile; _platformAdaptor = CreatePlatformAdaptor(options.PlatformABI); @@ -122,7 +128,14 @@ namespace HybridCLR.Editor.MethodBridge { if (method.IsPrivate || (method.IsAssembly && !method.IsPublic && !method.IsFamily)) { - return; + if (!_preservedMethods.Contains(new GenericMethod(method, klassInst, methodInst))) + { + return; + } + else + { + //Debug.Log($"[PreservedMethod] method:{method}"); + } } TypeSig returnType;