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

Share logic for discovering typereferences - #2287

Merged
sbomer merged 2 commits into
dotnet:mainfrom
sbomer:shareTyperefLogic
Sep 23, 2021
Merged

sbomer merged 2 commits into
dotnet:mainfrom
sbomer:shareTyperefLogic

Conversation

@sbomer

@sbomer sbomer commented Sep 21, 2021

Copy link
Copy Markdown
Member

Factor out the logic for walking an assembly to discover typerefs into a new abstract class, TypeReferenceWalker.

@mateoatr mateoatr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@vitek-karas vitek-karas left a comment

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.

Looks good. Looking forward to fixing the SweepStep to not call this twice :-)

Comment on lines +1411 to +1413
// Also mark the scopes of metadata typeref rows to cover any not discovered by the traversal.
// This can happen when the compiler emits typerefs into IL which aren't strictly necessary per ECMA 335.
foreach (TypeReference typeReference in assembly.MainModule.GetTypeReferences ()) {

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.

Side question (ignore for PR purposes): Would be interesting to know what would happen if we removed such type ref. If it's not used, then it should not matter that we don't preserve the type forwarder for it. I guess I don't know what Cecil will do when saving the assembly (will it rebuild the type-ref table from scratch, I guess it has to), but then again that will not happen for "copy".

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point - I think there would be no harm in not marking these, at least for the final output (which will just have unused dangling typerefs). There could be issues like #2267 since the in-memory representation would be unresolvable, but arguably custom steps should never be looking at these typerefs anyway.

- Add non-nullable property over "visited" hashset
- Hide construction/process pattern in static helpers
@sbomer
sbomer merged commit 8097e39 into dotnet:main Sep 23, 2021
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
* Share logic for discovering typereferences

* PR feedback

- Add non-nullable property over "visited" hashset
- Hide construction/process pattern in static helpers

Commit migrated from dotnet/linker@8097e39
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.

3 participants