From 97610ec59bbb8e4a0db74a713113fae77121c091 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Fri, 29 Oct 2021 21:46:43 +0300 Subject: [PATCH] Rename templates only used through aliases Signed-off-by: Dimitar Dobrev --- src/Generator/Passes/StripUnusedSystemTypesPass.cs | 14 +++++++++++--- src/Generator/Passes/TrimSpecializationsPass.cs | 2 +- tests/NamespacesDerived/NamespacesDerived.Tests.cs | 2 ++ tests/NamespacesDerived/NamespacesDerived.h | 5 ++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Generator/Passes/StripUnusedSystemTypesPass.cs b/src/Generator/Passes/StripUnusedSystemTypesPass.cs index 9422f43832..4d111cb7fb 100644 --- a/src/Generator/Passes/StripUnusedSystemTypesPass.cs +++ b/src/Generator/Passes/StripUnusedSystemTypesPass.cs @@ -59,8 +59,16 @@ private bool TryMarkType(Type desugared) var templateType = desugared as TemplateSpecializationType; if (templateType != null) { - MarkAsUsed(templateType.Template); - MarkAsUsed(templateType.Template.TemplatedDecl); + var template = templateType.Template; + if (template.TemplatedDecl is TypeAlias typeAlias && + typeAlias.Type.Desugar() is TemplateSpecializationType specializationType) + { + MarkAsUsed(template); + MarkAsUsed(template.TemplatedDecl); + template = specializationType.Template; + } + MarkAsUsed(template); + MarkAsUsed(template.TemplatedDecl); return true; } @@ -90,6 +98,6 @@ private void RemoveUnusedStdTypes(DeclarationContext context) } } - private HashSet usedStdTypes = new HashSet(); + private readonly HashSet usedStdTypes = new HashSet(); } } diff --git a/src/Generator/Passes/TrimSpecializationsPass.cs b/src/Generator/Passes/TrimSpecializationsPass.cs index 3c0df01920..22f718392d 100644 --- a/src/Generator/Passes/TrimSpecializationsPass.cs +++ b/src/Generator/Passes/TrimSpecializationsPass.cs @@ -158,7 +158,7 @@ private static void TryMoveExternalSpecializations(Class template) let module = arg.Type.Type.GetModule() where module != null select module).ToList().TopologicalSort(m => m.Dependencies); - if (modules.Any()) + if (modules.Count > 0) { var module = modules.Last(); module.ExternalClassTemplateSpecializations.Add(specialization); diff --git a/tests/NamespacesDerived/NamespacesDerived.Tests.cs b/tests/NamespacesDerived/NamespacesDerived.Tests.cs index b2a3d4c8de..f6dfe0973d 100644 --- a/tests/NamespacesDerived/NamespacesDerived.Tests.cs +++ b/tests/NamespacesDerived/NamespacesDerived.Tests.cs @@ -15,6 +15,8 @@ public void TestCodeGeneration() using (new DerivedFromSecondaryBaseInDependency()) { } using (var der2 = new Derived2()) using (der2.LocalTypedefSpecialization) { } + Std.Vector.__Internalc__N_std_S_vector__i___S_CustomAllocator__i i; + i.GetHashCode(); } [Test] diff --git a/tests/NamespacesDerived/NamespacesDerived.h b/tests/NamespacesDerived/NamespacesDerived.h index 5d14ebe2bb..9615a0e989 100644 --- a/tests/NamespacesDerived/NamespacesDerived.h +++ b/tests/NamespacesDerived/NamespacesDerived.h @@ -109,10 +109,13 @@ class DLL_API Ignored std::basic_string, CustomAllocator> customAllocatedString; }; +template> +using vector = ::std::vector; + class DLL_API StdFields { private: - std::vector> customAllocatedVector; + vector> customAllocatedVector; }; DLL_API bool operator<<(const Base& b, const char* str);