From 3c044c995644f668515c0a648ab568c5bf525e8c Mon Sep 17 00:00:00 2001 From: Jackson Schuster <36744439+jtschuster@users.noreply.github.com> Date: Mon, 14 Sep 2026 13:27:12 -0700 Subject: [PATCH] ILTrim: Preserve implemented interfaces on constructed types Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5f633264-d8a6-4199-a816-4c0da8e63873 --- .../TokenBased/TypeDefinitionNode.cs | 5 ++++- .../tools/ILTrim.Tests/ILTrimExpectedFailures.txt | 13 ------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs b/src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs index 081d10ba87bd76..66c97b15b9355d 100644 --- a/src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs +++ b/src/coreclr/tools/ILTrim.Core/DependencyAnalysis/TokenBased/TypeDefinitionNode.cs @@ -162,7 +162,10 @@ protected override EntityHandle WriteInternal(ModuleWritingContext writeContext) { InterfaceImplementation intfImpl = reader.GetInterfaceImplementation(intfImplHandle); EcmaType interfaceType = _module.TryGetType(intfImpl.Interface)?.GetTypeDefinition() as EcmaType; - if (interfaceType != null && writeContext.Factory.InterfaceUse(interfaceType).Marked) + if (interfaceType != null && + (writeContext.Factory.InterfaceUse(interfaceType).Marked || + (writeContext.Factory.ConstructedType((EcmaType)_module.GetObject(Handle)).Marked && + writeContext.Factory.TypeDefinition(interfaceType.Module, interfaceType.Handle).Marked))) { builder.AddInterfaceImplementation(outputHandle, writeContext.TokenMap.MapToken(intfImpl.Interface)); diff --git a/src/coreclr/tools/ILTrim.Tests/ILTrimExpectedFailures.txt b/src/coreclr/tools/ILTrim.Tests/ILTrimExpectedFailures.txt index a872f2dffdec3f..48ab85175bdcd8 100644 --- a/src/coreclr/tools/ILTrim.Tests/ILTrimExpectedFailures.txt +++ b/src/coreclr/tools/ILTrim.Tests/ILTrimExpectedFailures.txt @@ -51,9 +51,7 @@ Attributes.StructLayout.ExplicitClass Attributes.StructLayout.SequentialClass Attributes.TypeWithDynamicInterfaceCastableImplementationAttributeIsKept Basic.InstantiatedTypeWithOverridesFromObject -Basic.UninvokedInterfaceMemberGetsRemoved Basic.UsedGenericInterfaceIsKept -Basic.UsedInterfaceIsKept BCLFeatures.ETW.CustomEventSource BCLFeatures.ETW.CustomLibraryEventSource CommandLine.AddCustomStep @@ -186,15 +184,11 @@ Inheritance.Interfaces.OnReferenceType.BaseProvidesInterfaceMember.GenericInterf Inheritance.Interfaces.OnReferenceType.BaseProvidesInterfaceMember.GenericInterfaceWithMethodOnNoInstanceCtor2 Inheritance.Interfaces.OnReferenceType.BaseProvidesInterfaceMember.SimpleMethodOnNoInstanceCtor Inheritance.Interfaces.OnReferenceType.BaseProvidesInterfaceMember.SimpleMethodOnNoInstanceCtor2 -Inheritance.Interfaces.OnReferenceType.ClassImplementingInterfaceMethodsNested2 -Inheritance.Interfaces.OnReferenceType.ClassUsedFromConcreteTypeHasInterfaceMethodRemoved2 Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter2 -Inheritance.Interfaces.OnReferenceType.InterfaceMarkOrderingDoesNotMatter3 Inheritance.Interfaces.OnReferenceType.InterfaceNeededOnUnrelatedInterfaceList Inheritance.Interfaces.OnReferenceType.InterfaceTypeInOtherUsedOnlyByCopiedAssembly Inheritance.Interfaces.OnReferenceType.InterfaceTypeInOtherUsedOnlyByCopiedAssemblyExplicit -Inheritance.Interfaces.OnReferenceType.InterfaceUsedOnlyAsConstraintIsKept Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.NoInstanceCtorAndAssemblyPreserveAll Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.NoInstanceCtorAndTypePreserveAll Inheritance.Interfaces.OnReferenceType.NoInstanceCtor.NoInstanceCtorAndTypePreserveMethodsWithInterfacesMarked @@ -208,7 +202,6 @@ Inheritance.Interfaces.OnReferenceType.NoKeptCtor.LocalDowncastDoesNotCuaseOther Inheritance.Interfaces.OnReferenceType.NoKeptCtor.PreserveDependencyPreservesInterfaceMethod Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeHasExplicitInterfaceMethodPreservedViaXml Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeHasExplicitInterfacePropertyPreservedViaXml -Inheritance.Interfaces.OnReferenceType.NoKeptCtor.UnusedTypeWithPreserveMethodsAndInterfaceTypeMarked Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded.ArrayWithIndexAssignedToReturnValue Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded.FieldDowncastedToInterface Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded.GenericType @@ -232,13 +225,8 @@ Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded.ParameterAnd Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded.ParameterOutAndLocal Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded.ParameterRefAndLocal Inheritance.Interfaces.OnReferenceType.NoKeptCtorButInterfaceNeeded.ReturnValueDowncastedToInterface -Inheritance.Interfaces.OnReferenceType.ObjectCastedToSecondInterfaceHasMemberRemovedButInterfaceKept Inheritance.Interfaces.OnReferenceType.UnusedComInterfaceIsKept Inheritance.Interfaces.OnReferenceType.UnusedExplicitInterfaceHasMethodPreservedViaXml -Inheritance.Interfaces.OnValueType.NoKeptCtor.InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethod -Inheritance.Interfaces.OnValueType.NoKeptCtor.InterfaceTypeRemovedWhenOnlyUsedByClassWithOnlyStaticMethodMultiple -Inheritance.Interfaces.OnValueType.StructImplementingInterfaceMethodsNested2 -Inheritance.Interfaces.OnValueType.StructUsedFromConcreteTypeHasInterfaceMethodRemoved2 Inheritance.Interfaces.OnValueType.StructWithNestedStructImplementingInterface Inheritance.Interfaces.OnValueType.UnusedExplicitInterfaceHasMethodPreservedViaXml Inheritance.Interfaces.RecursiveInterfaces.GenericInterfaceImplementedRecursively @@ -304,7 +292,6 @@ LinkXml.EmbeddedLinkXmlPreservesAdditionalAssemblyWithOverriddenMethod LinkXml.LinkXmlErrorCases LinkXml.TypeWithPreserveFieldsHasBackingFieldsOfPropertiesRemoved LinkXml.UnusedFieldPreservedByLinkXmlIsKept -LinkXml.UnusedInterfaceTypeOnTypeWithPreserveAllIsKept LinkXml.UnusedNonRequiredTypeIsRemoved LinkXml.UsedNonRequiredExportedTypeIsKept LinkXml.UsedNonRequiredExportedTypeIsKeptWhenRooted