dotnet / dotnet/linker

MarkInterfacesNeededByBodyStack keeps more interfaces than necessary

Open
#1,428 0 comments 0 reactions 0 assignees View on GitHub
area-Linker: Steps enhancement
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

I found this by accident when I failed one of the tests for this and was left scratching my head why the test expects a useless interface to be kept.

The `MarkInterfacesNeededByBodyStack` logic was introduced in #463. The argument for adding this was that this is necessary to produce correct IL. The IL is correct even without this step. This step is necessary to produce _verifiable_ IL (both "correct" and "verifiable" IL are terms defined in the ECMA-335 spec).

E.g. the implementation of `Unsafe.As` does exactly this and is unverifiable, but correct.

E.g. here's correctness and verifiabilily of stfld as defined in the ECMA spec:

![image](https://user-images.githubusercontent.com/13110571/89882429-1ecdcc80-dbc7-11ea-9c5e-c1e4d117dc49.png)

The logic in question is trying to ensure the "verifier-assignable-to" relationship, which is necessary for verifiable IL. Correct IL only requires that the type of the location matches the IL stack type (e.g. we're not trying to store a reference type into a `float` field).

Do we need linker to produce verifiable IL by default? I think it would be fine to put the `MethodBodyScanner` heuristic under a switch that is off by default and squeeze out a couple extra kB in savings.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.