From 1dc677b4e09e1540f4fdb4a0eeff1529c19691cf Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Tue, 7 Nov 2017 11:28:20 -0800 Subject: [PATCH] Adjust TemplateConstructableTypes to ensure that templates are present - Previous logic worked except for types without methods (interfaces and structures) due to other rules that ensured the presence of a TemplateTypeLayout Fixes #4860 [tfs-changeset: 1680445] --- .../DependencyAnalysis/NodeFactory.NativeLayout.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.NativeLayout.cs b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.NativeLayout.cs index 196e7836ddf..5392ad1cde5 100644 --- a/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.NativeLayout.cs +++ b/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NodeFactory.NativeLayout.cs @@ -229,6 +229,13 @@ public IEnumerable TemplateConstructableTypes(TypeDesc type) TypeDesc canonicalType = type.ConvertToCanonForm(CanonicalFormKind.Specific); yield return _factory.MaximallyConstructableType(canonicalType); + // Add a dependency on the template for this type, if the canonical type should be generated into this binary. + if (canonicalType.IsCanonicalSubtype(CanonicalFormKind.Any) && !_factory.NecessaryTypeSymbol(canonicalType).RepresentsIndirectionCell) + { + if (!_factory.TypeSystemContext.IsCanonicalDefinitionType(canonicalType, CanonicalFormKind.Any)) + yield return _factory.NativeLayout.TemplateTypeLayout(canonicalType); + } + foreach (TypeDesc instantiationType in type.Instantiation) { foreach (var dependency in TemplateConstructableTypes(instantiationType))