-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make all of the trimmer aware of recursive interfaces #103317
Open
jtschuster
wants to merge
34
commits into
dotnet:main
Choose a base branch
from
jtschuster:RecursiveGenericInterfaces
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
d6564fb
Use recursive-interface-aware types and methods in TypeMapInfo
jtschuster 8e94b0e
Use RuntimeInterfaceImplementations in MethodBodyScanner and ICustomM…
jtschuster cf304f2
Add remarks regarding checking for marked ifaceImpls with RuntimeInte…
jtschuster fcbfbb7
Fix ApiCompat failures
jtschuster e5e0679
Fix visibility and sealed warnings
jtschuster 451b677
Add DAM annotations for recursive interfaces
jtschuster 1e1451a
Add additional test cases and annotate reflection types with ifdefs
jtschuster ac5a42a
Use suppressions instead of annotating in System.Reflection.Context
jtschuster 4e1f6f9
Add test and fix for failure in System.Text.Json
jtschuster f8dad6b
Check for implementor to be marked, not overridingMethod.DeclaringType
jtschuster 2aca6c4
PR feedback:
jtschuster bb308c7
Separate out generic DIM matching fix
jtschuster 4848448
Remove unused parameter, Add test case
jtschuster dec9745
Mark all implementation chains for interface impls
jtschuster a7d785f
Merge branch 'main' of https://github.com/dotnet/runtime into Recursi…
jtschuster b6f101a
Add runtimeInterface assertions to tests
jtschuster 66a3bcf
Add tests for TypeMapInfo
jtschuster 4fa8ec5
Merge branch 'main' of https://github.com/dotnet/runtime into Recursi…
jtschuster e524b22
Move RuntimeInterfaces algorithm to its own class
jtschuster a8dfbd3
Inline the runtime interfaces helpers to avoid confusing naming
jtschuster d6cc947
Merge branch 'main' of https://github.com/dotnet/runtime into Recursi…
jtschuster 01e4518
Undo unrelated formatting
jtschuster df04484
Revert "Implement type name resolution for ILLink analyzer (#106209)"
jtschuster ce27822
Don't warn on methods implementing iface methods if the iface is not …
jtschuster db02cfb
Undo unrelated analyzer changes
jtschuster d88b219
Undo unrelated formatting
jtschuster 259d734
Revert suppression changes
jtschuster 291e2e6
Merge branch 'main' of https://github.com/dotnet/runtime into Recursi…
jtschuster 1d769b2
Undo unrelated formatting
jtschuster 6a01772
Merge branch 'main' of https://github.com/dotnet/runtime into Recursi…
jtschuster 756d90e
Add 'as' cast to RuntimeInterfacesAlgorithm
jtschuster 626934c
Add generated analyzer tests
jtschuster 41acd7e
Merge branch 'main' into RecursiveGenericInterfaces
jtschuster f285f9a
Merge branch 'main' into RecursiveGenericInterfaces
jtschuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/tools/illink/src/linker/Linker/InterfaceImplementationChain.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using Mono.Cecil; | ||
|
||
namespace Mono.Linker | ||
{ | ||
internal sealed class InterfaceImplementationChain | ||
{ | ||
/// <summary> | ||
/// The type that has the InterfaceImplementation - either the <see cref="Implementor"/> or a base type of it. | ||
/// </summary> | ||
public TypeReference TypeWithInterfaceImplementation { get; } | ||
|
||
/// <summary> | ||
/// The path of .interfaceimpl on <see cref="RuntimeInterfaceImplementation.Implementor"/> or a base type that terminates with <see cref="RuntimeInterfaceImplementation.InflatedInterfaceType"/>. | ||
/// </summary> | ||
public ImmutableArray<InterfaceImplementation> InterfaceImplementations { get; } | ||
|
||
/// <summary> | ||
/// Returns true if the interface implementation is directly on the implementing type. | ||
/// </summary> | ||
public bool IsExplicitInterfaceImplementation => InterfaceImplementations.Length == 1; | ||
|
||
public InterfaceImplementationChain (TypeReference typeWithInterfaceImplementation, ImmutableArray<InterfaceImplementation> interfaceImplementation) | ||
{ | ||
Debug.Assert (interfaceImplementation.Length > 0); | ||
TypeWithInterfaceImplementation = typeWithInterfaceImplementation; | ||
InterfaceImplementations = interfaceImplementation; | ||
} | ||
|
||
/// <summary> | ||
/// Returns true if all the .interfaceImpls in the chain and the are marked. | ||
/// </summary> | ||
/// <param name="annotations"></param> | ||
/// <returns></returns> | ||
public bool IsMarked (AnnotationStore annotations, ITryResolveMetadata context) | ||
{ | ||
var typeDef = context.TryResolve (TypeWithInterfaceImplementation); | ||
// If we have the .interfaceImpls on this type, it must be resolvable | ||
Debug.Assert (typeDef is not null); | ||
if (!annotations.IsMarked (typeDef)) | ||
return false; | ||
|
||
foreach (var impl in InterfaceImplementations) { | ||
if (!annotations.IsMarked (impl)) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is the reason for the
IL2046
warning not being suppressed.Since
BaseType
provides the interface implementation method forDerived
, we decided to put the warning method on the type that implements the interface. I think that makes sense for ifDerived
implementsIFoo
andBase
doesn't, but if both do (and both implementations are marked), it might make sense to report the warning forDerived
on the implementation method, or not at all (assuming it would warn when analyzingBaseType
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so it sounds like it's due to a combination of this PR and #104753. I think it's fine to produce another warning on the derived type in that case - it's similar to the compiler error behavior.
I think we should just add the same suppressions to the derived types, citing dotnet/linker#1187, no need to block this PR on that issue.