Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Mark forwarders for all TypeReferences - #2276

Merged
sbomer merged 6 commits into
dotnet:release/6.0from
sbomer:markForwardersForBuiltinTypes
Sep 17, 2021
Merged

sbomer merged 6 commits into
dotnet:release/6.0from
sbomer:markForwardersForBuiltinTypes

Conversation

@sbomer

@sbomer sbomer commented Sep 16, 2021

Copy link
Copy Markdown
Member

Fixes #2267.

This fixes the issue by taking the first approach mentioned in #2267 (comment). We now mark type forwarders referenced from any TypeReference we discover for a copy assembly, including TypeReferences to built-in types which only exist as bytes in metadata rather than typeref rows.

The walking logic in TypeReferenceMarker is copied from AssemblyReferencesCorrector in SweepStep and adjusted so that instead of updating the scopes of typereferences, it just marks any type forwarders they point to. The walking logic was duplicated to avoid touching SweepStep to reduce the risk of this change.

This includes a change to the test infrastructure to build tests against System.Runtime, which is necessary to reproduce the issue (since it has to do with references to builtin types forwarded from System.Runtime to System.Private.CoreLib). That change caused the compiler to produce different code for event methods - before the change, there were unnecessary locals in the generated code. Either way the unreachablebodies optimization removes all locals for unreachable event methods, which is why I removed the ExpectLocalsModified from a few testcases.

I plan to factor out the duplicated logic in a follow-up that we won't consider taking into .NET6.

@sbomer
sbomer requested a review from marek-safar as a code owner September 16, 2021 18:22
@sbomer
sbomer changed the base branch from main to release/6.0 September 16, 2021 18:27
@sbomer
sbomer requested a review from radekdoulik as a code owner September 16, 2021 18:27
@sbomer
sbomer force-pushed the markForwardersForBuiltinTypes branch from 4275362 to 3a60602 Compare September 16, 2021 18:30
@sbomer sbomer closed this Sep 16, 2021
@sbomer sbomer reopened this Sep 16, 2021
Comment thread src/linker/Linker.Steps/MarkStep.cs Resolved
Leave the logic as before and mark them from MarkStep.
@sbomer
sbomer requested a review from vitek-karas September 16, 2021 23:20
if (typeDefinition.HasProperties) {
foreach (var p in typeDefinition.Properties) {
WalkCustomAttributesTypesScopes (p);
// p.PropertyType is not saved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference - this feels dangerous - not because of saving, but because of custom steps. We update the type refs in sweep step - but we don't update this one (intentionally). Again - nothing to do with this change, just that I noticed this...

Comment thread src/linker/Linker.Steps/MarkStep.cs Resolved
- Use ref assemblies for ReferenceAttribute
- Avoid adding to common references unless needed by test dependencies
@sbomer
sbomer requested a review from marek-safar September 17, 2021 20:23
@sbomer
sbomer merged commit 60e655f into dotnet:release/6.0 Sep 17, 2021
sbomer added a commit to sbomer/linker that referenced this pull request Sep 17, 2021
* Build testcases against reference assemblies

* Reproduce issue in testcase

* Add TypeReferenceMarker

* Update one more testcase

* Don't mark forwarders in TypeReferenceMarker

Leave the logic as before and mark them from MarkStep.

* PR feedback

- Use ref assemblies for ReferenceAttribute
- Avoid adding to common references unless needed by test dependencies
@vitek-karas

Copy link
Copy Markdown
Member

@sbomer - can you please prepare a backport to 6.0 RC2 for this? My understanding is that Xamarin will need this - @rolfbjarne can you please confirm?

@rolfbjarne

Copy link
Copy Markdown
Member

@sbomer - can you please prepare a backport to 6.0 RC2 for this? My understanding is that Xamarin will need this - @rolfbjarne can you please confirm?

Correct, we need this.

@sbomer

sbomer commented Sep 20, 2021

Copy link
Copy Markdown
Member Author

This went into the RC2 SDK with this change: dotnet/sdk#21118.

@vitek-karas

Copy link
Copy Markdown
Member

Sorry - I didn't notice this PR was for the 6.0 branch.

sbomer added a commit that referenced this pull request Sep 20, 2021
* Build testcases against reference assemblies

* Reproduce issue in testcase

* Add TypeReferenceMarker

* Update one more testcase

* Don't mark forwarders in TypeReferenceMarker

Leave the logic as before and mark them from MarkStep.

* PR feedback

- Use ref assemblies for ReferenceAttribute
- Avoid adding to common references unless needed by test dependencies
sbomer added a commit to sbomer/linker that referenced this pull request Sep 21, 2021
* Build testcases against reference assemblies

* Reproduce issue in testcase

* Add TypeReferenceMarker

* Update one more testcase

* Don't mark forwarders in TypeReferenceMarker

Leave the logic as before and mark them from MarkStep.

* PR feedback

- Use ref assemblies for ReferenceAttribute
- Avoid adding to common references unless needed by test dependencies
@rolfbjarne

Copy link
Copy Markdown
Member

@vitek-karas

Copy link
Copy Markdown
Member

@agocke - do you know what branch flows to the 6.0.1xx SDK? It might be that the answer is "none yet" and we would definitely need to fix that.

@agocke

agocke commented Sep 24, 2021

Copy link
Copy Markdown
Member

Ah I thought there was automerge in sdk like there is in runtime. I'll insert the same build into both for now.

agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
…inker#2280)

* Build testcases against reference assemblies

* Reproduce issue in testcase

* Add TypeReferenceMarker

* Update one more testcase

* Don't mark forwarders in TypeReferenceMarker

Leave the logic as before and mark them from MarkStep.

* PR feedback

- Use ref assemblies for ReferenceAttribute
- Avoid adding to common references unless needed by test dependencies

Commit migrated from dotnet/linker@ff06442
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to resolve some types from System.Runtime.dll in custom linker step

5 participants