Skip to content

Trim static interface methods - #2

Closed
jtschuster wants to merge 28 commits into
FixLibraryInterfacefrom
trimStaticInterfaces
Closed

jtschuster wants to merge 28 commits into
FixLibraryInterfacefrom
trimStaticInterfaces

Conversation

@jtschuster

@jtschuster jtschuster commented Apr 11, 2022 •

Copy link
Copy Markdown
Owner

This removes a static interface method from the list of Overrides of the implementation method. Since the interface method is removed as an override, it will not mark the interface method by default. However, if the interface method is called through the interface on a constrained type parameter (T.StaticInterfaceMethodImplementation() where T: IInterfaceWithStaticMethod).

Note we have to completely remove the interface method from the list of overrides. If we only skip the override from the marking, Cecil will fail to write the assembly because the overridden method can't be found anywhere.

sbomer and others added 11 commits April 1, 2022 11:08
* Add tests for nested functions called from nested state machines

The existing algorithm to recursively discover calls to local functions
from a user method was incorrect for the case where a local function
was called from a state machine local function's MoveNext method.
These methods were being treated as roots for the discovery, as if they
were user code, which caused a failure downstream when we assumed that
each local function belongs to a unique user method - since a local function
might be called from a user method _and_ a nested state machine local function.

The existing behavior also had the issue that a local function state machine's
attributes could suppress warnings from nested local functions, going against the
behavior for normal nested functions in the linker.

* Don't fail on multiple user methods for same nested function

* Correctly handle iterator local functions calling nested functions

This fixes the issues shown in the tests by letting the state machine
types participate in the call graph discovery instead of being considered
as roots. Now any local functions called from state machine local functions
will be associated with the user method, not with the state machine MoveNext
method.

* Fix test for analyzer

* Update src/linker/Linker/CompilerGeneratedState.cs

Co-authored-by: Vitek Karas <[email protected]>

* Adjust comments and docs

* Fix docs

Co-authored-by: Vitek Karas <[email protected]>
The main change is sharing of the GetConstructor intrinsic and related tests.
To make those tests work this also implements Type.EmptyTypes and String.Empty and Array.Empty intrinsics.
These are all treated as special cases:
* Type.EmptyTypes and String.Empty are actually field accesses, so we don't have infra to share these yet, no need to add one for now
* Array.Empty is a generic method where we need to know the generic instantiation. The current sharing doesn't propagate this information
  so this forced the implementation to NOT be shared but instead done as a fallback which the shared one doesn't handle.

The rest of the changes are all about fixing how the shared intrinsic handling propagates return value from intrinsics.
Lot of small subtle bugs around null or emtpy inputs and forgetting to add return value and so on. The main changes are in GetMethod and GetNestedType intrinsics which had lot of issues.

Added tests for all of the corner cases.
NestedTypesUsedViaReflection test has been reworked as previously it didn't work correctly. Lot of the [Kept] attributes were fulfilled by some of the negative tests and thus the positive tests didn't have coverage (for example calling GetNestedType(unknownName) will mark all nested types on the type, so a subsequent call to GetNestedType("knownname") will not have an observable effect).
Add check for cref in generic parameter dataflow to avoid failing with a nullreference exception
Refactor code to reuse the while loop for both INamedType and Method symbols
Add tests
Fixes dotnet#2724
@jtschuster

This comment was marked as outdated.

jtschuster and others added 17 commits April 12, 2022 10:54

This will make sure that we keep all interfaces and all interface method implementations on such type.

* Change the solution to rely on the optimization setting only

* wip

* Add implicit interface implementation case

* Edit tests to remove issue-specific code and names

* Mark members of CollectedType as kept

* Add private interface test and simplify external interface example

* Replace early exit for non-interfaces

* License headers and use IsMethodNeededByTypeDueToPreservedScope instead of Interface specific version

* Add check for static methods before skipping virtual marking

Check for optimization before skipping marking interface methods for
PreservedScope

Add doc comments

* Add more clarifying comments, move static method check, rename method

Rename IsVirtualNeededByInstantiatedTypeDueToPreservedScope to IsOverrideNeededByInstantiatedTypeDueToPreservedScope
Added more comments describing purpose of methods
Moved the static interface method check to the method that is called on all types regardless of instantiation

* Renames and comment cleanup + tests

This doesn't change product behavior, only renamed methods and improved comments.

Added new tests for the RootLibrary:
- Added a dependency to an "copy" assembly (mainly because I can define a static interface in it)
- Added more combinations to the interfaces/classes in the test
- Since this uses static interface methods I had to enable "preview" language features for the test project and for the test infra.

* More tests for interface behavior

Co-authored-by: vitek-karas <[email protected]>
Co-authored-by: vitek-karas <[email protected]>
@jtschuster jtschuster closed this Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants