Skip to content
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

Mark forwarders for all TypeReferences #2276

Merged
merged 6 commits into from
Sep 17, 2021

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Sep 16, 2021

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 changed the base branch from main to release/6.0 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
Leave the logic as before and mark them from MarkStep.
if (typeDefinition.HasProperties) {
foreach (var p in typeDefinition.Properties) {
WalkCustomAttributesTypesScopes (p);
// p.PropertyType is not saved
Copy link
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...

- Use ref assemblies for ReferenceAttribute
- Avoid adding to common references unless needed by test dependencies
@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
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
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
Copy link
Member Author

sbomer commented Sep 20, 2021

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

@vitek-karas
Copy link
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
Member

I can confirm this is in RC2, but it's not in the 6.0.1xx branch: https://github.com/dotnet/sdk/blob/7156781d4c687ddf6e0f24d244c0c239a92dd02e/eng/Version.Details.xml#L123-L131

@vitek-karas
Copy link
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
Copy link
Member

agocke commented Sep 24, 2021

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 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.

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