MarkInterfacesNeededByBodyStack keeps more interfaces than necessary
- 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:

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.